Hey that code I posted doesn't make sense. Anyways here is my full code:
`INITIAL SETUP
sync rate 40
sync on
randomize timer()
disable escapekey
backdrop on
#include "keynames.dba"
dim keyboard$(221)
`DECLARE ARRAYS
dim speedk(1)
dim leftk(1)
dim rightk(1)
dim hitk(1,2)
dim jumpk(1)
dim held(1,2)
dim pos(1,1)
dim velo#(1,1)
dim image(1)
dim dir(1)
dim points(1)
dim char$(1)
dim energy#(1)
dim impulse(1,1)
dim ai(1)
`if value is 0 then it is a human player
`if value is 1 then it is a computer player
dim aido(1,4)
`CREATE CONSTANTS
aSPEED=0
aLEFT=1
aRIGHT=2
aHIT=3
aJUMP=4
RED=rgb(255,0,0)
GREEN=rgb(0,255,0)
BLUE=rgb(0,0,255)
CYAN=rgb(0,255,255)
MAGENTA=rgb(255,0,255)
YELLOW=rgb(255,255,0)
WHITE=rgb(255,255,255)
`DEFAULT CONTROLS
speedk(1)=156
leftk(1)=75
rightk(1)=77
hitk(1,0)=210
hitk(1,1)=199
hitk(1,2)=209
jumpk(1)=72
speedk(0)=33
leftk(0)=30
rightk(0)=32
hitk(0,0)=15
hitk(0,1)=42
hitk(0,2)=29
jumpk(0)=17
keynames()
`LOAD CHARACTERS
open to read 1,"chars.ch"
read byte 1, charnum
dim charname$(charnum)
dim charmove#(charnum,2)
dim imgname$(charnum)
dim charimpl#(charnum,2,1)
for i = 0 to charnum
read string 1, charname$(i)
read string 1, imgname$(i)
for j = 0 to 2
read float 1, charmove#(i,j)
next j
for j = 0 to 2
for k=0 to 1
read float 1,charimpl#(i,j,k)
next k
next j
next i
close file 1
`LOAD ICONS
for i = 0 to charnum
load image imgname$(i)+"0.bmp",10+i
next i
`LOAD SOUNDS
load sound "punch.wav",1
load sound "punch.wav",2
load sound "punch.wav",3
`INITIAL VALUES
dir(0) = 0
dir(1) = 0
begin:
points(0)=0
points(1)=0
pos(0,0)=160
pos(0,1)=100
pos(1,0)=480
pos(1,1)=100
image(0) = 1
image(1) = 1
color backdrop rgb(0,0,123)
show mouse
do
char$(0)=charname$(ch0)
char$(1)=charname$(ch1)
center text 320,200, "Time Limit="+str$(tlimit)
center text 320,240, "Point Limit="+str$(plimit)
if sel=1 then ink red,0 else ink white,0
center text 320,300, "P1 Character="+char$(0)
if sel=2 then ink red,0 else ink white,0
center text 320,320, "P2 Character="+char$(1)
ink white,0
if ai(0)=0 then ai0$="Human" else ai0$ = "Computer"
if ai(1)=0 then ai1$="Human" else ai1$ = "Computer"
center text 320, 360,"P1 is "+ai0$+ " controlled"
center text 320, 380,"P2 is "+ai1$+ " controlled"
if mousey()=>200 and mousey()<220 and mouseclick()=1 then inc tlimit,2: wait 10
if mousey()=>200 and mousey()<220 and mouseclick()=2 then dec tlimit,2: wait 10
if mousey()=>240 and mousey()<260 and mouseclick()=1 then inc plimit,40: wait 5
if mousey()=>240 and mousey()<260 and mouseclick()=2 then dec plimit,40: wait 5
if tlimit<0 then tlimit=0
if plimit<0 then plimit=0
if mousey()=>300 and mousey()<320 and mouseclick()=1 then inc ch0:mousestop()
if mousey()=>300 and mousey()<320 and mouseclick()=2 then dec ch0:mousestop()
if mousey()=>320 and mousey()<340 and mouseclick()=1 then inc ch1:mousestop()
if mousey()=>320 and mousey()<340 and mouseclick()=2 then dec ch1:mousestop()
if ch0<0 then ch0=charnum
if ch1<0 then ch1=charnum
if ch0>charnum then ch0=0
if ch1>charnum then ch1=0
if mousey()=>360 and mousey()<380 and mouseclick()=1 and ai(0)=0 then ai(0)=1:mousestop()
if mousey()=>360 and mousey()<380 and mouseclick()=1 and ai(0)=1 then ai(0)=0:mousestop()
if mousey()=>380 and mousey()<400 and mouseclick()=1 and ai(1)=0 then ai(1)=1:mousestop()
if mousey()=>380 and mousey()<400 and mouseclick()=1 and ai(1)=1 then ai(1)=0:mousestop()
sprite 3,20,20,10+ch0:if m=0 then mirror sprite 3: m=1
sprite 4,620,20,10+ch1
size sprite 3,128,128
size sprite 4,128,128
offset sprite 4, sprite width(4),0
if returnkey() then delete sprite 3:delete sprite 4:exit
sync
loop
t=0
`LOAD IMAGES
for i = 1 to 4
load image imgname$(ch0)+str$(i)+".bmp", i
load image imgname$(ch1)+str$(i)+".bmp", 4+i
next i
color backdrop 0
hide mouse
if ai(0)=1 then startI=0 else startI=1
if ai(1)=1 then endI=1 else endI=0
energy#(0)=1
energy#(1)=1
`MAIN LOOP
Do
for i = 0 to 1
sprite 1+i,pos(i,0),pos(i,1),image(i)+(4*i)
offset sprite i+1, sprite width(i+1)/2, sprite height(i+1)/2
next i
if ai(0)=1 or ai(1)=1 then gosub art_int
gosub velocities
pos(0,0)=pos(0,0)+ velo#(0,0)
pos(1,0)=pos(1,0)+ velo#(1,0)
if pos(0,0)<pos(1,0)
if dir(0) = 0 then mirror sprite 1: dir(0)=1
if dir(1) = 1 then mirror sprite 2: dir(1)=0
endif
if pos(0,0)>pos(1,0)
if dir(0) = 1 then mirror sprite 1: dir(0)=0
if dir(1) = 0 then mirror sprite 2: dir(1)=1
endif
for i = 0 to 1
if pos(i,0) < 30 then pos(i,0) = 30
if pos(i,0) > 610 then pos(i,0) = 610
next i
image(0)=1+hit(0)
image(1)=1+hit(1)
if escapekey() then gosub options
`keep track of how long attack buttons held
if hit(0)=0 then held(0,0)=0: held(0,1)=0:held(0,2)=0
if hit(0)=1 then held(0,0)=held(0,0)+1: held(0,1)=0:held(0,2)=0
if hit(0)=2 then held(0,0)=0: held(0,1)=held(0,1)+1:held(0,2)=0
if hit(0)=3 then held(0,0)=0: held(0,1)=0:held(0,2)=held(0,2)+1
if hit(1)=0 then held(1,0)=0: held(1,1)=0:held(1,2)=0
if hit(1)=1 then held(1,0)=held(1,0)+1: held(1,1)=0:held(1,2)=0
if hit(1)=2 then held(1,0)=0: held(1,1)=held(1,1)+1:held(1,2)=0
if hit(1)=3 then held(1,0)=0: held(1,1)=0:held(1,2)=held(1,2)+1
if sprite collision(1,2)
mh = 1+screen fps()/4
for i = 1 to 3
if held(0,i-1)<mh and hit(0)=i and hit(0)<>hit(1)
points(0)=points(0)+charmove#(ch0,i-1)
impulse(1,0)=charimpl#(ch0,i-1,0) *(-1+2*dir(0))
impulse(1,1)=charimpl#(ch0,i-1,1)* energy#(0)
if sound playing(i)=0 then play sound i
endif
```````
if held(1,i-1)<mh and hit(1)=i and hit(0)<>hit(1)
points(1)=points(1)+charmove#(ch1,i-1)
impulse(0,0)=charimpl#(ch1,i-1,0)*(-1+2*dir(1))
impulse(0,1)=charimpl#(ch1,i-1,1)* energy#(1)
if sound playing(i)=0 then play sound i
endif
next i
endif
inc t
tim$=str$(t/40)
if plimit =0
text 1,1,"P1 Hits: "+str$(points(0))
text 550-10*len(str$(points(1))),1,"P2 Hits: "+str$(points(1))
endif
center text 320, 21, "Time: "+tim$
text 1,460,"Press Esc for menu"
if plimit <> 0
health0 = (250*(plimit-points(1)))/plimit
health1 = (250*(points(0)-plimit))/plimit
ink rgb(255,32,32),0
box 1,1,health0,21
box 640+health1,1,639,21
ink rgb(255,255,255),0
endif
if tlimit <> 0 and val(tim$)=>tlimit then goto gamedone
if plimit <> 0
if points(0)=>plimit or points(1)=>plimit then goto gamedone
endif
sync
Loop
`SUBROUTINES
`GAME OVER
gamedone:
delete sprite 1
delete sprite 2
do
if points(0)=points(1) then center text 320,180,"The Game Was Drawn"
if points(0)<points(1) then center text 320,180,"Player 2 ["+char$(1)+"] Wins"
if points(0)>points(1) then center text 320,180,"Player 1 ["+char$(0)+"] Wins"
center text 320,240, "Press space to continue"
if spacekey() then goto begin
sync
loop
return
`options screen
options:
delete sprite 1
delete sprite 2
do
center text 320, 10, "OPTIONS"
center text 320, 200, "(R)esume Game"
center text 320, 240, "(C)onfigure Controls"
center text 320, 280, "(E)nd Game"
center text 320, 320, "E(x)it BeatThemUp"
if lower$(inkey$())="r" then exit
if lower$(inkey$())="c" then gosub controlconfig
if lower$(inkey$())="e" then goto gamedone
if lower$(inkey$())="x" then end
sync
loop
return
`configure controls
controlconfig:
show mouse
do
for n = 0 to 1
text (n*320)+1,1, "Player "+str$(n+1)
text (n*320)+1,41, " Left: " + keyboard$(leftk(n))
text (n*320)+1,61, " Right: " + keyboard$(rightk(n))
text (n*320)+1,81, " Speed: " + keyboard$(speedk(n))
text (n*320)+1,101, "High Attack: " + keyboard$(hitk(n,0))
text (n*320)+1,121, " Mid Attack: " + keyboard$(hitk(n,1))
text (n*320)+1,141, " Low Attack: " + keyboard$(hitk(n,2))
text (n*320)+1,161, " Jump: " + keyboard$(jumpk(n))
next n
if mouseclick()=1 then selectx = mousex(): selecty=mousey()
if selectx<310 then p=0 else p=1
if selecty=>41 and selecty<61
leftk(p)=scancode()
endif
if selecty=>61 and selecty<81
rightk(p)=scancode()
endif
if selecty=>81 and selecty<101
speedk(p)=scancode()
endif
if selecty=>101 and selecty<121
hitk(p,0)=scancode()
endif
if selecty=>121 and selecty<141
hitk(p,1)=scancode()
endif
if selecty=>141 and selecty<161
hitk(p,2)=scancode()
endif
if selecty=>161 and selecty<181
jumpk(p)=scancode()
endif
if scancode()>0 then selectx=0: selecty=0
if escapekey() then exit
sync
loop
hide mouse
return
`calculate new accelerations, velocities
velocities:
`horizontal acceleration
collision=sprite collision(1,2)
if pos(i,0)=>30 or pos(i,0)<=610
acc0#=0.5*(1+speed(0))*(horizontal(0))
acc1#=0.5*(1+speed(1))*(horizontal(1))
else
acc0#=0:acc1#=0
endif
velo#(0,0)=velo#(0,0)+acc0#+impulse(0,0)
velo#(1,0)=velo#(1,0)+acc1#+impulse(1,0)
impulse(0,0)=0:impulse(1,0)=0
slowdown#=(1-collision*0.2)
for i = 0 to 1
if i=0 then j=1 else j=0
if pos(i,0)<30 or pos(i,0)>610
points(j)=points(j)+20*abs(velo#(i,0)/20)
endif
if pos(i,0)<=30 and velo#(i,0)<0
velo#(i,0)=0
endif
if pos(i,0)>610 and velo#(i,1)>0
velo#(i,0)=0
endif
if abs(velo#(i,0))>0 then velo#(i,0)=velo#(i,0)*0.9*slowdown#
next i
if spacekey()=1 then impulse(0,1)=-10
`veritical acceleration
for n = 0 to 1
width=sprite width(i+1)
height=sprite height(i+1)
optDist=width/2
if pos(n,1) <= 360-height then velo#(n,1) = velo#(n,1)+ 1
if pos(n,1) > 360-height then pos(n,1)=361-height
velo#(n,1)=velo#(n,1)+impulse(n,1)
pos(n,1)=pos(n,1)+velo#(n,1)
next n
impulse(0,1)=0:impulse(1,1)=0
if jump(0)=1 and pos(0,1) => 486-sprite height(1) then velo#(0,1)=-15
if jump(1)=1 and pos(1,1) => 486-sprite height(2) then velo#(1,1)=-15
if jump(0)=0 and pos(0,1) => 486-sprite height(1) then velo#(0,1) = 0
if jump(1)=0 and pos(1,1) => 486-sprite height(2) then velo#(1,1) = 0
return
`artificial intelligence
art_int:
for i = startI to endI
if i=0 then j=1 else j=0
width=sprite width(i+1)
height=sprite height(i+1)
strike=0
if pos(i,0)+width*0.75<pos(j,0)
aido(i,aright)=1
else
aido(i,aright)=0
endif
if pos(i,0)-width*0.75>pos(j,0)
aido(i,aleft)=1
else
aido(i,aleft)=0
endif
if pos(i,0)+width*2<pos(j,0) or pos(i,0)-width*2>pos(j,0)
aido(i,aspeed)=1
else
aido(i,aspeed)=0
endif
if pos(i,1)>pos(j,1)+sprite height(j+1)/2
aido(i,ajump)=1
else
aido(i,ajump)=0
endif
if pos(i,0)+width*0.75>=pos(j,0) and pos(i,0)-width*0.75<=pos(j,0)
if pos(i,1)+height*0.75>=pos(j,1) and pos(i,1)-height*0.75<=pos(j,1)
aido(i,ahit)=rnd(2)+1
else
aido(i,ahit)=0
endif
endif
next i
return
`FUNCTIONS
`speed pressed
function speed(p)
if ai(p)=0
a = keystate(speedk(p))
else
a=aido(p,0)
endif
endfunction a
`left/right pressed
function horizontal(p)
if ai(p)=0
a = keystate(rightk(p))-keystate(leftk(p))
else
a = aido(p,2)-aido(p,1)
endif
endfunction a
`attack pressed
function hit(p)
if ai(p)=0
if keystate(hitk(p,1))=1 then a = 2: goto detected
if keystate(hitk(p,0))=1 then a = 1: goto detected
if keystate(hitk(p,2))=1 then a = 3: goto detected
a = 0
else
a = aido(p,3)
endif
detected:
endfunction a
`jump pressed
function jump(p)
if ai(p)=0
a = keystate(jumpk(p))
else
a=aido(p,4)
endif
endfunction a
`wait for user to let go of all keys
function stop()
repeat:until scancode()=0
endfunction
`wait for user to let go of all mouse buttons
function mousestop()
repeat:until mouseclick()=0
endfunction
by full I mean that's how far I got before I got bored.