Löve Platformer Game Programming Tut - 01
This is a series of tutorials that I'm writing as I learn game programming in Löve2D.I will put lots of work into the game itself
and I will make sure you will understand every single detail of the
program.
Please remember this isnt for complete beginners but for those who
know some knowledge in programming like:
What is a variable? And how is it different than a command statement?
What is an array? A table? An integer? A boolean?
How to draw in Löve?what is 1 + 1?
To follow along you will need to download the Löve engine and install
it,and have a decent text editor.I would reccomend sublime text 2
unlicensed because it is very easy and comfortable to use, or you can
use notepad++.
For this tutorial I will also translate everything into a non
complicated language called english ;D
-THE SKELETON OF A Löve CODE-
The basic skeleton of a love code for me is the first 3 lua files
you will create.
the first is a text file called "main.lua" (remove the quotation marks)
this lua text file is basically the vertebrae in your game, it consists of 3
(note: later on there will be more functions!)
functions which are:
Code: Select all
function love.load()
end
function love.update(dt)
end
function love.draw()
end
As you noticed the 2nd function has a dt in the parenthesis
this stands for delta time which we are gonna use later on.
For now these functions will be empty unless you want to add in
the code:
love.graphics.setBackgroundColor(0,0,0)
into function love.load()
which sets the games background color.The 3 numbers are in order
"red,green,blue" right now the bg color is black.
right now your code should look like this
(I added in comments to tell you what each function will handle.To add comments type in -- then your comment i.e --this is awesome!)
Code: Select all
function love.load()
--love.load loads/sets all the variables and images
love.graphics.setBackgroundColor(255,255,255)
end
function love.update(dt)
--love.update does all the math work
end
function love.draw()
--love.draw draws stuff...
end
The config file is what gives our game the basics to be a game.
To make our config file,you gotta go to file>new which creates a new text file,save the file and name it "conf.lua". (remove the quotation)
In this lua text file there will be only one function through out the series,
this function will be called:
Code: Select all
function love.conf(t)
end
4 lines of code which are
Code: Select all
t.title = "Adventure tutorial game" --sets the name of the game (dont remove quotations)
t.author = "Jacobe the test name" --sets the name of author (dont remove quotations)
t.screen.width = 800 --sets screen width
t.screen.height = 600 --sets screen height
have to mess around with screen.height/width because everyone has a different screen measure so
just mess around with it in your game.
your code should now look like this:
Code: Select all
function love.conf(t)
t.title = "Adventure tutorial game" --sets the name of the game (dont remove quotations)
t.author = "Jacobe the test name" --sets the name of author (dont remove quotations)
t.screen.width = 800 --sets screen width
t.screen.height = 600 --sets screen height
end
on to the head of the game,AKA the player file!
with this the final piece of the skeleton we can finally call it a game!
To make our player file,you gotta go to file>new which creates a new text file.Inside of your
game folder containing main and conf.lua,make a new folder called "includes" (remove quotations)
save the file and put it inside of the includes folder and name it "player.lua". (remove the
quotations)
In this lua text file there will be a BAZILLION functions through out the series, and to start
off player.lua,go into main.lua and at the very top of the whole source code, and yes ontop of
love.load() type in require "includes/player" if you put in includes/player.lua it will create
problems.
your code in main.lua should now look like this
Code: Select all
require "includes/player"
function love.load()
--love.load loads/sets all the variables and images
love.graphics.setBackgroundColor(255,255,255)
end
function love.update(dt)
--love.update does all the math work
end
function love.draw()
--love.draw draws stuff...
end
to start off with
player.lua you will need to create the player variables
inside of player.lua
which are:
Code: Select all
player = {}
player.x = 5
player.y = 5
player.xvel = 0
player.yvel = 0
player.friction = 10
player.speed = 1500
With these variables set, you can now move on
into drawing the player.
The first step to drawing a player is making a new folder inside
of your game folder which holds main.lua and conf.lua,make a new
folder called "resources" (remove quotations), with this put in
your player's picture, the player needs 2 different
pictures that shows the player facing left and right.
rename your 2 images with playerL and playerR
with the player facing left being playerL and the player
facing right being playerR.
now you can finally draw your player by making a new variable
called:
Code: Select all
player.pic = love.graphics.newImage("resources/playerR.png")
Code: Select all
player = {}
player.x = 5
player.y = 5
player.xvel = 0
player.yvel = 0
player.friction = 10
player.speed = 1500
player.pic = love.graphics.newImage("resources/playerR.png")