Thursday, October 1, 2009

Fangs Invasion - Your Help Needed to Save World

Over the last couple of days I have been working on transforming my bat animation into a simple game that is inspired by space invaders. In this post I am going to share with you this work-in-progress, along with the plan and code that I have written to bring it to reality. There is much work that I still need to do on this game, but before I tell you about the improvements that I have in mind lets delve into what has been created thus far.

Here is an overview of how the game works. The small black bat at the bottom of the screen is under attack by a mad pack of diseased vampire bats. This disease, which makes bats turn into crazy colors, also makes them into mad killers. You are the only hope left for the bats on earth, good luck. To play the game, use the left and right arrow keys to move around, and use the mouse button to fire off your bullet-like fangs - click the area below to start the game.



Planning Notes for Development of Game
I build this game using code that I had already created; I had build a "bat" class over the past several weeks as I've been learning to use processing. Therefore, this planning section only focuses on building the other elements of the game (and customizing this class).
Turning Little Fangs into a Bat Invader Game

Overview:
The objective of the game will be to shoot down as many bats as possible within a 3-minute window of time. If the bats are able to reach the bottom of the screen then the game will end before the 2-minute window is over. As the time passes the number of bats will increase. The longer a bat stays on the screen the further down he will come.

Random Ideas:
• The black bat could be the shooter who is trying to destroy the colored bats who are carrying some type of virus (hence their non-bat-like color).
• Find way to cap the number of bats on the screen using an array of a pre-defined size. Once a bat dies remove that instance from the array (per the example in book).

Objects Required:
• Bats
• Bullets
• Shooter
• Timer

Functionality Required - Base
• Shooter to appear on bottom of screen
• Bats to appear on screen gradually
o Timer program needed to manage timing of bat appearances
• Bats to move from one side of the screen to the other
• Bats to slowly make their way down the screen
• Shooter to move right and left
• Shooter to shoot bullets upward towards bats
• Bat and bullet to disappear if contact occurs
• Game to end if a bat reaches the bottom of the screen
• Count of dead bats to be increased for every bat killed

Functionality Required – Extension
• Move shooter from left to right of screen using bi-directional toggle switch
• Shoot bullets by pressing a spring-loaded push button


Functionality by Object:

Bats
• Display the bat on the screen       
• Manage rhythm of bat generation    
• Move within pre-defined flight space
• Move pre-defined flight space downwards
• Detect intersection of bat and other object
• Destroy/kill bat
• Detect bat reaching bottom of screen

Bullets
• Display bullet
• Shoot bullet
• Move bullet 
• Detect intersection of bullet and other object

Shooter
• Display shooter
• Move shooter
• Shoot bullet

Timer
• Set time when game began
• Set intervals for generation of new bats
• Determine when game ends




Detailed Notes – Bat Object

(1) Display the bat on the screen - completed

(2) Manage rhythm of bat generation 
• Function that provides a timer functionality for entire game (to be created)
• Function to make bats appear in random locations as currently the bats always appeared behind the cursor (to be created) 

(3) Move within pre-defined flight space (completed)
• Function that moves bat around screen based on random speed and direction (completed)
• Variable to hold the time in which each individual bat was created (completed)
• Function to course correct bat when he reaches edge of his flight area. Leverage existing speedYadj and speedXadj functions by adding a parameter that enables us to limit the area where bats can fly (completed)

(4) Move pre-defined flight space downwards (completed)
• Function to calculate how far down each bat can move based on time variable that holds when the bat was created. (completed)

(5) Detect intersection of bat and other object (completed)
• Function that determines whether bat and other object have come into contact with one another.
• Variable that holds life status of the bat

(6) Destroy/kill bat (completed)
• Function that makes bat disappear once their life status is changed to false

(7) Detect bat reaching bottom of screen (completed)
• Function that identifies when the bat has reached the bottom of the screen and sets the game to over.
• Variable that confirms if game is active or not.
• Using the intersection detection function to check this as well.


Detailed Notes - Bullets
(1) Display bullet (completed)
• Function to draw bullet shape on the screen (completed)
• Function that makes bullet disappear from screen if it hits a bat. This can probably be a part of the display function (e.g. if statement).

(2) Shoot bullet (completed)
• Function to set bullet speed and starting location (completed)
• Variable to hold the constant bullet speed (completed)
• Variable to hold the movement of the shooter when shooting (in case we want to make game physics more real, and have bullet keep momentum).

(3) Move bullet  (completed)
• Function to move bullet based on speed and current location

(4) Detect intersection of bullet and other object (completed)
• Function to detect bullet’s intersection with other objects and sets bullet state accordingly
• Variable to hold bullet state (true = active, false = inactive)


Detailed Notes – Shooter
(1) Display shooter
• Function that displays the shooter

(2) Move shooter
• Function that moves shooter based on the press of the mouse (and eventually an external input). Movement limited to left and right. Constant speed.

(3) Shoot bullet
• Function that shoots bullets (or at least provides location of shooter so that bullet knows where to display from).

Detailed Notes – Timer
(1) Set time when game began  (completed)
• Function the initiates the time when game begins

(2) Set intervals for generation of new bats and other game elements (potentially a hello screen)

(3) Determine when game ends  (completed)
• Function that determines when game time has run out.

Processing Code (Work in Progress)
To view the code for check out my page on the Open Processing website. Considering how long the code is, and that it contains multiple tabs worth of content, it is easier to view it through the interface available on this website. The code can be found on the lower right hand corner of this page.

More to Come
There are several things that I still want to do to this game. Here is a short list of the things that I am thinking about or working one:
  • Finish coding the game rules to determine when a player has won or lost the game
  • Create a joystick that enables users to control the game without using the keyboard
  • Develop a points system for the game so that players can keep track of their score
  • Enable the player to re-start and/or reset the game

No comments: