-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f30484
commit 3603718
Showing
8 changed files
with
151 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Engine } from "excalibur"; | ||
import Projectile, { ProjectileParams } from "./projectile"; | ||
import { projectile01Sprite } from "./resources"; | ||
|
||
abstract class PBullet extends Projectile { | ||
speed: number = 400; | ||
|
||
constructor(params: ProjectileParams) { | ||
super({ | ||
width: 16, | ||
height: 16, | ||
...params, | ||
}); | ||
} | ||
|
||
public destroy(offScreen: boolean = false) { | ||
if (!offScreen) { | ||
// Create particle effect | ||
} | ||
this.kill(); | ||
} | ||
|
||
public update(engine: Engine, delta: number): void { | ||
super.update(engine, delta); | ||
} | ||
|
||
public onInitialize(engine: Engine) { | ||
super.onInitialize(engine); | ||
this.graphics.use(projectile01Sprite); | ||
} | ||
} | ||
|
||
export default PBullet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Actor, ActorArgs, CollisionType, Engine, vec } from "excalibur"; | ||
|
||
export interface ProjectileParams extends ActorArgs { | ||
/** | ||
* The angle in radians to fire the projectile | ||
*/ | ||
directionAngle: number; | ||
} | ||
|
||
abstract class Projectile extends Actor { | ||
abstract speed: number; | ||
private directionAngle: number; | ||
|
||
constructor({ directionAngle, ...rest }: ProjectileParams) { | ||
super({ | ||
pos: vec(0, 0), | ||
...rest, | ||
}); | ||
this.directionAngle = directionAngle; | ||
} | ||
|
||
abstract destroy(offScreen: boolean): void; | ||
|
||
public update(engine: Engine, delta: number): void { | ||
super.update(engine, delta); | ||
if (this.isOffScreen) { | ||
this.destroy(true); | ||
} | ||
} | ||
|
||
public onInitialize(engine: Engine) { | ||
super.onInitialize(engine); | ||
this.body.collisionType = CollisionType.Passive; | ||
this.vel = vec( | ||
this.speed * Math.cos(this.directionAngle), | ||
this.speed * Math.sin(this.directionAngle), | ||
); | ||
this.rotation = this.directionAngle; | ||
} | ||
} | ||
|
||
export default Projectile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ImageSource } from "excalibur"; | ||
import bulletSprite from "../../assets/images/weapons/bullet_01.png"; | ||
|
||
export const ProjectileResources = { | ||
Projectile01Sprite: new ImageSource(bulletSprite), | ||
} as const; | ||
|
||
export const projectile01Sprite = | ||
ProjectileResources.Projectile01Sprite.toSprite(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters