Camera Shake? / Collisions / Enemies...

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: Camera Shake?

Post by Mud » Sun Nov 07, 2010 9:39 am

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.
Last edited by Mud on Sun Nov 07, 2010 9:59 am, edited 1 time in total.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Camera Shake? / Collisions

Post by Robin » Sun Nov 07, 2010 9:44 am

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.)
Help us help you: attach a .love.

User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Camera Shake? / Collisions

Post by Ryne » Sun Nov 07, 2010 8:26 pm

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.
@rynesaur

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Camera Shake? / Collisions

Post by Robin » Sun Nov 07, 2010 9:42 pm

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. :)
Help us help you: attach a .love.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Camera Shake? / Collisions

Post by Robin » Sun Nov 07, 2010 9:50 pm

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
Help us help you: attach a .love.

User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Camera Shake? / Collisions

Post by Ryne » Sun Nov 07, 2010 10:47 pm

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!
@rynesaur

User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

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

Post by Ryne » Mon Nov 08, 2010 9:32 am

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.
@rynesaur

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin » Mon Nov 08, 2010 9:41 am

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
?
Help us help you: attach a .love.

User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

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

Post by Ryne » Mon Nov 08, 2010 9:56 am

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 :|.
Last edited by Ryne on Mon Nov 08, 2010 11:16 am, edited 1 time in total.
@rynesaur

User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

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

Post by Mud » Mon Nov 08, 2010 10:22 am

I love the look of your game. Did you do the sprites?

Post Reply

Who is online

Users browsing this forum: Bing [Bot], kicknbritt and 12 guests