Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 11:47 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Health bar
PostPosted: Thu Jul 19, 2012 1:00 pm 
Offline

Joined: Wed Jul 18, 2012 3:46 pm
Posts: 2
Hey im little new, and only know how to make a simple game where you can just walk but i wounderd if someone could explain to me how to make a health bar or if someone knows a website that has good tutorials on slick :)


Top
 Profile  
 
 Post subject: Re: Health bar
PostPosted: Tue Jul 24, 2012 9:43 am 
Offline
User avatar

Joined: Wed Jun 20, 2012 8:10 pm
Posts: 54
There are several ways to do this, one is simply to draw rects depending on your health.
Let's say your health is represented by a variable health, and the max by maxhealth, you could do :

Code:
gr.setColor(Color.white);
gr.fillRect(x,y,maxhealth,10);
gr.setColor(Color.red);
gr.fillRect(x+1,y+1,health,8);


If you maxhealth were to change but you want to keep the same size you could do :

Code:
gr.setColor(Color.white);
gr.fillRect(x,y,HEALTHBARSIZE,10);
gr.setColor(Color.red);
gr.fillRect(x+1,y+1,HEALTHBARSIZE*health/maxhealth,8);


Pretty classic stuff, concerning tutorials, good luck, it's pretty hard to find (though this could easily be covered by google)

_________________
Seventeen


Top
 Profile  
 
 Post subject: Re: Health bar
PostPosted: Tue Jul 24, 2012 11:22 am 
Offline

Joined: Fri Jul 06, 2012 6:42 am
Posts: 3
Here are some tutorials. Some are older, some are newer, some are incomplete, some won't work by copy/paste/compile, but they should be fine, if you're looking for some basic slick and gamedev concept explanation.


Top
 Profile  
 
 Post subject: Re: Health bar
PostPosted: Tue Aug 14, 2012 7:04 pm 
Offline

Joined: Wed Jul 18, 2012 3:46 pm
Posts: 2
ok thx but how can i rotate the health bar


Top
 Profile  
 
 Post subject: Re: Health bar
PostPosted: Wed Aug 15, 2012 5:26 pm 
Offline
User avatar

Joined: Wed Jun 20, 2012 8:10 pm
Posts: 54
Quote:
public void rotate(float rx,
float ry,
float ang)

Apply a rotation to everything draw on the graphics context

Parameters:
rx - The x coordinate of the center of rotation
ry - The y coordinate of the center of rotation
ang - The angle (in degrees) to rotate by



on the object Graphics.
You should read the API documentation and some tutorials.

_________________
Seventeen


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group