parent
d180df45e8
commit
d96ce52696
13 changed files with 112 additions and 341 deletions
@ -1,92 +0,0 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public class GunPlatformProjectile implements Projectile { |
||||
public final static int SPEED = 3; |
||||
public final static int DAMAGE = 1; |
||||
public final static int RANGE = 300; |
||||
|
||||
private final int rotation; |
||||
private PImage sprite; |
||||
|
||||
private int x; |
||||
private int y; |
||||
|
||||
private int distanceTravelled; |
||||
|
||||
public GunPlatformProjectile(int initialX, int initialY, int initialRotation, PImage sprite) { |
||||
this.x = initialX; |
||||
this.y = initialY; |
||||
this.rotation = initialRotation; |
||||
this.sprite = sprite; |
||||
this.distanceTravelled = 0; |
||||
} |
||||
|
||||
//copy constructor |
||||
public GunPlatformProjectile(GunPlatformProjectile projectile) { |
||||
this.x = projectile.getX(); |
||||
this.y = projectile.getY(); |
||||
this.rotation = projectile.getRotation(); |
||||
this.sprite = projectile.getSprite(); |
||||
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")); |
||||
} |
||||
|
||||
@Override |
||||
public Projectile clone() { |
||||
return new GunPlatformProjectile(this); |
||||
} |
||||
} |
@ -1,92 +0,0 @@ |
||||
/** |
||||
* 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; |
||||
} |
||||
|
||||
//copy constructor |
||||
public PlayerProjectile(PlayerProjectile projectile) { |
||||
this.x = projectile.getX(); |
||||
this.y = projectile.getY(); |
||||
this.rotation = projectile.getRotation(); |
||||
this.sprite = projectile.getSprite(); |
||||
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")); |
||||
} |
||||
|
||||
@Override |
||||
public Projectile clone() { |
||||
return new PlayerProjectile(this); |
||||
} |
||||
} |
@ -1,92 +0,0 @@ |
||||
/** |
||||
* Copyright 2022 Jamie Munro, All rights reserved |
||||
* CS5041 P1 |
||||
* Game 1 |
||||
*/ |
||||
|
||||
public class SaucerProjectile implements Projectile { |
||||
public final static int SPEED = 3; |
||||
public final static int DAMAGE = 1; |
||||
public final static int RANGE = 200; |
||||
|
||||
private final int rotation; |
||||
private PImage sprite; |
||||
|
||||
private int x; |
||||
private int y; |
||||
|
||||
private int distanceTravelled; |
||||
|
||||
public SaucerProjectile(int initialX, int initialY, int initialRotation, PImage sprite) { |
||||
this.x = initialX; |
||||
this.y = initialY; |
||||
this.rotation = initialRotation; |
||||
this.sprite = sprite; |
||||
this.distanceTravelled = 0; |
||||
} |
||||
|
||||
//copy constructor |
||||
public SaucerProjectile(SaucerProjectile projectile) { |
||||
this.x = projectile.getX(); |
||||
this.y = projectile.getY(); |
||||
this.rotation = projectile.getRotation(); |
||||
this.sprite = projectile.getSprite(); |
||||
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")); |
||||
} |
||||
|
||||
@Override |
||||
public Projectile clone() { |
||||
return new SaucerProjectile(this); |
||||
} |
||||
} |
After Width: | Height: | Size: 207 B |
After Width: | Height: | Size: 219 B |
Loading…
Reference in new issue