Jump to content


Photo

Lose Hearts by falling


  • Please log in to reply
14 replies to this topic

#1 ThatOneGuyX

ThatOneGuyX

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 04 March 2012 - 08:41 AM

Hello i am trying to make a side scrolling game were you run around but you can lose Hearts by falling
how would you do this so if they fall it removes a Heart the more you fall the more Hearts get removed\
please help
  • 0

#2 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 04 March 2012 - 09:01 AM

Just make a variable that keeps track of how long you've been in the air. Basically check if you're at rest, if so, set that timer to 0, otherwise increase it by 1 every frame. If it reaches a certain amount, when you check if you're about to reset it to 0, also check if it got to that amount. If so, subtract "hearts" based on that amount. I can't say more without knowing your movement code, but that is simple enough that you can probably figure the exact code on your own.

Edited by greep, 04 March 2012 - 09:02 AM.

  • 0

#3 creativebunch

creativebunch

    The Bunchiest

  • GMC Member
  • 886 posts
  • Version:GM:Studio

Posted 04 March 2012 - 10:05 AM

Or even easier, in a collision event with your floor object check the vspeed, if it's greater than the safe speed remove hearts.

Example, removes 1 heart for every 5 over the safe speed.
if (vspeed > safe_speed) hearts -= ceil((vspeed - safe_speed) / 5);

  • 0

#4 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2297 posts
  • Version:GM7

Posted 04 March 2012 - 10:19 AM

Actually on second thought, only his code would work anyways, as if you jumped on a trampoline an bounced really high, e.g., my code would fail.
  • 0

#5 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5396 posts
  • Version:GM:Studio

Posted 04 March 2012 - 11:59 AM

Actually on second thought, only his code would work anyways, as if you jumped on a trampoline an bounced really high, e.g., my code would fail.

nah, yours would work too .. just check for how long in air with positive vspeed
counter += vspeed>0

  • 0

#6 ThatOneGuyX

ThatOneGuyX

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 10 March 2012 - 10:07 AM

Or even easier, in a collision event with your floor object check the vspeed, if it's greater than the safe speed remove hearts.

Example, removes 1 heart for every 5 over the safe speed.

if (vspeed > safe_speed) hearts -= ceil((vspeed - safe_speed) / 5);

I don't understand were i put the code??
  • 0

#7 shinyjiggly

shinyjiggly

    a lame wanderer

  • GMC Member
  • 119 posts
  • Version:GM:Studio

Posted 10 March 2012 - 10:28 AM

In your solid block floor thing's collision event (where you put the code that happens when the character comes in contact with the ground). Most likely placed after the code that is already there but maybe still within the outer brackets? You might want to experiment a bit with it to get the desired result.
  • 0

#8 DaRk_bLaDe

DaRk_bLaDe

    Super Spy Fat Guy

  • GMC Member
  • 373 posts
  • Version:GM8

Posted 10 March 2012 - 10:40 AM

EDIT: ^^^^^^^^^^^^^^^^^^^^^his

Edited by DaRk_bLaDe, 10 March 2012 - 10:41 AM.

  • 0

#9 ThatOneGuyX

ThatOneGuyX

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 09 April 2012 - 12:52 AM

I have a idea on how im going to do this when the player is no longer on the object ground it starts the timer if the player is in the air for 3 seconds when he hits the ground he lose 1 health if its 4 seconds he lose 2 health once hes in contact with the ground again i just need some help doing this
  • 0

#10 fireblade212

fireblade212

    GMC Member

  • GMC Member
  • 325 posts
  • Version:GM8

Posted 09 April 2012 - 01:03 AM

this is how minecraft deals with it:

when your on the ground. Last_On = Z (or Y)
then next time you land. check if Now_On < Last_On. then check if the gap is big enough to deal damage.
  • 0

#11 ThatOneGuyX

ThatOneGuyX

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 09 April 2012 - 08:10 AM

this is how minecraft deals with it:

when your on the ground. Last_On = Z (or Y)
then next time you land. check if Now_On < Last_On. then check if the gap is big enough to deal damage.

Ok but were am i supposed to put that and yes i understand that's how minecraft does it but minecraft is written in java

Edited by ThatOneGuyX, 09 April 2012 - 08:10 AM.

  • 0

#12 fireblade212

fireblade212

    GMC Member

  • GMC Member
  • 325 posts
  • Version:GM8

Posted 09 April 2012 - 07:31 PM

language means nothing.

i have not much coding experience with platformers, but in theory, your using place_meet or a function like that to see if the player lands on the ground.
lets just for example the below code (the place_meat is basicly, this is a example extending your gravity stop code)

if( place_meet(x,y-16) = true)
{//this is start of block
gravity = 0; //stop gravity
dif = last_y - y; //different in levels
if last_y > y and dif > 32 //if the last gound usage is BELOW (meaning a fall) AND difference is enough to take damage (32 pixels)
{//start of block
health -= (dif-32)/32; //every 32 pixels = 1 health damage, tinker with values to check it. 32 pixels is a safe non-hurt
}
last_y = y; //now set our ground_level
}

Edited by fireblade212, 09 April 2012 - 07:34 PM.

  • 0

#13 ThatOneGuyX

ThatOneGuyX

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 09 April 2012 - 10:13 PM

language means nothing.

i have not much coding experience with platformers, but in theory, your using place_meet or a function like that to see if the player lands on the ground.
lets just for example the below code (the place_meat is basicly, this is a example extending your gravity stop code)

if( place_meet(x,y-16) = true)
{//this is start of block
gravity = 0; //stop gravity
dif = last_y - y; //different in levels
if last_y > y and dif > 32 //if the last gound usage is BELOW (meaning a fall) AND difference is enough to take damage (32 pixels)
{//start of block
health -= (dif-32)/32; //every 32 pixels = 1 health damage, tinker with values to check it. 32 pixels is a safe non-hurt
}
last_y = y; //now set our ground_level
}

Im guessing you put this in step event and by the way place_meet is an unknown code it dose to work with game maker

Edited by ThatOneGuyX, 09 April 2012 - 10:16 PM.

  • 0

#14 fireblade212

fireblade212

    GMC Member

  • GMC Member
  • 325 posts
  • Version:GM8

Posted 09 April 2012 - 11:19 PM

sorry, i was under the assumption you knew what your current code does. You DO have a working gravity system in your platform game, correct?
  • 0

#15 ThatOneGuyX

ThatOneGuyX

    GMC Member

  • New Member
  • 66 posts
  • Version:GM8

Posted 10 April 2012 - 03:20 AM

sorry, i was under the assumption you knew what your current code does. You DO have a working gravity system in your platform game, correct?

Yes for the player
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users