Game Dev Meeting: Love2D
11/12/15
Announcements
Game night this Friday.
Come to IEEE (ECE 105) and play some games.
Game jam next Friday.
Come to IEEE and make a game!
Ryan, from RedBull, is hosting a Destiny tournament this Saturday happening at Amazing Discoveries. Going to compete in a fire team. Win and go to the RedBull studios in Santa Montica.
First gaming tournament by the U of A RedBull team. Just show up.
Free redbull for everyone!
Love2D
What is LOVE? (Insert obvious joke)
- Free
- Simple
- Cross-platform
- Lua-Based
- 2D
...game engine!
I've got it good, what do I need with LOVE?
LOVE is a great...
- First game engine
- Prototyping tool
- Engine for game jams (hint, hint)
- Friend for those lonely winter nights
What's the catch?
Well, LOVE also...
- Has no user interface, just code
- Can't export to web or mobile
- Requires plugins for a lot of functionality
- Cannot be hugged
-
Doesn't provide a lot natively
- No default animation library
How do I get started?
You will need...
- The engine itself (from love2d.org)
- A text editor (recommends Sublime with their LOVE setup)
Time for a Live Demo!
Note: I tried to follow along, but I haven't validated the code I copied along the way. I'm sorry if some of it doesn't work.
Some technical difficulties.
Empty folder start.
Save new file in that folder ("main.lua").
You now have a LOVE project.
From there drag the main file onto the LOVE executable to start it. Right now, it's a blank game.
function love.load()
end
This is how a function is defined. love.load is the first "callback" function called.
function love.load()
love.graphics.setBackgroundColor(255, 0, 0)
end
This makes the background red.
function love.draw()
love.graphics.circle('fill', 400, 300, 20)
end
Where rendering is done. This draws a white circle in the middle of the screen.
function love.draw()
love.graphics.setColor(0, 255, 0)
love.graphics.circle('fill', 400, 300, 20)
end
Now the circle is green.
function love.draw()
love.graphics.setColor(0, 255, 0, 0)
love.graphics.circle('fill', 400, 300, 20)
end
Now, the circle is invisible.
What if we want an image?
function love.load()
player = love.graphics.newImage('blob.png')
end
function love.draw()
love.graphics.draw(player, 0, 0)
end
Player image is drawn at top-left corner.
function love.load()
player = love.graphics.newImage('blob.png')
end
function love.draw()
love.graphics.draw(player, love.graphics.getWidth()/2, love.graphics.getHeight()/2)
end
This draws the player image in the center of the screen.
Another function!
function love.update()
end
This is where game math takes place. Let's do some game stuffs!
function love.draw()
love.graphics.draw(player, x, love.graphics.getHeight()/2)
end
function love.update()
x = x + 20*dt
end
Now the player is slowly moving to the right at a rate of 20 pixels per second.
function love.load()
player = love.graphics.newImage('blob.png')
bg = love.graphics.newImage('bg.png')
end
function love.draw()
love.graphics.draw(bg, 0, 0);
love.graphics.draw(player, love.graphics.getWidth()/2, love.graphics.getHeight()/2)
end
Draw draws ontop of what has already been drawn. This puts a background that the player renders on top of.
function love.update()
if love.keyboard.isDown('left') then
x = x + 500*dt
elseif love.keyboard.isDown('left') then
x = x - 500*dt
end
end
The player can control the blob now!
Other events to listen for for player input!
function love.keypressed(key)
end
function love.mousepressed(x, y, button)
end
Let's add jump functionality.
function love.load()
player = love.graphics.newImage('blob.png')
bg = love.graphics.newImage('bg.png')
x = 0
y = 500
dy = 0
end
function love.draw()
love.graphics.draw(bg, 0, 0);
love.graphics.draw(player, x, y)
end
function love.update()
if love.keyboard.isDown('left') then
x = x + 500*dt
elseif love.keyboard.isDown('left') then
x = x - 500*dt
end
y = y + dy*dt
dy = dy + 400*dt
if y > 300 then
y = 300
dy = 0
end
end
function love.keypressed()
if key == ' ' and dy == 0 then
dy = -300
end
end
Now jumping can happen!
Let's organize the code a bit.
function love.load()
bg = love.graphics.newImage('bg.png')
player = {}
player.sprite = love.graphics.newImage('blob.png')
player.x = 0
player.y = 500
player.dy = 0
end
function love.draw()
love.graphics.draw(bg, 0, 0);
love.graphics.draw(player.sprite, player.x, player.y)
end
function love.update()
if love.keyboard.isDown('left') then
player.x = player.x + 500*dt
elseif love.keyboard.isDown('left') then
player.x = player.x - 500*dt
end
player.y = player.y + player.dy*dt
player.dy = player.dy + 400*dt
if player.y > 300 then
player.y = 300
player.dy = 0
end
end
function love.keypressed()
if key == ' ' and player.dy == 0 then
player.dy = -300
end
end
Let's make an enemy!
function love.load()
bg = love.graphics.newImage('bg.png')
player = {}
player.sprite = love.graphics.newImage('blob.png')
player.x = 0
player.y = 500
player.dy = 0
enemy = {}
enemy.x = 0
enemn.y = 0
enemn.dy = 0
enemn.dy = 0
end
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(bg, 0, 0);
love.graphics.draw(player.sprite, player.x, player.y)
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle('fill', enemy.x, enemy.y, 20, 20)
love.graphics.setColor(255, 0, 0)
if exploded then
love.graphics.print('EXPLODED', 0, 200, 0, 10, 10)
end
end
function love.update()
if enemy.x < player.x + 169 and enemy.x > player.x and enemy.y < player.y + 180 and enemy.y > player. y then
exploded = true
end
end
Okay, the game is ready for Steam!
Demos of Previous Prototypes
- Missle Command
- Random Dungeon Generator
- 2D Rubix Cube
- Trail Prototype
- RPS overhead action game
Post about this on Facebook.
Put code on GitHub! Please!