I took Mike's Health Bar tutorial and modified it heavily so you can calculate your players Health based on two stats: STR and DEX.
It took me awhile to figure things out on my own but I got the basic jist of it after constant and endless fiddling with variables.
The result is the code you see below:
` This is done just like Mike's tutorial the only exception
` is we're using stats to calculate health instead of
` just using a direct approach, this method is good for RPG based games.
` I also removed the limits because unlike FPS's there are no limits on
` Health, Mana, and Stats in an RPG (at least the good RPG's.)
sync on : sync rate 60
backdrop on : color backdrop 60
set text size 24
ink rgb (255,255,255),1
`Health box variable
H=0 `Health: its set at zero so we can see how STR and DEX directly affect it.
`Stats, these are what we'll use to calculate our maximum health, mana, etc.
ST_STR = 0 `Strength
ST_DEX = 0 `Dexterity
ST_WIZ = 0 `Wisdom: we won't actually be using this but I thought I'd put it here so you could see how
`you can add your own variables to do the same with Mana.
do `enter loop
`health box setup
`this box is so we have a visual refrence on the amount of Health we have.
box 10,15,H,20
`Increase HP Maximum if STR+DEX increases by 1 point.
`this is where we do our STR and DEX calculation the
`result will be our Maximum Health increasing.
`we divide by two because there are two stats that
`determine maximum health.
if ST_STR+1
H = (ST_STR+ST_DEX)/2
endif
`test functions go here
`these are simple if/endif statements so we can play
`with our stats with simple keypresses, we use
`keystates so we can press more than one key at a time.
`On a side note these are test keys and can be replaced
`or removed.
`I include these keys just to show you
`how this program works
` W key increases STR
if keystate(17)=1
ST_STR = ST_STR+1
endif
`S key decreases STR
if keystate(31)=1
ST_STR = ST_STR-1
endif
`Q key increases DEX
if keystate(16)=1
ST_DEX = ST_DEX+1
endif
`A key decreases DEX
if keystate(30)=1
ST_DEX = ST_DEX-1
endif
set cursor 5,20 `these coordinates are where our text will be placed when the program runs.
print "Health / "+str$((int(H/1))*1) `this is so the text "Health" is dsplayed and next to it the amount.
set cursor 5,100
print "STR / "+str$((int(ST_STR))*1) `this displays out amount of strength on the screen.
set cursor 5,112
print "DEX / "+str$((int(ST_DEX))*1) `ditto for dexterity
sync
loop `exit loop
Not the best method probably but it was the easiest..at least for me.
Edit: terribly sorry folks I forgot to put parenthisis around the calculation in the if statement:
if ST_STR+1
H = (ST_STR+ST_DEX)/2
endif
is what it should be, terribly sorry.