Ive added some moving enemies, unfortunately they appear to have random movement but they arent meant to, all I wanted them to do was to go as far right as they could, then go as far left as they could, with gravity of falling off the platforms. But they tend to migrate to the left side after awhile and the more I have on screen the faster they do that. Also I have made enemy into a seperate gosub, maybe doing them all at once may have been better. I remed out the 2 last enemies to make things look a little better
heres my code, maybe its quite long for a simple rework/fix
rem Setup environment
cls
`set display mode 1024,768,32
autocam off
`backdrop on
`color backdrop 0
hide mouse
set text size 20
set text to bold
sync on
sync rate 60
rem Position camera
position camera 0,0,-900
rem Setup game
gosub variables
gosub makeworld
gosub makeplayers
`load image "c:\Bubble-Bobble\bback.jpg",1
`load image "c:\bubble-Bobble\Bricks.bmp",2
`load music "c:\Bubble-Bobble\Bubble-Bobble.mp3",1
`load sound "c:\Bubble-Bobble\jump1.wav",1
make object plain 1000,3000,1800
position object 1000,300,150,120
color object 1000,rgb(200,0,200)
`texture object 1000,1
rem Start main loop
do
`play music 1
gosub enemy
gosub enemy2
`gosub enemy3
`gosub enemy4
gosub player
gosub controls
a#=wrapvalue(a#+2.0)
position object 1000,20+sin(a#)*20.0,20+cos(a#)*30.0,535.0
text 10,0, "PLAYER ONE SCORE " + STR$(playerone#)
text 650,0, "PLAYER TWO SCORE " + STR$(playertwo#)
text 400,0, "HI SCORE " + STR$(hiscore#)
rem Update screen
sync
rem End main loop
loop
rem Detect input from the keyboard
controls:
rem Store old player positions for collision
ox#=x#
oy#=y#
oz#=z#
rem Move player
if leftkey()=1 then x#=x#-player_speed#
if rightkey()=1 then x#=x#+player_speed#
rem Control player jumping
if upkey()=1 and jump=0 then player_grav#=jump_power#:jump=1
`: play sound 1
return
rem Move player
player:
rem Control gravity
player_grav#=player_grav#-gravity#
y#=y#+player_grav#
rem Limit player's falling speed like ing bobble-bobble
if player_grav#<player_grav_limit# then player_grav#=player_grav_limit#
rem Adjust position if it falls off the bottom of the screen
if y#<-540 then y#=540
rem Detect for static collision
if get static collision hit(ox#-s#,oy#-s#,oz#-s#,ox#+s#,oy#+s#,oz#+s#,x#-s#,y#-s#,z#-s#,x#+s#,y#+s#,z#+s#)=1
rem Adjust player position
dec x#,get static collision x()
dec y#,get static collision y()
rem Control jumping and player gravity
if get static collision y()<0 then player_grav#=0.0:jump=0
if get static collision y()>0 then player_grav#=0.0
endif
rem Detect for collision
if object collision(1,0)>0
rem Adjust player position
dec x#,get object collision x()
dec y#,get object collision y()
rem Control jumping and player gravity
if get object collision y()<0 then player_grav#=0.0:jump=0
if get object collision y()>0 then player_grav#=0.0
endif
if object collision(1,0)>0
rem Adjust player position
dec x#,get object collision x()
dec y#,get object collision y()
rem Control jumping and player gravity
if get object collision y()<0 then player_grav#=0.0:jump=0
if get object collision y()>0 then player_grav#=0.0
`text 400,400,"Player HIt"
endif
rem Position character
position object 1,x#,y#,z#
return
rem Move enemy
enemy:
rem Get old enemy positions for static collision
eox#=ex#
eoy#=ey#
eoz#=ez#
rem Control gravity
enemy_grav#=enemy_grav#-gravity#
ey#=ey#+enemy_grav#
rem Limit enemy's falling speed like ing bobble-bobble
if enemy_grav#<enemy_grav_limit# then enemy_grav#=enemy_grav_limit#
rem Adjust position if it falls off the bottom of the screen
if ey#<-540 then ey#=540
rem Detect for static collision
if get static collision hit(eox#-s#,eoy#-s#,eoz#-s#,eox#+s#,eoy#+s#,eoz#+s#,ex#-s#,ey#-s#,ez#-s#,ex#+s#,ey#+s#,ez#+s#)=1
rem Adjust player position
dec ex#,get static collision x()
dec ey#,get static collision y()
rem Control jumping and player gravity
if get static collision y()<0 then enemy_grav#=0.0
if get static collision y()>0 then enemy_grav#=0.0
endif
if ex#<=-570 then direction$ = "right"
if ex#>=570 then direction$ = "left"
if direction$ = "right" then ex# = ex# + 10
if direction$ = "left" then ex# = ex# - 6
rem Detect for collision
if object collision(2,0)>0
rem Adjust player position
dec ex#,get object collision x()
dec ey#,get object collision y()
rem Control jumping and player gravity
if get object collision y()<0 then enemy_grav#=0.0
if get object collision y()>0 then enemy_grav#=0.0
if get object collision x()>50 then ex#=ex#+enemy_speed#
if get object collision x()<50 then ex#=ex#-enemy_speed#
endif
rem Position character
position object 2,ex#,ey#,ez#
return
enemy2:
rem Get old enemy positions for static collision
eox1#=ex1#
eoy1#=ey1#
eoz1#=ez1#
rem Control gravity
enemy_grav1#=enemy_grav1#-gravity1#
ey1#=ey1#+enemy_grav1#
rem Limit enemy's falling speed like ing bobble-bobble
if enemy_grav1#<enemy_grav_limit1# then enemy_grav1#=enemy_grav_limit1#
rem Adjust position if it falls off the bottom of the screen
if ey1#<-540 then ey1#=540
rem enemy 2 collision starts here
if get static collision hit(eox1#-s#,eoy1#-s#,eoz1#-s#,eox1#+s#,eoy1#+s#,eoz1#+s#,ex1#-s#,ey1#-s#,ez1#-s#,ex1#+s#,ey1#+s#,ez1#+s#)=1
rem Adjust player position
dec ex1#,get static collision x()
dec ey1#,get static collision y()
rem Control jumping and player gravity
if get static collision y()<0 then enemy_grav1#=0.0
if get static collision y()>0 then enemy_grav1#=0.0
endif
if ex1#<=-570 then direction$ = "right1"
if ex1#>=570 then direction$ = "left1"
if direction$ = "right1" then ex1# = ex1# + 10
if direction$ = "left1" then ex1# = ex1# - 6
rem Detect for collision
if object collision(3,0)>0
rem Adjust player position
dec ex1#,get object collision x()
dec ey1#,get object collision y()
rem Control jumping and player gravity
if get object collision y()<0 then enemy_grav1#=0.0
if get object collision y()>0 then enemy_grav1#=0.0
if get object collision x()>50 then ex1#=ex1#+enemy_speed1#
if get object collision x()<50 then ex1#=ex1#-enemy_speed1#
endif
rem Position character
position object 3,ex1#,ey1#,ez1#
return
enemy3:
rem Get old enemy positions for static collision
eox2#=ex2#
eoy2#=ey2#
eoz2#=ez2#
rem Control gravity
enemy_grav2#=enemy_grav2#-gravity2#
ey2#=ey2#+enemy_grav2#
rem Limit enemy's falling speed like ing bobble-bobble
if enemy_grav2#<enemy_grav_limit2# then enemy_grav2#=enemy_grav_limit2#
rem Adjust position if it falls off the bottom of the screen
if ey2#<-540 then ey2#=540
rem enemy 3 collision starts here
if get static collision hit(eox2#-s#,eoy2#-s#,eoz2#-s#,eox2#+s#,eoy2#+s#,eoz2#+s#,ex2#-s#,ey2#-s#,ez2#-s#,ex2#+s#,ey2#+s#,ez2#+s#)=1
rem Adjust player position
dec ex2#,get static collision x()
dec ey2#,get static collision y()
rem Control jumping and player gravity
if get static collision y()<0 then enemy_grav2#=0.0
if get static collision y()>0 then enemy_grav2#=0.0
endif
if ex2#<=-570 then direction$ = "right2"
if ex2#>=570 then direction$ = "left2"
if direction$ = "right2" then ex2# = ex2# + 10
if direction$ = "left2" then ex2# = ex2# - 6
rem Detect for collision
if object collision(4,0)>0
rem Adjust player position
dec ex2#,get object collision x()
dec ey2#,get object collision y()
rem Control jumping and player gravity
if get object collision y()<0 then enemy_grav2#=0.0
if get object collision y()>0 then enemy_grav2#=0.0
if get object collision x()>50 then ex2#=ex2#+enemy_speed2#
if get object collision x()<50 then ex2#=ex2#-enemy_speed2#
endif
rem Position character
position object 4,ex2#,ey2#,ez2#
return
enemy4:
rem Get old enemy positions for static collision
eox3#=ex3#
eoy3#=ey3#
eoz3#=ez3#
rem Control gravity
enemy_grav3#=enemy_grav3#-gravity3#
ey3#=ey3#+enemy_grav3#
rem Limit enemy's falling speed like ing bobble-bobble
if enemy_grav3#<enemy_grav_limit3# then enemy_grav3#=enemy_grav_limit3#
rem Adjust position if it falls off the bottom of the screen
if ey3#<-540 then ey3#=540
rem enemy 4 collision starts here
if get static collision hit(eox3#-s#,eoy3#-s#,eoz3#-s#,eox3#+s#,eoy3#+s#,eoz3#+s#,ex3#-s#,ey3#-s#,ez3#-s#,ex3#+s#,ey3#+s#,ez3#+s#)=1
rem Adjust player position
dec ex3#,get static collision x()
dec ey3#,get static collision y()
rem Control jumping and player gravity
if get static collision y()<0 then enemy_grav3#=0.0
if get static collision y()>0 then enemy_grav3#=0.0
endif
if ex3#<=-570 then direction$ = "right3"
if ex3#>=570 then direction$ = "left3"
if direction$ = "right3" then ex3# = ex3# + 10
if direction$ = "left3" then ex3# = ex3# - 6
rem Detect for collision
if object collision(5,0)>0
rem Adjust player position
dec ex3#,get object collision x()
dec ey3#,get object collision y()
rem Control jumping and player gravity
if get object collision y()<0 then enemy_grav3#=0.0
if get object collision y()>0 then enemy_grav3#=0.0
if get object collision x()>50 then ex3#=ex3#+enemy_speed3#
if get object collision x()<50 then ex3#=ex3#-enemy_speed3#
endif
rem Position character
position object 5,ex3#,ey3#,ez3#
return
rem Set variables for physics and game
variables:
rem Player start co-ordinates
x#=0.0
y#=0.0
z#=0.0
s#=25
rem Enemy start co-ordinates
ex#=250.0
ey#=400.0
ez#=0.0
es#=25
ex1#=-240.0
ey1#=400.0
ez1#=0.0
es1#=25
ex2#=500.0
ey2#=400.0
ez2#=0.0
es2#=25
ex3#=-500.0
ey3#=400.0
ez3#=0.0
es3#=25
rem PLayer attributes
player_speed#=5.0
jump_power#=30.0
gravity#=2.0
rem Enemy attributes
enemy_speed#=5.0
jump_power#=30.0
gravity#=2.0
enemy_speed1#=5.0
jump_power1#=30.0
gravity1#=2.0
enemy_speed2#=5.0
jump_power2#=30.0
gravity2#=2.0
enemy_speed3#=5.0
jump_power3#=30.0
gravity3#=2.0
rem Gravity limits
player_grav_limit#=-15.0
enemy_grav_limit#=-15.0
enemy_grav_limit1#=-15.0
enemy_grav_limit2#=-15.0
enemy_grav_limit3#=-15.0
return
rem Make the world
makeworld:
rem The top
make object box 10,400,50,50
position object 10,-400,475,0
`make static object 10
make static collision box -600,455,-25,-200,505,25
make object box 11,400,50,50
position object 11,400,475,0
`make static object 11
make static collision box 200,455,-25,600,505,25
rem The bottom
make object box 12,400,50,50
position object 12,-400,-475,0
`make static object 12
make static collision box -600,-505,-25,-200,-455,25
make object box 13,400,50,50
position object 13,400,-475,0
`make static object 13
make static collision box 200,-505,-25,600,-455,25
rem The right
make object box 14,50,1000,50
position object 14,620,0,0
`make static object 14
make static collision box 595,-500,-25,645,500,25
rem The left
make object box 15,50,1000,50
position object 15,-620,0,0
`make static object 15
make static collision box -645,-500,-25,-595,500,25
rem The first layer
make object box 16,800,50,50
position object 16,0,-300,0
`make static object 16
make static collision box -400,-325,-25,400,-275,25
rem The second layer
make object box 17,400,50,50
position object 17,-400,-100,0
`texture object 17,2
`make static object 17
make static collision box -600,-125,-25,-200,-75,25
make object box 18,400,50,50
position object 18,400,-100,0
`texture object 18,2
`make static object 18
make static collision box 200,-125,-25,600,-75,25
rem The third layer
make object box 19,800,50,50
position object 19,0,100,0
`texture object 19,2
`make static object 19
make static collision box -400,75,-25,400,125,25
return
rem Make the characters
makeplayers:
rem Make the player
make object cube 1,s#*2
color object 1,rgb(255,0,0)
make object collision box 1,0-s#,0-s#,0-s#,s#,s#,s#,0
rem Make the enemy
make object cube 2,es#*2
color object 2,rgb(255,255,0)
make object collision box 2,0-es#,0-es#,0-es#,es#,es#,es#,0
make object cube 3,es#*2
color object 3,rgb(255,0,255)
make object collision box 3,0-es#,0-es#,0-es#,es#,es#,es#,0
make object cube 4,es#*2
color object 4,rgb(0,0,255)
make object collision box 4,0-es#,0-es#,0-es#,es#,es#,es#,0
make object cube 5,es#*2
color object 5,rgb(0,255,255)
make object collision box 5,0-es#,0-es#,0-es#,es#,es#,es#,0
return