Skip to content

Commit

Permalink
Add character selection screen
Browse files Browse the repository at this point in the history
You can now choose between Annie and Abed when playing the game. I'll be
adding more characters soon, probably starting with Troy
  • Loading branch information
kyleconroy committed May 26, 2012
1 parent 8a822c6 commit 337e783
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 26 deletions.
Binary file added psds/characterselect.psd
Binary file not shown.
23 changes: 23 additions & 0 deletions src/characters/abed.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local anim8 = require 'vendor/anim8'

local plyr = {}
plyr.name = 'ABED NADIR'
plyr.sheet = love.graphics.newImage('images/abed.png')
local g = anim8.newGrid(46, 46, plyr.sheet:getWidth(), plyr.sheet:getHeight())

plyr.animations = {
jump = {
right = anim8.newAnimation('once', g('7,2'), 1),
left = anim8.newAnimation('once', g('7,1'), 1)
},
walk = {
right = anim8.newAnimation('loop', g('2-4,2', '3,2'), 0.16),
left = anim8.newAnimation('loop', g('2-4,1', '3,1'), 0.16)
},
idle = {
right = anim8.newAnimation('once', g(1,2), 1),
left = anim8.newAnimation('once', g(1,1), 1)
}
}
return plyr

22 changes: 22 additions & 0 deletions src/characters/annie.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local anim8 = require 'vendor/anim8'

local plyr = {}
plyr.name = 'ANNIE EDISON'
plyr.sheet = love.graphics.newImage('images/annie.png')
local g = anim8.newGrid(46, 46, plyr.sheet:getWidth(), plyr.sheet:getHeight())

plyr.animations = {
jump = {
right = anim8.newAnimation('once', g('7,2'), 1),
left = anim8.newAnimation('once', g('7,1'), 1)
},
walk = {
right = anim8.newAnimation('loop', g('2-4,2', '3,2'), 0.16),
left = anim8.newAnimation('loop', g('2-4,1', '3,1'), 0.16)
},
idle = {
right = anim8.newAnimation('once', g(1,2), 1),
left = anim8.newAnimation('once', g(1,1), 1)
}
}
return plyr
33 changes: 9 additions & 24 deletions src/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ end
local Player = {}
Player.__index = Player

function Player.create(sheet_path)
local sheet = love.graphics.newImage(sheet_path)
function Player.create(character)
local plyr = {}
local g = anim8.newGrid(46, 46, sheet:getWidth(), sheet:getHeight())

setmetatable(plyr, Player)
plyr.rebounding = false
Expand All @@ -129,26 +127,13 @@ function Player.create(sheet_path)
plyr.flash = false
plyr.width = 48
plyr.height = 48
plyr.sheet = sheet
plyr.sheet = character.sheet
plyr.actions = {}
plyr.position = {x=love.graphics.getWidth() / 2 - 23, y=300}
plyr.velocity = {x=0, y=0}
plyr.state = 'idle' -- default animation is idle
plyr.direction = 'right' -- default animation faces right direction is right
plyr.animations = {
jump = {
right = anim8.newAnimation('once', g('7,2'), 1),
left = anim8.newAnimation('once', g('7,1'), 1)
},
walk = {
right = anim8.newAnimation('loop', g('2-4,2', '3,2'), 0.16),
left = anim8.newAnimation('loop', g('2-4,1', '3,1'), 0.16)
},
idle = {
right = anim8.newAnimation('once', g(1,2), 1),
left = anim8.newAnimation('once', g(1,1), 1)
}
}
plyr.animations = character.animations
return plyr
end

Expand Down Expand Up @@ -333,12 +318,9 @@ end
function collision_stop(dt, shape_a, shape_b)
end


function game:init()
function game:enter(previous, character)
love.audio.stop()
endscreen = love.graphics.newImage("images/abed.png")

player = Player.create("images/annie.png")
player = Player.create(character)
enemy = Enemy.create("images/hippy.png")

map = atl.Loader.load("hallway.tmx")
Expand Down Expand Up @@ -366,6 +348,10 @@ function game:init()

end


function game:init()
end

function game:update(dt)
player:update(dt)
enemy:update(dt)
Expand All @@ -384,7 +370,6 @@ end

function game:draw()
if game.over then
love.graphics.draw(endscreen)
return
end

Expand Down
Binary file added src/images/arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/selectscreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/menu.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local Gamestate = require 'vendor/gamestate'
local tween = require 'vendor/tween'
local game = require 'game'
local character_state = require 'select'
local menu = Gamestate.new()


Expand All @@ -26,7 +26,7 @@ end

function menu:keypressed(key)
if key == "return" then
Gamestate.switch(game)
Gamestate.switch(character_state)
end
end

Expand Down
47 changes: 47 additions & 0 deletions src/select.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
local Gamestate = require 'vendor/gamestate'
local game = require 'game'
local state = Gamestate.new()

local selections = {}
selections[0] = {}
selections[0][0] = require 'characters/abed'
selections[0][1] = require 'characters/annie'

function state:init()
self.side = 0 -- 0 for left, 1 for right
self.level = 0 -- 0 through 3 for characters
self.screen = love.graphics.newImage("images/selectscreen.png")
self.arrow = love.graphics.newImage("images/arrow.png")
love.graphics.setFont(love.graphics.newFont("fonts/xen3.ttf", 32))
end

function state:character()
return selections[0][self.level]
end

function state:update(dt)
end

function state:keypressed(key)
if key == "up" then
self.level = (self.level + 1) % 2
elseif key == "down" then
self.level = (self.level - 1) % 2
elseif key == "return" then
Gamestate.switch(game, self:character())
end
end

function state:draw()
love.graphics.draw(self.screen)

love.graphics.draw(self.arrow, 224 - 72 * self.level, 270 + 72 * self.level)
love.graphics.printf(self:character().name, 0, 425,
love.graphics:getWidth(), 'center')
love.graphics.printf('PRESS ENTER', 0, 460,
love.graphics:getWidth(), 'center')
end


return state

0 comments on commit 337e783

Please sign in to comment.