B-17: Crop Duster

Community Forums/Showcase/B-17: Crop Duster

WedgeBob(Posted 2006) [#1]
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.


ckob(Posted 2006) [#2]
just a thought but isnt a B-17 just a little to big to be a crop duster?


WedgeBob(Posted 2006) [#3]
Well, here's a screenie for the title/splash screen:




WedgeBob(Posted 2006) [#4]
Also, here's a post from the game itself:




WedgeBob(Posted 2006) [#5]
Well, this was the first pic of the program, but then later on, I decided to shrink down the plane and the hay bale images to make it a little more on a realistic scale. Here's the updated pic for the game. I also did a hay bale salvo to prove the power of this game:



(Posted 4 minutes ago)
just a thought but isnt a B-17 just a little to big to be a crop duster?


Well, to answer your question about that. I was originally going to make a World War II flight sim, but that idea was taken in a professional, commercial game already (I think that it was Microprose or somebody like that from a long time ago). However, to make a bi-plane would be a little more difficult, so I decided to recycle the B-17 image and use it in a non-war flight sim, but still letting you toss bales of hay out the door. Just didn't get enough time to think about another plane that would be better for this.


Braincell(Posted 2006) [#6]
so I decided to recycle the B-17 image


How do you recycle an image that takes approx 43 seconds to make?


WedgeBob(Posted 2006) [#7]
so I decided to recycle the B-17 image


How do you recycle an image that takes approx 43 seconds to make?


Well, it all depends on detailing, with a 64x64 image, you almost need to do all sorts of close up work. For quality work, it's more than 43 seconds, more like 4.3 minutes to 7.25 minutes. When you want to try and center everything, and work using the binary system when it comes to graphics. That's all part of the industry, what can I tell you?


WedgeBob(Posted 2006) [#8]
Well, I did decide to add something to shoot at, mainly a crow or another large bird that you toss your bale of hay at. Either that, or the crow crashes into you, and you dive down into the ground, KA-BOOM!


WedgeBob(Posted 2006) [#9]
Well, now that I'm thinking about it, I may scrap this project and move onto a real flight war sim of sorts. I think I'm catching onto this engine, and may want to develop a project based on more current events, like the War in Iraq or Afghanistan, maybe with a jet fighter, or even a stealth bomber, whatever the case might be.

Ahh, I don't know if anyone did any games based on the SR-71, cool jet, may be worth using:


WedgeBob(Posted 2006) [#10]
After careful consideration, and long thought, I have decided to dump this project, and move onto a one-on-one flight combat game. I also hope to make a widescreen, 3-D version sometime soon. For now, the top-down perspective seems to be the easiest form to program right now. Another thing, I'm probably going to introduce joypad/joystick inputs sometime soon, as well. Right now, I'll focus on a 4:3 full-screen with keyboard inputs (sort of standard, but this will be a start). However, I'll start a brand new thread once I make my upcoming project official. This one with the Crop Duster doesn't seem to fit the times, sorry to say. It's probably better to do a one-on-one dogfight-type game. Have yet to think of a name for it. As for this project, it's not gonna happen, as I am revamping the whole thing from the ground up.


Nexus6(Posted 2006) [#11]
I hope you recycle the B-17, a lot of hard work has gone into its making and it would be such a waste not use it. Have you considered selling your textures as a pack ?


WedgeBob(Posted 2006) [#12]
Well, right now, I'm going to use the B-17 as a skinnable model, as well as the sound effects. However, the default fighter plane will be a jet (maybe an F-16 Falcon, or F/A-18 Hornet vs. the enemy plane (maybe a Mig-29, or Mig-21, haven't decided)), and the default setting will be in the Middle East. However, there may be different plane skins, and backgrounds to change the setting of the game (all of the media components are "open architecture" if you wish to mod this game (I'm only one of few game authors in the world that'll let you do this)). Just trying to make like an "OEM" in the freeware gaming world, so other developers will use this in a 3rd party program.


Banshee(Posted 2006) [#13]
The humour took a moment to sink in... ;)

I like the idea of crop dusting though. There's too much violence about already.


WedgeBob(Posted 2006) [#14]
Well, it wasn't my choice to dump this project, it was a sign of the times that made me base a flight game on current events. Even tho flight games are all about combat these days, it's about time to look at air combat with plans that involve other than WWII gaming (have we had enough World War II games already? That's about 65 years ago, for crying out loud!). My plans now are to make a flight game based in the Middle East, circa 2002, so you know that the game's sort of current. Yeah, it's where you gun down suicide bombers before they crash into you. This is a "one-on-one" tournament that I'm thinking of now. The first plane to knock down the other 20 times wins (sounds like a tournament in Q3A again). At least this will bring flight games back to the old NES/SNES days of air combat, give or take. You'll like my new project when I release info in another thread.