The VG Resource

Full Version: PBG's ADVENTURE! (Yeah!)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2


ALPHA TEST 1: I'm making this a thing. It is a thing. I'm rebuilding the engine, as the previous engines coding was a big mess of text. I've sorted it out, and so far it's working out. What you'll see is a test room with the current sprite set. No tileset however.
Controls are simple;

I'll be adjusting the run to use momentum soon. Now, what would be the best way to make:
-a frame long landing sprite
-a heart based health bar
-text boxes RPG style

UPDATE: tiles and placeholder background added, sword added.
Aerial spin attack i-- EDIT: Added aerial spin attack with place holder sprite.

UPDATE 2: Aerial attack has a new sprite, you can roll if you use the attack close enough to the ground. Hold K to use the attack longer. Added platforms you can jump through. One test ball enemy. Use F8 to restart the test. Hurt sprite is WIP.
So, I won't be including SpaceHamster like I intended. This'll be a game based mainly around PBG. So... Does anyone have a good editable Zelda based heart system and RPG text box system?
So... I need help with the health system. It's gonna be a Zelda like health system. I have the variables down, but I'm not sure how to actually draw the hearts. In specific:
-Drawing the amount of hearts PBG has
-making a new row every 10 hearts......-
Well, if you played Zelda, you know what I'm going for. I'd love some help making this code.
Are you unsure of of to set up the code for a health system, or just specifically rendering hearts appropriately?

How do you track the current health? Since each heart has a smallest value of 1/4, you can use integers to represent health. For every 4 whole numbers, you have 1 whole heart. Doing this makes it easier to render than using decimal numeric types and comparing decimal values like .25, .5, .75, etc. You can use the % (remainder) operator like so:

wholeHearts = totalHealth / 4; //integer math, so 3/4 = 0 whole hearts.
fractionalHearts = totalhealth % 4; //Ex) 5 % 4 = 1, 4 % 4 = 0, 3 % 4 = 3

For the fractionalHearts, you render whatever sprite represents the fraction, 1 -> 1/4, 2 -> 1/2, 3 -> 3/4.

To render new rows of hearts, you can probably iterate over all your hearts when rendering while tracking the total. If the total is greater than the max row size, then you reset the render position and offset in the YAxis.
:p Welp, I shoulda mentioned that I'm not using half and quarter hearts... I wasn't planning on needing half hearts. I'd just prefer it slightly simpler. Each heart is a hit basically. I don't think any attacks would take more than 3 hearts.

Anyways, I need help rendering the hearts. I keep track of it using two variables: hp and maxhp, both set as global variables. Obviously collecting a heart container adds to maxhp by one. It's "simple". I need code that'll render the total amount of hearts, which hearts are empty, and it to render a new row every 10 hearts Cute Thanks to anyone that helps!
I was gonna explain it, but this little section of code should show a solution much quicker:

//I assume that hp and maxhp are whole integer values and that each of these variables are defined
    short hp, maxhp, maxHeartsPerRow;
    short cellX, cellY, cellPixelWidth, cellPixelHeight;
    short wholeHeartSpriteID, emptyHeartSpriteID;

    //originX and originY are the top left position to begin rendering hearts from.
    short i;
    short originX, originY, posX, posY;

    Imagine the hearts being rendered in cells like in a tile grid.
    CellX, CellY refer to their cell index. Using i, the number of
    hearts rendered, we can determine the position to render each heart.
    for (i = 0; i < maxhp; i++)
        cellX = i % maxHeartsPerRow;
        cellY = i / maxHeartsPerRow;

        posX = cellX * cellPixelWidth + originX;
        posY = cellY * cellPixelHeight + originY;

        if (i < hp)
            RenderSprite(wholeHeartSpriteID, posX, posY);
            RenderSprite(emptyHeartSpriteID, posX, posY);
Now, are any of those functions that aren't supported by GameMaker 8.0...? Another thing i shoulda mentioned earlier...
Oh yeah, they're just psuedo functions. Look at the overarching idea. You determine the XY location of each heart by using it's index. The way its calculated causes hearts to begin a new row every 10 hearts, full or empty. After you find the location, you just use whatever GM function you know of to render the appropriate sprite.
Alright... What's the Short function for? That was my main concern.
The only function is "RenderSprite(...)". The rest of the names are just integers.
Ok, so, what is the reasoning for listing the variables at the top after the word "short"?

short hp, maxhp, maxHeartsPerRow, i;
    short cellX, cellY, cellPixelWidth, cellPixelHeight;
    short wholeHeartSpriteID, emptyHeartSpriteID;

Is this setting variables or...?

Also, what would I replace cellX/cellY, cellPixelWidth/height with? Or should I replace them at all?
Declaring the variables in a list like that only shows that the following variables are all of the same type.

//I assume that hp and maxhp are whole integer values and that each of these variables are defined
    short hp, maxhp, maxHeartsPerRow;
    short cellPixelWidth, cellPixelHeight;
    short originX, originY;
    short wholeHeartSpriteID, emptyHeartSpriteID;

    //originX and originY are the top left position to begin rendering hearts from.
    short i;
    short posX, posY;
    short cellX, cellY;
Note that I moved "originX" and "originY" to the group of variables that you set yourself, and moved "cellX" and "cellY" to the group of variables that are determined within the loop which you do not set yourself. For the first group, I assume that you have all of these values and can set them. "originX" and "originY" represent the starting position to render the hearts at. "cellPixelWidth" and "cellPixelHeight" represent the size of each heart, though the values can include some padding (be larger than the sprite sizes).
Dammit, I updated my post after you post a reply to it. Fortunately you answered the question anyways. Alright, thanks for clearing that up!

EDIT: One last thing, whats the % for?
It's the remainder operator. It's the value that you would get after long division and getting a remainder. So:

7 % 3 = 1
6 % 3 = 0 (no remainder from 6 / 3)
5 % 3 = 2
4 % 3 = 1
3 % 3 = 0
2 % 3 = 2
1 % 3 = 1
0 % 3 = 0


I'll make something real quick to show how it's used to find cellX.
Well, the problem is, i don't believe there's anything with that function in GameMaker.
Pages: 1 2