Code: Select all
Type Bullets
Field Bullet_X As Float
Field Bullet_Y As Float
Field Bullet_Z As Float
Field Bullet_Oldz As Float
EndType
SCREEN 800,600
Dim Stars(512,2) As Float
For i = 0 To 128
Stars(i,0) = Rand(-ScreenWidth(),ScreenWidth())
Stars(i,1) = Rand(-ScreenHeight(),ScreenHeight())
Stars(i,2) = Rand(-500,0)
Next i
bullet = LoadImage("Media\Bullet.BMP")
guy = LoadImage("Media\Soldier.BMP")
auto = LoadImage("Media\Car.BMP")
z# = 5
Repeat
For i = 0 To 128
oldx# = Stars(i,0)
oldy# = Stars(i,1)
oldz# = Stars(i,2)
Color 255,255,255
If Stars(i,2) > 0 Then syvyys = -500 : oldz = syvyys : Stars(i,2) = syvyys
Stars(i,2) = Stars(i,2) + z#
DrawImageScaled3D(bullet,Stars(i,0),Stars(i,1),Stars(i,2),2,2)
Next i
x = x + RightKey() - LeftKey()
y = y + UpKey() - DownKey()
If KeyDown(57) And reload = 0 Then
PlaySound "Media\Blaster.Wav",100
reload = 5
shooted = shooted + 1
Bull.Bullets = New(Bullets)
If (shooted Mod 2) = True Then
Bull\Bullet_X = x - 10
Else
Bull\Bullet_X = x + 10
EndIf
Bull\Bullet_Y = y
Bull\Bullet_Z = - 10
Bull\Bullet_OldZ = - 10
EndIf
If reload Then reload - 1
For Bull.Bullets = Each Bullets
Color cbred
tmp# = Bull\Bullet_Z
'Line3D(Bull\Bullet_X,Bull\Bullet_Y,Bull\Bullet_Oldz ,Bull\Bullet_X,Bull\Bullet_Y,Bull\Bullet_Z)
DrawImageLine3D(guy,Bull\Bullet_X,Bull\Bullet_Y,Bull\Bullet_Oldz ,Bull\Bullet_X,Bull\Bullet_Y,Bull\Bullet_Z)
Bull\Bullet_Oldz = tmp
'DrawImageScaled3D(bullet,Bull\Bullet_X,Bull\Bullet_Y,Bull\Bullet_Z,5,5)
'Ellipse3D(Bull\Bullet_X,Bull\Bullet_Y,Bull\Bullet_Z,5,5,True)
Bull\Bullet_Z = Bull\Bullet_Z - 10
If Bull\Bullet_Z < - 2000 Then
Delete Bull
EndIf
Next Bull
Color 255,255,255
Remstart
Line3D(x,y,-10,x-10,y,-10)
Line3D(x,y,-10,x+10,y,-10)
Line3D(x,y,-10,x,y-5,-10)
Line3D(x,y,-10,x,y+5,-10)
Line3D(x,y,-10,x,y,-20)
Line3D(x-10,y,-10,x,y,-20)
Line3D(x+10,y,-10,x,y,-20)
Line3D(x,y-5,-10,x,y,-20)
Line3D(x,y+5,-10,x,y,-20)
Line3D(x-10,y,-10,x,y+5,-10)
Line3D(x-10,y,-10,x,y-5,-10)
Line3D(x+10,y,-10,x,y+5,-10)
Line3D(x+10,y,-10,x,y-5,-10)
Remend
DrawImageLine3D(auto,x,y,-10,x-10,y,-10,5)
DrawImageLine3D(auto,x,y,-10,x+10,y,-10,5)
DrawImageLine3D(auto,x,y,-10,x,y-5,-10,5)
DrawImageLine3D(auto,x,y,-10,x,y+5,-10,5)
DrawImageLine3D(auto,x,y,-10,x,y,-20,5)
DrawImageLine3D(auto,x-10,y,-10,x,y,-20,5)
DrawImageLine3D(auto,x+10,y,-10,x,y,-20,5)
DrawImageLine3D(auto,x,y-5,-10,x,y,-20,5)
DrawImageLine3D(auto,x,y+5,-10,x,y,-20,5)
DrawImageLine3D(auto,x-10,y,-10,x,y+5,-10,5)
DrawImageLine3D(auto,x-10,y,-10,x,y-5,-10,5)
DrawImageLine3D(auto,x+10,y,-10,x,y+5,-10,5)
DrawImageLine3D(auto,x+10,y,-10,x,y-5,-10,5)
Text 0,0,FPS()
DrawScreen Not KeyDown(28),True
Forever
Function Ellipse3D(x#,y#,z#,w#,h#,filled=0)
If z# => 0 Then Return 0
xz# = X3D(x#,z#)
yz# = Y3D(y#,z#)
xz2# = X3D(x#+w#,z#)
yz2# = Y3D(y#+h#,z#)
Ellipse xz - Distance(xz#,0,xz2#,0) / 2, yz - Distance(0,yz#,0,yz2) / 2, Distance(xz#,0,xz2#,0), Distance(0,yz#,0,yz2),filled
EndFunction
Function Box3D(x#,y#,z#,w#,h#,filled=0)
If z# => 0 Then Return 0
xz# = X3D(x#,z#)
yz# = Y3D(y#,z#)
xz2# = X3D(x#+w#,z#)
yz2# = Y3D(y#+h#,z#)
Box xz - Distance(xz#,0,xz2#,0) / 2, yz - Distance(0,yz#,0,yz2) / 2, Distance(xz#,0,xz2#,0), Distance(0,yz#,0,yz2),filled
EndFunction
Function Line3D(x#,y#,z#,x2#,y2#,z2#)
Line X3D(x#,z#),Y3D(y#,z#),X3D(x2#,z2#),Y3D(y2#,z2#)
EndFunction
Function X3D(x#,z#)
sz# = 1 / z#
Return ScreenWidth() / 2 - x# * sz * 100
EndFunction
Function Y3D(y#,z#)
sz# = 1 / z#
Return ScreenHeight() / 2 + y# * sz * 100
EndFunction
Function DrawImageLine3D(img,x#,y#,z#,x2#,y2#,z2#,h=0)
DrawImageLine(img,X3D(x#,z#),Y3D(y#,z#),X3D(x2#,z2#),Y3D(y2#,z2#),h)
EndFunction
Function DrawImageScaled3D(img,x#,y#,z#,w#,h#)
If z# => 0 Then Return 0
xz# = X3D(x#,z#)
yz# = Y3D(y#,z#)
xz2# = X3D(x#+w#,z#)
yz2# = Y3D(y#+h#,z#)
DrawImageScaled(img,xz - Distance(xz#,0,xz2#,0) / 2, yz - Distance(0,yz#,0,yz2) / 2, Distance(xz#,0,xz2#,0), Distance(0,yz#,0,yz2))
EndFunction
Function DrawImageLine(img,x,y,x2,y2,h=0)
a# = GetAngle(x,y,x2,y2)
d# = Distance(x,y,x2,y2)
If h = 0 Then
tmp = DSG_ScaleImage(img,Int(d),ImageHeight(img))
Else
tmp = DSG_ScaleImage(img,Int(d),h)
EndIf
If tmp<>0 Then
RotateImage tmp,-Int(a#)
DrawImage tmp,x+Cos(a)*d/2,y-Sin(a)*d/2
DeleteImage tmp
EndIf
Return 0
EndFunction
Function DrawImageScaled(img,x,y,w,h)
tmp = DSG_ScaleImage(img,w,h)
If tmp <> 0 Then
DrawImage tmp,x,y
DeleteImage tmp
EndIf
Return 0
EndFunction
Function DSG_ScaleImage(img,w,h) ' Made by DSG, alkuperäinen toteutus idea Marcoderilta
iw = ImageWidth(img)
ih = ImageHeight(img)
If w =< 0 Or h =< 0 Then Return 0
newimg = MakeImage(w,ih)
newimg2 = MakeImage(w,h)
DrawToImage newimg
For i = 0 To w
DrawImageBox img,i,0,Int(Float(iw)/Float(w)*Float(i)),0,1,ih
Next i
DrawToScreen
DrawToImage newimg2
For i = 0 To h
DrawImageBox newimg,0,i,0,Int(Float(ih)/Float(h)*Float(i)),w,1
Next i
DrawToScreen
DeleteImage newimg
Return newimg2
EndFunction