Health Bar help
Author |
Message |
Wasabicheese
|
Posted: Wed May 20, 2009 1:01 pm Post subject: Health Bar help |
|
|
do you know of any tutorials that focus on health bars? heres my code, if you think you can help me. Where i have put "collision" in my program, is where i want the the character to take damage. when the health hits zero, its a game over. Could anyone help me?
Turing: |
%Music
process BgmSound
loop
Music.PlayFile ("music2.mp3")
end loop
end BgmSound
fork BgmSound
View.Set ("title:Space Survival")
%Intro
var x3, y3 : int %Intro Coordinates
x3 := 35
y3 := 60
var mypic4 : int := Pic.FileNew ("intro.bmp") %Intro
drawfillbox (1, 1, 660, 470, black) %Background
Pic.Draw (mypic4, x3, y3, 0)
View.Update
delay (3000)
cls
%Logo Intro
var x, y : int %Logo Coordinates
x := 160
y := 10
var mypic3 : int := Pic.FileNew ("logo.bmp") %Logo
drawfillbox (1, 1, 660, 470, black) %Background
Pic.Draw (mypic3, x, y, 0)
View.Update
delay (3000)
cls
%Title Screen
var x4, y4 : int %Title Coordinates
x4 := 35
y4 := 60
var mypic6 : int := Pic.FileNew ("Title.bmp") %Title
drawfillbox (1, 1, 660, 470, black) %Background
Pic.Draw (mypic6, x4, y4, 0)
View.Update
delay (5000)
cls
%
%Controls Screen
var x5, y5 : int %Controls Coordinates
x5 := 45
y5 := 60
var mypic7 : int := Pic.FileNew ("Controls.bmp") %Controls image
drawfillbox (1, 1, 660, 470, black) %Background
Pic.Draw (mypic7, x5, y5, 0)
delay (5000)
cls
%
%Story Screen
var x6, y6 : int %Story Coordinates
x6 := 45
y6 := 60
var mypic8 : int := Pic.FileNew ("story.bmp") %Story image
drawfillbox (1, 1, 660, 470, black) %Background
Pic.Draw (mypic8, x5, y5, 0)
delay (7000)
cls
%
var mDamage, cHP : int
var mypic1 : int := Pic.FileNew ("StrikerRight.bmp")
var mypic2 : int := Pic.FileNew ("Enemy.bmp")
var CharacterX : array 1 .. 2 of int
var CharacterY : array 1 .. 2 of int
var MonsterX : array 1 .. 2 of int
var MonsterY : array 1 .. 2 of int
var MaxHealth, Health, Dmg: int
var chars : array char of boolean
View.Set ("offscreenonly, graphics:650;410")
CharacterX (1) := 50 % Characters X value (Horizontal Axis)
CharacterY (1) := 50 % Characters Y value (Verticle Axis
CharacterX (2) := 0
CharacterY (2) := 0
MonsterX (1) := 200 % Monsters X value (Horizontal Axis)
MonsterY (1) := 200 % Monsters Y value (Verticle Axis)
MonsterX (2) := 0
MonsterY (2) := 0
cHP := 1000
const Speed := 5
MonsterX (2) := MonsterX (1) + Pic.Width (mypic2 )
MonsterY (2) := MonsterY (1) + Pic.Height (mypic2 )
procedure mDamageHandler % Damage System
mDamage := Rand.Int (1, 60)
end mDamageHandler
% Health System
procedure cHealthHandler
end cHealthHandler
procedure HitTest
if CharacterX (2) > MonsterX (1) and CharacterX (1) < MonsterX (2) and CharacterY (2) > MonsterY (1) and CharacterY (1) < MonsterY (2) then
put "collision!"
end if
end HitTest
loop
Input.KeyDown (chars )
if chars (KEY_UP_ARROW) then
CharacterY (1) + = Speed
HitTest
CharacterY (2) := CharacterY (1) + Pic.Height (mypic1 )
if CharacterY (1) + Pic.Height (mypic1 ) >= maxy then
CharacterY (1) := maxy - Pic.Height (mypic1 )
end if
end if
if chars (KEY_RIGHT_ARROW) then
CharacterX (1) + = Speed
HitTest
CharacterX (2) := CharacterX (1) + Pic.Width (mypic1 )
if CharacterX (1) + Pic.Width (mypic1 ) >= maxx then
CharacterX (1) := maxx - Pic.Width (mypic1 )
end if
end if
if chars (KEY_LEFT_ARROW) then
CharacterX (1) - = Speed
HitTest
CharacterX (2) := CharacterX (1) + Pic.Width (mypic1 )
if CharacterX (1) <= 0 then
CharacterX (1) := 0
end if
end if
if chars (KEY_DOWN_ARROW) then
CharacterY (1) - = Speed
HitTest
CharacterY (2) := CharacterY (1) + Pic.Height (mypic1 )
if CharacterY (1) <= 1 then
CharacterY (1) := 1
end if
end if
View.Set("offscreenonly")
Pic.Draw (mypic2, MonsterX (1), MonsterY (1), picMerge) % Enemy
Pic.Draw (mypic1, CharacterX (1), CharacterY (1), picMerge) % Character
View.Update
delay (13)
cls
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Wed May 20, 2009 1:21 pm Post subject: RE:Health Bar help |
|
|
Your health bar is just a visual representation of some sort of internal hit point value, compared to an internal hit point maximum.
For example, a unit might have 100hp at maximum (when it's created), but only 37hp at the moment; you would therefore have 37 / 100 = 0.37 of the health bar green, with the rest red or black or whatever. If the health bar is allowed to be 40 pixels across, you would have 40 * 0.37 ~= 15 pixels of green, and 25 pixels of red.
You can draw them with Draw.FillBox(). |
|
|
|
|
![](images/spacer.gif) |
|
|