Author Options:

Game Maker Issues (Attacking An Enemy) Answered

Hi all. I've been working with Game Maker for a few days now and am embarking on my first game (name pending). Everything is going relatively smoothly, except I need to be able to let the player attack the enemies. So far, when the player presses the space bar, the character sprite will change to the "Sword swinging" sprite, and change back. I want it to be able to hit the space bar, and check if an enemy is beside the player, and if so, destroy the enemy. Can you help me with this?

1000 Thanks.


You can use the check object function in the controls tab.

Nevermind, I fixed it. For the record, what I had to do was use a global variable for whether the character was attacking, and then check that variable when the enemy collides with the player.

Now I have a new problem: I need to be able to check how many enemies are in the current room, and if there are none, let the player go to the next one by colliding with the door object. Any ideas?

By the by: The name of the game is "Goblins!"

In the door object, create a collision event with the player. Then use a Test Instance Count question to check if there is less than 1 enemy. If so, go to the next room. Now, if you don't want the player to go through the door if there are still enemies left, then the door should be a solid object. To do this add an "Else" action at the end, then a Move to Contact action. Set it to: direction "direction", maximum 12, against solid objects. Is this game a side-scroller-type game, top-down, or something else? Also, what version of Game Maker are you using, and which mode (simple or advanced)? Hope this helps!

It was a big help indeed! It's a top down style game, and I am using Game Maker 8 lite edition.