Jump to content


Photo

Underwater breathing *solved*


  • Please log in to reply
16 replies to this topic

#1 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 26 February 2012 - 06:31 PM

Hi, theres a lot of water in my platformer so I wanted to do a breath bar that gradually runs out whilst in water. Trouble is I've already used the default health bar and I'm not sure how to go about doing another.
I'd need the bar to slowly run out when in water but when you surface the bar then refills.
If anyone can help then I'd be very thankful and would feature your username (or real name if you so desire) in the credits.
Thanks

~Blaze

Edited by Blazingocean, 28 February 2012 - 08:10 PM.

  • 0

#2 RangerX

RangerX

    GMC Member

  • GMC Member
  • 922 posts
  • Version:GM8.1

Posted 26 February 2012 - 06:53 PM

Your character should have a "in water" state (could be done by simply turning a boolean on).
Have a sprite that represents the full breathing bar.

Now, at every step, reduce the xscale of that breathing bar by a given amount (this will make the bar shrink on the x axis, just like if its depleting)
When the xscale of that breathing bar is 0 = character drowns.
  • 0

#3 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 26 February 2012 - 06:55 PM

Your character should have a "in water" state (could be done by simply turning a boolean on).
Have a sprite that represents the full breathing bar.

Now, at every step, reduce the xscale of that breathing bar by a given amount (this will make the bar shrink on the x axis, just like if its depleting)
When the xscale of that breathing bar is 0 = character drowns.

K i'll give it a shot

Edit: K i've got to the stage where im changing the xscale. But, do i have to do seperate events or is there a way to scale the obj relative to its current scale?

Edited by Blazingocean, 26 February 2012 - 07:01 PM.

  • 0

#4 RangerX

RangerX

    GMC Member

  • GMC Member
  • 922 posts
  • Version:GM8.1

Posted 26 February 2012 - 07:00 PM

Forgot to tell you (and sorry if that was obvious) but reduce the bar only when "in water=true" ...
  • 0

#5 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 26 February 2012 - 07:05 PM

yh but now im faced with another problem. I've got a var to change when in water however now my character just stops on top of the water :yucky: and i'm not sure how to fix it. Any ideas. It mite be easier if someone were to just write out a bit of code?
  • 0

#6 RangerX

RangerX

    GMC Member

  • GMC Member
  • 922 posts
  • Version:GM8.1

Posted 26 February 2012 - 07:10 PM

That "in water" variable shouldn't be a condition for your character to go down or to regulate your gravity. When you character touches water it should simply be turned on. (well, depending how your water is done).
We can't code stuff for you and there's multiple ways to make things work, it depends on what your game is and how you handled things so far. If you show me/explain more about how your character and your water works, I would be able to help your further. I would still prefer not to code for you because its better for you to learn the way of thinking and then learn to code after. This way you won't need much help at some point because you will truly understand what you're doing and how to debug your stuff.
  • 0

#7 Mr B

Mr B

    GMC Member

  • GMC Member
  • 172 posts

Posted 26 February 2012 - 07:15 PM

Don't make a new object for a breathing bar.

Define a variable breath = 100

in draw event:
draw_healthbar(x1,y1,x2,y2,breath,backcol,mincol,maxcol,0,showback,showborder)

remember to use draw_self() if you use the draw event of the character or a similar object.
  • 1

#8 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 26 February 2012 - 07:33 PM

Don't make a new object for a breathing bar.

Define a variable breath = 100

in draw event:

draw_healthbar(x1,y1,x2,y2,breath,backcol,mincol,maxcol,0,showback,showborder)

remember to use draw_self() if you use the draw event of the character or a similar object.

Now thats what I'm talking about! I'll message again whether it worked

Edit: This works perfectly - thank you very much. You will be featured in the credits. Would you like your username or real name featured?

Edited by Blazingocean, 26 February 2012 - 07:46 PM.

  • 0

#9 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 26 February 2012 - 07:55 PM

You don't actually need a SPRITE for the bar. You can just use draw_rectangle(x1,y1,x2,y2,outline). x1,y1,x2 and y2 define points 1 and 2, which are the top-left and the bottom-right corners of the rectangle, respectively. Three of those variables should be static, while the remaining one should vary with your breath variable. Outline should be set to 0.

draw_set_color(c_blue) //Sets the color of the bar
draw_rectangle(50,60,90,60+breath,0) //Draws the actual bar
draw_set_color(c_black) //Sets a new color
draw_rectangle(50,60,90,60+maxbreath,1) //Makes a second bar, which is a nice little black outline. This one always has the same size (the maximum breath possible).

  • 0

#10 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 26 February 2012 - 08:03 PM

You don't actually need a SPRITE for the bar. You can just use draw_rectangle(x1,y1,x2,y2,outline). x1,y1,x2 and y2 define points 1 and 2, which are the top-left and the bottom-right corners of the rectangle, respectively. Three of those variables should be static, while the remaining one should vary with your breath variable. Outline should be set to 0.

draw_set_color(c_blue) //Sets the color of the bar
draw_rectangle(50,60,90,60+breath,0) //Draws the actual bar
draw_set_color(c_black) //Sets a new color
draw_rectangle(50,60,90,60+maxbreath,1) //Makes a second bar, which is a nice little black outline. This one always has the same size (the maximum breath possible).

Thanks, I'll bear that in mind next time. Mr B's seems to be working fine for now tho

Edit: Hmm, the bar stays full when i'm in water now that i've tryed to make it fill back up.
I'm using this code in the step
if place_meeting(x,y,Swampwater)
then breathe -=0.5
else breathe +=2

Can any1 help?

Edited by Blazingocean, 26 February 2012 - 08:18 PM.

  • 0

#11 Thagrahn

Thagrahn

    GMC Member

  • GMC Member
  • 33 posts
  • Version:GM8

Posted 27 February 2012 - 06:10 AM

In your "else breathe +=2" is the problem since it is not checking for a max value for breathe, this means while you are out of the water the number can climb past 100.

if place_meeting(x,y,Swampwater)
then breathe -=0.5
else
if (breathe < 100)
then breathe +=2
else breathe = 100

The second if statement keeps the value for breathe from going above 100
  • 0

#12 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 27 February 2012 - 02:19 PM

That code could be a bit shorter:

if place_meeting(x,y,Swampwater)
then breathe -= 0.5 //Is this "then" actually needed? I've never used it so I wouldn't know.
else breathe = min(breathe+2,100) //Chooses the smallest between breath+2 and 100.

Edited by PetzI, 06 April 2012 - 04:46 PM.

  • 1

#13 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 27 February 2012 - 04:26 PM

That code could be a bit shorter:

if place_meeting(x,y,Swampwater)
then breathe -= 0.5 //Is this "then" actually needed? I've never used it so I wouldn't know.
else breathe += min(breathe+2,100) //Chooses the smallest between breath+2 and 100.

Wait - nonononono this isn't working :confused: i see no reason why it shouldn't. The bar just stays full.
In more detail : in character create, it creates a breath invisible obj.
in step it uses that code above.
in breath obj draw event it uses:

draw_healthbar(view_xview+2,view_yview+50,view_xview+60,view_yview+55,breathe,c_black,c_blue,c_blue,
0,true,true)

any1 know why it doesn't work? Is it a problem with my collisions?

Edited by Blazingocean, 27 February 2012 - 04:59 PM.

  • 0

#14 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 28 February 2012 - 05:19 AM

else breathe += min(breathe+2,100) //Chooses the smallest between breath+2 and 100.

There seem to be a little mistake.
else breathe = min(breathe+2,100) //Chooses the smallest between breath+2 and 100.
As to "then", that's a leftover of Pascal-style syntax that is deprecated in older versions a decade ago. It is no longer needed (nor mentioned in the manual) but is only kept for backward compatibility.
  • 1

#15 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 28 February 2012 - 05:59 PM


else breathe += min(breathe+2,100) //Chooses the smallest between breath+2 and 100.

There seem to be a little mistake.
else breathe = min(breathe+2,100) //Chooses the smallest between breath+2 and 100.
As to "then", that's a leftover of Pascal-style syntax that is deprecated in older versions a decade ago. It is no longer needed (nor mentioned in the manual) but is only kept for backward compatibility.

Cheers :thumbsup: that did it!
  • 0

#16 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1026 posts
  • Version:GM8.1

Posted 28 February 2012 - 06:53 PM

Oops, sorry about that.
  • 0

#17 Blazingocean

Blazingocean

    GMC Member

  • New Member
  • 27 posts
  • Version:GM8

Posted 28 February 2012 - 07:17 PM

Oops, sorry about that.

np
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users