The Daily Click ::. Forums ::. Klik Coding Help ::. Getting hit?
 

Post Reply  Post Oekaki 
 

Posted By Message

Devernath



Registered
  04/12/2004
Points
  54

VIP Member
29th February, 2008 at 18:24:32 -

Ok, you know how in old NES and SNES games whenever a character gets hit, he automatically backs away and flashes for a seconds, and during that period he is invincible?

I have been trying to figure out how to do it, but I cannot. Can someone help me?

 
n/a

Devernath



Registered
  04/12/2004
Points
  54

VIP Member
29th February, 2008 at 18:26:57 -

Oh, and I forgot to say I'm using movement like in zelda games (overhead) and I'm using Games Factory.

 
n/a

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
29th February, 2008 at 18:32:48 -

Have a alterable value so that if it's lower then 0, add one and then subtract 1 from players position. If it's greater then 0, subtract one then add one to players position. This way when the person gets hit from say the left, you can change this alterable value to 30 or something, causing him to move to the right for around 30 loops or around 0.5 a second (assuming framerate is 60fps).

You can also make it so that every other time it subtracts or adds to the variable, it toggles a flag. If the flag is On, make player invisible. If flag is Off, make him reappear. Make sure you make it so that if the alterable value is 0 though, that you force the flag off, that way he doesn't accidentally toggle invisible and stay that way.

(Edit) PS: This could be used the same way, but instead of only having 1 alterable value for just left and right, you would also want another alterable value for up and down.

Image Edited by the Author.

 
http://www.facebook.com/truediamondgame

Devernath



Registered
  04/12/2004
Points
  54

VIP Member
29th February, 2008 at 18:40:06 -

I was thinking something like that, and I would need invisible collision detectors(to recognize what direction it's coming from) right? And also to make the event "if collsion "collison detector" and "enemy" AND "player" flag :1 off, then do the damage.

I'll try it out. Thanks. Had to read it a couple of times to understand what you were saying, lol.

 
n/a

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
29th February, 2008 at 18:47:31 -

Yeah, but if you're using a custom engine, I don't think sensors should be a major problem. Even with enemies, it's a little trickier with them, but it's possible with fast loops.

 
http://www.facebook.com/truediamondgame

Cecilectomy

noPE

Registered
  19/03/2005
Points
  305

Has Donated, Thank You!VIP MemberWeekly Picture Me This Winner!Cardboard BoxGhostbuster!Pokemon Ball!ComputerBox RedSanta HatSnowman
I am an April Fool
29th February, 2008 at 20:25:24 -

if its a top down game im assuming its 8 direction movment?

if so, instead of using a bunch of detectors and fastloops, you could just base it on the direction to the main character.

if the character strikes an enemy and is to the left then you start moving the x to the right based on brandons method.
if to the right then move x to the left.
you can do this for diagonals as well. just move the x and y together in the appropriate direction.

that would get rid of a bunch of actives and loops.

 
n/a

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
1st March, 2008 at 10:01:01 -

Yeah, an easy workaround is to put a "AND monster flag 0 is off" even in the "Player sword collides with enemy" or whatever event, and then when it gets hit, instead of just decreasing its HP value by 1, make it;

+Sword Hits Monster
=Subtract 1 from Monster Health
=Set Monster Flag 0 On
=Change Monster Animation to "Getting Hit"

+Monster Animation "Getting Hit" is over
=Set Monster Flag 0 Off
=Change Animation to "Stopped"


One problem you will encounter is that any event which is reliant on an animation being "over" will not inevitably come around if some other event changes its animation, too. So if its the middle of playing the "Getting Hit" Flash, and then your code tells it to attack and change its animation to "Attacking", its flag 0 will be stuck ON, and it will be unhittable. The way to work around this is to flag EVERY SINGLE EVENT that can change a monsters animation, and disable it from doing so while it is in one of these animations that MUST play to finish. It can be rather tedious.
Another error you can run into, is that an event which rapidly changes a monsters animation might get it permanently stuck in it, without reverting to its "stopped" animation. This is easily solved by including a "When Animiation X is over, change animation sequence to Stopped" event, exactly like I have above. Without it, a player might hit an enemy over and over again and get it stuck.



 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Silveraura

God's God

Registered
  08/08/2002
Points
  6747

Game of the Week WinnerKlikCast StarAlien In Training!VIP Member360 OwnerWii OwnerSonic SpeedThe Cake is a LieComputerChristmas Tree!
I am an April Fool
1st March, 2008 at 10:13:44 -

Unless the monster has a unique getting hit animation, and the getting hit animation is not just flashing, then the point of using an animation just to make him flash is stupid and pointless. I could be jumping off the gun pretty early here and if I am, I'm sorry, but if you don't know how to use flags and alterable values effectively, don't suggest inefficient idea's. If you add a small sensor system (which takes all of 5 minutes) for enemies, then I see no reason to find work arounds for my suggestion, let alone work arounds for my work arounds.

 
http://www.facebook.com/truediamondgame

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
1st March, 2008 at 10:42:29 -

Eh, unless you're adding a single detector that runs in a fastloop around all the enemies (which is extraordinarily complicated to program in comparison) then it will DOUBLE the amount of AO's onscreen, as well as require a system to pin the detectors to the AO's, which is even MORE complicated :/

I think you hit the the "move the object left/right" issue right on the ball, but using visibility/invisibility to simulate a flashing effect is iffy business. I personally prefer my baddies to flash white rather then going all invisible.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
1st March, 2008 at 10:55:50 -


Originally Posted by BrandonC
Unless the monster has a unique getting hit animation, and the getting hit animation is not just flashing, then the point of using an animation just to make him flash is stupid and pointless.



I make enemies flash when getting hit all the time. It's not stupid and pointless, it's 1.) easy for the programmer to do and 2.) fufills the requirement of letting the player know that he's hit an enemy.

But if you really want to make big "getting hit" animations for every monster you have, go for it. Most people will want to use their game making time for things other than that though (hence why using this easy method might be a good idea for some).

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Devernath



Registered
  04/12/2004
Points
  54

VIP Member
1st March, 2008 at 11:17:11 -

Hey, BrandonC, thanks for the advice. It was kinda tough to program, but it runs very smoothly. I can effectively make it so that the player flashes and backs away from the enemy, (and also when he is flashing to make him immune to attacks) and take damage appropiately.


Thanks. Now I gotta do the same with vice versa, enemies flashing and backing away when player hits them. Since I'm going to have lots of enemies with different pixel sizes (which would imply all of them needed different sized collision detectors), should I just bunch each (top, bottom, right, left) detectors for enemies and the enemies themselves in one group?

 
n/a
   

Post Reply



 



Advertisement

Worth A Click