Re: Camera Shake?
Posted: Sat Nov 06, 2010 11:24 pm
I just tested the code you sent Robin, and its exactly what I wanted. I might as well ask while I'm here but one major issue that I'm hours away from facing is collision. I have done basic pixel collision but it seems really inefficient. Is there a way to create a sort of "hitbox" around the character and enemies? This is the corresponding code for love.load, love.update, and love.draw for how my characters are set up and drawn:
This also serves as a basic setup to force the sprite to look at the mouse cursor, that's where all of the mouse stuff comes in. I know its pretty sloppy but it works pretty well. Any help would be appreciated, thanks again guys!
Code: Select all
function love.load()
player = {
hp = 100,
status = "ALIVE",
x = 100,
y = 100,
}
animsource = {
walkleft = love.graphics.newImage("assets/sprites/walk_left.png"),
walkright = love.graphics.newImage("assets/sprites/walk_right.png"),
walkup = love.graphics.newImage("assets/sprites/walk_up.png"),
walkdown = love.graphics.newImage("assets/sprites/walk_down.png"),
standleft = love.graphics.newImage("assets/sprites/stand_left.png"),
standright = love.graphics.newImage("assets/sprites/stand_right.png"),
standup = love.graphics.newImage("assets/sprites/stand_up.png"),
standdown = love.graphics.newImage("assets/sprites/stand_down.png"),
shotgun = love.graphics.newImage("assets/weapons/shotgun_anim.png"),
}
anim = {
walkleft = newAnimation(animsource.walkleft, 32, 32, 0.18, 0),
walkright = newAnimation(animsource.walkright, 32, 32, 0.18, 0),
walkup = newAnimation(animsource.walkup, 32, 32, 0.18, 0),
walkdown = newAnimation(animsource.walkdown, 32, 32, 0.18, 0),
standleft = newAnimation(animsource.standleft, 32, 32, 0.18, 0),
standright = newAnimation(animsource.standright, 32, 32, 0.18, 0),
standup = newAnimation(animsource.standup, 32, 32, 0.18, 0),
standdown = newAnimation(animsource.standdown, 32, 32, 0.18, 0),
shotgun = newAnimation(animsource.shotgun, 16, 6, 0.18, 0),
}
direction = "down"
end
function love.update()
-- animation updates
anim.walkleft:update(dt)
anim.walkright:update(dt)
anim.walkup:update(dt)
anim.walkdown:update(dt)
anim.standleft:update(dt)
anim.standright:update(dt)
anim.standup:update(dt)
anim.standdown:update(dt)
anim.shotgun:update(dt)
state = anim.walkleft
if direction == "right" then
state = anim.standright
end
if direction == "left" then
state = anim.standleft
end
if direction == "up" then
state = anim.standup
end
if direction == "down" then
state = anim.standdown
end
-- mouse rotation
mouse_x = love.mouse.getX()
mouse_y = love.mouse.getY()
if mouse_x >= player.x then
state = anim.standright
elseif mouse_x <= player.x then
state = anim.standleft
end
if mouse_y >= player.y + 50 then
state = anim.standdown
elseif mouse_y <= player.y - 50 then
state = anim.standup
end
-- keys
if love.keyboard.isDown( "w" ) then
direction = "up"
state = anim.walkup
player.y = player.y - 1
elseif love.keyboard.isDown( "s" ) then
direction = "down"
state = anim.walkdown
player.y = player.y + 1
elseif love.keyboard.isDown( "d" ) then
direction = "right"
state = anim.walkright
player.x = player.x + 1
elseif love.keyboard.isDown( "a" ) then
direction = "left"
state = anim.walkleft
player.x = player.x - 1
end
end
function love.draw()
state:draw(player.x, player.y)
end