Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help making a health bar
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Presto81




PostPosted: Thu Dec 08, 2016 4:18 pm   Post subject: Need help making a health bar

What is it you are trying to achieve?
I'm testing a health bar I'm going to use for a text-based game. I just need help making it work right.


What is the problem you are having?
I'm new at coding, so I just need some direct help.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


%Test Health Bar
var HP:nat
var maxHP:int:=10
var hit:boolean
HP:=maxHP

loop
put "Type 'true' to simulate damage"
get hit
if hit= true then
HP:=maxHP-2
put HP, "/10"
end if
exit when HP=0
end loop

%I really just cobbled this together based on my (very limited) knowledge.



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Presto81




PostPosted: Fri Dec 09, 2016 9:09 am   Post subject: RE:Need help making a health bar

I can't seem to get HP further down than it gets the first time. It does it on another one I tried too.

%Attack simulator
var monsterHP:nat:=5
var monstermaxHP:int:=5
var monsterNAME:string:= "TEST MONSTER 01"

var attack:boolean
var damage:int:=2

put monsterNAME, " approaches."
loop
put "Shall you attack? true/false"
get attack
if attack= true then
put "You stabbed TEST MONSTER 01."
put monsterNAME, " is at ", monsterHP-damage, "/", monstermaxHP
end if
if attack= false then
put monsterNAME, " stands robotically."
end if
exit when monsterHP=0
end loop
Insectoid




PostPosted: Fri Dec 09, 2016 1:26 pm   Post subject: RE:Need help making a health bar

What does monsterHP-damage output?
Presto81




PostPosted: Tue Dec 13, 2016 8:13 am   Post subject: RE:Need help making a health bar

It takes away health from the monster.
Presto81




PostPosted: Tue Dec 13, 2016 8:21 am   Post subject: RE:Need help making a health bar

What I really want to know is how to stack damage taken and if you can, how to make turns for a fight.
Gaming Lyfe




PostPosted: Fri Dec 16, 2016 7:07 pm   Post subject: RE:Need help making a health bar

I fiddled with your code for a second and it turns out that you aren't setting the monster's HP to be 2 lower than it was previously during every loop.

put monsterNAME, " is at ", monsterHP-2, "/", monstermaxHP
monsterHP:=monsterHP-2

I plugged this into the second code section and it allowed the damage to stack. Only problem is that it ends up with an error becuase the Monster's health can't be -1/5
Gaming Lyfe




PostPosted: Fri Dec 16, 2016 7:24 pm   Post subject: RE:Need help making a health bar

I made a program using your code where damage stacks perfectly. I also added a health bar for fun. The only problem is that get erases anything on that line so the health bar gets a bit mangled, but I'm sure you can fix that. (maybe make the health bar horizontal across the bottom or make the writing appear in the same spot instead of continuing down the page.)

%Attack simulator
var monsterHP:nat:=5
var monstermaxHP:int:=5
var monsterNAME:string:= "Megatron"

var attack:boolean

put monsterNAME, " approaches."
drawbox (600,10,620,310,black)
drawfillbox(601,10,619,71,red)
drawfillbox(600,70,619,130,red)
drawfillbox(600,130,619,190,red)
drawfillbox(600,190,619,250,red)
drawfillbox(601,251,619,309,red)
loop
put "Shall you attack? true/false"
get attack
if attack= true then
put "You stabbed ", monsterNAME, " who is now at ", monsterHP-1, "/", monstermaxHP, " HP"
monsterHP:=monsterHP-1
end if
if attack= false then
put monsterNAME, " stands robotically."
end if
if attack=true and monsterHP=4 then
drawfillbox(601,251,619,309,white)
end if
if attack=true and monsterHP=3 then
drawfillbox(601,190,619,250,white)
end if
if attack=true and monsterHP=2 then
drawfillbox(601,130,619,190,white)
end if
if attack=true and monsterHP=1 then
drawfillbox(601,70,619,130,white)
end if
if attack=true and monsterHP=0 then
drawfillbox(601,11,619,70,white)
end if
if monsterHP = 0 then
put "You killed the monster!"
end if
exit when monsterHP=0
end loop
Insectoid




PostPosted: Sat Dec 17, 2016 7:43 am   Post subject: Re: RE:Need help making a health bar

Presto81 @ Tue Dec 13, 2016 8:13 am wrote:
It takes away health from the monster.


Are you sure?
Presto81




PostPosted: Mon Dec 19, 2016 8:58 am   Post subject: RE:Need help making a health bar

Yes. It does, but my issue is that it doesn't go any further down.
Presto81




PostPosted: Mon Dec 19, 2016 9:00 am   Post subject: RE:Need help making a health bar

Thanks, BTW Gaming Life!
Presto81




PostPosted: Mon Dec 19, 2016 9:06 am   Post subject: RE:Need help making a health bar

Now I just need the monster to fight back...
Insectoid




PostPosted: Mon Dec 19, 2016 9:23 am   Post subject: RE:Need help making a health bar

No, it doesn't, that's what I was hinting at. That line of code does not do what you think it does. Unfortunately Gaming Lyfe gave it away so you don't get to learn what you did wrong.
Presto81




PostPosted: Mon Dec 19, 2016 9:26 am   Post subject: RE:Need help making a health bar

Thanks for trying to help anyway insectiod
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: