im begining an explosion effect (not finish yet)..in my Tank War Game.....
but its maybe not.what you want...
and if you try it..just say me if the flash/explosion/bullet are syncronised on YOUR computer...thx
Intro1()
Gosub Initialisation_Graphique
Gosub Intro
Gosub Initialisation_Variable
Gosub Loading
debut:
Gosub Generer_Terrain
Gosub Dessiner_Terrain
do
for i=1 to NbPlayer
Oponent=i+1
if oponent>NbPlayer then Oponent=1
update=1
while spacekey()=0
Gosub Inputs
if Update=1 then gosub Update_Screen
sync
endwhile
Gosub Initialisation_Variable_Tir
while Tire=1
Gosub Update_Variable_Tir
Gosub Check_Collision_Mur
Gosub Dessiner_Projectile
Gosub Check_Collision_Grass
Gosub Check_Collision_Oponent
if (Y#=OldY#(1)) and (Y#=oldY#(2)) then tire=0
sync
endwhile
while spacekey()<>0:endwhile
next i
loop
Quit:
end
`################################################ Sub ###############################################
Intro:
Print "Up/Down arrow keys = Change Speed of the...shot"
Print "Left/Right arrow keys = rotate tank"
print "SpaceBar=shot"
wait key
return
`***************************************************************************************
Initialisation_Graphique:
ink rgb(255,255,255),0
sync on
randomize timer()
return
`***************************************************************************************
Initialisation_Variable:
dim hdc(1)
dim pixel(700,500)
dim color(2)
dim y#(700)
dim OldY#(2)
Gravite#=((-9.8)*(10/3))
rotate#=1
NbPlayer=2
dim tank#(NbPlayer,5)
return
`***************************************************************************************
Loading:
create bitmap 1,640,480
set current bitmap 0
load dll "user32.dll",1
load dll "gdi32.dll",2
hWnd = call dll(1,"GetActiveWindow")
hDC(1) = call dll(1,"GetWindowDC",hWnd)
return
`***************************************************************************************
Generer_Terrain:
y#(1)=rnd(300)+180
for x=51 to 700 step 50
y#(x)=180+rnd(300)
next x
last50=1
ink rgb(0,188,35),0
for x=1 to 640
if x-last50<>50:y#(x)=y#(last50)+((x-last50)*((y#(last50+50)-y#(last50))/50)):else:last50=x:endif
next x
for i=1 to NbPlayer
tank#(i,1)=rnd(618)+11
tank#(i,2)=y#(tank#(i,1))
tank#(i,3)=rgb(rnd(150)+100,rnd(150)+100,rnd(150)+100)
tank#(i,5)=10
next i
return
`***************************************************************************************
Dessiner_Terrain:
Set Current bitmap 1
cls
ink rgb(0,188,35),0
for x=1 to 640
line x,y#(x),x,480
next x
ink rgb(9,17,173),0
for i=0 to 1
line 0,0+i+20,639,0+i+20
line 0,0+i,639,0+i
line 0+i,0,0+i,479
line 0,479-i,639,479-i
line 639-i,0,639-i,479
next i
for i=1 to NbPlayer
Player(tank#(i,1),tank#(i,2),tank#(i,3))
next i
copy bitmap 1,0
set current bitmap 0
Return
`***************************************************************************************
Inputs:
if rightkey()=1 then OldAngle#=tank#(i,4):tank#(i,4)=tank#(i,4)-1:Update=1
if leftkey()=1 then OldAngle#=tank#(i,4):tank#(i,4)=tank#(i,4)+1:Update=1
if upkey()=1 then tank#(i,5)=tank#(i,5)+Rotate#:update=1
if downkey()=1 then tank#(i,5)=tank#(i,5)-Rotate#:update=1
if (shiftkey()=1) and (LastShift=0)
LastShift=1
rotate#=rotate#*10
if rotate#>10 then rotate#=0.1
endif
if ShiftKey()=0 then LastShift=0
if tank#(i,5)<0 then tank#(i,5)=400
if tank#(i,5)>400 then tank#(i,5)=0
if tank#(i,4)>180:tank#(i,4)=tank#(i,4)-180.0:endif
if tank#(i,4)<0:tank#(i,4)=180+tank#(i,4):endif
Return
`***************************************************************************************
Update_Screen:
ink 0,0
box 3,2,637,19
line tank#(i,1),tank#(i,2),tank#(i,1)+(20.0*cos(OldAngle#)),tank#(i,2)-(20.0*sin(OldAngle#))
Player(tank#(i,1),tank#(i,2),tank#(i,3))
line tank#(i,1),tank#(i,2),tank#(i,1)+(20.0*cos(tank#(i,4))),tank#(i,2)-(20.0*sin(tank#(i,4)))
ink tank#(i,3),0
text 5,5,"Player="+str$(i)
text 100,5,"Speed="+str$(tank#(i,5))
text 200,5,"Angle="+str$(tank#(i,4))
update=0
Return
`***************************************************************************************
Initialisation_Variable_Tir:
x#=tank#(i,1)+(20.0*cos(tank#(i,4)))
y#=tank#(i,2)-(20.0*sin(tank#(i,4)))
Vx#=(tank#(i,5)*cos(tank#(i,4)))
Vy#=(tank#(i,5)*sin(tank#(i,4)))
tire=1
old=0
time1#=timer()
return
`***************************************************************************************
Update_Variable_Tir:
old=old+1
if old=3 then old=1
time2#=timer()-time1#
time1#=timer()
OldX#=x#
Oldy#(Old)=y#
Vy#=Vy#+(Gravite#*(time2#/500.0))
x#=x#+(vx#*(time2#/500.0))
y#=y#-(vy#*(time2#/500.0))
Return
`***************************************************************************************
Check_Collision_Mur:
if (x#>=637) or (x#<=2)
if (x#>=637):Murx#=637:else:MurX#=2:endif
Y#=Y#+(Vy#*(time2#/500.0))
if (X#-Oldx#)<>0 then y#=y#-(((Vy#*(time2#/500.0))*(MurX#-oldx#))/(X#-Oldx#))
x#=MurX#
vx#=-1*vx#
endif
if (y#<=22) or (y#>=477)
if (y#<=22):MurY#=22:else:MurY#=477:endif
X#=X#-(Vx#*(time2#/500.0))
if (Y#-OldY#(old))<>0 then X#=X#+(((Vx#*(time2#/500.0))*(MurY#-OldY#(old)))/(Y#-OldY#(old)))
Y#=MurY#
vy#=-1*vy#
endif
return
`***************************************************************************************
Dessiner_Projectile:
ink tank#(i,3),0
line OldX#,OldY#(old),x#,y#
Return
`***************************************************************************************
Check_Collision_Grass:
if y#>=y#(x#)
ink rgb(0,0,0),0
for Ang=0 to 360
ang#=ang
R#=15
line x#,y#,x#+(r#*cos(ang#)),y#-(r#*sin(ang#))
next ang
ink rgb(255,0,0),0
DescendX1=x#-16
DescendX2=x#+16
DescendY=y#+16
DescendHerbe(DescendX1,DescendX2,DescendY)
RemakeY(DescendX1,DescendX2)
tire=0
endif
Return
`***************************************************************************************
Check_Collision_Oponent:
if y#<=tank#(oponent,2) and ((sqrt((x#-tank#(oponent,1))^2+(y#-tank#(oponent,2))^2))<=10)
ink rgb(255,0,0),0
center text 320,240,"Player "+str$(Oponent)+" is DEAD"
set cursor 265,270
question:
input "Play Again (y/n)?=",ReGame$
regame$=lower$(regame$)
if Regame$="y"
goto debut
else
goto quit
endif
endif
Return
`############################################### Function #############################################
function Player(X#,Y#,Color#)
ink color#,0
For i=1 to 360
for j=1 to 10
dot x#+(j*cos(i/2.0)),y#-(j*sin(i/2.0))
next j
next i
endfunction
`***************************************************************************************
function DescendHerbe(x1,x2,y1)
sync
sync
y2=y1-180
for X=X1 to X2
for y=1 to y2
Pixel(x,y1-y)=call dll(2,"GetPixel",hDC(1),X,y1-y)
Pixel(x,y1-y)=rgb(rgbb(Pixel(x,y1-y)),rgbg(Pixel(x,y1-y)),rgbr(Pixel(x,y1-y)))
next y
next X
y2=y1-180
descendre=1
while descendre>0
descendre=0
for X=X1 to X2
for y=1 to y2
if (Pixel(x,y1-y)=rgb(0,188,35)) and (Pixel(x,(y1-y)+1)=0)
descendre=descendre+1
Pixel(x,y1-y)=0
Pixel(x,(y1-y)+1)=rgb(0,188,35)
ink 0,0
dot x,y1-y
ink rgb(0,188,35),0
dot x,(y1-y)+1
endif
next y
next X
sync
endwhile
endfunction
`***************************************************************************************
function RemakeY(X1,X2)
for x=x1 to x2
changed=0
for y=180 to 480
Color=call dll(2,"GetPixel",hDC(1),x,y)
Color=rgb(rgbb(Color),rgbg(Color),rgbr(Color))
if (color=rgb(0,188,35)) then changed=1:y#(x)=y:exit
next y
if (changed=0) and (x>=0) and (x<=640) then y#(x)=500
next x
endfunction
`***************************************************************************************
function Intro1()
set display mode 640,480,32
sync on
backdrop off
set camera range 1,15000
randomize timer()
set ambient light 100
color light 0,rgb(255,255,255)
autocam off
sync rate 0
set gamma 255,255,255
Rem Herbe
create bitmap 1,1025,1025
ink rgb(0,90,20),0
box 0,0,512,512
ink rgb(0,60,5),0
for i=1 to 20000
dot rnd(512),rnd(512)
next i
rem terre
ink rgb(110,57,0),0
box 512,0,1024,512
ink rgb(125,77,15),0
for i=1 to 20000
dot rnd(512)+512,rnd(512)
next i
get image 1,0,0,1024,1024
delete bitmap 1
Rem Ciel
create bitmap 1,1025,1025
ink rgb(0,0,255),0
box 0,0,1024,1024
ink rgb(0,0,90),0
for i=1 to 20000
dot rnd(1024),rnd(1024)
next i
get image 2,0,0,1024,1024
delete bitmap 1
rem tank
create bitmap 1,257,257
ink rgb(155,0,0),0
box 0,0,256,128
get image 3,0,0,256,256
delete bitmap 1
make object sphere 1,15000
set object 1,1,1,0
texture object 1,2
position object 1,5000,0,5000
fog on
fog color rgb(0,255,0)
fog distance 5000
make matrix 1,10000,10000,70,70
prepare matrix texture 1,1,2,2
fill matrix 1,0.0,1
randomize matrix 1,500
update matrix 1
make object sphere 2,200
set object 2,1,0,0
color object 2,rgb(190,0,0)
position object 2,3000,get ground height(1,3000,5000),5000
make object sphere 151,200
set object 151,1,0,0
color object 151,rgb(255,0,0)
position object 151,3000,get ground height(1,3000,5000),5000
make object sphere 3,200
set object 3,1,0,0
color object 3,rgb(0,0,190)
position object 3,7000,get ground height(1,7000,5000),5000
for i=2 to 3
set matrix height 1,int(object position x(i)/(10000.0/70.0)),int(object position z(i)/(10000.0/70.0)),500
set matrix height 1,int(object position x(i)/(10000.0/70.0))+1,int(object position z(i)/(10000.0/70.0))+1,500
set matrix height 1,int(object position x(i)/(10000.0/70.0))-1,int(object position z(i)/(10000.0/70.0))-1,500
set matrix height 1,int(object position x(i)/(10000.0/70.0))+1,int(object position z(i)/(10000.0/70.0))-1,500
set matrix height 1,int(object position x(i)/(10000.0/70.0))-1,int(object position z(i)/(10000.0/70.0))+1,500
set matrix height 1,int(object position x(i)/(10000.0/70.0))+1,int(object position z(i)/(10000.0/70.0)),500
set matrix height 1,int(object position x(i)/(10000.0/70.0))-1,int(object position z(i)/(10000.0/70.0)),500
set matrix height 1,int(object position x(i)/(10000.0/70.0)),int(object position z(i)/(10000.0/70.0))-1,500
set matrix height 1,int(object position x(i)/(10000.0/70.0)),int(object position z(i)/(10000.0/70.0))+1,500
next i
update matrix 1
position object 2,3000,get ground height(1,3000,5000),5000
position object 3,7000,get ground height(1,7000,5000),5000
position object 151,3000,get ground height(1,3000,5000),5000
for i=152 to 300
i#=i
make object cylinder i,50
color object i,rgb(0,0,255)
zrotate object i,45+(90*((i#-152)/150.0))
position object i,object position x(3)-((i-150)*27),object position y(3)+(500.0*sin((i#-152.0)*1.2)),object position z(3)
next i
for i=200 to 300
hide object i
next i
position camera 2000,3000,0
point camera object position x(2),object position y(2),object position z(2)
yrotate camera camera angle y()+12
Ax#=camera angle x()
Ay#=camera angle y()
Az#=camera angle z()
dim Object#(150,10)
rem 1=x
rem 2=y
rem 3=z
rem 4=Ax
rem 5=Ay
rem 6=Az
rem 7=Vx
rem 8=Vy
rem 9=Vz
create bitmap 1,128,128
set current bitmap 1
for n=1 to 5000
x=rnd(32)+rnd(32)+rnd(32)+rnd(32):y=rnd(32)+rnd(32)+rnd(32)+rnd(32)
i1=abs(64-x):i1=i1*i1:i2=abs(64-y):i2=i2*i2
i=256-6*sqrt(i1+i2):ink rgb(255,i,0),0:dot x,y
next n
get image 2,0,0,128,128
delete bitmap 1
create bitmap 1,1025,1025
for i=-150 to 640 step 50
for j=-150 to 640 step 50
paste image 2,i,j,1
next j
next i
get image 3,0,0,640,640
delete bitmap 1
texture object 2,3
ghost object on 2
dim Ptime#(150)
Pacc#=-200
for i=5 to 150
object#(i,1)=object position x(2)
object#(i,2)=object position y(2)
object#(i,3)=object position z(2)
VPXZ#=rnd(400)+200
APY#=rnd(360)
object#(i,7)=vpxz#*sin(apy#)
object#(i,9)=vpxz#*cos(apy#)
object#(i,8)=rnd(600)+300
Ptime#(i)=timer()
object#(i,5)=apy#
object#(i,10)=90+rnd(90)
next i
for i=5 to 150
make object plain i,200+rnd(200),rnd(200)+200
set object i,1,0,0
texture object i,2
position object i,object#(i,1),object#(i,2),object#(i,3)
next i
gama=500
sc=0
obb=200
scale#=98
CTime#=Timer()
while sqrt((object position x(2)-camera position x())^2+(object position y(2)-camera position y())^2+(object position z(2)-camera position z())^2)>1500
if obb<300:obb=obb+1:show object obb:else:sc=1:endif
if scale#>100
if gama>255:gama=gama-10:set gamma gama,gama,gama:endif
if Launch=0
launch=1
color object 151,rgb(50,0,0)
for i=5 to 150
Ptime#(i)=timer()
next i
endif
for i=5 to 150
position object i,object#(i,1),object#(i,2),object#(i,3)
rotate object i,object#(i,4),object#(i,5),object#(i,6)
object#(i,8)=object#(i,8)+Pacc#*((timer()-ptime#(i))/500.0)
object#(i,1)=object#(i,1)+(object#(i,7)*((timer()-ptime#(i))/500.0))
object#(i,3)=object#(i,3)+(object#(i,9)*((timer()-ptime#(i))/500.0))
object#(i,2)=object#(i,2)+(object#(i,8)*((timer()-ptime#(i))/500.0))
object#(i,4)=wrapvalue(object#(i,4)+(object#(i,10)*((timer()-ptime#(i))/500.0)))
ptime#(i)=timer()
next i
endif
rotate camera ax#,ay#,az#
Scale object 2,Scale#,scale#,scale#
move camera (1000*((timer()-Ctime#)/1000.0))
if sc=1 then Scale#=(Scale#^(1+(0.3*((timer()-Ctime#)/1000.0))))+(15*((timer()-Ctime#)/1000.0))
CTime#=Timer()
point camera object position x(2),object position y(2),object position z(2)
sync
endwhile
Ay1#=atanfull((camera position x()-object position x(2)),(camera position z()-object position z(2)))
Dist1#=sqrt((object position x(2)-camera position x())^2+(object position z(2)-camera position z())^2)
y1#=camera position y()
dist#=dist1#
CTime#=Timer()
ay#=0
while Ay#<360
for i=5 to 150
position object i,object#(i,1),object#(i,2),object#(i,3)
rotate object i,object#(i,4),object#(i,5),object#(i,6)
object#(i,8)=object#(i,8)+Pacc#*((timer()-ptime#(i))/500)
object#(i,1)=object#(i,1)+(object#(i,7)*((timer()-ptime#(i))/500))
object#(i,3)=object#(i,3)+(object#(i,9)*((timer()-ptime#(i))/500))
object#(i,2)=object#(i,2)+(object#(i,8)*((timer()-ptime#(i))/500))
ptime#(i)=timer()
next i
ay#=ay#+(90.0*((timer()-Ctime#)/1000.0))
CTime#=Timer()
dist#=dist1#-(1000*sin(ay#/2))
y#=y1#-(300*sin(ay#))
X#=object position x(2)+(sin(wrapvalue(ay1#-ay#))*Dist#)
z#=object position z(2)+(cos(wrapvalue(ay1#-ay#))*Dist#)
position camera X#,y#,z#
point camera object position x(2),object position y(2),object position z(2)
sync
endwhile
for i=5 to 150
if object exist(i) then delete object i
next i
delete object 2
Ax3#=camera angle x()
Ay3#=camera angle y()
Az3#=camera angle z()
point camera object position x(3),object position y(3),object position z(3)
Ax2#=camera angle x()
Ay2#=camera angle y()
Az2#=camera angle z()
yrotate camera camera angle y()+12
Ax#=camera angle x()
Ay#=camera angle y()
Az#=camera angle z()
time#=50
while sqrt((object position x(3)-camera position x())^2+(object position y(3)-camera position y())^2+(object position z(3)-camera position z())^2)>1000
rotate camera ax#,ay#,az#
move camera 40
point camera object position x(3),object position y(3),object position z(3)
Ax2#=camera angle x()
Ay2#=camera angle y()
Az2#=camera angle z()
ax3#=curveangle(az2#,ax3#,50)
ay3#=curveangle(ay2#,ay3#,50)
az3#=curveangle(az2#,az3#,50)
rotate camera ax3#,ay3#,az3#
time#=time#-1
sync
endwhile
Ax#=camera angle x()
Ay#=camera angle y()
Az#=camera angle z()
point camera object position x(3),object position y(3),object position z(3)
Ax2#=camera angle x()
Ay2#=camera angle y()
Az2#=camera angle z()
rotate camera ax#,ay#,az#
while (ax2#<>camera angle x() ) and (ay2#<>camera angle y() ) and (az2#<>camera angle z() )
xrotate camera curveangle(ax2#,camera angle x(),20)
yrotate camera curveangle(ay2#,camera angle y(),20)
zrotate camera curveangle(az2#,camera angle z(),20)
endwhile
Ay1#=atanfull((camera position x()-object position x(3)),(camera position z()-object position z(3)))
Dist1#=sqrt((object position x(3)-camera position x())^2+(object position z(3)-camera position z())^2)
y1#=camera position y()
dist#=dist1#
vitess#=0
acc#=2
ay#=0
gamma#=255
while gamma#<450
if y#>4000
gamma#=gamma#+5
gamma=int(gamma#)
SET GAMMA gamma#, gamma#, gamma#
endif
ay#=ay#+1
dist#=dist1#-(1000*sin(ay#/2))
acc#=acc#+0.5
vitess#=vitess#+acc#
y#=y1#+vitess#
X#=object position x(3)+(sin(wrapvalue(ay1#-ay#))*Dist#)
z#=object position z(3)+(cos(wrapvalue(ay1#-ay#))*Dist#)
position camera X#,y#,z#
point camera object position x(3),object position y(3),object position z(3)
sync
endwhile
for i=1 to 200
if object exist(i) then delete object i
next i
delete matrix 1
for i=1 to 3
delete image i
next i
ink 0,0
cls 0
ink rgb(0,255,0),0
texte_size=text size()
set text size 48
center text 320,240,"Tank War"
color2#=rgb(255,0,0)
color1#=rgb(0,0,255)
Player(245.0,249.0,color1#)
line 245,249,265,239
Player(405.0,258.0,color2#)
line 405,258,385,248
for gamma1=1 to 245
set gamma 500-gamma1,500-gamma1,500-gamma1
next gamma1
wait key
set text size texte_Size
endfunction