TGC Codebase Backup



ATB System by Jacava

27th May 2005 4:55
Summary

Just something I got bored enough to do one day. Should work, but can't compile due to DB Errors.



Description

Select key is X. Nothing else is in here, and there are currently no other executable commands.
Add in your own sprites (you'll need to add some, or remove the commands for them), make it 3D, do whatever the hell you like with it. I just made it because I got bored.
THIS MUST REMAIN FREEWARE. The ATB System I believe is copyrighted by Square Enix, and if it isn't I still just want to be sure.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Project: ATB System
Rem Created: 02/04/2005 15:14:00

Rem ***** Main Source File *****

Rem Setup
Hide Mouse
RANDOMIZE TIMER()

Rem Load Media
`Load Image "",1 (Character Image(s))
`Load Image "",2 (Enemy image(s))
`Load Music "",1 (Music, duh!)

Rem Give Variables Values
time1=rnd(10000)
time2=rnd(10000)
time3=rnd(10000)
Etime=rnd(10000)
HP1#=8760
aHP1#=HP1#
bHP1=HP1#
MaxHP1#=HP1#
MP1#=1191
aMP1#=MP1#
bMP1=MP1#
MaxMP1#=MP1#
HP2#=8922
aHP2#=HP2#
bHP2=HP2#
MaxHP2#=HP2#
MP2#=3437
aMP2#=MP2#
bMP2=MP2#
MaxMP2#=MP2#
HP3#=8186
aHP3#=HP3#
bHP3=HP3#
MaxHP3#=HP3#
MP3#=893
aMP3#=MP3#
bMP3=MP3#
MaxMP3#=MP3#
STR1=204
STR2=255
STR3=189
DEF1=118
DEF2=130
DEF3=109
SPD1=220
SPD2=255
SPD3=198
pickenemyagain:
enemy=rnd(5)
if enemy=0 then goto pickenemyagain
if enemy=1
   ename$="Rat Lv.7"
   EHP#=2087
   MaxEHP#=2087
   ESTR=56
   EDEF=40
   ESPD=120
endif
if enemy=2
   ename$="Boulderman Lv.16"
   EHP#=5712
   MaxEHP#=5712
   ESTR=14
   EDEF=98
   ESPD=79
endif
if enemy=3
   ename$="Workout Guy Lv.31"
   EHP#=12206
   MaxEHP#=12206
   ESTR=91
   EDEF=47
   ESPD=255
endif
if enemy=4
   ename$="Robot Lv.59"
   EHP#=21886
   MaxEHP#=21886
   ESTR=149
   EDEF=144
   ESPD=181
endif
if enemy=5
   ename$="Helior Lv. 86"
   EHP#=60489
   MaxEHP#=60489
   ESTR=212
   EDEF=153
   ESPD=248
endif
If time1=>9500 or time2=>9500 or time3=>9500 or Etime=<500
   time1=10000
   time2=10000
   time3=10000
   oldt1=10000
   oldt2=10000
   oldt3=10000
   Etime=0
   oldet=0
   begbat=1
EndIf
If time1=<500 or time2=<500 or time3=<500 or Etime=>9500
   time1=0
   time2=0
   time3=0
   oldt1=0
   oldt2=0
   oldt3=0
   Etime=10000
   oldet=10000
   begbat=2
EndIf
commands=0
Animate=0
Animate2=0
dAnimate1=0
dAnimate2=0
dAnimate3=0
edAnimate=0
tAnimate=0
bounce1=198
bounce2=198
bounce3=198
ebounce=128
traj1=-10
traj2=-10
traj3=-10
etraj=-10
atbred1=225
atbgreen1=225
atbblue1=0
atbred2=225
atbgreen2=225
atbblue2=0
atbred3=225
atbgreen3=225
atbblue3=0
a#=100
selection=1
magcomshown=0
sumcomshown=0
itemcomshown=0

Rem Set Things to do with font
Set Text Font "Courier New"
Set Text Size 20

Rem Set names and Active or Wait style ATB Bars
naming:
PRINT "Max Name Length: 7 Characters"
PRINT
INPUT "Name: ",name1$
INPUT "Name: ",name2$
INPUT "Name: ",name3$
If len(name1$)>7 or len(name2$)>7 or len(name3$)>7
   PRINT "One or more of your names is too long. Please change it."
   suspend for key
   CLS
   goto naming
EndIf
Set Cursor text width("Name: "+name1$+"++"),40
PRINT "Speed: ",SPD1
Set Cursor text width("Name: "+name2$+"++"),60
PRINT "Speed: ",SPD2
Set Cursor text width("Name: "+name3$+"++"),80
PRINT "Speed: ",SPD3
suspend for key
CLS
PRINT "Select ATB Mode"
PRINT "1 - Active - All constantly increasing"
PRINT "2 - Wait - Others wait as you select commands for one character"
INPUT "Well? What shall it be? ",aorw

Rem Set Time-Limit in 1/1000 of a second
If aorw=1
   If begbat>0
      elapsed=TIMER()+3601000`Must be 2000 more than other
   Else
      elapsed=TIMER()+3599000
   EndIf
EndIf
If aorw=2
   If begbat>0
      elapsed=TIMER()+3601000`Must be 2000 more than other
   Else
      elapsed=TIMER()+3599000
   EndIf
EndIf

Rem Play Music
`Loop Music 1

Rem Begin Main Loop
do

Rem Set Background
ink rgb(100,100,100),0
Box 0,0,640,480

Rem Set screen stuff, then print names, HP, MP, ATB Bars and something at the top which tells you which bit is which
ink rgb(255,255,255),0
Set Text Font "Courier New"
Set Text Size 20
Set Cursor 260,380
If HP1#=<0
   HP1#=0
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIf
If time1=>10000 and HP1#>0 and commands=1
   ink rgb(atbred1,atbgreen1,atbblue1),0
EndIf
If time1<10000 and HP1#>0
   ink rgb(255,255,255),0
EndIf
PRINT name1$
If HP1#<(MaxHP1#/4) and HP1#>0
   ink rgb(255,255,0),0
EndIf
If HP1#=>(MaxHP1#/4)
   ink rgb(255,255,255),0
EndIf
Set Cursor 340,380
If bHP1=>1000
   PRINT str$(bHP1)
EndIf
If bHP1<1000 and bHP1=>100
   PRINT " ",str$(bHP1)
EndIf
If bHP1<100 and bHP1=>10
   PRINT "  ",str$(bHP1)
EndIf
If bHP1<10
   PRINT "   ",str$(bHP1)
EndIf
If HP1#=0
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIf
Set Cursor 340+(text width("    ")),380
If MaxHP1#=>1000
   PRINT "/",str$(MaxHP1#)
EndIf
If MaxHP1#<1000 and MaxHP1#=>100
   PRINT "/ ",str$(MaxHP1#)
EndIf
If MaxHP1#<100
   PRINT "/  ",str$(MaxHP1#)
EndIf
Box 340,398,430,399,rgb(70,0,0),rgb(70,0,0),rgb(90,0,0),rgb(90,0,0)
Box 340,398,((aHP1#/MaxHP1#)*90)+340,399,rgb(195,0,0),rgb(195,0,0),rgb(255,0,0),rgb(255,0,0)
Box 340,398,((HP1#/MaxHP1#)*90)+340,399,rgb(40,40,255),rgb(40,40,255),rgb(200,200,255),rgb(200,200,255)
If MP1#<(MaxMP1#/5)
   ink rgb(255,255,0),0
Else
   ink rgb(255,255,255),0
EndIf
If HP1#=0 then ink rgb(255,0,0),0
Set Cursor 460,380
If bMP1=>1000
   PRINT str$(bMP1)
EndIf
If bMP1<1000 and bMP1=>100
   PRINT " ",str$(bMP1)
EndIf
If bMP1<100 and bMP1=>10
   PRINT "  ",str$(bMP1)
EndIf
If bMP1<10
   PRINT "   ",str$(bMP1)
EndIf
Box 460,398,500,399,rgb(70,0,0),rgb(70,0,0),rgb(90,0,0),rgb(90,0,0)
Box 460,398,((aMP1#/MaxMP1#)*40)+460,399,rgb(195,0,0),rgb(195,0,0),rgb(255,0,0),rgb(255,0,0)
Box 460,398,((MP1#/MaxMP1#)*40)+460,399,rgb(80,255,80),rgb(80,255,80),rgb(200,255,200),rgb(200,255,200)
Set Cursor 260,410
If HP2#=<0
   HP2#=0
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIf
If time2=>10000 and HP2#>0 and commands=2
   ink rgb(atbred2,atbgreen2,atbblue2),0
EndIf
If time2<10000 and HP2#>0
   ink rgb(255,255,255),0
EndIf
PRINT name2$
If HP2#<(MaxHP2#/4) and HP2#>0
   ink rgb(255,255,0),0
EndIf
If HP2#=>(MaxHP2#/4)
   ink rgb(255,255,255),0
EndIf
Set Cursor 340,410
If bHP2=>1000
   PRINT str$(bHP2)
EndIf
If bHP2<1000 and bHP2=>100
   PRINT " ",str$(bHP2)
EndIf
If bHP2<100 and bHP2=>10
   PRINT "  ",str$(bHP2)
EndIf
If bHP2<10
   PRINT "   ",str$(bHP2)
EndIf
If HP2#=0
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIF
Set Cursor 340+(text width("    ")),410
If MaxHP2#=>1000
   PRINT "/",str$(MaxHP2#)
EndIf
If MaxHP2#<1000 and MaxHP2#=>100
   PRINT "/ ",str$(MaxHP2#)
EndIf
If MaxHP2#<100
   PRINT "/  ",str$(MaxHP2#)
EndIf
Box 340,428,430,429,rgb(70,0,0),rgb(70,0,0),rgb(90,0,0),rgb(90,0,0)
Box 340,428,((aHP2#/MaxHP2#)*90)+340,429,rgb(195,0,0),rgb(195,0,0),rgb(255,0,0),rgb(255,0,0)
Box 340,428,((HP2#/MaxHP2#)*90)+340,429,rgb(40,40,255),rgb(40,40,255),rgb(200,200,255),rgb(200,200,255)
If MP2#<(MaxMP2#/5)
   ink rgb(255,255,0),0
Else
   ink rgb(255,255,255),0
EndIf
If HP2#=0 then ink rgb(255,0,0),0
Set Cursor 460,410
If bMP2=>1000
   PRINT str$(bMP2)
EndIf
If bMP2<1000 and bMP2=>100
   PRINT " ",str$(bMP2)
EndIf
If bMP2<100 and bMP2=>10
   PRINT "  ",str$(bMP2)
EndIf
If bMP2<10
   PRINT "   ",str$(bMP2)
EndIf
Box 460,428,500,429,rgb(70,0,0),rgb(70,0,0),rgb(90,0,0),rgb(90,0,0)
Box 460,428,((aMP2#/MaxMP2#)*40)+460,429,rgb(195,0,0),rgb(195,0,0),rgb(255,0,0),rgb(255,0,0)
Box 460,428,((MP2#/MaxMP2#)*40)+460,429,rgb(80,255,80),rgb(80,255,80),rgb(200,255,200),rgb(200,255,200)
If HP3#=<0
   HP3#=0
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIf
Set Cursor 260,440
If time3=>10000 and HP3#>0 and commands=3
   ink rgb(atbred3,atbgreen3,atbblue3),0
EndIf
If time3<10000 and HP3#>0
   ink rgb(255,255,255),0
EndIf
PRINT name3$
If HP3#<(MaxHP3#/4) and HP3#>0
   ink rgb(255,255,0),0
EndIf
If HP3#=>(MaxHP3#/4)
   ink rgb(255,255,255),0
EndIf
Set Cursor 340,440
If bHP3=>1000
   PRINT str$(bHP3)
EndIf
If bHP3<1000 and bHP3=>100
   PRINT " ",str$(bHP3)
EndIf
If bHP3<100 and bHP3=>10
   PRINT "  ",str$(bHP3)
EndIf
If bHP3<10
   PRINT "   ",str$(bHP3)
EndIf
If HP3#=0
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIf
Set Cursor 340+(text width("    ")),440
If MaxHP3#=>1000
   PRINT "/",str$(MaxHP3#)
EndIf
If MaxHP3#<1000 and MaxHP3#=>100
   PRINT "/ ",str$(MaxHP3#)
EndIf
If MaxHP3#<100
   PRINT "/  ",str$(MaxHP3#)
EndIf
Box 340,458,430,459,rgb(70,0,0),rgb(70,0,0),rgb(90,0,0),rgb(90,0,0)
Box 340,458,((aHP3#/MaxHP3#)*90)+340,459,rgb(195,0,0),rgb(195,0,0),rgb(255,0,0),rgb(255,0,0)
Box 340,458,((HP3#/MaxHP3#)*90)+340,459,rgb(40,40,255),rgb(40,40,255),rgb(200,200,255),rgb(200,200,255)
If MP3#<(MaxMP3#/5)
   ink rgb(255,255,0),0
Else
   ink rgb(255,255,255),0
EndIf
If HP3#=0 then ink rgb(255,0,0),0
Set Cursor 460,440
If bMP3=>1000
   PRINT str$(bMP3)
EndIf
If bMP3<1000 and bMP3=>100
   PRINT " ",str$(bMP3)
EndIf
If bMP3<100 and bMP3=>10
   PRINT "  ",str$(bMP3)
EndIf
If bMP3<10
   PRINT "   ",str$(bMP3)
EndIf
Box 460,458,500,459,rgb(70,0,0),rgb(70,0,0),rgb(90,0,0),rgb(90,0,0)
Box 460,458,((aMP3#/MaxMP3#)*40)+460,459,rgb(195,0,0),rgb(195,0,0),rgb(255,0,0),rgb(255,0,0)
Box 460,458,((MP3#/MaxMP3#)*40)+460,459,rgb(80,255,80),rgb(80,255,80),rgb(200,255,200),rgb(200,255,200)
If EHP#<0 then EHP#=0
enemybar#=EHP#/MaxEHP#
ink rgb(255,255,255),0
Box 99,233,165,245
ink rgb(100,100,100),0
Box 100,234,164,244
If enemybar#=<0.25
   Box 100,234,(enemybar#*64)+100,244,rgb(150,0,0),rgb(150,0,0),rgb(190,0,0),rgb(190,0,0)
Else
   Box 100,234,(enemybar#*64)+100,244,rgb(170,200,0),rgb(170,200,0),rgb(200,220,0),rgb(200,220,0)
EndIf
Ink rgb(255,255,255),0
Center Text 132,150,ename$
Set Cursor 82,250
If EHP#=>10000
   PRINT EHP#,"/",MaxEHP#
EndIf
If EHP#<10000 and EHP#=>1000
   PRINT " ",EHP#,"/",MaxEHP#
EndIf
If EHP#<1000 and EHP#=>100
   PRINT "  ",EHP#,"/",MaxEHP#
EndIf
If EHP#<100 and EHP#=>10
   PRINT "   ",EHP#,"/",MaxEHP#
EndIf
If EHP#<10
   PRINT "    ",EHP#,"/",MaxEHP#
EndIf
Set Text Size 10
Set Cursor 270,370
PRINT "Name"
Set Cursor 350,370
PRINT "HP"
Set Cursor 470,370
PRINT "MP"
Set Cursor 530,370
PRINT "ATB"
Line 260,373,266,373
Line 292,373,345,373
Line 362,373,465,373
Line 482,373,525,373
Line 549,373,620,373
ink rgb(255,255,255),0
Box 519,379,621,401
ink rgb(100,100,100),0
Box 520,380,620,400
ink rgb(255,255,255),0
Box 519,409,621,431
ink rgb(100,100,100),0
Box 520,410,620,430
ink rgb(255,255,255),0
Box 519,439,621,461
ink rgb(100,100,100),0
Box 520,440,620,460
Rem Show 'Characters' and 'Enemy'
Sprite 1,540,100,1
Sprite 2,540,170,1
Sprite 3,540,240,1
Sprite 4,100,170,2
Set Sprite 1,0,1
If HP1#=<0
   delete sprite 1
   sprite 1,604,100,1
   rotate sprite 1,90
EndIf
Set Sprite 2,0,1
If HP2#=<0
   delete sprite 2
   sprite 2,604,170,1
   rotate sprite 2,90
EndIf
Set Sprite 3,0,1
If HP3#=<0
   delete sprite 3
   sprite 3,604,240,1
   rotate sprite 3,90
EndIf
Set Sprite 4,0,1

Rem Deciding Factors
If EHP#=<0 then goto win
If bHP1=<0 and bHP2=<0 and bHP3=<0 then goto lose
If TIMER()=>elapsed  and eHP#>0 then goto time_lose

Rem Sets Max Variables
If time1>10000 then time1=10000
If time2>10000 then time2=10000
If time3>10000 then time3=10000
If HP1#>MaxHP1# then HP1#=MaxHP1#
If HP2#>MaxHP2# then HP2#=MaxHP2#
If HP3#>MaxHP3# then HP3#=MaxHP3#

Rem Makes the Current Command Executor's ATB Bar Flash, and the other 2 wait in 'Wait' mode
If time1=>10000 and commands=0
   commands=1
EndIf
If commands=1
   If aorw=2
      time2=oldt2
      time3=oldt3
      Etime=oldet
   EndIf
   If animate<=10
      atbred1=225+Animate
      atbgreen1=225+Animate
      atbblue1=Animate*25
   EndIf
   If Animate>10
      atbred1=225+(20-Animate)
      atbgreen1=225+(20-Animate)
      atbblue1=(20-Animate)*25
   EndIf
EndIf
If time1<10000
   atbred1=225
   atbgreen1=225
   atbblue1=0
EndIf

If time2=>10000 and commands=0
   commands=2
EndIf
If commands=2
   If aorw=2
      time1=oldt1
      time3=oldt3
      Etime=oldet
   EndIf
   If animate<=10
      atbred2=225+Animate
      atbgreen2=225+Animate
      atbblue2=Animate*25
   EndIf
   If Animate>10
      atbred2=225+(20-Animate)
      atbgreen2=225+(20-Animate)
      atbblue2=(20-Animate)*25
   EndIf
EndIf
If time2<10000
   atbred2=225
   atbgreen2=225
   atbblue2=0
EndIf

If time3=>10000 and commands=0
   commands=3
EndIf
IF commands=3
   If aorw=2
      time1=oldt1
      time2=oldt2
      Etime=oldet
   EndIf
   If animate<=10
      atbred3=225+Animate
      atbgreen3=225+Animate
      atbblue3=Animate*25
   EndIf
   If Animate>10
      atbred3=225+(20-Animate)
      atbgreen3=225+(20-Animate)
      atbblue3=(20-Animate)*25
   EndIf
EndIf
If time3<10000
   atbred3=225
   atbgreen3=225
   atbblue3=0
EndIf

If commands=1 and HP1#=<0
   commands=0
endif
If commands=2 and HP2#=<0
   commands=0
endif
If commands=3 and HP3#=<0
   commands=0
endif

Rem Enemy's Attack - Decide when ATB is full, select a target that isn't already KO'd, and Attack
If Etime=>10000
   ecommands=1
EndIf
If ecommands=1
   If aorw=2
      time1=oldt1
      time2=oldt2
      time3=oldt3
   EndIf
   chooseagain:
   target=rnd(200)+1
   If target=<66
      If HP1#=0 and HP2#=0 and HP3#=0 then goto gameover_waitingforhpbars
      If HP1#=0 then goto chooseagain
      edamage=(((0.7*ESTR)+rnd(ESTR*0.6))*1.5)-((0.7*DEF1)+rnd(DEF1*0.6))
      HP1#=HP1#-edamage
   EndIf
   If target>66 and target=<132
      If HP1#=0 and HP2#=0 and HP3#=0 then goto gameover_waitingforhpbars
      If HP2#=0 then goto chooseagain
      edamage=(((0.7*ESTR)+rnd(ESTR*0.6))*1.5)-((0.7*DEF2)+rnd(DEF2*0.6))
      HP2#=HP2#-edamage
   EndIf
   If target>132 and target=<199
      If HP1#=0 and HP2#=0 and HP3#=0 then goto gameover_waitingforhpbars
      If HP3#=0 then goto chooseagain
      edamage=(((0.7*ESTR)+rnd(ESTR*0.6))*1.5)-((0.7*DEF3)+rnd(DEF3*0.6))
      HP3#=HP3#-edamage
   EndIf
   If target=>200
      If HP1#=0 and HP2#=0 and HP3#=0 then goto gameover_waitingforhpbars
      If HP1#>0
         edamage1=(((0.7*ESTR)+rnd(ESTR*0.6))*5)-((0.7*DEF1)+rnd(DEF1*0.6))
      else
         edamage1=0
      endif
      HP1#=HP1#-edamage1
      If HP2#>0
         edamage2=(((0.7*ESTR)+rnd(ESTR*0.6))*5)-((0.7*DEF2)+rnd(DEF2*0.6))
      else
         edamage2=0
      endif
      HP2#=HP2#-edamage2
      If HP3#>0
         edamage3=(((0.7*ESTR)+rnd(ESTR*0.6))*5)-((0.7*DEF3)+rnd(DEF3*0.6))
      else
         edamage=0
      endif
      HP3#=HP3#-edamage3
   EndIf
   gameover_waitingforhpbars:
   edAnimate=0
   ecommands=0
   Etime=0
   oldet=0
EndIf

notyourturn:

Rem Increases and colours ATB Bars
time1=time1+SPD1
time2=time2+SPD2
time3=time3+SPD3
Etime=Etime+ESPD
If time1=>10000 then time1=10000
If time2=>10000 then time2=10000
If time3=>10000 then time3=10000
If Etime=>10000 then Etime=10000
If HP1#=0 then time1=0
If HP2#=0 then time2=0
If HP3#=0 then time3=0
ink rgb(atbred1,atbgreen1,atbblue1),0
Box 520,380,(time1/100)+520,400
ink rgb(atbred2,atbgreen2,atbblue2),0
Box 520,410,(time2/100)+520,430
ink rgb(atbred3,atbgreen3,atbblue3),0
Box 520,440,(time3/100)+520,460
If begbat=1
   begbat=0
EndIf

Rem Shows Command Menu
If commands>0
   IF commandsshown=0
      Animate2=0
   EndIf
   ink rgb(255,255,255),0
   Box 33,373,117,467
   ink rgb(0,0,255),0
   Box 35,375,115,465
   ink rgb(255,255,255),0
   Set Text Size 20
   Set Cursor 40,380
   PRINT "Attack"
   Set Cursor 40,400
   PRINT "Magic"
   Set Cursor 40,420
   PRINT "Summon"
   Set Cursor 40,440
   PRINT "Item"
   ink rgb(100,100,100),0
   Box 35,375,75-(Animate2*8),465
   Box 35,375,115,420-(Animate2*9)
   Box 75+(Animate2*8),375,115,465
   Box 35,420+(Animate2*9),115,465
   ink rgb(255,255,255),0
   commandsshown=1
EndIf

Rem "x" key is the selection button, and this attacks
If inkey$()="x" and commands=1 and xpressed=0
   time1=0
   commands=0
   xpressed=1
   commandsshown=0
   damage1=(((STR1*0.7)+rnd(STR1*0.6))*1.5)-((0.7*EDEF1)+rnd(EDEF*0.6))
   EHP#=EHP#-damage1
   dAnimate1=0
EndIf
If inkey$()="x" and commands=2 and xpressed=0
   time2=0
   commands=0
   xpressed=1
   commandsshown=0
   damage2=(((STR2*0.7)+rnd(STR2*0.6))*1.5)-((0.7*EDEF1)+rnd(EDEF*0.6))
   EHP#=EHP#-damage2
   danimate2=0
EndIf
If inkey$()="x" and commands=3 and xpressed=0
   time3=0
   commands=0
   xpressed=1
   commandsshown=0
   damage3=(((STR3*0.7)+rnd(STR3*0.6))*1.5)-((0.7*EDEF1)+rnd(EDEF*0.6))
   EHP#=EHP#-damage3
   danimate3=0
EndIf
Rem Can't just hold the 'x' key
If inkey$()=""
   xpressed=0
EndIf

Rem Increment Animate Variables, including bouncy damage numbers
oldcom=commands
Animate=Animate+1
If Animate>20 then Animate=0
Animate2=Animate2+1
If Animate2>5 then Animate2=5
If totalseconds=<20 then tAnimate=tAnimate+1
If tAnimate=>20 then tAnimate=0
If edamage>0 or edamage1>0 or edamage2>0 or edamage3>0
   If edAnimate<20
      ebounce=ebounce+etraj
      If ebounce>128 then ebounce=128
      ink rgb(255,255,255),0
      Set Text Size 20
      If target=<66 then Center Text 572,ebounce,str$(edamage)
      If target>66 and target=<132 then Center Text 572,ebounce+70,str$(edamage)
      If target>132 and target=<199 then Center Text 572,ebounce+140,str$(edamage)
      If target=>200
         If edamage1>0 then Center Text 572,ebounce,str$(edamage1)
         If edamage2>0 then Center Text 572,ebounce+70,str$(edamage2)
         If edamage3>0 then Center Text 572,ebounce+140,str$(edamage3)
      EndIf
      inc edAnimate
      etraj=etraj+2
   EndIf
EndIf
If damage1>0
   If dAnimate1<20
      bounce1=bounce1+traj1
      If bounce1>198 then bounce1=198
      ink rgb(255,255,255),0
      Set Text Size 20
      Center Text 132,bounce1,str$(damage1)
      inc dAnimate1
      traj1=traj1+2
   EndIf
EndIf
If damage2>0
   If dAnimate2<20
      bounce2=bounce2+traj2
      If bounce2>198 then bounce2=198
      ink rgb(255,255,255),0
      Set Text Size 20
      Center Text 132,bounce2,str$(damage2)
      inc dAnimate2
      traj2=traj2+2
   EndIf
EndIf
If damage3>0
   If dAnimate3<20
      bounce3=bounce3+traj3
      If bounce3>198 then bounce3=198
      ink rgb(255,255,255),0
      Set Text Size 20
      Center Text 132,bounce3,str$(damage3)
      inc dAnimate3
      traj3=traj3+2
   EndIf
EndIf
If aHP1#>HP1# then aHP1#=aHP1#-(MaxHP1#/1000)
If aHP1#<HP1# then aHP1#=HP1#
If aHP2#>HP2# then aHP2#=aHP2#-(MaxHP2#/1000)
If aHP2#<HP2# then aHP2#=HP2#
If aHP3#>HP3# then aHP3#=aHP3#-(MaxHP3#/1000)
If aHP3#<HP3# then aHP3#=HP3#
bHP1=aHP1#
bHP2=aHP2#
bHP3=aHP3#
If aMP1#>MP1# then aMP1#=aMP1#-(MaxMP1#/1000)
If aMP1#<MP1# then aMP1#=MP1#
If aMP2#>MP2# then aMP2#=aMP2#-(MaxMP2#/1000)
If aMP2#<MP2# then aMP2#=MP2#
If aMP3#>MP3# then aMP3#=aMP3#-(MaxMP3#/1000)
If aMP3#<MP3# then aMP3#=MP3#
bMP1=aMP1#
bMP2=aMP2#
bMP3=aMP3#

Rem Reset Variables
If dAnimate1=>20
dAnimate1=0
damage1=0
traj1=-10
EndIf
If dAnimate2=>20
dAnimate2=0
damage2=0
traj2=-10
EndIf
If dAnimate3=>20
dAnimate3=0
damage3=0
traj3=-10
EndIf
If edAnimate=>20
edAnimate=0
edamage=0
edamage1=0
edamage2=0
edamage3=0
etraj=-10
EndIf

Rem Keeps time variables in 'Wait' mode
If commands=0
   oldt1=time1
   oldt2=time2
   oldt3=time3
   oldet=Etime
EndIf

Rem Show Timer and give cool effects
If HP1#=0 and HP2#=0 and HP3#=0
   elapsed=TIMER()+(elapsed-TIMER())
   goto skiptimersequence
EndIf
totalseconds=(elapsed-TIMER())/1000
tens=(elapsed-TIMER())/10
For a=0 to (elapsed-TIMER())/1000 step 60
If totalseconds=>a then minutes=a/60
Next a
seconds=totalseconds-(60*minutes)
If totalseconds=<20 and tAnimate=>10
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIf
Box 574,14,636,46
ink rgb(100,100,100),0
Box 575,15,635,45
If totalseconds=<20 and tAnimate=>10
   ink rgb(255,0,0),0
Else
   ink rgb(255,255,255),0
EndIf
Set Text Size 20
Set Cursor 580,20
If minutes=<9
   If tens-(totalseconds*100)<50
      If seconds=<9
         PRINT "0",minutes," 0",seconds
      Else
         PRINT "0",minutes," ",seconds
      EndIf
   EndIf
   If tens-(totalseconds*100)=>50
      If seconds=<9
         PRINT "0",minutes,":0",seconds
      Else
         PRINT "0",minutes,":",seconds
      EndIf
   EndIF
EndIf
If minutes>9
   If tens-(totalseconds*100)<50
      If seconds=<9
         PRINT minutes," 0",seconds
      Else
         PRINT minutes," ",seconds
      EndIf
   EndIf
   If tens-(totalseconds*100)=>50
      If seconds=<9
         PRINT minutes,":0",seconds
      Else
         PRINT minutes,":",seconds
      EndIf
   EndIF
EndIf
skiptimersequence:

Rem Shows Status at start of battle
If begbat>0 and messdone=0
   ink rgb(255,255,255),0
   Box 18,18,622,42
   ink rgb(0,0,255),0
   Box 20,20,620,40
   If begbat=1
      ink rgb(225,225,0),0
      Box 520,380,620,400
      Box 520,410,620,430
      Box 520,440,620,460
   EndIf
   ink rgb(255,255,255),0
   Set Text Size 20
   IF begbat=1
      Center Text 320,20,"Pre-emptive Strike!"
   EndIf
   If begbat=2
      Center Text 320,20,"Ambushed!"
   EndIf
   WAIT 2000
   messdone=1
EndIf

Rem Sync and restart loop
sync
loop

Rem When Enemy is defeated
win:
`Stop Music 1
Set Text Size 30
ink rgb(255,255,255),0
Center Text 320,220,"GAME OVER"
Center Text 320,260,"VICTORY"
Set Text Size 10
Center Text 320,300,"Press Q to quit, or any other key to start again"
suspend for key
If inkey$()="q"
   END
else
   goto startagain
endif

Rem When all characters are KO'd
lose:
Set Text Size 30
`for t=255 to 0 step -8
`   set music volume 1,(t/3)
`   set gamma t,t,t
`next t
ink rgb(255,0,0),0
Center Text 320,240,"GAME OVER"
Set Text Size 10
Center Text 320,300,"Press Q to quit, or any other key to start again"
suspend for key
If inkey$()="q"
   END
else
   goto startagain
endif

Rem When Time is up
time_lose:
`for t=255 to 0 step -8
`   set music volume 1,(t/3)
`   set gamma t,t,t
`next t
Set Text Size 30
ink rgb(255,0,0),0
Center Text 320,220,"TIME'S UP"
Center Text 320,260,"GAME OVER"
Set Text Size 10
Center Text 320,300,"Press Q to quit, or any other key to start again"
suspend for key
If inkey$()="q"
   END
else
   goto startagain
endif