Page 4 of 6

Re: Camera Shake?

Posted: Sun Nov 07, 2010 9:39 am
by Mud
zac352 wrote:Can has video?
Here you go (excuse the terrible 'game').

Code's something like this (I set shaketimer to 1 second, so the max shake amount is 10 pixels, then it settles down):

Code: Select all

function love.update(dt)
   shaketimer = shaketimer - dt
   ...

function love.draw()
   if shaketimer >= 0 then
      local shake = 10 * shaketimer
      love.graphics.translate(math.random(-shake,shake), math.random(-shake,shake))
   end
   ...
EDIT: I just tried throwing a little scale jitter in there (+/- .02) and it makes it look a lot cooler, kinda warbly and unsettling.

Re: Camera Shake? / Collisions

Posted: Sun Nov 07, 2010 9:44 am
by Robin
Another fascinating application of camera shaking. In Space, the amplitude for the in-game shaking depended on proximity to the black hole, while the amplitude for the logo shaking in the menu depended on the vertical speed of the menu items. (When you change your selection in the menu, the whole menu goes up or down.)

Re: Camera Shake? / Collisions

Posted: Sun Nov 07, 2010 8:26 pm
by Ryne
So assuming I understand correctly. I create the function using Robin's example, with obj1, and obj2. Then I create the if statement using player and enemy (which take the roles of obj1, and obj2? or was I supposed to switch them?) so everything gets swapped respectively? Now, assuming I did everything right. Its still not working. Alas, I will upload the love file and hope you guys will take a look and point out my stupid mistakes. Thanks again.

Use WASD to walk. The player that is walking to the left takes the place as "enemy" for now, Until I fully create the zombie sprites.

http://dl.dropbox.com/u/7905642/lovely_zombies.love

Everything inside of the function is easy enough to understand. I guess I just don't know how to use the function itself.

Re: Camera Shake? / Collisions

Posted: Sun Nov 07, 2010 9:42 pm
by Robin
Ryne wrote:(which take the roles of obj1, and obj2? or was I supposed to switch them?)
That doesn't matter. If x collides with y, surely y collides with x as well, right?
Ryne wrote:Alas, I will upload the love file and hope you guys will take a look and point out my stupid mistakes. Thanks again.
I'll take a look. :)

Re: Camera Shake? / Collisions

Posted: Sun Nov 07, 2010 9:50 pm
by Robin
I (think I) found the problem:

Code: Select all

if CheckCollision(player, enemy) == true then
player.hp = 50
end
That's in your love.load(). Now love.load() only runs once. So collision is only checked once.

If you move it to love.update(dt), it'll probably work better, although I suggest doing something like:

Code: Select all

if CheckCollision(player, enemy) then -- CheckCollision returns a boolean, so it's the same
player.hp = player.hp - 10 -- or something, but you probably knew that and just used = 50 for testing purposes, right?
end

Re: Camera Shake? / Collisions

Posted: Sun Nov 07, 2010 10:47 pm
by Ryne
Robin wrote:I (think I) found the problem:

Code: Select all

if CheckCollision(player, enemy) == true then
player.hp = 50
end
That's in your love.load(). Now love.load() only runs once. So collision is only checked once.

If you move it to love.update(dt), it'll probably work better, although I suggest doing something like:

Code: Select all

if CheckCollision(player, enemy) then -- CheckCollision returns a boolean, so it's the same
player.hp = player.hp - 10 -- or something, but you probably knew that and just used = 50 for testing purposes, right?
end
Firstly. Yes, using "player.hp = 50" was for testing. Also apparently It's been working the entire time. My method for testing was checking to see if the "health bar" was going down, the problem is that it only reads in 25 hp amounts. Onces the hit-boxes touch the hp would shoot to a negative amount instantly so the health bar wouldnt change.

That being said, I'm sorry for all of the trouble, apparently the very first thing I did would have worked fine.. Thanks for the help guys, everything is working fine now!

Re: Camera Shake? / Collisions / Enemies...

Posted: Mon Nov 08, 2010 9:32 am
by Ryne
Hit-boxes are working fine and I've continued onward to enemies. Here's my basic demo of an enemy following the player, if they touch, the player loses 25 health.

That being said I have a few more questions:

1. I was wondering how to limit the damage to 25 per 1 - 1.5 seconds. That way hp wont drop infinitely, but assuming you are still being attacked you would lose another 25 if you don't kill the zombie that is on you. Anyone know how I could do this?

2. Is there a way to color bounding boxes? Mine seem to be offset but I cant see exactly where they are so its a pain to fix them.

3. Is there an easy way to create a timer? I could think of a basic one using "dt" but it wouldnt go up in seconds, like I would want.

UPDATE

I added shadow, bounding boxes for the floor and ceiling, added the health bar with face, and you can now pick up the gun (though it only goes off screen for the time being). Also something weird is happening when I package the game as a .love file. The enemy approaches from the left instead of the right If I play directly from the folder. Even more odd is that if the .love file isn't in the same directory as the LOVE shortcut enemy approaches from the left, but if its in the same directory enemy approaches from the right. Is this happening for anyone else?

http://dl.dropbox.com/u/7905642/lz_test.love

Again, I greatly appreciate the help from everyone, I hope I can repay it someday.

Re: Camera Shake? / Collisions / Enemies...

Posted: Mon Nov 08, 2010 9:41 am
by Robin
Ryne wrote:1. I was wondering how to limit the damage to 25 per 1 - 1.5 seconds. That way hp wont drop infinitely, but assuming you are still being attacked you would lose another 25 if you don't kill the zombie that is on you. Anyone know how I could do this?
This depends on what you really want, but you could multiply the damage done by dt.
Ryne wrote:2. Is there a way to color bounding boxes? Mine seem to be offset but I cant see exactly where they are so its a pain to fix them.
http://love2d.org/wiki/love.graphics.rectangle ;)
Ryne wrote:3. Is there an easy way to create a timer? I could think of a basic one using "dt" but it wouldnt go up in seconds, like I would want. Thanks guys!
Something like:

Code: Select all

-- in love.load
atimer = 0
-- in love.update
if atimer then
    atimer = atimer + dt
    if atimer > 1 then
        atimer = atimer - 1
        -- do something, set atimer to nil or false to disable the timer
    end
end
?

Re: Camera Shake? / Collisions / Enemies...

Posted: Mon Nov 08, 2010 9:56 am
by Ryne
You are a gentleman and a scholar. Thanks a bunch Robin, I'm sticking your name in the super-special-thanks section of the credits. :D

Also do you know why this is happening?

Ryne wrote: Also something weird is happening when I package the game as a .love file. The enemy approaches from the left instead of the right If I play directly from the folder. Even more odd is that if the .love file isn't in the same directory as the LOVE shortcut enemy approaches from the left, but if its in the same directory enemy approaches from the right. Is this happening for anyone else?
[/b]
I have a folder on my desktop called "Game" inside of which is the love shortcut, and another "game" folder containing my main file etc. If I copy and paste the game folder on my desktop and try to run the game inside of it, the same thing happens. The enemy approaches from the left instead of the right, its weird since its an exact copy of my work folder :|.

Re: Camera Shake? / Collisions / Enemies...

Posted: Mon Nov 08, 2010 10:22 am
by Mud
I love the look of your game. Did you do the sprites?