Skip to content

Commit

Permalink
Add lives
Browse files Browse the repository at this point in the history
  • Loading branch information
diguifi committed Oct 4, 2018
1 parent d1251bd commit 1e6e62f
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 61 deletions.
9 changes: 8 additions & 1 deletion Dude-SideScroller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<Content Include="assets\buttons\button-round.png" />
<Content Include="assets\buttons\button-vertical.png" />
<Content Include="assets\images\back.png" />
<Content Include="assets\images\heart.png" />
<Content Include="assets\images\hud.png" />
<Content Include="assets\images\logo.png" />
<Content Include="assets\levels\jungle\jungle_tileset.png" />
<Content Include="assets\levels\jungle\plx-1.png" />
Expand All @@ -84,6 +86,12 @@
<Content Include="assets\levels\jungle\plx-4.png" />
<Content Include="assets\levels\jungle\plx-5.png" />
<Content Include="assets\sprites\dude_spritesheet.png" />
<Content Include="assets\sprites\enemy.png" />
<Content Include="assets\sprites\itens\heart.png" />
<Content Include="assets\sprites\itens\spr_coin_ama.png" />
<Content Include="assets\sprites\itens\spr_coin_azu.png" />
<Content Include="assets\sprites\itens\spr_coin_cin.png" />
<Content Include="assets\sprites\itens\spr_coin_ver.png" />
<Content Include="build\phaser.map" />
<Content Include="assets\levels\jungle1.json" />
<None Include="Web.Debug.config">
Expand All @@ -102,7 +110,6 @@
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
<TypeScriptCompile Include="scripts\app.ts" />
<TypeScriptCompile Include="engine\phaser.d.ts" />
<TypeScriptCompile Include="scripts\ControllerManager.ts" />
<TypeScriptCompile Include="scripts\Enemy.ts" />
Expand Down
Binary file added assets/images/heart.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 assets/sprites/itens/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 24 additions & 23 deletions game.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion game.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<body>

<center><h1>Collect all the gems!</h1></center>
<center><h1></h1></center>

<div id="content"></div>

Expand Down
29 changes: 24 additions & 5 deletions scripts/Hud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,44 @@

export class Hud extends Phaser.Sprite {
player: Player;
lives: number;
hearts: Phaser.Sprite[] = [];

constructor(game: Phaser.Game, player: Player) {
super(game, 0, 0, 'hud', 0);
super(game, 0, 0, 'hud', 0);

this.fixedToCamera = true;

this.player = player;

this.lives = player.lives;

this.fillLives();

game.add.existing(this);
}

update() {
if (this.lives != this.player.lives) {
this.lives = this.player.lives;

this.fillLives();
}
}

render() {
this.game.debug.text("This is debug text", 200, 200);
this.game.debug.geom(new Phaser.Rectangle(100, 100, 100, 100), 'rgba(255,0,0,1)');
console.log("is it working?");
fillLives() {
this.hearts.forEach(function (heart) {
heart.destroy();
});

this.hearts = [];

for (var i = 0; i < this.lives; i++)
this.hearts.push(this.game.add.sprite(35 * i + 30, 23, 'heart2'));

this.hearts.forEach(function (heart) {
heart.fixedToCamera = true;
});
}
}
}
2 changes: 2 additions & 0 deletions scripts/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
super(game, x, y, 'dude', 0);

this.gems = 0;
this.lives = 3;

// attributes
this.playingOnDesktop = this.game.device.desktop;
Expand Down Expand Up @@ -37,6 +38,7 @@

animSpeeds;
controller;
lives: number;
gems: number;
size: number;
speed: number;
Expand Down
2 changes: 2 additions & 0 deletions scripts/Preloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
this.game.load.image('enemy1', 'assets/sprites/enemy.png?v=1');

this.game.load.spritesheet('greygem', 'assets/sprites/itens/spr_coin_cin.png?v=1', 16, 16, 4);
this.game.load.image('heart', 'assets/sprites/itens/heart.png');

this.game.load.image('titlepage', 'assets/images/back.png');
this.game.load.image('logo', 'assets/images/logo.png');

this.game.load.image('hud', 'assets/images/hud.png');
this.game.load.image('heart2', 'assets/images/heart.png');

this.game.load.image('jungle_paralax5', 'assets/levels/jungle/plx-5.png');
this.game.load.image('jungle_paralax4', 'assets/levels/jungle/plx-4.png');
Expand Down
30 changes: 0 additions & 30 deletions scripts/app.ts

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/levels/Level1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
}

update() {
if (this.player.lives < 0)
this.game.state.start('MainMenu');

this.game.physics.arcade.collide(this.player, this.walls);
this.game.physics.arcade.collide(this.enemies, this.walls);
this.game.physics.arcade.collide(this.gems, this.walls);
Expand Down Expand Up @@ -121,10 +124,12 @@
enemy.kill();
}
else {
player.lives--;
player.position.x = 6;
}

} else {
player.lives--;
player.position.x = 6;
}
}
Expand Down

0 comments on commit 1e6e62f

Please sign in to comment.