A3: General Guidelines
Start with creating a Character superclass and define a BasicEnemy subclass.
Build an enemy subclass that draws your enemy and bounces from walls or
wraps around the screen. Create an ArrayList of enemies and have them
appearing and moving on the screen. Build the hitCharacter() method, for now,
use the mouse to “hit” the enemy and see that your removal of enemies and
the 1-second timer to let them die works. Leave the projectiles for later.
Now build your Player character. Make it move around the screen using keys.
Now is the time to build a collision detection between BasicEnemy objects and
the Player object, see the requirement “player takes damage if it collides with
the basic enemy”. You have two options: either the Player needs to check
against each BasicEnemy, or every BasicEnemy needs to check against the
Player. You need to decide which class will detect the collision between these
two. (Hint: what is the result of the collision, which object needs to have the
health changed?) Also, remember that the requirement that you have to
prevent an autorepeat; you can use some timer not to allow another health
decrease within certain time (e.g. within 20? frames). In any case, the detect
hit method needs to be called from the main sketch on the BasicEnemy or on
the Player object, and it needs to be passed either the Player object or enemy
ArrayList as a parameter.
At this point, you should have a “Dodge ’em all” game, where your Player is
trying to avoid bumping into enemies. Add health display at this point.
Now is the time for building projectiles. Build the class. Make the Player to
“fire” projectiles by the space bar. The firing means you create a new
Projectile object, with the Player’s location as a start and some velocity in
some direction (your decision). Now, this new object needs to be kept
somewhere, and the spec says the Player “keeps track”. This means that the
Player will need to keep making sure that each projectile is updated when the
Player is updated, that each projectile gets drawn when the Player is drawn, to
make sure that the projectile is removed when the projectile leaves the screen,
e.g. you have to be able to call the method that will tell you that the projectile
has left the screen. At this point, you should have the projectiles that are
being fired, they are being drawn flying, and when they leave the screen, they
It is time to check hitting enemies. The spec says that “player class has a
method checkProjectiles() that will check each projectile against each enemy”.
This is a hint, that the main sketch will be calling this method. However, the
Player needs to know where the enemy objects are. The main sketch has an
array list of them, and it needs to pass them as a parameter to
checkProjectiles() method. The question is, which object should implement
the hit detection, which will check if a projectile hit an enemy? Player?
Projectile? Enemy? The spec says the projectile should have “hit method that
takes a single parameter of type Character”. So, the Player will call this
method for each projectile and for each enemy (nested loop). Now, what is in
the hit() method in the Projectile class? It takes a Character as a parameter
(for now only BasicEnemies). The Character knows about its geometry, so
when given the location of the projectile (and maybe also the radius of
projectile is bigger, like a ball of mud), it will be able to check that it was hit.
The Projectile calls this method. If there is a hit, Character needs to be
updated after the hit (BasicEnemy for now, e.g. its health goes to zero). Player
needs to remove Projectile.
Now we have the mechanism for hitting enemies and for removing projectiles.
However, we could not remove enemies when they got hit, as the list of
enemies is kept in the main sketch. We have just updated hit enemies health
to zero, or something similar. It is the main sketch that keeps the list of
enemies, and therefore the main sketch needs to check, after calling
checkProjectiles(), which enemies are still alive, and update the enemies list
Now is the time for the BossEnemy. Create a subclass of the BasicEnemy. The
boss needs to fire the projectiles, probably triggered by the timer (say every 5
seconds), in the direction of the Player (compute the Projectile’s velocity
vector for the Projectile from the player location and the boss location. Use
the same logic for dealing with boss’s projectiles as you did with the Player’s
Finish remaining requirements.
A3: Detail Specification
Because the overall purpose of this assignment is to start you the process of using
OOP concepts and techniques to design and implement your program, weʼve
imposed a lot of requirements on how you need to create the game. Be sure to
read the requirements very carefully and use them to design and implement your
various classes and methods!
Effort, Creativity, Originality
Application Requirements (4 points max)
Visual collision between enemies and player (and the player projectile)
must be designed accurately.
You have not met this requirement if a player projectile damages the enemy
without reaching it visually, or does not damage after reaching it. The same
with the player when hit the enemy.
Visual collision between the boss and player (and their projectile) must
be designed accurately.
You have not met this requirement if player or boss projectiles damages their
target without reaching it visually, or does not damage after reaching it. The
same with the player when hit the boss.
When enemies or boss hit the player, player must lose one health for each
You have not met this requirement if enemies or boss reduce the playerʼs
health continually as long as they are in contact with the player, i.e. you have
to pay attention to “autorepeat”.
Each of the Player, Basic Enemy, Boss Enemy, and Projectiles objects
must be displayed on the screen to get credit.
You would be penalized for application requirements (-1) and your maximum
number of points to score on coding requirements would be one half of those
listed for classes not displayed (see below).
Return to: top or Assignment 3
Coding Requirements (20 points max)
Coding requirements are specified on per class basis. The listed requirements
must be follow exactly.
In addition, you will be making decisions on your own. You may add fields and
methods as needed, however you need to follow an inheritance model and not
“redefine” fields when this is not necessary and/or rewrite the method “from
scratch” if you can expand the method from the superclass.
You are expected to follow good practice of clearly structuring the code into
methods that are coherent in their function and allow for good readability of your
code. Comment your code clearly specifying the purpose of every method in your
A Character superclass (max 3 points)
at least five fields, including for position (PVector), velocity (PVector), health,
method moveCharacter() for moving character using fields,
method accelerate() for acceleration that changes Character’s velocity using
an accelerator (PVector)
a “dummy” drawCharacter() method for drawing character that draws a
placeholder shape (to be overridden by subclasses)
a hitCharacter(), with a single parameter of type Character, which returns true
if the character this Character has collided with the one passed as a
a decreaseHealth() method that decreases health by teh value passed as a
a checkWalls() method that checks if character is off boundaries and
compensates in some way. The method has correctly consider dimensions of
Character and its shape (roundish or squarish).
an update() method that calls move and checkWalls methods
Return to: top or Assignment 3
A Player subclass of Character (max 5 points)
human user can move Player using four keys (either WASD or arrow keys)
the player character can move freely horizontally, vertically and diagonally
can fire and keeps track of its projectiles (make a proper choice for storing
projectiles that were fired)
player class has a method checkProjectiles() that will check each projectile
against each enemy if the enemy was hit (use projectile’s hit method – see
below). If the enemy was hit, the player damages the enemy accordingly
(either basic or boss enemy) and the projectile is removed.
overrides Character’s update method to check projectiles
overrides Character’s draw method
Return to: top or Assignment 3
A BasicEnemy subclass of Character (max 3 points)
must not fire projectiles
player takes damage if it collides with the basic enemy
to kill the basic enemy player needs to hit it with 2-3 projectiles
when the basic enemy is killed (its health is 0), it appears dead/captured/
different for 1 second before it is removed from the game
overrides Character’s update method so it checks whether it collides with a
player and if so damages the player (i.e. decreases its health)
overrides Character draw method
本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝交易！
E-mail: [email protected] 微信:itcsdx