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?
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.
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.
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.
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.
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.
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.
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.
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!
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?