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.

Newcomers DBPro Corner / I need help creating cubes

Author
Message
ysuleman
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 12th Apr 2010 19:45
I am making a game. I want to add cubes around the ground but I have no idea how to do that. Can someone please help me add cubes randomly around the ground.

here is the code for the game.

` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com


_MENU:
rem make a simple Menu
set display mode 640,480,16
cls rgb(0,0,0)

do
ink rgb(255,0,0),0
box 230,120,430,160
box 230,200,430,240

if mousex()>230 and mousex()<430 and mousey()>120 and mousey()<160
ink rgb(0,255,0),0
box 230,120,430,160
if mouseclick()=1 then GOTO NEW_GAME
endif
if mousex()>230 and mousex()<430 and mousey()>200 and mousey()<240
ink rgb(0,255,0),0
box 230,200,430,240
if mouseclick()=1 then end
endif
ink rgb(255,255,255),0
set text font "Viner Hand ITC"
set text size 60
text 300,10,"ZeuG"
set text font "Times New Roman"
set text size 14
text 300,130,"New Game"
text 310,210,"Exit"
sync
loop
return


NEW_GAME:
rem make a quick texture for the matrix
cls rgb(0,255,0)
for x=0 to 1024
dot rnd(32),rnd(32),rgb(0,125,0)
next x
get image 1,0,0,32,32


rem make player object
make object cube 1,1
color object 1,rgb(255,0,0)

rem make an enemy object
rem with a smiley face!
ink rgb(255,0,0),rgb(255,255,0)
cls rgb(255,255,0)
circle 16,16,16
dot 9,5 ; dot 23,5
line 9,23,23,23
get image 3,0,0,32,32

make object cube 2,1
texture object 2,3

rem make matrix, and apply to it
rem the texture we just made
make matrix 1,500,500,100,100
randomize matrix 1,2
prepare matrix texture 1,1,1,1

rem make a bunch of holes
for x=1 to 99
for y=1 to 99
yes=rnd(20)
if yes=10
set matrix height 1,x,y,-70
set matrix height 1,x,y+1,-70
set matrix height 1,x+1,y,-70
set matrix height 1,x+1,y+1,-70
endif
next y
next x

update matrix 1


rem setup the particles
cls rgb(255,0,0)
for x=0 to 512
dot rnd(32),rnd(32),rgb(255,255,0)
next x
get image 2,0,0,32,32
make particles 1,2,100,2
set particle floor 1,0
set particle life 1,5

rem set the "scary" scene
color backdrop rgb(0,0,0)
set ambient light 0
set point light 0,0,100,0
color light 0,255,255,255
set light range 0,50


rem set up the variables
x#=260
z#=260
enemx#=265
enemz#=265
direction#=270
y#=get ground height(1,x#,z#)
gravity#=0
power=1000
lives=5
sync on
sync rate 60




`******************************************
rem begin the loop
`******************************************
do
IF LIVES<0 then gosub end_game
if power<1000 then power=power+1
gosub _control_physics
gosub _control_player
gosub _control_camera
gosub _control_effects
gosub _control_enemy

rem make the life counter change
text 0,0,"Energy:"+str$(INT(power/10))+"%"
if lives>=3 then text 0,15,"You have "+str$(lives)+" lives."
if lives=2 then text 0,15,"You have just "+str$(lives)+" lives!"
if lives=1 then text 0,15,"Beware, you only have 1 life left!"
if lives=0 then text 0,15,"Uh Oh!, this is your last life!"
sync
loop

rem *************************************
rem SUBROUTINES
rem *************************************

_control_player:
powerup=0
if keystate(17)=1 and power>=0 then powerup=1
rem decrease the power of your jump
if jumpower#>0 then jumpower#=jumpower#-0.004

rem move player forwards
if upkey()=1 and move=1
x#=newxvalue(x#,a#,0.2)
z#=newzvalue(z#,a#,0.2)
if powerup=1
x#=newxvalue(x#,a#,0.3)
z#=newzvalue(z#,a#,0.3)
power=power-5
endif
endif

rem move player backwards
if downkey()=1
rem try putting your own code here,
rem to reverse the player
endif

rem turn the player
if leftkey()=1 then a#=a#-2
if rightkey()=1 then a#=a#+2

rem if you press space, set the
rem jumppower to a high number
rem if you are on the ground
if spacekey()=1 and move=1
if y#=g# then jumpower#=0.3
endif


rem update y value based on jumping
y#=y#+jumpower#
rem update player a bit higher
rem than calculated due to the
rem origin of the object being
rem in the centre
yrotate object 1,a#
position object 1,x#,y#+0.5,z#

rem if slope is too steep, dont move!
move=1
frontx#=newxvalue(x#,a#,1)
frontz#=newzvalue(z#,a#,1)
fronth#=get ground height(1,frontx#,frontz#)
if fronth#-y#>0.5 then move=0
rem for when you impliment moving backwards
`backx#=newxvalue(x#,a#,-1)
`backz#=newzvalue(z#,a#,-1)
`backh#=get ground height(1,backx#,backz#)
rem you do the last bit here...

rem die if you fall down a hole!
if y#<-60
x#=rnd(500)
z#=rnd(500)
y#=6
lives=lives-1
endif
return







_control_camera:

rem set up the third person camera
if y#>-5
cx#=newxvalue(x#,a#,-10)
cz#=newzvalue(z#,a#,-10)
else
cx#=x#
cz#=z#
endif
position camera cx#,6,cz#
point camera x#,y#,z#
return

_control_physics:

rem if the player is higher than the height
rem of the ground then set the gravity
rem to get faster
g#=get ground height(1,x#,z#)
if y#>g#
gravity#=gravity#+0.005
y#=y#-gravity#
else
y#=g#
gravity#=0
endif
return

_control_effects:
rem put a simple light from the camera to
rem put a ring around the player
position light 0,cx#,camera position y(),cz#
point light 0,x#,y#,z#
rem will put the emission object for our
rem particle system at the origin of the
rem player
if powerup=1
position particle emissions 1,x#,y#,z#
else
position particle emissions 1,-100000,-100000,-100000
endif
return

_control_enemy:
enemt#=ATANFULL(x#-enemx#,z#-enemz#)
yrotate object 2,enemt#
enemlengthx#=(x#-enemx#)
enemlengthz#=(z#-enemz#)
enemcross#=((enemlengthx#*enemlengthx#)+(enemlengthz#*enemlengthz#))
enemdist#=sqrt(enemcross#)
enemfront#=get ground height(1,newxvalue(enemx#,enemt#,1),newzvalue(enemz#,enemt#,1))

rem move enemy code
if enemdist#>5
if enemfront#>-1
enemx#=newxvalue(enemx#,enemt#,0.1)
enemz#=newzvalue(enemz#,enemt#,0.1)
else
rem make the enemy jump
if enemjump#<0 then enemjump#=3

if enemjump#>0
enemx#=newxvalue(enemx#,enemt#,0.1)
enemz#=newzvalue(enemz#,enemt#,0.1)
endif
endif
endif


if enemjump>0
enemjump#=enemjump#-0.001
enemy#=enemjump#
else
enemy#=get ground height(1,enemx#,enemz#)+0.5
endif
position object 2,enemx#,enemy#,enemz#
rem enemy stuff goes here
return

end


end_game:
rem this delets everything, and allows you to either restart or quit
for x=1 to 10
if object exist(x)=1 then delete object x
if image exist(x)=1 then delete image x
if matrix exist(x)=1 then delete matrix x
next x
GOSUB _MENU
return

rem ***********************************
rem A FEW HANDY NOTES 4 n00b5
rem ***********************************

remstart

Are you new to DB Pro? Well then this is a short
turorial for you. If you read through the code,
you'll notice I've left bits out. As a quick
challenge, so you can test and improve your
coding abilities, try filling in the missed out
bits.

Okay, done that? Now try replacing the upkey()
etc commands with keystate(keynumber) commands.
a quick program to find out which number
corresponds to which key would be so:
sync on
do
number=SCANCODE
text 0,0,str$(number)
sync
loop

Once you have done that, you could try replacing
my simple in-drawn images with outside media, and
models, then you could even introducing more enemies.
I've laid the basics down for one that follows you,
but you could try making it shoot!
GOOD LUCK!

If that's too hard try using a and d as strafe
keys, that would sure be easier!
remend
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Apr 2010 22:46 Edited at: 12th Apr 2010 22:50
First of all, see 9 here:

http://forum.thegamecreators.com/?m=forum_view&b=10&t=116024&p=0

Though reading the rest won't be a waste of time...

As for your question, this doesn't add up - looking at 'your' code and then looking at the fact that you are asking for help to create cubes that is.

Obviously we can see you didn't write this (and are clearly not claiming you did) but you are trying to shortcut (or completely avoid) the learning process by patching other people's code to do what you want.

I've no problem with that if you can understand the code you are working with. But if you are not, then you are heading for disappointment. Plus, you are simply wasting everybody's time - including your own.

For a start, you aren't going to even understand the answers to your question!

So, I for one don't see it's worth me bothering. Why should we write your program for you if you don't want to learn how to do it yourself?

I suggest you start learning how to program properly - with tutorials and the help files - and come back to modifying that code when you know what you are doing.

If you do, then start here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

Besides that, I wouldn't rely on poor 'tutorials' like that one that teach bad programming habits like using the Goto command.

TDK

Login to post a reply

Server time is: 2024-11-24 19:03:48
Your offset time is: 2024-11-24 19:03:48