Jump to content


Photo

enemy destroy when player only jump onto it


  • Please log in to reply
11 replies to this topic

#1 imsweet

imsweet

    GMC Member

  • New Member
  • 38 posts
  • Version:GM8

Posted 06 May 2012 - 02:48 AM

Hello...How I need to do to make enemy destroy when player only jump onto it. I already can destroy the enemy. But if the player just collide with the enemy it will also destroy. I want the player to jump onto enemy and it will destroy and get points. If the player just collide, the enemy still have and deduct the points. Can this be done using drag and drop method? I'm new using game maker...



Thanks :)
  • 0

#2 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 06 May 2012 - 03:07 AM

This can be done using drag and drop. In the collision event with the enemy, check the y position and the vspeed. You only want the player to kill the enemy when he is falling and is above the enemy, so in the player's collision event with the enemy, the code would look like this:

if (y < other.y && vspeed > 0) //if y position is smaller (above, since y = 0 is the top of the room, and it gets bigger as you go down) and vspeed is biger than 0 (falling)
{
  with (other) instance_destroy(); //destroy enemy object
}
else
{
  //enemy kills you
}

To convert this into Drag and Drop:

:GM060: in the box put: y < other.y && vspeed > 0
:GM026: be sure to click the "other" radio button
:GM064:
:GM026: this time leave it as "self"

This will detroy the enemy if you are above it (and falling), and destroy the player if you are not above it.
You probably don't want to destroy the objects (maybe change enemy to "dying_enemy", and restart the room if player dies), but this should give you the idea.
  • 0

#3 imsweet

imsweet

    GMC Member

  • New Member
  • 38 posts
  • Version:GM8

Posted 06 May 2012 - 03:25 AM

This can be done using drag and drop. In the collision event with the enemy, check the y position and the vspeed. You only want the player to kill the enemy when he is falling and is above the enemy, so in the player's collision event with the enemy, the code would look like this:

if (y < other.y && vspeed > 0) //if y position is smaller (above, since y = 0 is the top of the room, and it gets bigger as you go down) and vspeed is biger than 0 (falling)
{
  with (other) instance_destroy(); //destroy enemy object
}
else
{
  //enemy kills you
}

To convert this into Drag and Drop:

:GM060: in the box put: y < other.y && vspeed > 0
:GM026: be sure to click the "other" radio button
:GM064:
:GM026: this time leave it as "self"

This will detroy the enemy if you are above it (and falling), and destroy the player if you are not above it.
You probably don't want to destroy the objects (maybe change enemy to "dying_enemy", and restart the room if player dies), but this should give you the idea.



I have done using the drag and drop. But both of the enemy and player were destroy. Where did it wrong?
  • 0

#4 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 06 May 2012 - 03:27 AM

Did you remember to put the "else" in there? Also, only put the actions in the player's collision event with the enemy, not in the enemy's collision event with the player.
  • 0

#5 imsweet

imsweet

    GMC Member

  • New Member
  • 38 posts
  • Version:GM8

Posted 06 May 2012 - 06:20 AM

Did you remember to put the "else" in there? Also, only put the actions in the player's collision event with the enemy, not in the enemy's collision event with the player.


Yes..I get what you say. That mean when the player collide with the enemy it will die. So the player need to restart the level. How I need to do to make sure the player at specific position?
  • 0

#6 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 06 May 2012 - 07:34 AM

The collision event makes sure the player is touching the enemy, then the "if" expression takes care of checking where the player is in relation to the enemy.

I have made you an example, hopefully this helps you work it out:

http://www.davesexam...jumponenemy.gmk
  • 0

#7 imsweet

imsweet

    GMC Member

  • New Member
  • 38 posts
  • Version:GM8

Posted 06 May 2012 - 08:17 AM

The collision event makes sure the player is touching the enemy, then the "if" expression takes care of checking where the player is in relation to the enemy.

I have made you an example, hopefully this helps you work it out:

http://www.davesexamples.com/jumponenemy.gmk



Thank you very much it help. But how I need to do to make the player restart at the latest place before he died. I have a long room. I do not know on how to restart at the latest position. My room width is about 10000. What I had did right now is the player will restart at the beginning of the room even the latest position before it died is x=9783. I want the player to restart at the latest position before it died.
  • 0

#8 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 06 May 2012 - 09:00 AM

If you restarted him at *exactly* the spot *immediately* before he died, then chances are he would die again straight away. Usually it's pretty hard to work out a good respawn spot automatically, so a better idea is to use checkpoints. Add checkpoints every so often in safe areas. When the player passes them, either save the game or store the position in variables. Then when the player dies, send them back to the checkpoint.

I think it's best to show the checkpoints so the player knows where they are, but if you don't want to, you can also make the checkpoint invisible so the player doesn't know it's there, but it will still take him back there if he dies.
  • 0

#9 imsweet

imsweet

    GMC Member

  • New Member
  • 38 posts
  • Version:GM8

Posted 06 May 2012 - 09:08 AM

If you restarted him at *exactly* the spot *immediately* before he died, then chances are he would die again straight away. Usually it's pretty hard to work out a good respawn spot automatically, so a better idea is to use checkpoints. Add checkpoints every so often in safe areas. When the player passes them, either save the game or store the position in variables. Then when the player dies, send them back to the checkpoint.

I think it's best to show the checkpoints so the player knows where they are, but if you don't want to, you can also make the checkpoint invisible so the player doesn't know it's there, but it will still take him back there if he dies.



Actually i'm developing the game based learning. In my game the player have to answer the question. Along the long room I put the door sprite. When the player collide with the door the player will go the another room to answer the question. Then the player will back to the room. I have 10 door. Can the door use as a checkpoints?
  • 0

#10 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 06 May 2012 - 09:16 AM

If the player will always touch the door when moving from one room to the next, it is the perfect place for a checkpoint.

Depending on your game, you may want to use the "save a game" action, which saves everything in the game exactly as it is at the time of saving (with a few exceptions you wont come across until you start coding), and it will load exactly as it was when saved. This can be an easy way to create a checkpoint, but can have problems. For example, if your game has lives, then you may only have one life left when you pass the checkpoint, then die in the room. When you respawn, you will only have one life (because that is how many you had when you saved the game), but you may want the player to respawn with 3 lives.

There are many reasons why a "save game" type checkpoint wouldn't work, so the other option is just to save the player's position in a variable.

When the player passes the door (use "object at position" in the step event, as you may have problems placing it in the collision event since you want to be able to walk freely through the door), use "set the value of a variable" to set the variable "save_x" to "x" and the variable "save_y" to "y" (without the quotes). You should also initialise the variables in the create event of the player, using the exact same actions. Then when the player dies, use the "jump to position" action, and put "save_x" in the "x" box, and "save_y" in the "y" box.
  • 0

#11 imsweet

imsweet

    GMC Member

  • New Member
  • 38 posts
  • Version:GM8

Posted 06 May 2012 - 09:52 AM

If the player will always touch the door when moving from one room to the next, it is the perfect place for a checkpoint.

Depending on your game, you may want to use the "save a game" action, which saves everything in the game exactly as it is at the time of saving (with a few exceptions you wont come across until you start coding), and it will load exactly as it was when saved. This can be an easy way to create a checkpoint, but can have problems. For example, if your game has lives, then you may only have one life left when you pass the checkpoint, then die in the room. When you respawn, you will only have one life (because that is how many you had when you saved the game), but you may want the player to respawn with 3 lives.

There are many reasons why a "save game" type checkpoint wouldn't work, so the other option is just to save the player's position in a variable.

When the player passes the door (use "object at position" in the step event, as you may have problems placing it in the collision event since you want to be able to walk freely through the door), use "set the value of a variable" to set the variable "save_x" to "x" and the variable "save_y" to "y" (without the quotes). You should also initialise the variables in the create event of the player, using the exact same actions. Then when the player dies, use the "jump to position" action, and put "save_x" in the "x" box, and "save_y" in the "y" box.



I can't get you. I'm new to this. But it's okay...:(
  • 0

#12 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9276 posts
  • Version:Unknown

Posted 06 May 2012 - 10:07 AM

If you don't understand it, just skip to the last paragraph:

When the player passes the door (use "object at position" in the step event, as you may have problems placing it in the collision event since you want to be able to walk freely through the door), use "set the value of a variable" to set the variable "save_x" to "x" and the variable "save_y" to "y" (without the quotes). You should also initialise the variables in the create event of the player, using the exact same actions. Then when the player dies, use the "jump to position" action, and put "save_x" in the "x" box, and "save_y" in the "y" box.


That hopefully describes how to go about it.

Edit: if you still can't work it out, I've made you another example :) http://www.davesexam...ointexample.gmk

Edited by Dangerous_Dave, 06 May 2012 - 10:18 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users