Well, I have made a lot of progress, and I think I finally have what looks like a game made!
Setup_Screen()
Gosub _InitialiseGlobals
Create_Maze()
Do
If Object Collision(FinishObject, PlayerObject) = 1 Then Player_Win()
Handle_Bullets(1.5)
Handle_Bombs(.1)
Check_Wall_Collisions(2.0,0.25)
Move_Camera(.25)
Sync
loop
Function Create_Bomb(Moving, X#, Y#, Z#)
Add to queue Bombs(0)
BNum = Array Count(Bombs(0))
Bombs(BNum).X = X#
Bombs(BNum).Y = Y#
Bombs(BNum).Z = Z#
Bombs(BNum).Num = Get_Free_Object_Number()
Bombs(BNum).Active = RND(1)+1
Bombs(BNum).Moving = Moving
Bombs(BNum).DestinationX = X#
Bombs(BNum).DestinationZ = Z#
Make Object Sphere Bombs(BNum).Num,5
If Bombs(BNum).Active = 1 Then Texture Object Bombs(BNum).Num, BombRed
If Bombs(BNum).Active = 2 Then Texture Object Bombs(BNum).Num, BombGreen
Position Object Bombs(BNum).Num, Bombs(BNum).X, Bombs(BNum).Y, Bombs(BNum).Z
endfunction
Function Change_Bomb_States()
For b = 1 To Array Count(Bombs(0))
If RND(2) = 2 Then Bombs(b).Active = 2: Texture Object Bombs(b).Num, BombGreen
If RND(2) = 1 Then Bombs(b).Active = 1: Texture Object Bombs(b).Num, BombRed
next b
endfunction
Function Create_Maze()
BrickImage = Get_Free_Image_Number()
BrickTexture(BrickImage)
BombRed = Get_Free_Image_Number()
BombTexture1(BombRed)
BombGreen = Get_Free_Image_Number()
BombTexture2(BombGreen)
For z = 1 To MapHeight
For x = 1 To MapWidth
Read Cube(x,z).Tile
Cube(x,z).X = (x-1)*Cubesize+(Cubesize/2)
Cube(x,z).Y = (Cubesize/2)
Cube(x,z).Z = (z-1)*Cubesize+(Cubesize/2)
Cube(x,z).num = Get_Free_Object_Number()
Make Object Cube Cube(x,z).num,Cubesize
Texture Object Cube(x,z).num,BrickImage
Position Object Cube(x,z).num, Cube(x,z).X, Cube(x,z).Y, Cube(x,z).Z
If Cube(x,z).Tile <> 1 Then Hide Object Cube(x,z).num
If Cube(x,z).Tile = 2 Then RePositionCamera(Cube(x,z).X, Cube(x,z).Y, Cube(x,z).Z)
If Cube(x,z).Tile = 3 Then Create_Bomb(0, Cube(x,z).X, Cube(x,z).Y, Cube(x,z).Z)
If Cube(x,z).Tile = 4 Then Create_Bomb(1, Cube(x,z).X, Cube(x,z).Y, Cube(x,z).Z)
If Cube(x,z).Tile = 10 Then Create_Finish(Cube(x,z).X, 2, Cube(x,z).Z)
next x
next z
FloorObject = Get_Free_Object_Number()
FloorImage = Get_Free_Image_Number()
FloorTexture(FloorImage)
Make Object Plain FloorObject, MapWidth*Cubesize, MapHeight*CubeSize
xrotate object FloorObject,90
Position Object FloorObject, (MapWidth*Cubesize)/2,0,(MapHeight*CubeSize)/2
Texture Object FloorObject, FloorImage
CeilingObject = Get_Free_Object_Number()
CeilingImage = Get_Free_Image_Number()
FloorTexture(CeilingImage)
Make Object Plain CeilingObject, MapWidth*Cubesize, MapHeight*CubeSize
xrotate object CeilingObject,90
Position Object CeilingObject, (MapWidth*Cubesize)/2,Cubesize,(MapHeight*CubeSize)/2
Texture Object CeilingObject,CeilingImage
EndFunction
Function Player_Death()
Ink RGB(255,0,0),0
Set Text Size 50
Text 50,50,"KABOOOM!!!"
Sync
Wait Key
End
endfunction
Function Player_Win()
Ink RGB(255,0,0),0
Set Text Size 50
Text 50,50,"YOU WIN!!!"
Sync
Wait Key
End
endfunction
Function Destroy_Bomb(BNum)
Delete Object Bombs(BNum).Num
Array Delete Element Bombs(0), BNum
endfunction
Function Handle_Bombs(Speed#)
If BombCount < 0
BombCount = 180
Change_Bomb_States()
Else
dec BombCount,1
Endif
For BNum = 1 TO Array Count(Bombs(0))
If Object Collision(PlayerObject, Bombs(BNum).Num) = 1 Then Player_Death()
If Bombs(BNum).Moving = 1
If abs(Bombs(BNum).X-Bombs(BNum).DestinationX) < Speed# And abs(Bombs(BNum).Z-Bombs(BNum).DestinationZ) < Speed# Then ChooseBombDestination(BNum, Speed#)
If Bombs(BNum).X > Bombs(BNum).DestinationX Then Dec Bombs(BNum).X, Speed#
If Bombs(BNum).X < Bombs(BNum).DestinationX Then Inc Bombs(BNum).X, Speed#
If Bombs(BNum).Z > Bombs(BNum).DestinationZ Then Dec Bombs(BNum).Z, Speed#
If Bombs(BNum).Z < Bombs(BNum).DestinationZ Then Inc Bombs(BNum).Z, Speed#
Position Object Bombs(BNum).num, Bombs(BNum).X, Bombs(BNum).Y, Bombs(BNum).Z
endif
next bnum
endfunction
Function ChooseBombDestination(Bomb, Speed#)
BombSquareX = int(Bombs(Bomb).X/Cubesize) + 1
BombSquareZ = int(Bombs(Bomb).Z/Cubesize) + 1
Repeat
Direction = RND(4)
If Direction = 1 And Cube(BombSquareX-1, BombSquareZ).Tile <> 1 Then Dec Bombs(Bomb).DestinationX, 10
If Direction = 2 And Cube(BombSquareX, BombSquareZ+1).Tile <> 1 Then Inc Bombs(Bomb).DestinationZ, 10
If Direction = 3 And Cube(BombSquareX+1, BombSquareZ).Tile <> 1 Then Inc Bombs(Bomb).DestinationX, 10
If Direction = 4 And Cube(BombSquareX, BombSquareZ-1).Tile <> 1 Then Dec Bombs(Bomb).DestinationZ, 10
until abs(Bombs(Bomb).X-Bombs(Bomb).DestinationX) > Speed# Or abs(Bombs(Bomb).Z-Bombs(Bomb).DestinationZ) > Speed#
endfunction
Function Create_Finish(X#,Y#,Z#)
FinishObject = Get_Free_Object_Number()
FinishImage = Get_Free_Image_Number()
FinishTexture(FinishImage)
Make Object Cube FinishObject, 4
Position Object FinishObject, X#, Y#, Z#
Texture Object FinishObject, FinishImage
endfunction
Function Setup_Screen()
sync on: sync rate 60
autocam off `:Position Camera 15,5,15
Set ambient light 75
endfunction
_InitialiseGlobals:
`Textures And miscellaneous objects:
Global BrickImage As Integer
Global BombRed As Integer
Global BombGreen As Integer
Global FloorObject As Integer
Global FloorImage As Integer
Global CeilingObject As Integer
Global CeilingImage As Integer
Global FinishImage As Integer
Global FInishObject As Integer
`All of the map variables
Global MapWidth As Integer: MapWidth = 10
Global MapHeight As Integer: MapHeight = 10
Global Cubesize As Integer: CubeSize = 10
Type Object
X As Float: Y As Float: Z As Float
num As Integer
Tile As Integer
endtype
Dim Cube(MapWidth,MapHeight) As Object
`Bullets
Type Bullet
X As Float: Y As Float: Z As Float
SX As Float: SY As Float: SZ As Float
num As Integer
endtype
Dim Bullets(0) As Bullet
Global BulletTimeout As Integer
`Stuff for moving the camera
Dim WallExist(4)
Global PlayerX As Float: Global PlayerY As Float: Global PlayerZ As Float
Global PlayerAng As Float: PlayerAng = Camera angle Y()
Global PlayerObject As Integer
PlayerObject = Get_Free_Object_Number()
Make Object Cube PlayerObject, 5
Hide Object PlayerObject
`Bombs
Type Bomb
X As Float: Y As Float: Z As FLoat
Num As Integer
Active As Integer
Moving As Integer
DestinationX As Float
DestinationZ As Float
Endtype
Dim Bombs(0) As Bomb
Global BombCount As Integer: BombCount = 180
Return
Function Get_Free_Object_Number()
Remstart
This function just finds a free object, and then returns its number.
This is so that objects can be given variable names rather than numbers!
***Special Thanks to Ric in the Darkbasic Pro forums who I stole this
function from.***
Remend
Do
inc ObjectNumber
If Object Exist(ObjectNumber) = 0 Then Exit
Loop
EndFunction ObjectNumber
Function Get_Free_Image_Number()
Remstart
This function just finds a free image, and then returns its number.
This is so that images can be given variable names rather than numbers!
***Special Thanks to Ric in the Darkbasic Pro forums who I stole this
function from.***
Remend
Do
inc ImageNumber
If Image Exist(ImageNumber) = 0 Then Exit
loop
endfunction ImageNumber
Function BrickTexture(ImageNumber)
Ink Rgb(128,64,0),0
Box 0,0,64,64
Ink Rgb(0,0,0),0
For a = 0 To 7
Line 0,(a*8),64,(a*8)
next a
For x = 0 To 7
For y = 0 To 7
If (x+y) mod 2 = 0 Then Line (x*8),(y*8),(x*8),((y+1)*8)
next y
next x
Get Image Imagenumber, 0, 0, 64, 64
EndFunction
Function FloorTexture(ImageNumber)
Ink RGB(50,50,50),0
box 0,0,64,64
Get Image Imagenumber, 0, 0, 64, 64
endfunction
Function BombTexture1(ImageNumber)
Ink Rgb(200,50,50),0
Box 1,1,64,64
Get Image ImageNumber, 1, 1, 64, 64
endfunction
Function BombTexture2(ImageNumber)
Ink Rgb(50,200,50),0
Box 1,1,64,64
Get Image ImageNumber, 1, 1, 64, 64
endfunction
Function FinishTexture(ImageNumber)
Ink RGB(255,255,0),0
box 0,0,64,64
Get Image Imagenumber, 0, 0, 64, 64
endfunction
Function Check_Wall_Collisions(Buffer#,Speed#)
For direction = 1 To 4
WallExist(direction) = 0
next direction
For z = 1 To MapHeight
For x = 1 To MapWidth
If Cube(x,z).Tile = 1
If Abs((Cube(x,z).X-Buffer#-(Cubesize/2)-PlayerX)) < Speed# And Abs((Cube(x,z).Z)-PlayerZ)-Buffer# < (Cubesize/2) Then WallExist(1) = 1
If Abs((Cube(x,z).X+Buffer#+(Cubesize/2)-PlayerX)) < Speed# And Abs((Cube(x,z).Z)-PlayerZ)-Buffer# < (Cubesize/2) Then WallExist(3) = 1
If Abs((Cube(x,z).Z-Buffer#-(Cubesize/2)-PlayerZ)) < Speed# And Abs((Cube(x,z).X)-PlayerX)-Buffer# < (Cubesize/2) Then WallExist(2) = 1
If Abs((Cube(x,z).Z+Buffer#+(Cubesize/2)-PlayerZ)) < Speed# And Abs((Cube(x,z).X)-PlayerX)-Buffer# < (Cubesize/2) Then WallExist(4) = 1
endif
next x
next z
endfunction
Function RepositionCamera(X#,Y#,Z#)
Position Camera X#, Y#, Z#
PlayerX = Camera Position X(): PlayerY = Camera Position Y(): PlayerZ = Camera Position Z()
endfunction
Function Move_Camera(Speed#)
If Leftkey() = 1 Then PlayerAng = WrapValue(PlayerAng - Speed#*4.0)
If RightKey() = 1 Then PlayerAng = WrapValue(PlayerAng + Speed#*4.0)
If PlayerAng >= 0 AND PlayerAng <= 180
If WallExist(1) = 0 And Upkey() = 1 Then PlayerX = Newxvalue(PlayerX, PlayerAng, Speed#)
If WallExist(2) = 0 And ControlKey() = 1 Then PlayerZ = Newzvalue(PlayerZ, PlayerAng-90,speed#/2.0)
If WallExist(3) = 0 And Downkey() = 1 Then PlayerX = Newxvalue(PlayerX,PlayerAng,-Speed#)
If WallExist(4) = 0 And Keystate(82) = 1 Then PlayerZ = Newzvalue(PlayerZ, PlayerAng+90,speed#/2.0)
Endif
If PlayerAng >= 180 And PlayerAng <= 360
If WallExist(1) = 0 And Downkey() = 1 Then PlayerX = Newxvalue(PlayerX,PlayerAng,-Speed#)
If WallExist(2) = 0 And Keystate(82) = 1 Then PlayerZ = Newzvalue(PlayerZ, PlayerAng+90,speed#/2.0)
If WallExist(3) = 0 And Upkey() = 1 Then PlayerX = Newxvalue(PlayerX, PlayerAng, Speed#)
If WallExist(4) = 0 And ControlKey() = 1 Then PlayerZ = Newzvalue(PlayerZ, PlayerAng-90,speed#/2.0)
Endif
If PlayerAng >= 270 Or PlayerAng <= 90
If WallExist(3) = 0 And ControlKey() = 1 Then PlayerX = Newxvalue(Playerx, PlayerAng-90,speed#/2.0)
If WallExist(2) = 0 And Upkey() = 1 Then PlayerZ = Newzvalue(PlayerZ, PlayerAng, Speed#)
If WallExist(1) = 0 And Keystate(82) = 1 Then PlayerX = Newxvalue(Playerx, PlayerAng+90,speed#/2.0)
If WallExist(4) = 0 And Downkey() = 1 Then PlayerZ = Newzvalue(PlayerZ,PlayerAng,-Speed#)
Endif
If PlayerAng >= 90 And PlayerAng <= 270
If WallExist(4) = 0 And Upkey() = 1 Then PlayerZ = Newzvalue(PlayerZ, PlayerAng, Speed#)
If WallExist(1) = 0 And ControlKey() = 1 Then PlayerX = Newxvalue(Playerx, PlayerAng-90,speed#/2.0)
If WallExist(2) = 0 And Downkey() = 1 Then PlayerZ = Newzvalue(PlayerZ,PlayerAng,-Speed#)
If WallExist(3) = 0 And Keystate(82) = 1 Then PlayerX = Newxvalue(Playerx, PlayerAng+90,speed#/2.0)
Endif
Position Camera PlayerX, PlayerY, PlayerZ
Yrotate Camera PlayerAng
Position Object PlayerObject, PlayerX, PlayerY, PlayerZ
endfunction
Function Make_bullet(Speed#)
If Array Count(Bullets(0)) = 100 Then Destroy_Bullet(1)
Add To Queue Bullets(0)
BNum = Array Count(Bullets(0))
Pick Screen MouseX(),MouseY(), Speed#
Bullets(BNum).SX = Get Pick Vector X()
Bullets(BNum).SY = Get Pick Vector Y()
Bullets(BNum).SZ = Get Pick Vector Z()
Bullets(BNum).X = Camera Position X()+Bullets(BNum).SX*2
Bullets(BNum).Y = Camera Position Y()+Bullets(BNum).SY*2
Bullets(BNum).Z = Camera Position Z()+Bullets(BNum).SZ*2
Bullets(BNum).Num = Get_Free_Object_Number()
Make Object Sphere Bullets(BNum).Num,1
Position Object Bullets(BNum).Num,Bullets(BNum).X, Bullets(BNum).Y, Bullets(BNum).Z
`Endif
endfunction
Function Move_Bullets()
For tb = 1 To Array Count(Bullets(0))
Bullets(tb).X = Bullets(tb).X + Bullets(tb).SX
Bullets(tb).Y = Bullets(tb).Y + Bullets(tb).SY
Bullets(tb).Z = Bullets(tb).Z + Bullets(tb).SZ
Position Object Bullets(tb).Num,Bullets(tb).X, Bullets(tb).Y, Bullets(tb).Z
next tb
endfunction
Function Destroy_Bullet(BNum)
Delete Object Bullets(BNum).Num
Array Delete Element Bullets(0),BNum
endfunction
Function Handle_Bullets(Speed#)
If MouseClick() = 1 And BulletTimeout < 1
Make_Bullet(Speed#)
BulletTimeout = 30
Endif
If BulletTimeOut > 0 Then Dec BulletTimeout,1
Move_Bullets()
`Check if a bullet collides with a wall or a bomb
For tb = 1 To Array Count(Bullets(0))
If Object Position Y(Bullets(tb).Num) > CubeSize Or Object Position Y(Bullets(tb).Num) < 0
Destroy_Bullet(tb)
tb = tb - 1: If tb = 0 Then tb = 1: If tb > Array Count(Bullets(0)) Then Goto _HBExitLoop
endif
For z = 1 To MapHeight
For x = 1 To MapWidth
If Cube(x,z).Tile = 1
If Object Collision(Bullets(tb).Num, Cube(x,z).num) = 1
Destroy_Bullet(tb)
tb = tb - 1: If tb = 0 Then tb = 1: If tb > Array Count(Bullets(0)) Then Goto _HBExitLoop
Endif
Endif
next x
next z
For BNum = 1 To Array Count(Bombs())
If Object Collision(Bullets(tb).Num,Bombs(BNum).Num) = 1
If Bombs(Bnum).Active = 1 Then Player_Death()
If Bombs(Bnum).Active = 2 Then Destroy_Bomb(BNum)
Destroy_Bullet(tb)
tb = tb - 1: If tb = 0 Then tb = 1: If tb > Array Count(Bullets(0)) Then Goto _HBExitLoop
endif
next bnum
_HBExitLoop:
next tb
Endfunction
`Main Level (Current)
Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
Data 1, 2, 0, 4, 3, 0, 4, 0, 0, 1
Data 1, 0, 0, 0, 1, 1, 1, 1, 3, 1
Data 1, 0, 0, 0, 1, 0, 0, 0, 0, 1
Data 1, 4, 0, 4, 1, 0, 0, 0, 0, 1
Data 1, 3, 1, 1, 1, 0, 0, 0, 0, 1
Data 1, 0, 1, 0, 0, 0, 4, 4, 4, 1
Data 1, 4, 1, 0, 0, 0, 4, 3, 3, 1
Data 1, 0, 3, 0, 0, 0, 4, 3,10, 1
Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
`Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
`Data 1, 2, 0, 4, 0, 0, 0,10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
`Data 1, 0, 0, 3, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1
`Data 1, 3, 3, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1
`Data 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1
`Data 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1
`Data 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1
`Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1
`Data 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1
`Data 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1
`Data 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1
`Data 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1
`Data 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1
`Data 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1
`Data 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1
`Data 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1
`Data 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
`Data 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
`Data 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
`Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
Well, this is not your ordinary fps, so I'll do some explaining:
First of all, the controls are quite simple: Arrow keys move around, and the control and "0" keys (to the sides of the arrow keys) move you left and right (is it called "strafing?" I don't know...)Click to shoot.
Anywhoo, your goal is to get to a yellow box (you should find it pretty simply in this level). Unfortunately, your way is blocked by a number of bombs that all want to just blow you up. If you run into a bomb, you're toast.
Now, you could try to simply avoid all of the bombs (not suggested), or you could try shooting them. Here's the catch: bombs are destroyed when you shoot them and they're green, but if they're red then they detonate anyways and kill you. So only shoot green bombs (not red ones... They do change after a couple of seconds).
Well, it is currently a *finished* game, but I will be adding a number of things to it in the rest of this week:
*Multiple levels, and perhaps more than just one life!
*Better textures!
*More types of bombs (if I get to it)
*Anything else that enters my warped brain!