How to make a health bar

From EDukeWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

gamevar temp 0 2
gamevar temp2 0 2
gamevar xvar 0 2

define BARSCALE 10

onevent EVENT_DISPLAYREST {
	setvar xvar 0 // set starting x coordinate
	getactor[THISACTOR].extra temp // get the player's health.
	ifvarg temp 0 { // only proceed if the player has any health.
		setvarvar temp2 temp // save a copy for later.
		divvar temp BARSCALE // make each column worth 10 hp.
		modvar temp2 BARSCALE // gets the remainder of the division so that...
		ifvarg temp2 0 {
			addvar temp 1 // ...we can round up. each column will only disappear when all 10 hp are gone.
		}
		whilevarn temp 0 { // repeat for each column
			rotatesprite xvar 182 65536 0 NOTCHON 0 8 16 0 0 xdim ydim // draws one column at (xvar,182)
			addvar xvar 5 // move to the right
			subvar temp 1 // next column
		}
	}
} endevent