CST112
Projects 2 & 3
Project 2
For project 2, make the "hero" (your character) move diagonaly for each frame,
and bounce off the sides of the screen.
(Also draw a "scene", with grass, sky, and sun.)
Use global variables (for now) but everything should be fully modularized:
i.e the "draw()" method should contain only function calls to invoke other methods that you have written.
(Be sure to begin each of your functions with a brief COMMENT that says what this method is supposed to do)
Project 3 is not assigned yet.
This is only a partial specification.
Project 3 will include:
- A scene, with green grass below, blue sky above, a yellow sun, and a score.
- A "hero" (your character) who bounces off the sides of the screen (and jumps to mouse, when clicked).
- A bomb, which drops downward in every frame (after it is released by pressing a key).
- Three bullets, which move very fasta, horizontally (when fired, by pressing a key).
- The score is very simple for this project: just count the number of bombs, bullets, bounces, etc. and use a simple formula (to be supplied later).
Various events cause the sketch to change.
Use global variables (for now) but everything must be fully modularized.
- Clicking the mouse makes the hero jump to the mouse coordinates,
and sets the horizon to a random value.
- Pressing a key makes a new bomb start to fall (from behind the sun,
after moving the sun to a random X coordinate).
- Pressing a key makes a new set of three bullets begin at the left side of the screen,
at a random height (Y coordinate).
- Bad things happen if a bomb or bullet hits the hero (and the score changes, too).
////Fully-modularized:
void draw() //// Draw scene, hero, bomb, etc. Also move as necessary.
{
doScene();
doHero();
doBomb();
doBullets();
doScore();
}
/*
Scene:
Blue sky.
Sun high in the sky. (3/4 of the way up, above horizon.)
Green grass from horizon to bottm.
Hero:
(Whatever you want, but use at least three different methods to draw it.
Hero moves across and down by heroDX and heroDY
Bomb:
Drops downward by bombDY, every frame.
Bullets:
Three bullets move to right, by bulletDX, every frame.
They are spaced 50 pixels apart, vertically.
Score:
For now, just add one every time a bomb starts dropping.
*/
//////// EVENTS:
void setup() // ++++
{
size(640,480);
restart(); // Initialize all game variables.
}
void mousePressed() // Horizon adjusts randomly. Hero jumps to mouse
{
// ++++
}
void keyPressed() // Sun moves to random X position. Bomb starts dropping from sun.
{
// ++++
}