Now i try to make platform wars game, like Cat War 2
I got the problem when player and enemy had collide or overlap,
I dont have an idea for implementing their attack animation with number of damage and number of attack speed (aspd)
And there are no idea for implementing if more than 1 player sprite and more than 1 enemy sprite had collide or overlap.
i want all player attack one enemy and all enemy attack one player
here is my simple algorithm :
1. if player collide or overlap with enemy, player and enemy are stop.
2. player do "Attack" animation, with delay per animation
3. enemy do "Attack" animation, with delay per animation
4. if player "Attack" animation is finished, player attack set to 1 and do "Walk" animation
5. if enemy "Attack" animation is finished, enemy attack set to 1 and do "Walk" animation
6. subs player HP with enemy attack
7. subs enemy HP with player attack
here is C2 simple algorithm :
=== General Event ===
System: Every tick ->
For each: player ->
For each: enemy ->
Player: collide with enemy -> Player: set speed 0
--- or --- -> Enemy: set speed 0
Player: overlap with enemy -> Player: substract Enemy.Attack from HP
-> Enemy: substract Player.Attack from HP
Every 3 second -> Player: set animation "Attack" (beginning)
Every 3 second -> Enemy: set animation "Attack" (beginning)
=== Player Event ===
Player: is "Walk" animation playing -> Player: set attack to 0
Player: is "Attack" animation finished -> Player: set attack to 1
-> Player: set animation "Walk"
=== Enemy Event ===
Enemy: is "Walk" animation playing -> Enemy: set attack to 0
Enemy: is "Attack" animation finished -> Enemy: set attack to 1
-> Enemy: set animation "Walk"
here is my troubles :
1. When 1 player collide or overlap with 2 enemy, 1 player attack to 2 enemy (should be attack to 1 enemy)
2. When 1 player collide or overlap with 1 enemy, player attack delay (attack speed) is faster than enemy attack delay (attack speed) whereas the attack delay for them are same
here is my simple .capx :
Give me an idea or sample code please <img src="smileys/smiley2.gif" border="0" align="middle">
Read the frist tutorial!
Read the frist tutorial!
thanks for replying,
i already read the tutorial,
but the tutorial in only for 1 on 1 player and enemy with simple case
please check the updated post <img src="smileys/smiley36.gif" border="0" align="middle" />
someone help me please <img src="smileys/smiley19.gif" border="0" align="middle" />
I've never made a platform game yet, so I don't have specifics.
Would "Picking" the top most enemy when more than one are overlapped, work?
Add the condition "Pick top/bottom" (under the sprite's z-order) to the overlap event to filter it down to just one.
You might get more help if you made up a test Capx for people to add suggestions to. What your asking is a lot of work, try to make it easy to give you an answer.
Paradox, thank you for replying
i dont have an idea for implementing like your suggestions,
i think i must use an array for player and an array for enemy,
here is my simple .capx
After reading your code, here is my first thought : a simple "state" value one the player/enemy object could help you a lot (could take "fighting" and "walking" as values). You can then divide your program in 2 parts :
1/ collision detection, checking if all the "fighting" objects are still overlapping with some enemy (go "walking" if not), and checking if the "walking" objects are still not overlapping (go "fighting" if not)
Guizmus, hello thanks for replying
your alogorithm is almost same with my algorithm.
but still have a problem,
at System: Wait 10-Player.ASPD, it doesn't function because the player and the enemy still attack without delay
if there is many player and one enemy, enemy attack like splash attack because the player is die simultaneously
any code idea please?
well, what should the system do in the end ?
Let's say there are 3 enemies and 2 players. What should hit what ? Does every player hit all enemies ? Does each player target their own enemy ? Does all player target the same enemy ?
Guizmus, thank you for replying
yeah i want to all player target the same enemy, just same as for the enemy to the player
Develop games in your browser. Powerful, performant & highly capable.
Ok, so, I looked more into your problem.
The state changing was a good solution, I tried it, it worked.
I commented my code a lot, so you can understand why I did what I did. If any question rises, just ask :)
your .capx for r136
maybe i must download it first
btw, thank you <img src="smileys/smiley20.gif" border="0" align="middle" />
Yep, sorry, keeping up to date with the beta releases :)
I use the "timer" behavior, you'll need r136 to read it anyway :/
i just wanna ask about Player.UID,
does Player.UID cover the one player or all player?
maybe we can use Player.IID for cover the one player only (CMIIW)
so if the 3 Player and 2 Enemy with same HP, atkpow, and atkspeed and the winner is player with 2 Player left.
here is the simulation :
Player with 5 HP, 1 atkpow, 1 atkspeed
Enemy with 5 HP, 1 atkpow, 1 atkspeed
1st atk -> 2 Player (full HP) 1 Player (3 HP) and 1 Enemy (full HP) 1 Enemy (2 HP)
2nd atk -> 2 Player (full HP) 1 Player (1 HP) and 1 Enemy (full HP)
3rd atk -> 2 Player (full HP) and 1 Enemy (3 HP)
4th atk -> 1 Player (full HP) 1 Player (4 HP) and 1 Enemy (1 HP)
5th atk -> 1 Player (full HP) 1 Player (3 HP)
Player.UID is the UID of the selected player. For ensuring every player selected/every enemy selected has events 3 - 6 applied to them, you can just add a sub-event in each, cycling through the selected player/enemy. Using player.IID instead wouldn't help at all. on the contrary, the function "changeState" couldn't find the correct character.
If I'm not mistaking though, using a foreach should be useless. In the current state, the function should be called one time per player meeting the condition. (I could be mistaking though, better way to know is to use a debugger, here is mine)
But to debug and test as precisely as you want, you should put up some textDisplay per enemy/player, it's hard to know for now the real state of every characters. Using a container seems to be the way to do it, as there will never be a character with no life. And later you could replace it with a life bar if you prefer.
I moved the variables you used on player/enemy on their common family, character too, try to do this when things have the same comportment in game (bullet, life, attack speed, ...)
Plus, I would add a random Y (not a lot, just a little) so all characters are not above each others, and still trigger the collision detection.
Btw, if you want to push your program further, you should try to get rid of this every tick with 4 collision detection... it's costly, and in your case, you could just compare the maximum X of player and minimum X of enemy, to know where the fight is happening. It would be a lot easier on the CPU.