Skip to content

Commit

Permalink
made pipe set
Browse files Browse the repository at this point in the history
  • Loading branch information
dolanmiu committed Dec 19, 2016
1 parent 869b1e2 commit f0e2401
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
39 changes: 37 additions & 2 deletions dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@ var Flappy;
Flappy.DownPipe = DownPipe;
})(Flappy || (Flappy = {}));
var Flappy;
(function (Flappy) {
class PipeSet extends Phaser.Group {
constructor(game, x, y, gapSize, pipeBodyKey, pipeDownCapKey, pipeUpCapKey) {
super(game);
let upPipe = new Flappy.UpPipe(game, x, y + gapSize, pipeBodyKey, pipeUpCapKey);
let downPipe = new Flappy.DownPipe(game, x, y, pipeBodyKey, pipeDownCapKey);
this.add(upPipe);
this.add(downPipe);
//this.game.add.existing(this);
}
update() {
this.x -= 1;
}
}
Flappy.PipeSet = PipeSet;
})(Flappy || (Flappy = {}));
var Flappy;
(function (Flappy) {
class UpPipe extends Phaser.Group {
constructor(game, x, y, pipeBodyKey, pipeCapKey) {
super(game);
let pipeBody = new Phaser.TileSprite(game, x, y, 52, window.innerHeight, pipeBodyKey);
let pipeCap = new Phaser.Sprite(game, x, y, pipeCapKey);
pipeCap.anchor.y = 1;
this.add(pipeBody);
this.add(pipeCap);
this.game.add.existing(this);
}
}
Flappy.UpPipe = UpPipe;
})(Flappy || (Flappy = {}));
var Flappy;
(function (Flappy) {
class Sky extends Phaser.TileSprite {
constructor(game, x, y, width, height, key) {
Expand All @@ -84,26 +116,29 @@ var Flappy;
(function (Flappy) {
var State;
(function (State) {
const pipeGapSize = 100;
class Play extends Phaser.State {
preload() {
this.game.load.spritesheet('bird', 'assets/bird.png', 34, 24);
this.game.load.image('sky', 'assets/sky.png');
this.game.load.image('floor', 'assets/land.png');
this.game.load.image('pipeBody', 'assets/pipe.png');
this.game.load.image('pipeCap', 'assets/pipe-down.png');
this.game.load.image('pipeDownCap', 'assets/pipe-down.png');
this.game.load.image('pipeUpCap', 'assets/pipe-up.png');
}
create() {
this.game.physics.startSystem(Phaser.Physics.ARCADE);
this.game.physics.arcade.gravity.y = 100;
this.sky = new Flappy.Sky(this.game, 0, window.innerHeight - 112, window.innerWidth, 109, 'sky');
this.floor = new Flappy.Floor(this.game, 0, window.innerHeight, window.innerWidth, 112, 'floor');
this.bird = new Flappy.Bird(this.game, 100, 100, 'bird');
let d = new Flappy.DownPipe(this.game, 100, 700, 'pipeBody', 'pipeCap');
this.pipeTest = new Flappy.PipeSet(this.game, 700, 700, pipeGapSize, 'pipeBody', 'pipeDownCap', 'pipeUpCap');
this.game.physics.enable([this.bird], Phaser.Physics.ARCADE);
this.game.camera.follow(this.bird);
}
update() {
this.sky.update();
this.pipeTest.update();
}
}
State.Play = Play;
Expand Down
31 changes: 31 additions & 0 deletions src/pipe/pipe-pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Flappy {
/*export class PipePool<T> extends Phaser.Group {
constructor(game: Phaser.Game, spriteType: T, instances: number, name: string) {
super(game, game.world, name);
this.game = game;
this.spriteType = spriteType; // Needed when creating new objects in the pool
if (instances > 0) { // We don't need to add anything to the group
let sprite;
for (var i = 0; i < maxInstances; i++) {
sprite = this.add(new spriteType(game)); // Add new sprite
}
}
return this;
}
public create(x: number, y: number, data) {
// Find the first child that has a false exist property:
let obj = this.getFirstExists(false);
if (!obj) {
// We failed to find an availble child, so we create one now and add it to the pool.
obj = new this.spriteType(this.game);
this.add(obj, true);
}
// We call the childs spawn method and return the object to whatever triggered this.
// The spawn method will handle stuff like position, resetting the health property
// and setting exists to true. The spawned object will live even if the returned
// reference is ignored
return obj.spawn(x, y, data);
}
}*/
}
18 changes: 18 additions & 0 deletions src/pipe/pipe-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Flappy {
export class PipeSet extends Phaser.Group {

constructor(game: Phaser.Game, x: number, y: number, gapSize: number, pipeBodyKey: string, pipeDownCapKey: string, pipeUpCapKey: string) {
super(game);
let upPipe = new UpPipe(game, x, y + gapSize, pipeBodyKey, pipeUpCapKey);
let downPipe = new DownPipe(game, x, y, pipeBodyKey, pipeDownCapKey);

this.add(upPipe);
this.add(downPipe);
//this.game.add.existing(this);
}

public update(): void {
this.x -= 1;
}
}
}
9 changes: 7 additions & 2 deletions src/states/play.state.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
namespace Flappy.State {
const pipeGapSize = 100;

export class Play extends Phaser.State {

private bird: Bird;
private sky: Sky;
private floor: Floor;
private pipeTest: PipeSet;

public preload(): void {
this.game.load.spritesheet('bird', 'assets/bird.png', 34, 24);
this.game.load.image('sky', 'assets/sky.png');
this.game.load.image('floor', 'assets/land.png');
this.game.load.image('pipeBody', 'assets/pipe.png');
this.game.load.image('pipeCap', 'assets/pipe-down.png');
this.game.load.image('pipeDownCap', 'assets/pipe-down.png');
this.game.load.image('pipeUpCap', 'assets/pipe-up.png');
}

public create(): void {
Expand All @@ -20,14 +24,15 @@ namespace Flappy.State {
this.sky = new Sky(this.game, 0, window.innerHeight - 112, window.innerWidth, 109, 'sky');
this.floor = new Floor(this.game, 0, window.innerHeight, window.innerWidth, 112, 'floor');
this.bird = new Bird(this.game, 100, 100, 'bird');
let d = new DownPipe(this.game, 100, 700, 'pipeBody', 'pipeCap');
this.pipeTest = new PipeSet(this.game, 700, 700, pipeGapSize, 'pipeBody', 'pipeDownCap', 'pipeUpCap');
this.game.physics.enable([this.bird], Phaser.Physics.ARCADE);
this.game.camera.follow(this.bird);

}

public update(): void {
this.sky.update();
this.pipeTest.update();
}
}
}
3 changes: 3 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
],
"no-namespace": [
false
],
"max-line-length": [
false
]
}
}

0 comments on commit f0e2401

Please sign in to comment.