define NORMALSIZE 65536
define HALFSIZE 32768

// ******************************** Thanks to M210 for these. He saved me from lotsof work!

state drawNumX
  setvar col 0
  
  setvarvar tmp num
  modvar tmp 10
  setvar col 0
  addvar tmp 5299
  rotatesprite x y 65536 0  tmp 0 col 26 0 0 xdim ydim
ends

state drawNumY
  setvar col 0
  
  setvarvar tmp num
  modvar tmp 10
  setvar col 0
  addvar tmp 5079
  rotatesprite x y 65536 0  tmp 0 col 26 0 0 xdim ydim
ends

state drawweapnum
   setvarvar tmp num
   modvar tmp 10
   addvar tmp 5299
   rotatesprite x y 57344 0  tmp 0 col 26 0 0 xdim ydim
   addvar x -4
    ifvarg num 9
    {
      setvarvar tmp num
      divvar tmp 10
      modvar tmp 10
      addvar tmp 5299
      rotatesprite x y 57344 0  tmp 0 col 26 0 0 xdim ydim
      addvar x -4
    }
    ifvarg num 99
    {
      setvarvar tmp num
      divvar tmp 100
      addvar tmp 5299
      rotatesprite x y 57344 0  tmp 0 col 26 0 0 xdim ydim
      
    }
ends

state DISPLAYBLUEKEY
setvar xdr 305
setvar ydr 50
setvar pdr 0
setvar TEMP2 6283
rotatesprite xdr ydr HALFSIZE adr TEMP2 sdr pdr odr ZERO ZERO xdim ydim
ends

state DISPLAYREDKEY
setvar xdr 300
setvar ydr 45
setvar pdr 0
setvar TEMP2 6285
rotatesprite xdr ydr HALFSIZE adr TEMP2 sdr pdr odr ZERO ZERO xdim ydim
ends

state DISPLAYYELLOWKEY
setvar xdr 295
setvar ydr 40
setvar pdr 0
setvar TEMP2 6287
rotatesprite xdr ydr HALFSIZE adr TEMP2 sdr pdr odr ZERO ZERO xdim ydim
ends

onevent EVENT_DISPLAYREST

getuserdef[THISACTOR].screen_size num
setuserdef[THISACTOR].screen_size 0
ifvare num 4
{ 
ifvare hudtype 0 setvar hudtype 1 else
ifvare hudtype 1 setvar hudtype 0 
savegamevar hudtype
}
ifvare hudtype 0
{
setuserdef[THISACTOR].screen_size 8
// bar
  rotatesprite 0 168 65536 0 5298 0 0 26 0 0 xdim ydim
  rotatesprite 103 168 65536 0 5297 0 0 26 0 0 xdim ydim

// health

  getplayer[THISACTOR].last_extra num
  digitalnumberz 2472 76 174 num -16 0 26 0 0 xdim ydim 65536

// ammo
  getplayer[THISACTOR].curr_weapon num
  getplayer[THISACTOR].ammo_amount num num
  digitalnumberz 2472 25 174 num -16 0 26 0 0 xdim ydim 65536
  
  getplayer[THISACTOR].max_ammo_amount 3 num
  setvar x 310 setvar y 173 state drawweapnum
  getplayer[THISACTOR].max_ammo_amount 2 num
  setvar x 310 setvar y 179 state drawweapnum
  getplayer[THISACTOR].max_ammo_amount 4 num
  setvar x 310 setvar y 185 state drawweapnum
  getplayer[THISACTOR].max_ammo_amount 9 num
  setvar x 310 setvar y 191 state drawweapnum

  getplayer[THISACTOR].ammo_amount 3 num
  setvar x 283 setvar y 173 state drawweapnum
  getplayer[THISACTOR].ammo_amount 2 num
  setvar x 283 setvar y 179 state drawweapnum
  getplayer[THISACTOR].ammo_amount 4 num
  setvar x 283 setvar y 185 state drawweapnum
  getplayer[THISACTOR].ammo_amount 9 num
  setvar x 283 setvar y 191 state drawweapnum

// armor
  getplayer[THISACTOR].shield_amount num
  digitalnumberz 2472 207 174 num -16 0 26 0 0 xdim ydim 65536

// keys
  getplayer[THISACTOR].got_access num
  setvar sc 40000
  ifvarand num  4 rotatesprite 238 182 73728 0 2371 0 0 26 0 0 xdim ydim // YELLOW
  ifvarand num  2 rotatesprite 238 192 73728 0 2372 0 0 26 0 0 xdim ydim // RED
  ifvarand num  1 rotatesprite 238 172 73728 0 2370 0 0  26 0 0 xdim ydim // BLUE

// weapons

getplayer[THISACTOR].gotweapon 1 num
ifvare num 0
{ 
setvar col 0 setvar num 2
setvar x 110 setvar y 172 state drawNumY 
} else
{ 
setvar col 0 setvar num 2
setvar x 110 setvar y 172 state drawNumX 
}
getplayer[THISACTOR].gotweapon 2 num
ifvare num 0
{ 
setvar col 0 setvar num 3
setvar x 122 setvar y 172 state drawNumY 
} else
{ 
setvar col 0 setvar num 3
setvar x 122 setvar y 172 state drawNumX 
}
getplayer[THISACTOR].gotweapon 3 num
ifvare num 0
{ 
setvar col 0 setvar num 4
setvar x 134 setvar y 172 state drawNumY 
} else
{ 
setvar col 0 setvar num 4
setvar x 134 setvar y 172 state drawNumX 
}
getplayer[THISACTOR].gotweapon 4 num
ifvare num 0
{ 
setvar col 0 setvar num 5
setvar x 110 setvar y 182 state drawNumY 
} else
{ 
setvar col 0 setvar num 5
setvar x 110 setvar y 182 state drawNumX 
}
getplayer[THISACTOR].gotweapon 5 num
ifvare num 0
{ 
setvar col 0 setvar num 6
setvar x 122 setvar y 182 state drawNumY 
} else
{ 
setvar col 0 setvar num 6
setvar x 122 setvar y 182 state drawNumX 
}
getplayer[THISACTOR].gotweapon 6 num
ifvare num 0
{ 
setvar col 0 setvar num 7
setvar x 134 setvar y 182 state drawNumY 
} else
{ 
setvar col 0 setvar num 7
setvar x 134 setvar y 182 state drawNumX 
}
getplayer[THISACTOR].gotweapon 7 num
ifvare num 0
{ 
setvar col 0 setvar num 8
setvar x 110 setvar y 192 state drawNumY 
} else
{ 
setvar col 0 setvar num 8
setvar x 110 setvar y 192 state drawNumX 
}
getplayer[THISACTOR].gotweapon 8 num
ifvare num 0
{ 
setvar col 0 setvar num 9
setvar x 122 setvar y 192 state drawNumY 
} else
{ 
setvar col 0 setvar num 9
setvar x 122 setvar y 192 state drawNumX 
}
getplayer[THISACTOR].gotweapon 9 num
ifvare num 0
{ 
setvar col 0 setvar num 0
setvar x 134 setvar y 192 state drawNumY 
} else
{ 
setvar col 0 setvar num 0
setvar x 134 setvar y 192 state drawNumX 
}

setvar RETURN 1
}
ifvare hudtype 1
{
setuserdef[THISACTOR].screen_size 0
}

ifvare hudtype 0
{

ifvarg PLAYERHP 120
 {
  setvar TEMP3 6193
 }

 switch PLAYERHP
  case 120 case 119 case 118 case 117 case 116 case 115 case 114 case 113 case 112 case 111 case 110 case 109 case 108 case 107 case 106 case 105
  case 104 case 103 case 102 case 101 case 100
   setvar TEMP3 6168
   break
  case 99 case 98 case 97 case 96 case 95 case 94 case 93 case 92 case 91 case 90
  case 89 case 88 case 87 case 86 case 85 case 84 case 83 case 82 case 81 case 80
  case 79 case 78 case 77 case 76 case 75 case 74 case 73 case 72 case 71 case 70
   setvar TEMP3 6171
   break
  case 69 case 68 case 67 case 66 case 65 case 64 case 63 case 62 case 61 case 60 
  case 59 case 58 case 57 case 56 case 55 case 54 case 53 case 52 case 51 case 50
   setvar TEMP3 6174
   break
  case 49 case 48 case 47 case 46 case 45 case 44 case 43 case 42 case 41 case 40 case 39 case 38 case 37 case 36 case 35 case 34 case 33 case 32
  case 31 case 30
   setvar TEMP3 6177
   break
  case 29 case 28 case 27 case 26 case 25 case 24 case 23 case 22 case 21 case 20 case 19 case 18 case 17 case 16 case 15 case 14 case 13 case 12
  case 11 case 10 case 9 case 8 case 7 case 6 case 5 case 4 case 3 case 2 case 1
   setvar TEMP3 6180
   break
  case 0
   setvar TEMP3 6192
   break
 endswitch

ifp ponsteroids
{
  setvar TEMP3 6198
}

ifvare GODMODE 1
{
  setvar TEMP3 6198
}

setvar xdr 160
setvar ydr 178
rotatesprite xdr ydr NORMALSIZE adr TEMP3 sdr 0 odr ZERO ZERO xdim ydim

}
else
ifvare hudtype 1
{
setvar zdr 65536
setvar xdr 20
setvar ydr 158
setvar TEMP 5178
getplayer[THISACTOR].got_access ACCESCARD
ifvare ACCESCARD 1
{
state DISPLAYBLUEKEY
}
ifvare ACCESCARD 2
{
state DISPLAYREDKEY
}
ifvare ACCESCARD 3
{
state DISPLAYBLUEKEY
state DISPLAYREDKEY
}
ifvare ACCESCARD 4
{
state DISPLAYYELLOWKEY
}
ifvare ACCESCARD 5
{
state DISPLAYYELLOWKEY
state DISPLAYBLUEKEY
}
ifvare ACCESCARD 6
{
state DISPLAYYELLOWKEY
state DISPLAYREDKEY
}
ifvare ACCESCARD 7
{
state DISPLAYYELLOWKEY
state DISPLAYREDKEY
state DISPLAYBLUEKEY
}

ifvarg PLAYERHP 120
 {
  setvar TEMP3 6193
 }

 switch PLAYERHP
  case 120 case 119 case 118 case 117 case 116 case 115 case 114 case 113 case 112 case 111 case 110 case 109 case 108 case 107 case 106 case 105
  case 104 case 103 case 102 case 101 case 100
   setvar TEMP3 6168
   break
  case 99 case 98 case 97 case 96 case 95 case 94 case 93 case 92 case 91 case 90
  case 89 case 88 case 87 case 86 case 85 case 84 case 83 case 82 case 81 case 80
  case 79 case 78 case 77 case 76 case 75 case 74 case 73 case 72 case 71 case 70
   setvar TEMP3 6171
   break
  case 69 case 68 case 67 case 66 case 65 case 64 case 63 case 62 case 61 case 60 
  case 59 case 58 case 57 case 56 case 55 case 54 case 53 case 52 case 51 case 50
   setvar TEMP3 6174
   break
  case 49 case 48 case 47 case 46 case 45 case 44 case 43 case 42 case 41 case 40 case 39 case 38 case 37 case 36 case 35 case 34 case 33 case 32
  case 31 case 30
   setvar TEMP3 6177
   break
  case 29 case 28 case 27 case 26 case 25 case 24 case 23 case 22 case 21 case 20 case 19 case 18 case 17 case 16 case 15 case 14 case 13 case 12
  case 11 case 10 case 9 case 8 case 7 case 6 case 5 case 4 case 3 case 2 case 1
   setvar TEMP3 6180
   break
  case 0
   setvar TEMP3 6192
   break
 endswitch

ifp ponsteroids
{
  setvar TEMP3 6198
}

ifvare GODMODE 1
{
  setvar TEMP3 6198
}

setvar xdr 300
setvar ydr 10
rotatesprite xdr ydr NORMALSIZE adr TEMP3 sdr 0 odr ZERO ZERO xdim ydim

ifvarg PARMOUR 0
{
setvar xdr 15
setvar ydr 15
setvar TEMP3 54
rotatesprite xdr ydr HALFSIZE adr TEMP3 sdr 0 odr ZERO ZERO xdim ydim
digitalnumber DIGITALNUM xdr ydr PARMOUR sdr 0 33 ZERO ZERO xdim ydim
}
}
// ammo of player for hud 2
 getplayer[THISACTOR].curr_weapon num
 getplayer[THISACTOR].ammo_amount num num
 digitalnumberz 2472 25 174 num -16 0 26 0 0 xdim ydim 65536
// health of player for hud 2
 getplayer[THISACTOR].last_extra num
 digitalnumberz 2472 76 174 num -16 0 26 0 0 xdim ydim 65536

endevent

onevent EVENT_DISPLAYSBAR
  setvar RETURN 1
endevent

// ********************************