Added scrolling story if idle on title page. Implemented projectile and bomb. Added 3 different types of asteroid to shoot. Added shield on spawn and after taking damage.
parent
477cc2d019
commit
2aa1ae05e8
16 changed files with 1263 additions and 112 deletions
@ -0,0 +1,144 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public class Asteroid1 implements Enemy { |
||||
public static final int MINIMUM_DIFFICULTY = 0; |
||||
public static final int SCORE = 25; |
||||
public static final int INITIAL_HIT_POINTS = 1; |
||||
public static final int SCALE_FACTOR = 10; |
||||
public static final int CHANCE_OF_SPAWNING = 20; |
||||
public static final int MAX_SPEED = 4; |
||||
|
||||
private final PImage sprite; |
||||
private final int tintR; |
||||
private final int tintG; |
||||
private final int tintB; |
||||
|
||||
private final Level level; |
||||
|
||||
private int x; |
||||
private int y; |
||||
private int rotation; |
||||
private float speed; |
||||
|
||||
private int hitPoints; |
||||
|
||||
public Asteroid1(int x, int y, PImage sprite, Level level) { |
||||
this.x = x; |
||||
this.y = y; |
||||
this.rotation = int(random(0,360)); |
||||
|
||||
this.level = level; |
||||
|
||||
this.hitPoints = INITIAL_HIT_POINTS; |
||||
|
||||
this.sprite = sprite; |
||||
this.tintR = int(random(0, 256)); |
||||
this.tintG = int(random(0, 256)); |
||||
this.tintB = int(random(0, 256)); |
||||
|
||||
this.speed = random(0,MAX_SPEED+1); |
||||
} |
||||
|
||||
@Override |
||||
public int getX() { |
||||
return this.x; |
||||
} |
||||
|
||||
@Override |
||||
public int getY(){ |
||||
return this.y; |
||||
} |
||||
|
||||
@Override |
||||
public int getRotation(){ |
||||
return this.rotation; |
||||
} |
||||
|
||||
@Override |
||||
public PImage getSprite(){ |
||||
return this.sprite; |
||||
} |
||||
|
||||
@Override |
||||
public int getScaleFactor() { |
||||
return SCALE_FACTOR; |
||||
} |
||||
|
||||
@Override |
||||
public int getTintR() { |
||||
return this.tintR; |
||||
} |
||||
|
||||
@Override |
||||
public int getTintG() { |
||||
return this.tintG; |
||||
} |
||||
|
||||
@Override |
||||
public int getTintB() { |
||||
return this.tintB; |
||||
} |
||||
|
||||
@Override |
||||
public int getMinimumDifficulty() { |
||||
return MINIMUM_DIFFICULTY; |
||||
} |
||||
|
||||
@Override |
||||
public int getInitialHitPoints() { |
||||
return INITIAL_HIT_POINTS; |
||||
} |
||||
|
||||
@Override |
||||
public int getHitPoints(){ |
||||
return this.hitPoints; |
||||
} |
||||
|
||||
@Override |
||||
public int getScore() { |
||||
return SCORE; |
||||
} |
||||
|
||||
@Override |
||||
public int getChanceOfSpawning() { |
||||
return CHANCE_OF_SPAWNING; |
||||
} |
||||
|
||||
@Override |
||||
public void update(){ |
||||
int newX = this.getX() + Math.round(this.speed * sin(radians(this.getRotation()))); |
||||
int newY = this.getY() + Math.round(this.speed * -cos(radians(this.getRotation()))); |
||||
|
||||
//bounce off boundaries: https://forum.processing.org/two/discussion/10649/maths-calculate-reflection-angle.html |
||||
if ((newX <= 0) || (newX >= level.getCols()-1)) { |
||||
//verticle wall |
||||
this.rotation = 360 - rotation; |
||||
while (this.rotation < 0) this.rotation += 360; |
||||
} |
||||
else if ((newY <= 0) || (newY >= level.getRows()-1)){ |
||||
//horizontal wall |
||||
this.rotation = 180 - rotation; |
||||
while (this.rotation < 0) this.rotation += 360; |
||||
} |
||||
else { |
||||
this.x = newX; |
||||
this.y = newY; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean hit() { |
||||
this.hitPoints--; |
||||
if (this.hitPoints <= 0) return true; |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public List<Enemy> spawnlings() { |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public class Asteroid2 extends Asteroid1 { |
||||
public static final int SCALE_FACTOR = 20; |
||||
public static final int ENEMIES_TO_SPAWN = 3; |
||||
public static final int MINIMUM_DIFFICULTY = 1; |
||||
public static final int SCORE = 50; |
||||
public static final int CHANCE_OF_SPAWNING = 5; |
||||
public static final int MAX_SPEED = 2; |
||||
|
||||
public Asteroid2(int x, int y, PImage sprite, Level level) { |
||||
super(x, y, sprite, level); |
||||
super.speed = random(0,MAX_SPEED+1); |
||||
} |
||||
|
||||
@Override |
||||
public int getScaleFactor() { |
||||
return SCALE_FACTOR; |
||||
} |
||||
|
||||
@Override |
||||
public int getMinimumDifficulty() { |
||||
return MINIMUM_DIFFICULTY; |
||||
} |
||||
|
||||
@Override |
||||
public int getScore() { |
||||
return SCORE; |
||||
} |
||||
|
||||
@Override |
||||
public int getChanceOfSpawning() { |
||||
return CHANCE_OF_SPAWNING; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hit() { |
||||
super.hitPoints--; |
||||
if (super.hitPoints <= 0) return true; |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public List<Enemy> spawnlings() { |
||||
List<Enemy> spawnlings = new ArrayList<Enemy>(); |
||||
for (int i = 0; i < ENEMIES_TO_SPAWN; i++) { |
||||
spawnlings.add(new Asteroid1(super.x, super.y, super.sprite, super.level)); |
||||
} |
||||
return spawnlings; |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public class Asteroid3 extends Asteroid1 { |
||||
public static final int SCALE_FACTOR = 40; |
||||
public static final int ENEMIES_TO_SPAWN = 3; |
||||
public static final int MINIMUM_DIFFICULTY = 2; |
||||
public static final int SCORE = 100; |
||||
public static final int CHANCE_OF_SPAWNING = 2; |
||||
public static final int MAX_SPEED = 1; |
||||
|
||||
public Asteroid3(int x, int y, PImage sprite, Level level) { |
||||
super(x, y, sprite, level); |
||||
super.speed = random(0,MAX_SPEED+1); |
||||
} |
||||
|
||||
@Override |
||||
public int getScaleFactor() { |
||||
return SCALE_FACTOR; |
||||
} |
||||
|
||||
@Override |
||||
public int getMinimumDifficulty() { |
||||
return MINIMUM_DIFFICULTY; |
||||
} |
||||
|
||||
@Override |
||||
public int getScore() { |
||||
return SCORE; |
||||
} |
||||
|
||||
@Override |
||||
public int getChanceOfSpawning() { |
||||
return CHANCE_OF_SPAWNING; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hit() { |
||||
super.hitPoints--; |
||||
if (super.hitPoints <= 0) return true; |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public List<Enemy> spawnlings() { |
||||
List<Enemy> spawnlings = new ArrayList<Enemy>(); |
||||
for (int i = 0; i < ENEMIES_TO_SPAWN; i++) { |
||||
spawnlings.add(new Asteroid2(super.x, super.y, super.sprite, super.level)); |
||||
} |
||||
return spawnlings; |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public class Bomb { |
||||
private final Configuration conf; |
||||
|
||||
public final int x; |
||||
public final int y; |
||||
|
||||
private int expansion; |
||||
private boolean out; |
||||
|
||||
public Bomb(int x, int y, Configuration conf) { |
||||
this.conf = conf; |
||||
this.x = x; |
||||
this.y = y; |
||||
this.expansion = 0; |
||||
this.out = true; |
||||
} |
||||
|
||||
public int getExpansion() { |
||||
return this.expansion; |
||||
} |
||||
|
||||
public float getDiameter() { |
||||
return map(this.expansion, 0, 100, 0, 1.5*conf.viewportWidth); |
||||
} |
||||
|
||||
public boolean update() { |
||||
if (out) { |
||||
expansion += conf.bombSpeed; |
||||
if (expansion == 100) out = false; |
||||
} |
||||
else { |
||||
expansion -= conf.bombSpeed; |
||||
if (expansion == 0) return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public interface Enemy { |
||||
public int getX(); |
||||
public int getY(); |
||||
public int getRotation(); |
||||
public PImage getSprite(); |
||||
public int getScaleFactor(); |
||||
public int getTintR(); |
||||
public int getTintG(); |
||||
public int getTintB(); |
||||
|
||||
public int getMinimumDifficulty(); |
||||
public int getScore(); |
||||
public int getInitialHitPoints(); |
||||
public int getHitPoints(); |
||||
public int getChanceOfSpawning(); |
||||
|
||||
public void update(); |
||||
public boolean hit(); |
||||
public List<Enemy> spawnlings(); |
||||
} |
@ -0,0 +1,78 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public class PlayerProjectile implements Projectile { |
||||
public final static int SPEED = 10; |
||||
public final static int DAMAGE = 1; |
||||
public final static int RANGE = 260; |
||||
|
||||
private final int rotation; |
||||
private PImage sprite; |
||||
|
||||
private int x; |
||||
private int y; |
||||
|
||||
private int distanceTravelled; |
||||
|
||||
public PlayerProjectile(int initialX, int initialY, int initialRotation, PImage sprite) { |
||||
this.x = initialX; |
||||
this.y = initialY; |
||||
this.rotation = initialRotation; |
||||
this.sprite = sprite; |
||||
this.distanceTravelled = 0; |
||||
} |
||||
|
||||
@Override |
||||
public int getX() { |
||||
return this.x; |
||||
} |
||||
|
||||
@Override |
||||
public int getY() { |
||||
return this.y; |
||||
} |
||||
|
||||
@Override |
||||
public int getRotation() { |
||||
return this.rotation; |
||||
} |
||||
|
||||
@Override |
||||
public PImage getSprite() { |
||||
return this.sprite; |
||||
} |
||||
|
||||
@Override |
||||
public int getSpeed() { |
||||
return SPEED; |
||||
} |
||||
|
||||
@Override |
||||
public int getDamage() { |
||||
return DAMAGE; |
||||
} |
||||
|
||||
@Override |
||||
public int getRange() { |
||||
return RANGE; |
||||
} |
||||
|
||||
/* |
||||
* Update projectile position |
||||
* @return true if projectile should be destroyed |
||||
*/ |
||||
@Override |
||||
public boolean update() { |
||||
distanceTravelled++; |
||||
|
||||
this.x = this.getX() + Math.round(SPEED * sin(radians(this.getRotation()))); |
||||
this.y = this.getY() + Math.round(SPEED * -cos(radians(this.getRotation()))); |
||||
|
||||
if (distanceTravelled >= RANGE) return true; |
||||
|
||||
return Boolean.parseBoolean(level.getTile(this.x, this.y).getProperty("solid")); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public interface Projectile { |
||||
public int getX(); |
||||
public int getY(); |
||||
public int getRotation(); |
||||
public int getSpeed(); |
||||
public int getDamage(); |
||||
public int getRange(); |
||||
public PImage getSprite(); |
||||
|
||||
public boolean update(); |
||||
} |
After Width: | Height: | Size: 251 B |
After Width: | Height: | Size: 120 B |
After Width: | Height: | Size: 362 B |
Loading…
Reference in new issue