Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Level switch Code HELP!!!

Author
Message
TylerTheLizard
7
Years of Service
User Offline
Joined: 26th Sep 2016
Location:
Posted: 28th Nov 2016 13:59
So I have 5 days to figure out this stupid issue. I cannot figure out how to make it so when my score# gets to a certain point then the game deletes all objects and goes to the next level. I will only bore you guys with the first two levels. I have spent 4 hours on this problem already. Someone please help







sync on : sync rate 30
autocam off : Rem Set autocamera options
hide mouse
randomize timer()




LevelOne:
REM DECLARE VARIABLES
REM SCREEN DISPLAY
cls 0
backdrop on
color backdrop rgb(50,0,50)
REM LOAD IMAGES


load image "C:\Users\tyler_hatha172\Desktop\Textures\treetop.jpg", 1
load image "C:\Users\tyler_hatha172\Desktop\Textures\treebark.jpg", 2
load image "C:\Users\tyler_hatha172\Desktop\Textures\lavapool.jpg",3
load image "C:\Users\tyler_hatha172\Desktop\Textures\bloodmoon.jpg", 4
load image "C:\Users\tyler_hatha172\Desktop\Textures\pentacle1.jpg", 5
load image "C:\Users\tyler_hatha172\Desktop\Textures\pentacle3.jpg", 6
REM LOAD MUSIC
load music "M:\Video Game Design\Phase 4\Sounds\Lilith.wav", 7
load sound "M:\Video Game Design\Phase 4\Sounds\pickup.wav", 8
play music 7
loop music 7

REM OBJECT CREATION
make object cone 1, 100
texture object 1, 6
position object 1, 0,50,0
set object collision on 1
make object collision box 1 ,-50,-50,-50, 50,50,50 ,1
REM GROUND
make object plain 2, 3000,3000,10
texture object 2,3
rotate object 2, 90,0,0
REM EAST WALL
make object box 3, 3000,1000,10
position object 3, 1500,500,0
rotate object 3, 0,270,0
texture object 3,4
set object collision on 3
make object collision box 3 ,-1500,-500,-10, 1500,500,10 ,3
REM NORTH WALL
make object box 4, 3000,1000,10
position object 4, -1500,500,0
rotate object 4, 0,270,0
texture object 4,4
set object collision on 4
make object collision box 4 ,-1500,-500,-10, 1500,500,10 ,4
REM SOUTH WALL
make object box 5, 3000,1000,10
position object 5, 0,500,1500
texture object 5,4
set object collision on 5
make object collision box 5 ,-1500,-500,-10, 1500,500,10 ,5
REM EAST WALL
make object box 6, 3000,1000,10
position object 6, 0,500,-1500
texture object 6,4
set object collision on 6
make object collision box 6 ,-1500,-500,-10, 1500,500,10 ,6
REM TREES
make object cylinder 7, 100
position object 7, -300,0,200
texture object 7,2
set object collision on 7
make object collision box 7, -50,-50,-50 ,50,50,50 ,7
make object cylinder 9, 100
position object 9, 200,0,-450
texture object 9,2
set object collision on 9
make object collision box 9, -50,-50,-50 ,50,50,50 ,9
make object cylinder 11, 100
position object 11, 1000,0,-500
texture object 11,2
set object collision on 11
make object collision box 11, -50,-50,-50 ,50,50,50 ,11
make object cylinder 13, 100
position object 13, 400,0,100
texture object 13,2
set object collision on 13
make object collision box 13, -50,-50,-50 ,50,50,50 ,13
make object cylinder 15, 100
position object 15, -800,0,100
texture object 15,2
set object collision on 7
make object collision box 7, -50,-50,-50 ,50,50,50 ,7
make object cylinder 17, 100
position object 17, 900,0,200
texture object 17,2
make object cylinder 19, 100
position object 19, -110,0,600
texture object 19,2
make object cylinder 21, 100
position object 21, -600,0,750
texture object 21,2
REM LEAVES
make object cone 8, 200
position object 8, -300,150,200
texture object 8, 1
make object cone 10, 200
position object 10, 200,150,-450
texture object 10, 1
make object cone 12, 200
position object 12, 1000,150,-500
texture object 12, 1
make object cone 14, 200
position object 14, 400,150,100
texture object 14, 1
make object cone 16, 200
position object 16, -800,150,100
texture object 16, 1
make object cone 18, 200
position object 18, 900,150,200
texture object 18, 1
make object cone 20, 200
position object 20, -110,150,600
texture object 20, 1
make object cone 22, 200
position object 22, -600,150,750
texture object 22, 1
REM LIGHT
make light 23
set light range 23, 10000
position light 23, 0,100,0
point light 23, 0,0,0




make light 24
set light range 24, 10000
position light 24, 0,100,0
point light 24, 0,20,0
Rem SPHERES
for s = 25 to 31
make object sphere s, 100
texture object s , 5
position object s, rnd(950)-rnd(950),25,rnd(950)-rnd(950)
next s


REM LOAD MODELS
REM SET CAMERA
position camera -20,100,-300 : Rem Set camera position
point camera 0,50,0 : Rem Rotate camera to point at a specific place
REM REFRESH SCREEN
sync




REM *** MAIN SECTION LOOP



score#=0
do
for obj=1 to 30
if object exist(obj)=1 then if object collision(1,obj)=1 then position object 1, P1X#,P1Y#,P1Z#
next

if object collision(1,3)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,4)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,5)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,6)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,7)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,8)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,9)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,10)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,11)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,12)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,13)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,14)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,15)= 1
position object 1, P1X#,P1Y#,P1Z#
endif
if object collision(1,16)= 1
position object 1, P1X#,P1Y#,P1Z#
endif


REM SPECIAL EFFECTS
REM OBJECT ORIENTATIONS
P1X# = object position X(1)
P1Y# = object position Y(1)
P1Z# = object position Z(1)
A1X = object angle X(1)
A1Y = object angle Y(1)
A1Z = object angle Z(1)
REM CAMERA ORIENTATIONS
Rem Store the positions of the Camera as variables
cpX# = camera position X()
cpY# = camera position Y()
cpZ# = camera position Z()
Rem Store the angles of the Camera as variables
caX# = camera angle X()
caY# = camera angle Y()
caZ# = camera angle Z()







For s = 25 to 31
If Object collision (1,s) = 1
play sound 8
position object s , rnd(950)-rnd(950),25,rnd(950)-rnd(950)
score#= score# + 1
print


endif
Next S

If score# > 10
delete objects 1,100
then gosub leveltwo:
endif





if Upkey()=1 then move object 1,10
if Downkey()=1 then move object 1,-10
if Leftkey()=1 then Yrotate object 1,wrapvalue(A1Y-5)
if Rightkey()=1 then Yrotate object 1,wrapvalue(A1Y+5)




if Inkey$()="1"
position camera -20,100,-300 : Rem Set camera position
point camera 0,50,0 : Rem Rotate camera to point at a specific place
followMe = 0 : Rem Tell the program not to follow Object 1
endif




if Inkey$()="2"
position camera 0,1500,0 : Rem Set camera position
point camera 0,0,0 : Rem Rotate camera to point at a specific place
followMe = 0 : Rem Tell the program not to follow Object 1
endif




if Inkey$()="3"
followMe = 1 : Rem Tell the program to follow Object 1
endif




if Inkey$()="q"
for x = 1 to 100
if object exist(x) = 1 then delete object x
next x
backdrop off
gosub EndSection
endif
REM TRANSFORM OBJECTS
REM MOVE OBJECTS
REM CHECK FOR COLLISION
REM MOVE CAMERA
if followMe = 1 : Rem If the camera is following Object 1
cpZ# = Newzvalue(P1Z#,A1Y-180,200) : Rem Calculate the camera's new Z position
cpX# = Newxvalue(P1X#,A1Y-180,200) : Rem Calculate the camera's new X position
Position camera cpX#,200,cpZ# : Rem Set the camera placement
Point camera P1X#,P1Y#+50,P1Z# : Rem Point camera at the top of Object 1
AUTOMATIC CAMERA COLLISION 0, 5, 1
endif
REM REFRESH SCREEN
sync
loop




leveltwo:
REM DECLARE VARIABLES
REM SCREEN DISPLAY
cls 0
backdrop on
color backdrop rgb(50,0,50)
REM LOAD IMAGES


load image "C:\Users\tyler_hatha172\Desktop\Textures\forestleaf.jpg", 1
load image "C:\Users\tyler_hatha172\Desktop\Textures\forestbark.jpg", 2
load image "C:\Users\tyler_hatha172\Desktop\Textures\forestfloor.jpg",3
load image "C:\Users\tyler_hatha172\Desktop\Textures\forest.jpg", 4
load image "C:\Users\tyler_hatha172\Desktop\Textures\forestplayer.jpg", 5
load image "C:\Users\tyler_hatha172\Desktop\Textures\forestapple.jpg", 6
REM LOAD MUSIC
load music "C:\Users\tyler_hatha172\Desktop\Sounds\Forest.wav", 7
load sound "C:\Users\tyler_hatha172\Desktop\Sounds\pickup.wav", 8
play music 7
loop music 7

REM OBJECT CREATION
make object cone 1, 100
texture object 1, 6
position object 1, 0,50,0
set object collision on 1
make object collision box 1 ,-50,-50,-50, 50,50,50 ,1
REM GROUND
make object plain 2, 3000,3000,10
texture object 2,3
rotate object 2, 90,0,0
REM EAST WALL
make object box 3, 3000,1000,10
position object 3, 1500,500,0
rotate object 3, 0,270,0
texture object 3,4
set object collision on 3
make object collision box 3 ,-1500,-500,-10, 1500,500,10 ,3
REM NORTH WALL
make object box 4, 3000,1000,10
position object 4, -1500,500,0
rotate object 4, 0,270,0
texture object 4,4
set object collision on 4
make object collision box 4 ,-1500,-500,-10, 1500,500,10 ,4
REM SOUTH WALL
make object box 5, 3000,1000,10
position object 5, 0,500,1500
texture object 5,4
set object collision on 5
make object collision box 5 ,-1500,-500,-10, 1500,500,10 ,5
REM EAST WALL
make object box 6, 3000,1000,10
position object 6, 0,500,-1500
texture object 6,4
set object collision on 6
make object collision box 6 ,-1500,-500,-10, 1500,500,10 ,6
REM TREES
make object cylinder 7, 100
position object 7, -300,0,200
texture object 7,2
set object collision on 7
make object collision box 7, -50,-50,-50 ,50,50,50 ,7
make object cylinder 9, 100
position object 9, 200,0,-450
texture object 9,2
set object collision on 9
make object collision box 9, -50,-50,-50 ,50,50,50 ,9
make object cylinder 11, 100
position object 11, 1000,0,-500
texture object 11,2
set object collision on 11
make object collision box 11, -50,-50,-50 ,50,50,50 ,11
make object cylinder 13, 100
position object 13, 400,0,100
texture object 13,2
set object collision on 13
make object collision box 13, -50,-50,-50 ,50,50,50 ,13
make object cylinder 15, 100
position object 15, -800,0,100
texture object 15,2
set object collision on 7
make object collision box 7, -50,-50,-50 ,50,50,50 ,7
make object cylinder 17, 100
position object 17, 900,0,200
texture object 17,2
make object cylinder 19, 100
position object 19, -110,0,600
texture object 19,2
make object cylinder 21, 100
position object 21, -600,0,750
texture object 21,2
REM LEAVES
make object cone 8, 200
position object 8, -300,150,200
texture object 8, 1
make object cone 10, 200
position object 10, 200,150,-450
texture object 10, 1
make object cone 12, 200
position object 12, 1000,150,-500
texture object 12, 1
make object cone 14, 200
position object 14, 400,150,100
texture object 14, 1
make object cone 16, 200
position object 16, -800,150,100
texture object 16, 1
make object cone 18, 200
position object 18, 900,150,200
texture object 18, 1
make object cone 20, 200
position object 20, -110,150,600
texture object 20, 1
make object cone 22, 200
position object 22, -600,150,750
texture object 22, 1
REM LIGHT
make light 23
set light range 23, 10000
position light 23, 0,100,0
point light 23, 0,0,0




make light 24
set light range 24, 10000
position light 24, 0,100,0
point light 24, 0,20,0
Rem SPHERES
for s = 25 to 31
make object sphere s, 100
texture object s , 5
position object s, rnd(950)-rnd(950),25,rnd(950)-rnd(950)
next s


REM LOAD MODELS
REM SET CAMERA
position camera -20,100,-300 : Rem Set camera position
point camera 0,50,0 : Rem Rotate camera to point at a specific place
REM REFRESH SCREEN
sync




REM *** MAIN SECTION LOOP



score#=0
do
for obj=1 to 30
if object exist(obj)=1 then if object collision(1,obj)=1 then position object 1, P1X#,P1Y#,P1Z#
next

i

REM SPECIAL EFFECTS
REM OBJECT ORIENTATIONS
P1X# = object position X(1)
P1Y# = object position Y(1)
P1Z# = object position Z(1)
A1X = object angle X(1)
A1Y = object angle Y(1)
A1Z = object angle Z(1)
REM CAMERA ORIENTATIONS
Rem Store the positions of the Camera as variables
cpX# = camera position X()
cpY# = camera position Y()
cpZ# = camera position Z()
Rem Store the angles of the Camera as variables
caX# = camera angle X()
caY# = camera angle Y()
caZ# = camera angle Z()







For s = 25 to 31
If Object collision (1,s) = 1
play sound 8
position object s , rnd(950)-rnd(950),25,rnd(950)-rnd(950)
score#= score# + 1
print


endif
Next S






if Upkey()=1 then move object 1,10
if Downkey()=1 then move object 1,-10
if Leftkey()=1 then Yrotate object 1,wrapvalue(A1Y-5)
if Rightkey()=1 then Yrotate object 1,wrapvalue(A1Y+5)




if Inkey$()="1"
position camera -20,100,-300 : Rem Set camera position
point camera 0,50,0 : Rem Rotate camera to point at a specific place
followMe = 0 : Rem Tell the program not to follow Object 1
endif




if Inkey$()="2"
position camera 0,1500,0 : Rem Set camera position
point camera 0,0,0 : Rem Rotate camera to point at a specific place
followMe = 0 : Rem Tell the program not to follow Object 1
endif




if Inkey$()="3"
followMe = 1 : Rem Tell the program to follow Object 1
endif




if Inkey$()="q"
for x = 1 to 100
if object exist(x) = 1 then delete object x
next x
backdrop off
gosub EndSection
endif
REM TRANSFORM OBJECTS
REM MOVE OBJECTS
REM CHECK FOR COLLISION
REM MOVE CAMERA
if followMe = 1 : Rem If the camera is following Object 1
cpZ# = Newzvalue(P1Z#,A1Y-180,200) : Rem Calculate the camera's new Z position
cpX# = Newxvalue(P1X#,A1Y-180,200) : Rem Calculate the camera's new X position
Position camera cpX#,200,cpZ# : Rem Set the camera placement
Point camera P1X#,P1Y#+50,P1Z# : Rem Point camera at the top of Object 1
AUTOMATIC CAMERA COLLISION 0, 5, 1
endif
REM REFRESH SCREEN
sync
loop





EndSection:
REM DECLARE VARIABLES
REM SCREEN DISPLAY
cls 0
ink rgb(255,255,255),0 : set text font "times" : set text size 20 : set text to bold : set text transparent
center text 400,560,"PLAY AGAIN [y/n]?"
REM LOAD SOUNDS
REM SPECIAL EFFECTS
REM REFRESH SCREEN
sync




REM *** END SECTION LOOP







end
REM *** STOP END SECTION
REM *****************************************


Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 28th Nov 2016 22:20 Edited at: 28th Nov 2016 22:21
Your code is too messy
let alone the fact that the character can't even move due to collision settings of the wall box (it's Always colliding)
just stick to a single Do-Sync-Loop and use gosubs for level changing when conditions are met
I'll give you an example based on your code (textures and sound are missing of course)
I hope ypu will take it as a tutorial for decent programming (no pun intended of course)

Attachments

Login to view attachments
Scorpyo
21
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 28th Nov 2016 22:22
And..if you are reusing the same textures and objects, no need to delete and reload

Attachments

Login to view attachments
Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 28th Nov 2016 23:59 Edited at: 29th Nov 2016 23:05
Yeah, it's just an organizational problem... the logic of programming comes with experience so never give up!
Since you're short on time, maybe the following format will make good sense to you:



There are ways to simplify this even more, but maybe this will at least give you some ideas.
Send your parents to noisy sprite demo hell... enter the D-Zone
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 29th Nov 2016 07:48
what Derek said lol. your code can be simplified with a few for next loops there are a lot of lines that are somewhat redundant compressed version

your code is a bit out of order and doesn't seems to run proper. as is, player doesn't move always checks positive for collision and moves player back don't need to specify collision boxes on a box either i believe just set the collision on.
A child's dream never dies.





Login to post a reply

Server time is: 2024-03-28 11:01:34
Your offset time is: 2024-03-28 11:01:34