I got the ai working. I deleted all the objects in magic world and placed all the objects through code.
Demons breath, thank you, i used your code in my game.
I have another problem now. I have a box that is the finish line and another box on the other side of the race track. The second box detects if the player has gone all the way around the track. The problem is that it doesn't detect that i'm colliding with these boxes and it doesnt detect the laps when i go around the race track.
gosub menu
rem the game starts here
game:
`setup the variables for acceleration
maxspeed = 100
acceleration = 1
dacceleration# = 0.5
minspeed = 0
speed=0
linecrossed#=0
enemylinecrossed#=0
hide mouse
level = 1
chooseplayer#= 0
repeat
input "Who do you want to play as press 2 to play as penguin press 3 to play as snowman",player#
if player# = 2 then chooseplayer# = 200
if player# = 3 then chooseplayer# = 201
if player# < 2 or player#>3
cls
endif
until chooseplayer# > 0
sync on
sync rate 30
if level = 1 then gosub setup_level_1
laps#=0
do
` i am using this code because the loop music command is buggy
if music playing(1)=0
stop music 1
play music 1
endif
set cursor 0,0
Rem store object angle Y in ay#
ay#= Object Angle Y(200)
rem control input
if upkey()=1 then speed = speed + acceleration
if upkey()=0 then speed = speed - dacceleration#
if leftkey()=1 then yrotate object 200,wrapvalue(ay#-5)
if rightkey()=1 then yrotate object 200,wrapvalue(ay#+5)
if downkey()=1 then speed = speed - 5
if KEYSTATE(25) then gosub pausegame
rem set speed parameters
if speed < minspeed then speed = minspeed
if speed >= maxspeed then speed = maxspeed
newplayery = get ground height(1,x#,z#)
newplayery-oldplayery = heightdiffrence
if heightdiffrence < -10 then speed = 0
if heightdiffrence > 10 then speed = 0
move object 200, speed/4
x#=object position x(200)
z#=object position z(200)
position object 200,x#,get ground height(1,x#,z#)+20,z#
gosub enemy_ai
cameraz#=newzvalue(z#,ay#-180,100)
camerax#=newxvalue(x#,ay#-180,100)
position camera camerax#,100,cameraz#
point camera x#,50,z#
print "FPS"
print screen fps()
print "player x"
print x#
print "player z"
print z#
print "laps"
print laps#
print "linecrossed"
print linecrossed#
print "enemy line crossed"
print enemylinecrossed#
print "enemy laps"
print enemylaps#
print "speed"
print speed/4
if x#>800 and x#<850 and z#>953 and z#<1230 and linecrossed# = 1
laps#=laps#+1
linecrossed#=0
endif
if object collision(300,550)>0 and enemylinecrossed#=1
enemylaps# = enemylaps#+1
enemylinecrossed#=0
endif
if x#>800 and x#<850 and z#>270 and z#<270 then linecrossed#=1
if object collision(300,551)>0 then enemylinecrossed#=1
rem check to see if you won
if laps#=3 and laps# > enemylaps# then gosub youwon
if laps#=3 and laps# < enemylaps# then gosub youlost
if laps#=3 and laps# = enemylaps# then gosub youlost
oldplayery# = get ground height(1,x#,z#)
sync
loop
rem enemies a.i.
enemy_ai:
if object collision(300,500) then point object 300,object position x(501), object position y(501), object position z(501)
if object collision(300,501) then point object 300,object position x(502), object position y(502), object position z(502)
if object collision(300,502) then point object 300,object position x(503), object position y(503), object position z(503)
if object collision(300,503) then point object 300,object position x(500), object position y(500), object position z(500)
move object 300,20
enemyx#=object position x(300)
enemyz#=object position z(300)
position object 300, enemyx#,get ground height(1,enemyx#,enemyz#)+25,enemyz#
return
` the menu
menu:
sync on
sync rate 30
LOAD BITMAP "media/titlescreen.bmp",1
GET IMAGE 1,0,0,301,93
delete bitmap 1
load bitmap "media/penguin.bmp",1
get image 2,0,0,201,246
delete bitmap 1
load sound "media/click.wav",1
do
cls
PASTE IMAGE 1,200,0
paste image 2,200,150
white=rgb(255,255,255)
ink 0,white
text 0,130,"NEW GAME"
text 0,160,"HELP"
text 0,190,"OPTIONS"
text 0,220,"QUIT"
`NEW GAME
if mousex() > 0 and mousex() < 100 and mousey() > 130 and mousey() < 150 then ink rgb(0,0,100),white : text 0,130,"NEW GAME"
if mousex() > 0 and mousex() < 100 and mousey() > 130 and mousey() < 150 and mouseclick()=1 then play sound 1 : cls : gosub game
`LOAD
if mousex() > 0 and mousex() < 100 and mousey() > 160 and mousey() < 180 then ink rgb(0,0,100),white : text 0,160,"HELP"
if mousex() > 0 and mousex() < 100 and mousey() > 160 and mousey() < 180 and mouseclick()=1 then play sound 1 : text 100,120,"YOU CLICKED HELP"
`OPTIONS
if mousex() > 0 and mousex() < 100 and mousey() > 190 and mousey() < 210 then ink rgb(0,0,100),white : text 0,190,"OPTIONS"
if mousex() > 0 and mousex() < 100 and mousey() > 190 and mousey() < 210 and mouseclick()=1 then play sound 1 : text 100,120,"YOU CLICKED OPTIONS"
`QUIT
if mousex() > 0 and mousex() < 100 and mousey() > 220 and mousey() < 240 then ink rgb(0,0,100),white : text 0,220,"QUIT"
if mousex() > 0 and mousex() < 100 and mousey() > 220 and mousey() < 240 and mouseclick()=1 then play sound 1 : end
sync
loop
`pauses the game
pausegame:
repeat
wait 1
until scancode()=0
`above code means that if you hold down the key for opening the pause section,
`then it won't automatically open and then close. It does this by repeating
`until there is no key being pressed
do
center text 320,240,"PAUSED"
wait 5
if scancode()>0 then return
`if a key is being pressed then return to the game
loop
`sets up the level
setup_level_1:
load music "media/DodgeThis.mid",1
if chooseplayer# = 200
load object "media/penguin2.x",200
scale object 200,5000,5000,5000
yrotate object 200,180
fix object pivot 200
position object 200, 1075,0,1067
load object "media/snoman.x",300
scale object 300,5000,5000,5000
yrotate object 300,180
fix object pivot 300
position object 300,1049,0,1132
endif
if chooseplayer# = 201
load object "media/snoman.x",200
scale object 200,5000,5000,5000
yrotate object 200,180
fix object pivot 200
position object 200, 1075,0,1067
load object "media/penguin2.x",300
scale object 300,5000,5000,5000
yrotate object 300,180
fix object pivot 300
position object 300,1049,0,1132
endif
#include "levels/magicload1-1.dba"
`load world
MagicLoad("levels/racetrack1",1000,1,1000)
`point enemy towards ai block
yrotate object 300,270
` make Ai Blocks
make object cube 500,100
position object 500, 408,10,1105
hide object 500
make object cube 501,100
position object 501, 410,29,366
hide object 501
make object cube 502,100
position object 502, 1215, 29, 401
hide object 502
make object cube 503,100
position object 503, 1190, 52, 1118
hide object 503
` make finish line and lap checker
load image "media/finish line texture.bmp",5
make object box 550,50,2,400
position object 550,813,35,1100
texture object 550,5
make object box 551,50,010,400
position object 551, 793,50,396
hide object 551
oldplayery# = get ground height(1, object position x(200), object position z(200))
return
youwon:
repeat
wait 1
until scancode()=0
do
center text 320,240,"you won"
wait 5
if scancode()>0 then gosub menu
loop
youlost:
repeat
wait 1
until scancode()=0
do
center text 320,240,"You Lost"
wait 5
if scancode()>0 then gosub menu
loop
rem the game starts here
game:
hide mouse
level = 1
chooseplayer#= 0
repeat
input "Who do you want to play as press 2 to play as penguin press 3 to play as snowman",player#
if player# = 2 then chooseplayer# = 200
if player# = 3 then chooseplayer# = 201
if player# < 2 or player#>3
cls
endif
until chooseplayer# > 0
sync on
sync rate 30
if level = 1 then gosub setup_level_1
laps#=0
do
set cursor 0,0
Rem store object angle Y in ay#
ay#= Object Angle Y(200)
rem control input
if upkey()=1 then move object 200,10
if leftkey()=1 then yrotate object 200,wrapvalue(ay#-5)
if rightkey()=1 then yrotate object 200,wrapvalue(ay#+5)
if downkey()=1 then move object 200,-10
if KEYSTATE(25) then gosub pausegame
x#=object position x(200)
z#=object position z(200)
position object 200,x#,get ground height(1,x#,z#)+20,z#
gosub enemy_ai
cameraz#=newzvalue(z#,ay#-180,100)
camerax#=newxvalue(x#,ay#-180,100)
position camera camerax#,100,cameraz#
point camera x#,50,z#
print "FPS"
print screen fps()
print "player x"
print x#
print "player z"
print z#
print "laps"
print laps#
print "linecrossed"
print linecrossed#
print "enemy line crossed"
print enemylinecrossed#
print "enemy laps"
print enemylaps#
if object collision(200,550)>0 and linecrossed# = 1
laps#=laps#+1
linecrossed#=0
endif
if object collision(300,550)>0 and enemylinecrossed#=1
enemylaps# = enemylaps#+1
enemylinecrossed#=0
endif
if object collision(200,551)>0 then linecrossed#=1
if object collision(300,551)>0 then enemylinecrossed#=1
rem check to see if you won
if laps#=3 and laps# > enemylaps# then gosub youwon
if laps#=3 and laps# < enemylaps# then gosub youlost
if laps#=3 and laps# = enemylaps# then gosub youlost
sync
loop
rem enemies a.i.
enemy_ai:
if object collision(300,500) then point object 300,object position x(501), object position y(501), object position z(501)
if object collision(300,501) then point object 300,object position x(502), object position y(502), object position z(502)
if object collision(300,502) then point object 300,object position x(503), object position y(503), object position z(503)
if object collision(300,503) then point object 300,object position x(500), object position y(500), object position z(500)
move object 300,8
enemyx#=object position x(300)
enemyz#=object position z(300)
position object 300, enemyx#,get ground height(1,enemyx#,enemyz#)+25,enemyz#
return
` the menu
menu:
sync on
sync rate 30
LOAD BITMAP "media/titlescreen.bmp",1
GET IMAGE 1,0,0,301,93
delete bitmap 1
load bitmap "media/penguin.bmp",1
get image 2,0,0,201,246
delete bitmap 1
load sound "media/click.wav",1
do
cls
PASTE IMAGE 1,200,0
paste image 2,200,150
white=rgb(255,255,255)
ink 0,white
text 0,130,"NEW GAME"
text 0,160,"HELP"
text 0,190,"OPTIONS"
text 0,220,"QUIT"
`NEW GAME
if mousex() > 0 and mousex() < 100 and mousey() > 130 and mousey() < 150 then ink rgb(0,0,100),white : text 0,130,"NEW GAME"
if mousex() > 0 and mousex() < 100 and mousey() > 130 and mousey() < 150 and mouseclick()=1 then play sound 1 : cls : gosub game
`LOAD
if mousex() > 0 and mousex() < 100 and mousey() > 160 and mousey() < 180 then ink rgb(0,0,100),white : text 0,160,"HELP"
if mousex() > 0 and mousex() < 100 and mousey() > 160 and mousey() < 180 and mouseclick()=1 then play sound 1 : text 100,120,"YOU CLICKED HELP"
`OPTIONS
if mousex() > 0 and mousex() < 100 and mousey() > 190 and mousey() < 210 then ink rgb(0,0,100),white : text 0,190,"OPTIONS"
if mousex() > 0 and mousex() < 100 and mousey() > 190 and mousey() < 210 and mouseclick()=1 then play sound 1 : text 100,120,"YOU CLICKED OPTIONS"
`QUIT
if mousex() > 0 and mousex() < 100 and mousey() > 220 and mousey() < 240 then ink rgb(0,0,100),white : text 0,220,"QUIT"
if mousex() > 0 and mousex() < 100 and mousey() > 220 and mousey() < 240 and mouseclick()=1 then play sound 1 : end
sync
loop
`pauses the game
pausegame:
repeat
wait 1
until scancode()=0
`above code means that if you hold down the key for opening the pause section,
`then it won't automatically open and then close. It does this by repeating
`until there is no key being pressed
do
center text 320,240,"PAUSED"
wait 5
if scancode()>0 then return
`if a key is being pressed then return to the game
loop
`sets up the level
setup_level_1:
load music "media/DodgeThis.mid",1
`loop music 1
if chooseplayer# = 200
load object "media/penguin2.x",200
scale object 200,5000,5000,5000
yrotate object 200,180
fix object pivot 200
position object 200, 1075,0,1067
load object "media/snoman.x",300
scale object 300,5000,5000,5000
yrotate object 300,180
fix object pivot 300
position object 300,1049,0,1132
endif
if chooseplayer# = 201
load object "media/snoman.x",200
scale object 200,5000,5000,5000
yrotate object 200,180
fix object pivot 200
position object 200, 1075,0,1067
load object "media/penguin2.x",300
scale object 300,5000,5000,5000
yrotate object 300,180
fix object pivot 300
position object 300,1049,0,1132
endif
#include "levels/magicload1-1.dba"
`load world
MagicLoad("levels/racetrack1",1000,1,1000)
`point enemy towards ai block
yrotate object 300,270
` make Ai Blocks
make object cube 500,100
position object 500, 408,10,1105
hide object 500
make object cube 501,100
position object 501, 410,29,366
hide object 501
make object cube 502,100
position object 502, 1215, 29, 401
hide object 502
make object cube 503,100
position object 503, 1190, 52, 1118
hide object 503
` make finish line and lap checker
load image "media/finish line texture.bmp",5
make object box 550,50,2,400
position object 550,813,35,1100
texture object 550,5
make object box 551,50,010,400
position object 551, 793,50,396
hide object 551
linecrossed#=0
enemylinecrossed#=0
return
youwon:
repeat
wait 1
until scancode()=0
do
center text 320,240,"you won"
wait 5
if scancode()>0 then gosub menu
loop
youlost:
repeat
wait 1
until scancode()=0
do
center text 320,240,"You Lost"
wait 5
if scancode()>0 then gosub menu
loop
please help me
------------------------------------------------
edit: I am having a new problem. The game worked, except for the collision detection on the finish line. but about 10 seconds after i typed this post and copied and pasted the source code i ran into a new problem it says unknown command at the end of line 211 which is strange because it worked right before i posted this question. I didn't change anything.
line 211 says
MagicLoad("levels/racetrack1",1000,1,1000)
edit: I fixed this problem. I had a space before the magic load command and a space before the #include command. and i guess the space makes the diffrence because after i deleted the space it worked.
--------------------------------------------------
can u please help me with both of these problems.
-----------------------------------------------------
edit:
I have tried to fix the problem by replacing if object collision(200,550)>0 and enemylinecrossed#=1
with
if x#>800 and x#<850 and z#>953 and z#<1230 and linecrossed# = 1
but that doesn't work either and i dont understand why.
I have added in acceleration. It works.
I am trying to make it so that u can't climb up the walls in my level.
I want to do this without having to create invisble boxes and that stuff so i tried this
newplayery-oldplayery = heightdiffrence
if heightdiffrence < -10 then speed = 0
if heightdiffrence > 10 then speed = 0
I made it so that it checks to see the diffrence in y and if there is a big diffrence it will make it so that i can't climb up the wall. I am trying to do it this way so that i don't have to code a new collision with the wall thing with every level i make. The problem is that this doesn't work and i dont understand why it doesn't. There is a picture of my level on a post above.
I dont understand why the change in y thing and the collision with the finish line doesn't work. Can u please help me. Also i have downloaded a collision dll, i think it was called sparkys collision dll or something, the actual dll file is called DBCcollision.dll. I dont undersatnd how to use that either. I downloaded it because i thought it would help with the collision against the finish line.
my new code
gosub menu
rem the game starts here
game:
`setup the variables for acceleration
maxspeed = 100
acceleration = 1
dacceleration# = 0.5
minspeed = 0
speed=0
linecrossed#=0
enemylinecrossed#=0
hide mouse
level = 1
chooseplayer#= 0
repeat
input "Who do you want to play as press 2 to play as penguin press 3 to play as snowman",player#
if player# = 2 then chooseplayer# = 200
if player# = 3 then chooseplayer# = 201
if player# < 2 or player#>3
cls
endif
until chooseplayer# > 0
sync on
sync rate 30
if level = 1 then gosub setup_level_1
laps#=0
do
` i am using this code because the loop music command is buggy
if music playing(1)=0
stop music 1
play music 1
endif
set cursor 0,0
Rem store object angle Y in ay#
ay#= Object Angle Y(200)
rem control input
if upkey()=1 then speed = speed + acceleration
if upkey()=0 then speed = speed - dacceleration#
if leftkey()=1 then yrotate object 200,wrapvalue(ay#-5)
if rightkey()=1 then yrotate object 200,wrapvalue(ay#+5)
if downkey()=1 then speed = speed - 5
if KEYSTATE(25) then gosub pausegame
rem set speed parameters
if speed < minspeed then speed = minspeed
if speed >= maxspeed then speed = maxspeed
newplayery = get ground height(1,x#,z#)
newplayery-oldplayery = heightdiffrence
if heightdiffrence < -10 then speed = 0
if heightdiffrence > 10 then speed = 0
move object 200, speed/4
x#=object position x(200)
z#=object position z(200)
position object 200,x#,get ground height(1,x#,z#)+20,z#
gosub enemy_ai
cameraz#=newzvalue(z#,ay#-180,100)
camerax#=newxvalue(x#,ay#-180,100)
position camera camerax#,100,cameraz#
point camera x#,50,z#
print "FPS"
print screen fps()
print "player x"
print x#
print "player z"
print z#
print "laps"
print laps#
print "linecrossed"
print linecrossed#
print "enemy line crossed"
print enemylinecrossed#
print "enemy laps"
print enemylaps#
print "speed"
print speed/4
if x#>800 and x#<850 and z#>953 and z#<1230 and linecrossed# = 1
laps#=laps#+1
linecrossed#=0
endif
if object collision(300,550)>0 and enemylinecrossed#=1
enemylaps# = enemylaps#+1
enemylinecrossed#=0
endif
if x#>800 and x#<850 and z#>270 and z#<270 then linecrossed#=1
if object collision(300,551)>0 then enemylinecrossed#=1
rem check to see if you won
if laps#=3 and laps# > enemylaps# then gosub youwon
if laps#=3 and laps# < enemylaps# then gosub youlost
if laps#=3 and laps# = enemylaps# then gosub youlost
oldplayery# = get ground height(1,x#,z#)
sync
loop
rem enemies a.i.
enemy_ai:
if object collision(300,500) then point object 300,object position x(501), object position y(501), object position z(501)
if object collision(300,501) then point object 300,object position x(502), object position y(502), object position z(502)
if object collision(300,502) then point object 300,object position x(503), object position y(503), object position z(503)
if object collision(300,503) then point object 300,object position x(500), object position y(500), object position z(500)
move object 300,20
enemyx#=object position x(300)
enemyz#=object position z(300)
position object 300, enemyx#,get ground height(1,enemyx#,enemyz#)+25,enemyz#
return
` the menu
menu:
sync on
sync rate 30
LOAD BITMAP "media/titlescreen.bmp",1
GET IMAGE 1,0,0,301,93
delete bitmap 1
load bitmap "media/penguin.bmp",1
get image 2,0,0,201,246
delete bitmap 1
load sound "media/click.wav",1
do
cls
PASTE IMAGE 1,200,0
paste image 2,200,150
white=rgb(255,255,255)
ink 0,white
text 0,130,"NEW GAME"
text 0,160,"HELP"
text 0,190,"OPTIONS"
text 0,220,"QUIT"
`NEW GAME
if mousex() > 0 and mousex() < 100 and mousey() > 130 and mousey() < 150 then ink rgb(0,0,100),white : text 0,130,"NEW GAME"
if mousex() > 0 and mousex() < 100 and mousey() > 130 and mousey() < 150 and mouseclick()=1 then play sound 1 : cls : gosub game
`LOAD
if mousex() > 0 and mousex() < 100 and mousey() > 160 and mousey() < 180 then ink rgb(0,0,100),white : text 0,160,"HELP"
if mousex() > 0 and mousex() < 100 and mousey() > 160 and mousey() < 180 and mouseclick()=1 then play sound 1 : text 100,120,"YOU CLICKED HELP"
`OPTIONS
if mousex() > 0 and mousex() < 100 and mousey() > 190 and mousey() < 210 then ink rgb(0,0,100),white : text 0,190,"OPTIONS"
if mousex() > 0 and mousex() < 100 and mousey() > 190 and mousey() < 210 and mouseclick()=1 then play sound 1 : text 100,120,"YOU CLICKED OPTIONS"
`QUIT
if mousex() > 0 and mousex() < 100 and mousey() > 220 and mousey() < 240 then ink rgb(0,0,100),white : text 0,220,"QUIT"
if mousex() > 0 and mousex() < 100 and mousey() > 220 and mousey() < 240 and mouseclick()=1 then play sound 1 : end
sync
loop
`pauses the game
pausegame:
repeat
wait 1
until scancode()=0
`above code means that if you hold down the key for opening the pause section,
`then it won't automatically open and then close. It does this by repeating
`until there is no key being pressed
do
center text 320,240,"PAUSED"
wait 5
if scancode()>0 then return
`if a key is being pressed then return to the game
loop
`sets up the level
setup_level_1:
load music "media/DodgeThis.mid",1
if chooseplayer# = 200
load object "media/penguin2.x",200
scale object 200,5000,5000,5000
yrotate object 200,180
fix object pivot 200
position object 200, 1075,0,1067
load object "media/snoman.x",300
scale object 300,5000,5000,5000
yrotate object 300,180
fix object pivot 300
position object 300,1049,0,1132
endif
if chooseplayer# = 201
load object "media/snoman.x",200
scale object 200,5000,5000,5000
yrotate object 200,180
fix object pivot 200
position object 200, 1075,0,1067
load object "media/penguin2.x",300
scale object 300,5000,5000,5000
yrotate object 300,180
fix object pivot 300
position object 300,1049,0,1132
endif
#include "levels/magicload1-1.dba"
`load world
MagicLoad("levels/racetrack1",1000,1,1000)
`point enemy towards ai block
yrotate object 300,270
` make Ai Blocks
make object cube 500,100
position object 500, 408,10,1105
hide object 500
make object cube 501,100
position object 501, 410,29,366
hide object 501
make object cube 502,100
position object 502, 1215, 29, 401
hide object 502
make object cube 503,100
position object 503, 1190, 52, 1118
hide object 503
` make finish line and lap checker
load image "media/finish line texture.bmp",5
make object box 550,50,2,400
position object 550,813,35,1100
texture object 550,5
make object box 551,50,010,400
position object 551, 793,50,396
hide object 551
oldplayery# = get ground height(1, object position x(200), object position z(200))
return
youwon:
repeat
wait 1
until scancode()=0
do
center text 320,240,"you won"
wait 5
if scancode()>0 then gosub menu
loop
youlost:
repeat
wait 1
until scancode()=0
do
center text 320,240,"You Lost"
wait 5
if scancode()>0 then gosub menu
loop
please help me, i dont undersatnd why the collsion doesn't work