Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new enemy and changes to some scripts #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added media/images/blueenemy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/images/blueenemybeam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/data/wavesData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,24 @@
-
h: 15
e: 8
r: 1
-
g: 15
e: 8
a: 6
h: 4
r: 2
-
g: 20
e: 10
a: 4
h: 6
r: 3
-
g: 25
e: 10
a: 8
r: 4
-
g: 25
e: 10
Expand Down
25 changes: 24 additions & 1 deletion src/plugins/shooting.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class Shooting {

this.playerBullets = this.game.add.group();
this.enforcerBullets = this.game.add.group();
this.rangerBullets = this.game.add.group();
this.spears = this.game.add.group();
for (let x = 0; x < NUM_BULLETS; x++) {
let bullet = new Bullet(this.game, 0, 0);
Expand All @@ -27,17 +28,23 @@ export default class Shooting {
enforcerBullet.alive = enforcerBullet.exists = enforcerBullet.visible = false;
this.enforcerBullets.add(enforcerBullet);

let spear = new Spear(this.game, 0, 0);
let rangerBullet = new rangerBullet(this.game, 0, 0);
rangerBullet.alive = rangerBullet.exists = rangerBullet.visible = false;
this.rangerBullets.add(rangerBullet);

let spear = new Spear(this.game, 0, 0);
spear.alive = spear.exists = spear.visible = false;
this.spears.add(spear);
}

this.game.waves.onTransition.add(() => {
this.playerBullets.callAll('kill');
this.enforcerBullets.callAll('kill');
this.rangerBullets.callAll('kill');
this.spears.callAll('kill');
// Set tint on bullets and spears.
this.enforcerBullets.setAll('tint', this.game.tinting.currentTint);
this.rangerBullets.setAll('tint', this.game.tinting.currentTint);
this.spears.setAll('tint', this.game.tinting.currentTint);
});
}
Expand All @@ -63,6 +70,15 @@ export default class Shooting {
}
}

rangerShoot(sx, sy, vx, vy) {
let bullet = this.rangerBullets.getFirstExists(false);
if (bullet) {
bullet.reset(sx, sy);
bullet.fire(vx, vy);
//this.enforcerShootSound.play();
}
}

spearWarn() {
this.spearWarnSound.play();
}
Expand All @@ -87,6 +103,13 @@ export default class Shooting {
this.game.physics.arcade.overlap(player, this.spears, this.onEnforcerBullet, null, this);
}
}

let player = this.game.player;
if (player) {
this.game.physics.arcade.overlap(player, this.rangerBullets, this.onRangerBullet, null, this);
this.game.physics.arcade.overlap(player, this.spears, this.onRangerBullet, null, this);
}
}

onProcess(enemy) {
return enemy && enemy.alive;
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/waves.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ export default class Waves {
this.loaded = true;
});
}

for (let i = 0; i < wave.r; i++) {
let ranger = new Ranger(this.game, this.game.world.randomX, this.game.world.randomY);
this.enemiesGroup.add(ranger);
this.game.spawn.startSpawn(ranger, () => {
this.loading = false;
this.loaded = true;
});
}

for (let i = 0; i < wave.a; i++) {
let assassin = new Assassin(this.game, this.game.world.randomX, this.game.world.randomY);
this.enemiesGroup.add(assassin);
Expand Down
24 changes: 24 additions & 0 deletions src/sprites/ranger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Enemy from './enemy';
import OrbitPlayer from '../behaviors/orbitPlayer';
import ShootPlayer from '../behaviors/shootPlayer';

export default class Ranger extends Enemy {
constructor(game, x, y) {
super(game, x, y, 'blueenemy', 0);

this.addBehavior(new OrbitPlayer());
this.addBehavor(new ShootPlayer());

this.anchor.set(0.5);
this.body.width = 20;
this.body.height = 30;
this.body.bounce.set(0.6);

this.health = 40;
this.score = 600;




}
}
32 changes: 32 additions & 0 deletions src/sprites/rangerBullet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const BULLET_LIFETIME_MS = 2000;
const BULLET_MAIN_VELOCITY = 500;

export default class RangerBullet extends Phaser.Sprite {
constructor(game, x, y){
super(game, x, y, 'blueenemybeam', 0);
game.physics.arcade.enable(this);

this.anchor.setTo(0.5);
this.body.width = 4;
this.body.height = 4;
this.tint = game.tinting.currentTint;

}

update(){
this.rotation += 0.1 * this.game.time.physicsElapsedMS;
}
fire(velX, velY){
this.killEvent = this.game.time.events.add(BULLET_LIFETIME_MS, () =>{
this.kill();
});
this.body.velocity.x = BULLET_MAIN_VELOCITY * velX;
this.body.velocity.y = BULLET_MAIN_VELOCITY * velY;
}

kill() {
super.kill();
this.game.time.events.remove(this.killEvent);
}

}
4 changes: 3 additions & 1 deletion src/states/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export default class Preload extends Phaser.State {
this.game.load.image('button', require('../../media/images/button.png'), 240, 80);
this.game.load.image('phaserLogo', require('../../media/images/Phaser-Logo-Small.png'), 382, 331);
this.game.load.image('drhayesLogo', require('../../media/images/drhayes.png'), 552, 586);

this.game.load.image('blueenemy', require('../../media/images/blueenemy.png'), 32,32);
this.game.load.image('blueenemybeam', require('../../media/images/blueenemybeam.png'), 32,32);

this.game.load.audio('shoot', require('../../media/sounds/shoot.mp3'));
this.game.load.audio('smallBoom', require('../../media/sounds/smallBoom.mp3'));
this.game.load.audio('mediumBoom', require('../../media/sounds/mediumBoom.mp3'));
Expand Down