Summary
Bounce is a simple platformer where you bounce a blue sphere about, collecting rotating yellow 'coins'.
Demo
The current demo shows off a randomly generated level with moving/rotating blocks to rebound off, and randomly positioned coins that can be collected. It is just a simple demo of the game mechanics at the moment.
http://forumfiles.thegamecreators.com/?i=1201315
If you have Sparky's collision DLL, you can copy and paste the code from here into DBP - NO MEDIA REQUIRED!
` bounce
` setup
sync on: sync rate 0:color backdrop 0:
set camera range 1,99999
` level arrays
type blockdat
motion as integer
x# as float
y# as float
z# as float
a# as float
v# as float
amp# as float
endtype
dim block(300) as blockdat
` coin arrays
type coindat
x# as float
y# as float
z# as float
a# as float
endtype
dim coin(300) as coindat
` move arrays
type movedat
x# as float
y# as float
z# as float
ox# as float
oy# as float
oz# as float
vx# as float
vy# as float
vz# as float
endtype
dim mover(300) as movedat
` variable
global g#=-0.005
global nny#
global score#=0.0
global player_obj=0
global ground
` make level
make_random_level(1,1)
` make player
make_player(2,25,2)
player_obj=2
position object 2,100,100,100
mover(2).x#=100:mover(2).y#=100:mover(2).z#=100
sc_updateObject 2
` ink
ink RGB(192,192,192),0
` loop
do
set cursor 0,0
mouselook()
move_player(2)
move_level(10,100)
move_coins(200,260)
HUD()
if controlkey()=1 then screenie("bounce")
sync
loop
` mouselook
function mouselook()
d#=1
ax#=wrapvalue(camera angle x()+mousemovey())
ay#=wrapvalue(camera angle y()+mousemovex())
rotate camera ax#,ay#,0
position mouse 10,10
if mouseclick()=1 then move camera d#
if mouseclick()=2 then move camera (0-d#)
endfunction
` make random level
function make_random_level(blocks,walls)
tx=40:tz=40:tsize#=100:mi=10
make matrix 1,(tx*tsize#),(tz*tsize#),tx,tz
mo=9
make object box mo,(tx*tsize#),10,(tz*tsize#):position object mo,(tx*tsize#)/2,-5,(tx*tsize#)/2:hide object mo
sc_setupObject mo,1,2
`randomize matrix 1,50
` matrix texture
texsize#=63
ink RGB(155,155,155),RGB(255,255,255)
cls RGB(255,255,255)
line 0,0,0,texsize#
line 0,0,texsize#,0
line texsize#,0,texsize#,texsize#
line 0,texsize#,texsize#,texsize#
get image mi,0,0,texsize#+1,texsize#+1
prepare matrix texture 1,mi,1,1
` coin texture
ci=20
texsize#=128
ink RGB(255,240,51),RGB(255,255,255)
cls 0
box 0,0,texsize#,texsize#
get image ci,0,0,texsize#,texsize#
` blocks - make/position/set properties
if blocks=1
min=10:max=min+15+rnd(10)
bsize#=50
for o=min to max
sx#=(3+rnd(5))*bsize#:sz#=(1+rnd(4))*bsize#
sy#=(3+rnd(5))*bsize#/4
x#=(tx*tsize#)/10+rnd((tx*tsize#)*0.8):z#=(tz*tsize#)/10+rnd((tz*tsize#)*0.8)
y#=bsize#/2+rnd(15)*bsize#/2
make object box o,sx#,sy#,sz#
position object o,x#,y#,z#
rotate object o,(-10+rnd(10)),rnd(360),(-10+rnd(10))
texture object o,mi
set object filter o,0
` sc col
sc_setupObject o,1,2
` motion
block(o).motion=rnd(6)
block(o).a#=rnd(360)
block(o).v#=(35+rnd(35))
block(o).v#=block(o).v#/400
block(o).amp#=4*bsize#+rnd(4)*bsize#
block(o).x#=x#
block(o).y#=y#
block(o).z#=z#
if block(o).motion=6 then block(o).motion=3
if block(o).motion=3 and y#-block(o).amp#<sy# then block(o).amp#=y#-sy#
next o
endif
` walls
if walls=1
min=max+1:max=min+5+rnd(5)
for o=min to max
sx#=(3+rnd(5))*bsize#/4:sz#=(1+rnd(4))*bsize#
sy#=(7+rnd(7))*bsize#
x#=(tx*tsize#)/10+rnd((tx*tsize#)*0.8):z#=(tz*tsize#)/10+rnd((tz*tsize#)*0.8)
y#=7*bsize#+rnd(15)*bsize#/2
make object box o,sx#,sy#,sz#
position object o,x#,y#,z#
rotate object o,(-20+rnd(20)),rnd(360),(-20+rnd(20))
texture object o,mi
set object filter o,0
` sc col
sc_setupObject o,1,2
next o
endif
` coins
min=200:max=min+30+rnd(10)
bsize#=50
for o=min to max
x#=(tx*tsize#)/10+rnd((tx*tsize#)*0.8):z#=(tx*tsize#)/10+rnd((tx*tsize#)*0.8)
y#=bsize#*2+rnd(30)*bsize#/2
make object plain o,bsize#,bsize#
position object o,x#,y#,z#
rotate object o,0,0,45:fix object pivot o
yrotate object o,rnd(360)
texture object o,ci
set alpha mapping on o,60
set object light o,0
disable object zwrite o
next o
endfunction
function make_player(obj,r#,pi)
` player texture
ink RGB(0,0,255),0
cls 0
box 0,0,16,16
get image pi,0,0,16,16
` player
make object sphere obj,r#*2.0
texture object obj,pi:`ghost object on obj
sc_setupObject obj,0,1
endfunction
function move_player(obj)
` angle
pa#=camera angle y()
` old positions
mover(obj).ox#=mover(obj).x#
mover(obj).oy#=mover(obj).y#
mover(obj).oz#=mover(obj).z#
` control
acc#=0.005
if keystate(32)=1 then mover(obj).vx#=mover(obj).vx#+cos(pa#)*acc#:mover(obj).vz#=mover(obj).vz#-sin(pa#)*acc#
if keystate(30)=1 then mover(obj).vx#=mover(obj).vx#-cos(pa#)*acc#:mover(obj).vz#=mover(obj).vz#+sin(pa#)*acc#
if keystate(31)=1 then mover(obj).vx#=mover(obj).vx#-sin(pa#)*acc#:mover(obj).vz#=mover(obj).vz#-cos(pa#)*acc#
if keystate(17)=1 then mover(obj).vx#=mover(obj).vx#+sin(pa#)*acc#:mover(obj).vz#=mover(obj).vz#+cos(pa#)*acc#
` collision
r#=object size x(obj)/2
`collide=sc_SphereCastGroup(1,mover(obj).ox#,mover(obj).oy#,mover(obj).oz#,mover(obj).ox#,mover(obj).oy#+mover(obj).vy#,mover(obj).oz#,r#,0)
collide=sc_SphereCastGroup(1,mover(obj).ox#,mover(obj).oy#,mover(obj).oz#,mover(obj).ox#+mover(obj).vx#,mover(obj).oy#+mover(obj).vy#,mover(obj).oz#+mover(obj).vz#,r#,0)
if collide>0
`get normals
nx#=sc_getCollisionNormalX()
ny#=sc_getCollisionNormalY()
nz#=sc_getCollisionNormalZ()
nv#=sqrt(mover(obj).vx#^2+mover(obj).vy#^2+mover(obj).vz#^2)
nvx#=mover(obj).vx#/nv#
nvy#=mover(obj).vy#/ny#
nvz#=mover(obj).vz#/nz#
tmp=make vector3(1):tmp=make vector3(2)
set vector3 1,nx#,ny#,nz#:set vector3 2,nvx#,nvy#,nvz#
n#=dot product vector3(1,2)
` set velocity
speed#=2
mover(obj).vx#=speed#*nx#
mover(obj).vz#=speed#*nz#
mover(obj).vy#=speed#*ny#
endif
` calc position
mover(obj).x#=mover(obj).x#+mover(obj).vx#
mover(obj).y#=mover(obj).y#+mover(obj).vy#
mover(obj).z#=mover(obj).z#+mover(obj).vz#
` position object
position object obj,mover(obj).x#,mover(obj).y#,mover(obj).z#
` decrease speeds
mover(obj).vx#=mover(obj).vx#/1.005
mover(obj).vz#=mover(obj).vz#/1.005
mover(obj).vy#=mover(obj).vy#+g#
` update
sc_updateObject obj
endfunction
function move_level(a,b)
for o=a to b
if object exist(o)
if block(o).motion=1
block(o).a#=wrapvalue(block(o).a#+block(o).v#)
xrotate object o,block(o).a#
endif
if block(o).motion=2
block(o).a#=wrapvalue(block(o).a#+block(o).v#)
zrotate object o,block(o).a#
endif
if block(o).motion=3
block(o).a#=wrapvalue(block(o).a#+block(o).v#)
mv#=block(o).amp#*sin(block(o).a#)
position object o,block(o).x#,block(o).y#+mv#,block(o).z#
endif
if block(o).motion=4
block(o).a#=wrapvalue(block(o).a#+block(o).v#)
mv#=block(o).amp#*sin(block(o).a#)
position object o,block(o).x#,block(o).y#,block(o).z#+mv#
endif
if block(o).motion=5
block(o).a#=wrapvalue(block(o).a#+block(o).v#)
mv#=block(o).amp#*sin(block(o).a#)
position object o,block(o).x#+mv#,block(o).y#,block(o).z#
endif
` update
sc_updateObject o
endif
next o
endfunction
function move_coins(a,b)
for o=a to b
if object exist(o)
ca#=wrapvalue(object angle y(o)+0.4)
yrotate object o,ca#
mv#=sin(ca#)*0.2
position object o,object position x(o),object position y(o)+mv#,object position z(o)
`score
if abs(object position x(o)-object position x(player_obj))<50
if abs(object position y(o)-object position y(player_obj))<50
if abs(object position z(o)-object position z(player_obj))<50
score#=score#+100:delete object o
endif
endif
endif
endif
next o
endfunction
function HUD()
set cursor 0,0
print "BOUNCE"
print "_______________________"
print "player x: "+str$(object position x(player_obj))
print "player y: "+str$(object position y(player_obj))
print "player z: "+str$(object position z(player_obj))
print "_______________________"
print "score: "+str$(score#)
endfunction
function screenie(name$)
repeat
inc i
until file exist(name$+"_screen"+str$(i)+".jpg")=0
repeat
inc im
until image exist(im)=0
get image im,0,0,screen width(),screen height()
save image name$+"_screen"+str$(i)+".jpg",im
wait 1000
endfunction
if memblock exist(1) then delete memblock 1
Controls
W,A,S,D move the blue sphere
Look and move the camera with the mouse + mouse buttons
Current Features
- Basic player motion
- Camera control
- Randomly generated level
- Rotating/Moving blocks
- Coins to collect
Features not yet implemented
- Shadows
- Power-ups
- Level-editor
- Menus/HUD
-
A NEW NAME
What do you think so far?