Well, after catching onto some programming for Blitz 3D, I've decided to go ahead and do a nice flight sim involving tossing bales of hay out of a B-17 aircraft. Although this program isn't officially complete yet, this gives you an idea of what I've been coding over the past week or so, or trying to. Here's the code for starters, you may like the start of this:
; Duster.bb - This is the source code behind B-17: Crop Duster. Source code influence courtesy of Maneesh Sethi, author of
; "Game Programming for Teens." Special thanks to partnersinrhyme.com for the sound effects, University of Washington for the crop
; dusting photo background. Boeing Corporation for the photo of the B-17 Flying Fortress. Thanks to the Blitz Basic team for the
; language to program in, Microsoft for Paint, and Corel for Paint Shop Pro X. (c)2006, Robert A. Morin.
; Set the graphics resolution for this program
Graphics3D 800,600
; Load the initial settings for the pictures and the sound
themesound = LoadSound("b17.wav")
; Load the background image for the splash screen
splashimage = LoadImage("back.png")
; Draw the background
DrawImage splashimage,0,0
; Load the image of the B-17 Bomber
spriteimage = LoadImage("b17.png")
; Place the image in the center
MidHandle spriteimage
; Mask the image of the plane
MaskImage spriteimage,0,0,10
; Draw the image in the center
DrawImage spriteimage,400,300
; Play the plane sound
PlaySound themesound
; Tell the user to press any key to continue to the game
Text 0,512, "Press <ANY KEY> to Start Program: "
Flip
; Wait for the user to press a key, then continue into the game
WaitKey
; Make sure that the screen is clear before continuing to the next segment
Cls
; First off, Initialize the default settings for the AutoMidHandle and the BackBuffer()
AutoMidHandle True
SetBuffer BackBuffer()
; Below are the types for the program
; Here is the type for the bale of hay
Type bullet
Field x,y ; These explain the coordinates for the bale of hay
End Type
; Here is also the type for the player
Type player
Field x,y ; These explain the coordinates for the player to move
End Type
; Create the player for the game and initialize the setup for the field
Global player.player = New player
player\x = 400
player\y = 500
; load the bale of hay image for dropping from the airplane
Global hayimage = LoadImage("bayhale.png")
; Load the background tile of the clouds first
cloudimage = LoadImage("clouds.png")
; Then, load the background tile of the farmland below
farmimage = LoadImage("ground.png")
; For the airplane, load the image in for that
planeimage = LoadImage("plane.png")
; Now, load the sound for the propeller motors
propsound = LoadSound("prop.wav")
; Now, create a constant variable for the rotations
Const rotations = 16
; On the same token, create a constant for testing the keypress values
Const ESCKEY = 1, UPKEY = 200, LEFTKEY = 203, RIGHTKEY = 205, DOWNKEY = 208, SPACEBAR = 57
; Also, create the image array for the plane to rotate
Dim imagearray(rotations)
; Now, create the variable to track the scrolling
scrolly = 0
; Take all the rotations specified, copy the image and rotate the respective amount of positions
For frame = 0 To rotations - 1
imagearray(frame) = CopyImage (planeimage)
RotateImage imagearray(frame), frame*360/rotations
Next
; Start the plane in the north position
frame = 0
; Now begins the main loop for the program
While Not KeyDown(ESCKEY)
; Make sure the screen is clear again
Cls
; First, tile the images for the background at their respective speeds
TileImage farmimage,0,scrolly
TileImage cloudimage,0,scrolly*2
; Increase the scrolly variable by 1 frame
scrolly = scrolly + 1
; Once the scrolly variable exceeds the maximum value, reset to 0
If scrolly >= ImageHeight(cloudimage)
scrolly = 0
EndIf
; Add the text for the instructions in the game
Text 0,0, "Press <LEFT> to Turn Left, and throw the bales of hay to the left"
Text 0,12, "Press <RIGHT> to Turn Right, and throw the bales of hay to the right"
Text 0,24, "Press <UP> to throw the bales of hay north of the plane"
Text 0,36, "Press <DOWN> to throw the bales of hay behind the plane"
Text 0,48, "Press <SPACE BAR> to toss the bales of hay out of the plane"
Text 0,60, "Press <ESC> to Quit Game"
; Turn the plane to the left, once the player presses the left key
If KeyDown (LEFTKEY)
; Decrease the frame by 1 to turn the plane left
frame = frame - 1
; Once the frame count dwindles below the mimimum value, reset to the maximum value for the respective array
If frame <= 0
frame = rotations - 1
EndIf
; Turn the plane to the right, once the player presses the right key
ElseIf KeyDown (RIGHTKEY)
; Increase the frame by 1 to turn the plane to the right
frame = frame + 1
; Once the frame count exceeds the maximum value, reset the value to the north position
If frame >= rotations
frame = 0
EndIf
EndIf
; Test the key inputs
TestKeys()
; Update and move each bale of hay
UpdateBullets()
; Draw the frame that is currently shown
DrawImage imagearray(frame), 400,300
; Play the propeller motor sound for the airplane
PlaySound propsound
volume# = .600
Flip
; Standby for a brief delay
Delay 50
Wend
; This will conclude the main loop of the program
Function TestKeys()
; Turn the plane to the left, once the player presses the left key
If KeyDown (LEFTKEY)
; Decrease the frame by 1 to turn the plane left
frame = frame - 1
; Once the frame count dwindles below the mimimum value, reset to the maximum value for the respective array
If frame <= 0
frame = rotations - 1
EndIf
; Also, move the airplane 5 pixels to the left
player\x = player\x - 5
; Turn the plane to the right, once the player presses the right key
ElseIf KeyDown (RIGHTKEY)
; Increase the frame by 1 to turn the plane to the right
frame = frame + 1
; Once the frame count exceeds the maximum value, reset the value to the north position
If frame >= rotations
frame = 0
EndIf
; Also, move the airplane 5 pixels to the right
player\x = player\x + 5
; Make the option for the plane to move northwards up the screen
ElseIf KeyDown (UPKEY)
; Move the player up 5 pixels if he goes up north
player\y = player\y - 5
; Now, make the option if the player wants to go south with his plane
ElseIf KeyDown (DOWNKEY)
; Move the player down 5 pixels if he goes down south
player\y = player\y + 5
EndIf
; Now, if the player wants to deploy a bale of hay, create one for the player in his or her current location on the screen
If KeyHit (SPACEBAR)
bullet.bullet = New bullet
bullet\x = player\x
bullet\y = player\y
EndIf
End Function
Function UpdateBullets()
; For every bale of hay deployed, move it up 5 pixels
; If the bale of hay goes off the screen, remove it, if not, draw the hay bale
For bullet.bullet = Each bullet
bullet\y = bullet\y - 5
; Once the bullet goes off the screen or playing area, remove it, if not, draw the bale of hay
If bullet\y < 0
Delete bullet
Else
DrawImage hayimage, bullet\x, bullet\y ; Make sure the bale of hay is drawn
EndIf
Next ; Move onto the next bale of hay
End Function
I'll try and get some screenshots in here later, but this proves that I'm getting the hang of doing some cool games (albeit sort of like Atari or NES-type stuff). I bet the farmers will get their dose of entertainment with a game like this.
|