Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Rendering Health-System like Zelda or MineCraft?  (Read 1453 times)
0 Members and 1 Guest are viewing this topic.
Offline roseslayer

Senior Devvie

Medals: 12

« Posted 2013-03-29 12:16:16 »

Hello there,

Currently I'm working on a small RPG game, but in a RPG game you need health. So I started to begin with coding the health system. The only part that´s still missing is the part of rendering them. The part that I already finished is that you have total 12 hp (in half heart so 6 hp total) and the damage system.

My idea was to make "half" hearts, this aren't really half hearts but just the same heart image with other color.
If you have as example 7 hp (3,5 hearts total) But how can you code the rendering of this idea?

I don't want the full code, give me some hints/tips how I can do this. I still need too learn alot.
Offline Cero
« Reply #1 - Posted 2013-03-29 12:22:21 »

eeeh sure, well its kinda different if you use opengl directly or a lib or java2d...

Offline Opiop
« Reply #2 - Posted 2013-03-29 12:22:45 »

I would just make textures for all the hearts. That's just my lazy side talking though, I'm sure there's a way to actually do it with code. It would probably be much harder than just texturing hearts for every possibility though. Maybe someone else has a suggestion?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roseslayer

Senior Devvie

Medals: 12

« Reply #3 - Posted 2013-03-29 12:24:51 »

I want to save as much space in my spritesheet as possible, so not the greatest option.

I'm using eclipse with java jdk1.7_0 (maybe jdk1.6_0) only so nothing else then that.

Offline matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

« Reply #4 - Posted 2013-03-29 12:27:40 »

It's really easy:

int numberOfFilledHearts = hp / 2; // <- This HAS to be an Integer!
boolean extraHalfHeart = hp % 2 == 1;

int i = 0;
for (; i < numberOfFilledHearts; i++) {
    drawFilledHeart(x + i*heartWidth, y);
if (extraHalfheart)
    drawHalfHeart(x + i*heartWidth, y);

That's it.
(btw, the % operator is modulo <edit>modulo = remainder of division. So i % 2 == 0 for example checks, whether the number is a round number</edit>)

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline roseslayer

Senior Devvie

Medals: 12

« Reply #5 - Posted 2013-03-29 12:29:56 »


I will try the code out, but already thanks for helping me out!

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

numerical (54 views)
2017-02-21 07:32:16

numerical (53 views)
2017-02-21 07:31:46

theagentd (160 views)
2017-02-18 13:42:33

theagentd (163 views)
2017-02-18 13:35:16

h.pernpeintner (1326 views)
2017-01-24 22:39:11

h.pernpeintner (1314 views)
2017-01-24 22:38:32

Galdo (1874 views)
2017-01-12 13:44:09

Archive (1966 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2505 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2307 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!