Hmmm... I've edited the "wait no mouse" part as it's bad code anyway!
Quote: "Runtime Error 116[this command is now obsolete] at line 98"
My dbp must be out of date! What's the command for texturing the backdrop then?
I'll post my updated code once I've finished a small addition.
Quote: "My waife´s gonna kill me if start a new code"
I have a large thumbprint on my head too...
EDIT:
Quote: "sometimes both eyes fall simultaneously"
That would happen if you just took out the "wait no mouse" part!
I've just added in a sound effect from Ric's sound effect generator for effect. Here's the updated code:
Rem Project: EyeballJuggler
Rem Created: 16/02/2010 09:35:02
Rem ***** Main Source File *****
sync on
sync rate 60
randomize timer()
set text font "Papyrus"
set text size 30
`Make textures
`Eye Texture
global eyetex as integer:eyetex=freeimage()
ink RGB(255,255,255),0
box 0,0,256,256
R=100:G=100:B=0
ink RGB(R,G,B),0
for x=1 to 40
radius#=40-x
ellipse 128,128, radius#*.5,radius#
dec R
inc G
ink RGB(R,G,B),0
next x
ink RGB(0,0,0),0
for x=1 to 15
radius#=15-x
ellipse 128,128, radius#*.5,radius#
next x
ink RGB(150,0,0),0
for x=1 to 20
side=RND(3)+1
select side
case 1
x1=0:y1=RND(256)
x2=RND(33):y2=y1-20+RND(40)
x3=RND(33)+33:y3=y2-20+RND(40)
x4=RND(33)+66:y4=y3-20+RND(40)
line x1,y1,x2,y2
line x2,y2,x3,y3
line x3,y3,x4,y4
endcase
case 2
x1=256:y1=RND(256)
x2=256-RND(33):y2=y1-20+RND(40)
x3=256-RND(33)-33:y3=y2-20+RND(40)
x4=256-RND(33)-66:y4=y3-20+RND(40)
line x1,y1,x2,y2
line x2,y2,x3,y3
line x3,y3,x4,y4
endcase
case 3
y1=0:x1=RND(256)
y2=RND(33):x2=x1-20+RND(40)
y3=RND(33)+33:x3=x2-20+RND(40)
y4=RND(33)+66:x4=x3-20+RND(40)
line x1,y1,x2,y2
line x2,y2,x3,y3
line x3,y3,x4,y4
endcase
case 4
y1=256:x1=RND(256)
y2=256-RND(33):x2=x1-20+RND(40)
y3=256-RND(33)-33:x3=x2-20+RND(40)
y4=256-RND(33)-66:x4=x3-20+RND(40)
line x1,y1,x2,y2
line x2,y2,x3,y3
line x3,y3,x4,y4
endcase
endselect
next x
get image eyetex, 0,0,256,256
save image "eyetex.bmp", eyetex
`Make splat image
global splat as integer:splat=freeimage()
ink RGB(255,255,255),0
box 0,0,256,256, RGB(0,0,0),RGB(0,0,0),RGB(0,0,0),RGB(0,0,0)
for x=0 to 256
for y=0 to 256
dx#=128-x
dy#=128-y
d#=sqrt(dx#^2+dy#^2)
if d#<128
c=256-(d#*2)
dot x,y, RGB(c,c*.1,c*.1)
if x=128 and y=128 then dot x,y, RGB(255,255*.1,255*.1)
endif
next y
next x
get image splat, 0,0,256,256
save image "splat.bmp", splat
`Make backdrop
global BG as integer:BG=freeimage()
box 0,0,640,480, RGB(0,10,0),RGB(0,0,0),RGB(0,100,0),RGB(0,0,0)
get image BG, 0,0,256,256
save image "BG.bmp", BG
texture backdrop BG
`Make Eyeball
make object sphere 1, 1, 40,40
texture object 1, eyetex
SET OBJECT SPECULAR POWER 1, 100
set object specular 1, RGB(0,255,0)
autocam off
`Make Bat
global bat as integer
bat=101
make object box bat, 2,.5,1
color object bat, RGB(255,0,0)
position object bat, 0,-5,10
`Make splat particles
make particles 1, splat, 1, 5
set particle emissions 1, 0
set particle life 1, 10
`Make splat sound
REM This is from Ric's Sound effect maker!!
createsound("bubble burst",1,50,80,6000,-.4,2.0,0.1,10,1.2,0.2,10)
REM End of stolen code
`Lighting
set ambient light 10
color ambient light RGB(100,255,100)
hide light 0
`general light
make light 1
set point light 1, 50,-100,-50
set light range 1, 3000
color light 1, RGB(255,255,100)
`Dim Balls
type type1
fx as float
fy as float
obj as integer
rx as float
ry as float
rz as float
endtype
dim Balls(100) as type1
dim scores(2)
`Set globals
global st as integer
global bt as integer
global et as integer
global balls as integer
global mx as integer
global my as integer
global game as integer
global newhigh as integer
et=timer()
game=0
hide mouse
`################################################## MAIN LOOP START
DO
set particle emissions 1, 0
set cursor 10,10
ink RGB(0,200,0),0
if game=0
show object 1
hide object bat
print "Eyeball Juggling!!"
set cursor 10,40
print "Click to Start!"
if scores(2)>0
if scores(2)>scores(1) or newhigh=1
scores(1)=scores(2)
newhigh=1
set cursor 10,380
print "New High Score->",scores(1)
else
set cursor 10,340
print "Your Score->",scores(2)
set cursor 10,380
print "High Score->",scores(1)
endif
endif
if mouseclick()=1
if prevclick=0
game=1:st=timer():bt=st+5000:scores(2)=0
endif
prevclick=1
else
prevclick=0
endif
if timer()>et+1000
rx#=RND(90)-45:ry#=RND(90)-45
et=timer()+1000
else
dx#=object angle x(1)-rx#
dy#=object angle y(1)-ry#
if abs(dy#)>.1 then yrotate object 1, object angle y(1)-(dy#/30)
if abs(dx#)>.1 then xrotate object 1, object angle x(1)-(dx#/30)
endif
else
hide object 1
show object bat
endif
if game=1
if balls=0 then addball()
if mouseclick()=1
if prevclick=0 then addball()
prevclick=1
else
prevclick=0
endif
bat()
endif
showtimer(game)
updateballs()
sync
LOOP
`################################################## MAIN LOOP END
function bat()
`Move bat
if mousex()>20 and mousex()<620
x#=mousex()
x#=(x#-320)/30
position object bat, x#,-5,10
endif
`check for 'collisions'
b=2
while object exist(b)
if object position y(b)<=-4.25 and object position y(b)>-5.5
dx#=object position x(bat)-object position x(b)
if abs(dx#)<1.5
fx#=Balls(b).fx:fy#=Balls(b).fy
fx#=fx#-(dx#/10)
fy#=(1.5-abs(dx#))/3
Balls(b).fx=fx#:Balls(b).fy=fy#
`randomise rotation on impact
rx#=RND(100)-50:Balls(b).rx=rx#/10
ry#=RND(100)-50:Balls(b).ry=ry#/10
rz#=RND(100)-50:Balls(b).rz=rz#/10
`add splat
position particles 1, object position x(b),-4.75,object position z(b)
set particle emissions 1, 10
`play sound
play sound 1
endif
endif
inc b
endwhile
endfunction
function updateballs()
b=2
while object exist(b)
`get gravity and lateral movement
fx#=Balls(b).fx:fy#=Balls(b).fy
rx#=Balls(b).rx:ry#=Balls(b).ry:rz#=Balls(b).rz
`Update gravity and lateral movement
fx#=fx#*.995
if fy#<0 then fy#=fy#*1.03
if fy#>0
fy#=fy#*.95
if fy#<.005 then fy#=-.005
endif
`keep ball in screen
if object position x(b)<-9 or object position x(b)>9 then fx#=-fx#
`update object
position object b, object position x(b)+fx#,object position y(b)+fy#,object position z(b)
rotate object b, object angle x(b)+rx#,object angle y(b)+ry#,object angle z(b)+rz#
`update array
Balls(b).fx=fx#:Balls(b).fy=fy#
`game over
if object position y(b)<-8 then delete object b:game=0:cleanup()
inc b
endwhile
endfunction
function cleanup()
for b=2 to 100
if object exist(b)
delete object b
endif
next b
balls=0
newhigh=0
endfunction
function addball()
b=2
while object exist(b)
inc b
endwhile
clone object b, 1
position object b, 0,6,10
fx#=25-RND(50)
Balls(b).fx=fx#/400
Balls(b).fy=-.01
rx#=RND(100)-50:Balls(b).rx=rx#/10
ry#=RND(100)-50:Balls(b).ry=ry#/10
rz#=RND(100)-50:Balls(b).rz=rz#/10
inc balls
endfunction
function showtimer(game)
if game>0
elapsed#=(timer()-st)/1000
if elapsed#<60
time$=str$(elapsed#)+"secs"
else
minutes=elapsed#/60
seconds=elapsed#-(minutes*60)
time$=str$(minutes)+"mins "+str$(seconds)+"secs"
endif
print "Time: ",time$
if timer()>bt
score=scores(2)
score=score+balls
scores(2)=score
bt=timer()+1000
endif
set cursor 10,40
print "Score: ",scores(2)
set cursor 340,10
print "Left Click to add another Eyeball!"
endif
endfunction
function freeimage()
repeat
inc i
if image exist(i)=0 then found=1
until found
endfunction i
REM This is from Ric's Sound effect maker!!
`DB Sound Creator by Ric, and:
`Tommy S - Original waveform code
`Green Gandalf - Memblock format
`Lampton Worm - Load/Save format
`Lampton Worm/Raven - Real time parameter editor
`Xtom - GUI/parameter editor
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#)
outWord as word
dword1 as dword: dword2 as dword: dword3 as dword: dword4 as dword
dword5 as dword: dword6 as dword: dword7 as dword
samples=int((length#/1000)*44100)
if memblock exist(1) then delete memblock 1
make memblock 1,samples*2+28
` write 28 memblock header bytes
dword1=1 ` gg query: is this the number of channels?
dword2=2 ` gg query: is this the number of bytes per sample?
dword3=22050 ` gg query: seems to be half the number of samples per second - why?
dword4=88200 ` gg query: is this the number of bytes per second?
dword5=4 ` gg query: what does this represent?
dword6=16 ` gg query: (ditto) ?
dword7=0 ` gg query: (ditto) ?
position=0
write memblock dword 1, position, dword1 : inc position,4
write memblock dword 1, position, dword2 : inc position,4
write memblock dword 1, position, dword3 : inc position,4
write memblock dword 1, position, dword4 : inc position,4
write memblock dword 1, position, dword5 : inc position,4
write memblock dword 1, position, dword6 : inc position,4
write memblock dword 1, position, dword7 : inc position,4
rem generate and write wave
riseinloudness#=loudness#
for x=1 to samples
outInteger=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#-fallinloudness#-riseinloudness#+tremelodepth#*sin(phi#)))*3.0
if outInteger <-32767 then outInteger=-32767 ` gg query: is this the valid range?
if outInteger>32767 then outInteger=32767 ` gg query: (ditto) ?
outWord=outInteger
inc theta#,vibratospeed#
inc phi#,tremelospeed#
dec frequency#,bend#
if fallinloudness#<loudness#
inc fallinloudness#,decay#
endif
if riseinloudness#>0
dec riseinloudness#,attack#
endif
write memblock word 1, position, outWord : inc position,2
next x
if sound exist(soundnumber)=1 then delete sound soundnumber
make sound from memblock 999, 1 ` assumes you won't need sound number 999!
clone sound soundnumber, 999
delete sound 999
` memblock no longer required
delete memblock 1
endfunction
REM End of stolen code!