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: [Request / Listing] Can Someone Help...  (Read 2835 times)

0 Members and 1 Guest are viewing this topic.

PoeFacedKilla

Prussian Killer Bee
[Request / Listing] Can Someone Help...
« on: May 05, 2006, 06:53:30 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Can someone tell me how to make a heart engine? Cause I need one for a game I am working on and all the free ones I have found aren't very good, So can someone help me make a heart engine that has fourth heats?
« Last Edit: February 09, 2012, 02:51:55 pm by Niek »
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine

Goodnight

Once and future Captain
Re: Can Someone Help...
« Reply #1 on: May 05, 2006, 09:37:13 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
I sent mine to Sol to put on the Engines topic.. they're free and "pretty good".. so just hang on if you want to use one of them.

To make your own, here are my suggestions. You'll need two global variables (such as global.hearts and global.totalhearts) which are between 0 and 20, and change in increments of 0.25. You'll also need sprites. I'd recommend using one sprite with 5 subimages; empty, 1/4, 1/2, 3/4, and full, in that order.

Make an object that will be your "Heart engine". In its Draw event, the number of hearts you'll want to draw is the value of global.totalhearts, rounded down. For example, if you have 12 hearts and 3 heart containers (global.totalhearts==12.75) you'd still just draw 12.

So, make a for-loop!

Code: [Select]
for (i=0; i<floor(global.totalhearts); i+=1) {
For every iteration of i, you'll have to check which subimage to draw, and where to draw it. You can get the value of the current heart from global.hearts-i. If it's less than or equal to 0, this heart is empty. Greater than or equal to 1, and it's full.

Code: [Select]
subimg = global.hearts - i
if subimg<0 { subimg=0 }
else if subimg>1 { subimg=1 }

For the position of the heart, start by making it relative to the view. Let's say you want the hearts to start 16 pixels from the left edge and 32 from the top edge:

Code: [Select]
heartx = view_xview[0] + 16 + ...
hearty = view_yview[0] + 32 + ...

And let's say for instance that each heart should be 8 pixels apart, in rows of 10. You might think to add + (i * 8) to the first line, BUT, that will keep drawing on the same line after 10 hearts. Check out the mod and div operators. mod gives you the remainder when one number is divided by another (good for the x position) and div gives the total number of times one number divides into the other (good for the y position).

Code: [Select]
heartx = view_xview[0] + 16 + ((i mod 10) * 8)
hearty = view_yview[0] + 32 + ((i div 10) * 8)

Then, just draw the sprite! And end the loop, of course.

Code: [Select]
draw_sprite(sprHeart, subimg, heartx, hearty)
}
Logged

PoeFacedKilla

Prussian Killer Bee
Re: Can Someone Help...
« Reply #2 on: May 05, 2006, 10:05:31 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Ok, a heart engine would simply be this then?:

objHeartEngine:

create:
Code: [Select]
var global.hearts;
var global.totalhearts;

Draw:

Code: [Select]
{ global.drawhearts==3; }

Code: [Select]
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] + 16 + ((i mod 10) * 8)
hearty = view_yview[0] + 32 + ((i div 10) * 8)

draw_sprite(sprHeart, subimg, heartx, hearty
)}
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine

Goodnight

Once and future Captain
Re: Can Someone Help...
« Reply #3 on: May 05, 2006, 10:39:55 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
Yep, pretty much. :)

Except... I don't see the use in this part:
Code: [Select]
{ global.drawhearts==3; }Not only is the variable unnecessary (as far as I can see) but it will probably also cause an error since you're using two = signs, unless GM is more lenient than I thought!

And also, I'd be careful about how those two global variables are declared. You may even want to put them in some other object, that will declare them when the game starts. Otherwise, every time that you change rooms, to a room that uses the Heart engine, they will reset.

And, I made a little mistake. subimg, in my code, will be either 0, 0.25, 0.5, 0.75, or 1. This number is which subimage should be drawn, and should be 0, 1, 2, 3, or 4 instead. So, multiply it by 4 before it's drawn.

Finally, ode to Miles Lombardi, I wrote out each line for you to describe how they work, but if you wanted, you could compress it all into just two lines by putting those calculations right into the draw_sprite() function. ;)
Code: [Select]
for (i=0; i<floor(global.totalhearts); i+=1)
draw_sprite(sprHeart, min(max(global.hearts-i,0),1)*4, view_xview[0]+16+((i mod 10)*8), view_yview[0]+32+((i div 10)*8))

By the way, Game Maker is notorious for rounding errors. There's a chance you'll have trouble getting the 3/4 full sprite drawn.
Logged

PoeFacedKilla

Prussian Killer Bee
Re: Can Someone Help...
« Reply #4 on: May 05, 2006, 10:51:49 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
how should I declare the variables?
Logged
the Indyboard - User Generated Social Forum | Now With Even More Discussion!
Poe, The Independent Programmer
  • Zelda Shrine

Goodnight

Once and future Captain
Re: Can Someone Help...
« Reply #5 on: May 07, 2006, 05:22:25 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
how should I declare the variables?
I was leaving that up to you, since it depends on how you want your game set up. I guess one way would be in the Room Creation Code of the first room in the game.
Logged
Re: Can Someone Help...
« Reply #6 on: May 07, 2006, 05:45:09 pm »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
how should I declare the variables?
I was leaving that up to you, since it depends on how you want your game set up. I guess one way would be in the Room Creation Code of the first room in the game.
Or the objects create event.
Logged

Goodnight

Once and future Captain
Re: Can Someone Help...
« Reply #7 on: May 07, 2006, 07:30:56 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
how should I declare the variables?
I was leaving that up to you, since it depends on how you want your game set up. I guess one way would be in the Room Creation Code of the first room in the game.
Or the objects create event.
There's a reason why I suggested not doing that. ;)
Logged
Pages: [1]   Go Up

 


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



Page created in 0.19 seconds with 53 queries.

anything