Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [GM6] Help with heart engine  (Read 1070 times)

0 Members and 1 Guest are viewing this topic.

PoeFacedKilla

Prussian Killer Bee
[GM6] Help with heart engine
« on: October 30, 2009, 07:15:16 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Ok, i've had game maker for awhile, but I never really wanted to use it.  But now i've decided I really want to learn it.  So I started with a heart engine, but I don't know how to make the hearts go buy fourths.  I can draw a sprite the number of times I need, but i don't know how to make it show the heart in fourths.

in the create event
Code: [Select]
{

    /* Variables for the HUD */
    var global.totalhearts = 10;
    var global.hearts = 10;

}
in the draw event
Code: [Select]
{

    /* Draw Hearts */
    for( i = 0; i < floor( global.totalhearts ); i += 1 )
    {
   
        subimg = global.hearts - i;
        if( subimg < 0 )
        {
       
            subimg = 0;
       
        } else if( subimg > 1 )
        {
       
            subimg = 1
       
        }
       
        heartx = view_xview[0] + 5 + (i*25);
   
        draw_sprite( spr_heart_full, subimg, heartx, 1 );
       
    }

}
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine
Re: [GM6] Help with heart engine
« Reply #1 on: October 30, 2009, 07:37:26 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Well, you'll need an image for each piece of the heart (I think that much is a given though.)

The way I do it is I have a variable keeping track of the "active" heart and how much of that heart is available (i.e. 1, 2, 3 or 4).  I pass that number to the sub image so it draws the proper container, and when the available heart is 0, that heart is no longer the active heart and the one before it becomes active.
Logged



i love big weenies and i cannot lie
Re: [GM6] Help with heart engine
« Reply #2 on: October 31, 2009, 09:08:12 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Like MG said, but there is another way to do it, where you just keep track of the 2 variables you have (hearts and totalhearts). There are 3 things you need to know (which are pretty much a given):
1) The number of full hearts you need to draw.
2) The type of active heart to draw
3) The number of empty hearts.
Then the following math needs to be done:

1) full = hearts div 4; Followed by a for loop that draws the number of full.

2) active = hearts mod 4; Followed by an if or switch statement. If the value is 0 then that means you have drawn 1 full heart to many. The place where you draw it depends on the value of full.

3) empty = (totalhearts - hearts) div 4; Followed by another loop to draw the number of empty. The start position depends on the values of full and active.

Note that I assumed that you used a numeral value health system and that 10 hearts is equal to 40 points. But you probably used a real value health system, thus a quarter heart is represented with 0.25. If so you need to use 1 instead of 4. Or you could use floor( ) instead of div 4 and frac( ) instead of mod 4.

THose are my 2 cents
Logged

Mamoruanime

@Mamoruanime
Re: [GM6] Help with heart engine
« Reply #3 on: November 01, 2009, 03:55:54 am »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
I usually go with the way Neik described; it's never failed me in the past.

I'm actually curious to check out MG-Zero's though; I never thought about doing it that way D:
Logged
Re: [GM6] Help with heart engine
« Reply #4 on: November 02, 2009, 12:59:09 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Heh, I tend to come up with some...interesting algorithms for these things.  Oh, I should mention I've never actually used this with GM.  I used it in developing the Harvest Engine.
« Last Edit: November 02, 2009, 01:10:40 am by MG-Zero »
Logged



i love big weenies and i cannot lie
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.058 seconds with 47 queries.

anything