Skip to content

Commit

Permalink
Add level1 initial structure
Browse files Browse the repository at this point in the history
  • Loading branch information
diguifi committed Aug 18, 2018
1 parent 3910007 commit 8f0a383
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Dude-SideScroller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<TypeScriptSourceRoot />
</PropertyGroup>
<ItemGroup>
<Content Include="assets\levels\level1.png" />
<Content Include="assets\sprites\dudeD0.png" />
<Content Include="build\phaser.map" />
<None Include="Web.Debug.config">
Expand All @@ -77,6 +78,7 @@
<TypeScriptCompile Include="scripts\app.ts" />
<TypeScriptCompile Include="engine\phaser.d.ts" />
<TypeScriptCompile Include="scripts\Game.ts" />
<TypeScriptCompile Include="scripts\levels\Level1.ts" />
<TypeScriptCompile Include="scripts\Player.ts" />
</ItemGroup>
<ItemGroup>
Expand Down
Binary file added assets/levels/level1.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 modified assets/sprites/dudeD0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<title>Dude Game</title>
<link rel="stylesheet" href="style/app.css" type="text/css" />
<script src="engine/phaser.js"></script>
<script src="scripts/levels/Level1.js"></script>
<script src="scripts/Player.js"></script>
<script src="scripts/Game.js"></script>

</head>

<body>

<h1>Whoa! Gravity already?</h1>
<center><h1>Preety background, isn't it?</h1></center>

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

Expand Down
8 changes: 5 additions & 3 deletions scripts/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 scripts/Game.js.map

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

10 changes: 6 additions & 4 deletions scripts/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

constructor() {
this.game = new Phaser.Game(
800, 600,
800, 400,
Phaser.AUTO,
'content',
{
Expand All @@ -15,13 +15,15 @@
true,
Phaser.Physics.Arcade
);

this.game.state.add('Level1', Level1, false);
}

game: Phaser.Game;
player: Diguifi.Player;

preload() {
this.game.load.image('dude', 'assets/sprites/dudeD0.png');
this.game.load.image('dude', 'assets/sprites/dudeD0.png?v=1');
this.game.load.image('level1', 'assets/levels/level1.png?v=1');
}

create() {
Expand All @@ -36,7 +38,7 @@
this.game.physics.arcade.gravity.y = 200;
this.game.stage.backgroundColor = "#a9f0ff";

this.player = new Diguifi.Player(this.game, 130, 284);
this.game.state.start('Level1');
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions scripts/Player.js

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

2 changes: 1 addition & 1 deletion scripts/Player.js.map

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

23 changes: 13 additions & 10 deletions scripts/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

export class Player extends Phaser.Sprite {

constructor(game: Phaser.Game, x: number, y: number) {
constructor(game: Phaser.Game, x: number, y: number, speed, gravity) {
super(game, x, y, 'dude');

this.scale.setTo(2, 2);
this.size = 0.2;
this.scale.setTo(this.size, this.size);

this.game.physics.arcade.enableBody(this);
this.body.collideWorldBounds = true;
this.body.gravity.y = gravity;
this.body.bounce.y = 0.2;

this.anchor.setTo(0.5, 0);

this.speed = 100;
this.jumpStrength = 150;
this.speed = speed;
this.jumpStrength = gravity + (gravity * 0.33);

game.add.existing(this);
}

size: number;
speed: number;
jumpStrength: number;
movingRight: boolean;
Expand All @@ -43,17 +46,17 @@
this.body.velocity.x = this.speed;
this.movingRight = true;

if (this.scale.x == -2) {
this.scale.x = 2;
if (this.scale.x == -this.size) {
this.scale.x = this.size;
}
}

moveLeft() {
this.body.velocity.x = -this.speed;
this.movingRight = false;

if (this.scale.x == 2) {
this.scale.x = -2;
if (this.scale.x == this.size) {
this.scale.x = -this.size;
}
}

Expand All @@ -63,10 +66,10 @@
this.jumping = true;

if (this.movingRight) {
this.scale.x = 2;
this.scale.x = this.size;
}
else {
this.scale.x = -2;
this.scale.x = -this.size;
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions scripts/levels/Level1.js

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

1 change: 1 addition & 0 deletions scripts/levels/Level1.js.map

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

19 changes: 19 additions & 0 deletions scripts/levels/Level1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Diguifi {

export class Level1 extends Phaser.State {

background: Phaser.Sprite;
music: Phaser.Sound;
player: Diguifi.Player;

create() {

this.background = this.add.sprite(0, 0, 'level1');

this.player = new Diguifi.Player(this.game, 130, 284, 150, 200);

}

}

}

0 comments on commit 8f0a383

Please sign in to comment.