Skip to content

Commit 833a80e

Browse files
committed
update
1 parent 8a46a86 commit 833a80e

File tree

17 files changed

+777
-453
lines changed

17 files changed

+777
-453
lines changed

assets/json/forest03.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,4 @@
462462
"type":"map",
463463
"version":"1.10",
464464
"width":100
465-
}
465+
}

assets/json/forest04.json

Lines changed: 217 additions & 229 deletions
Large diffs are not rendered by default.

index.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@
8080
</div>
8181
</section>
8282
<!--CURTAIN-->
83-
<section id="playSceneCurtain">
84-
<div id= "message">
85-
-- <p id = "transitionToPlayMessage">Curtains Rolling...</p>
86-
</div>
87-
</section>
83+
<section id="playSceneCurtain"> </section>
8884
<!--PAUSE SCREEN-->
8985
<section id="pauseScreen">
9086
<button id="pause_resumeBtn">RESUME</button>

src/anims/playerAnims.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,30 @@
1010
frameRate: 4,
1111
repeat: -1
1212
});
13+
scene.anims.create({
14+
key: "player-climb",
15+
frames: scene.anims.generateFrameNumbers(
16+
"player-climb",
17+
{start: 0, end: 6},
18+
),
19+
frameRate: 25,
20+
repeat: 0
21+
});
22+
1323
scene.anims.create({
1424
key: "player-idle",
1525
frames: scene.anims.generateFrameNumbers(
1626
"player",
17-
{start: 0, end: 3},
27+
{start: 0, end: 9},
1828
),
19-
frameRate: 4,
29+
frameRate: 12,
2030
repeat: -1
2131
});
2232
scene.anims.create({
2333
key: "player-run",
2434
frames: scene.anims.generateFrameNumbers(
2535
"player-run",
26-
{start: 0, end: 7},
36+
{start: 0, end: 9},
2737
),
2838
frameRate: 12,
2939
repeat: -1
@@ -42,19 +52,55 @@
4252
key: "player-jump",
4353
frames: scene.anims.generateFrameNumbers(
4454
"player-jump",
45-
{start: 0, end: 3},
55+
{start: 0, end: 2},
4656
),
47-
frameRate: 3,
57+
frameRate: 2,
4858
repeat: -1
4959
});
5060
scene.anims.create({
5161
key: "player-fall",
5262
frames: scene.anims.generateFrameNumbers(
53-
"player-run",
54-
{start: 0, end: 3},
63+
"player-fall",
64+
{start: 0, end: 2},
5565
),
56-
frameRate: 3,
66+
frameRate: 2,
5767
repeat: -1
5868
});
69+
scene.anims.create({
70+
key: "player-crouch",
71+
frames: scene.anims.generateFrameNumbers(
72+
"player-crouch",
73+
{start: 2, end: 2},
74+
),
75+
frameRate: 5,
76+
repeat: 0
77+
});
78+
scene.anims.create({
79+
key: "player-crouch-walk",
80+
frames: scene.anims.generateFrameNumbers(
81+
"player-crouch-walk",
82+
{start: 0, end: 7},
83+
),
84+
frameRate: 5,
85+
repeat: 0
86+
});
87+
scene.anims.create({
88+
key: "player-roll",
89+
frames: scene.anims.generateFrameNumbers(
90+
"player-roll",
91+
{start: 0, end: 11},
92+
),
93+
frameRate: 25,
94+
repeat: 0
95+
});
96+
scene.anims.create({
97+
key: "player-slide",
98+
frames: scene.anims.generateFrameNumbers(
99+
"player-slide",
100+
{start: 0, end: 3},
101+
),
102+
frameRate: 8,
103+
repeat: 0
104+
});
59105
}
60106

src/audio/AudioControl.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class AudioControl{
1111

1212
this.winSong = new Audio("assets/sounds/win.wav");
1313

14-
this.buttonClickSound = new Audio("assets/sounds/button_hover_sound.wav");
15-
this.buttonHoverSound = new Audio("assets/sounds/button_sound.wav");
14+
this.buttonClickSound = new Audio("assets/sounds/button_sound.wav");
15+
this.buttonHoverSound = new Audio("assets/sounds/button_hover_sound.wav");
1616

1717
this.punchSound = new Audio("assets/sounds/punch.wav");
1818
this.punchImpactSound = new Audio("assets/sounds/punch_impact.wav");
@@ -23,7 +23,10 @@ class AudioControl{
2323
this.playerHitSound = new Audio("assets/sounds/player_hit.mp3");
2424
this.walkSound = new Audio("assets/sounds/walk.wav");
2525
this.doorOpenSound = new Audio("assets/sounds/door_open.ogg");
26+
this.errorSound = new Audio("assets/sounds/error_sound.wav");
27+
this.saveSound = new Audio("assets/sounds/save_sound.wav");
2628

29+
2730
this.playStateSongs = [this.forestSong, this.ruinsSong, this.cryptSong, this.cemeterySong];
2831
//ARRAY OF ALL SONGS
2932
this.songs = [this.menuSong, ...this.playStateSongs, this.winSong];

src/entities/Boss1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class Boss1 extends Phaser.Physics.Arcade.Sprite{
1313
this
1414
.setOrigin(0)
1515

16-
.setDepth(scene.player.depth || 200)
16+
.setDepth(200)
1717
.setGravityY(980)
1818
.setCollideWorldBounds(true)
1919
.setImmovable(true)

src/entities/Player.js

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,19 @@ import { Projectiles } from "../groups/Projectiles.js";
33
import { PlayerHealthbar } from "../hud/Healthbar.js";
44
import { ImageEffect } from "../effects/HitEffect.js";
55
import { audio } from "../audio/AudioControl.js";
6-
import { PlayerWalk, PlayerStateMachine } from "../states/PlayerStates.js";
6+
import { PlayerWalk, PlayerCrouch, PlayerCrouchWalk, PlayerStateMachine } from "../states/PlayerStates.js";
7+
import { drawStatus } from "../hud/Status.js";
78

89

910
export class Player extends Phaser.Physics.Arcade.Sprite{
10-
//state design
11-
static Status = {
12-
Walking: 1,
13-
Climbing: 2,
14-
Jumping: 3,
15-
Falling: 4
16-
}
1711
constructor(scene, x, y, texture){
1812
super(scene, x, y, texture);
1913

2014
this.scene = scene;
2115
scene.add.existing(this);
2216
scene.physics.add.existing(this);
2317
this.init();
24-
this.status = Player.Status.Walking;
18+
this.status;
2519

2620
}
2721

@@ -52,24 +46,38 @@ export class Player extends Phaser.Physics.Arcade.Sprite{
5246

5347
this
5448
.setOrigin(0.5, 1)
55-
.setSize(15, 40)
56-
.setOffset(this.width*0.4, this.height*0.4)
57-
.setScale(0.5)
49+
.setSize(15, 35)
50+
.setOffset(this.width*0.4, this.height*0.55)
51+
.setScale(0.8)
5852
.setDepth(100)
5953
.setGravityY(982)
6054
.setCollideWorldBounds(true);
6155

6256
this.healthbar = new PlayerHealthbar(this.scene, this);
6357
}
6458

59+
updateBoundingBox(){
60+
61+
if(this.currentState.name === "PlayerCrouch" || this.currentState.name == "PlayerCrouchWalk" ){
62+
this.setSize(15, 22)
63+
if(this.flipX) this.setOffset(this.width*0.48, this.height*0.72)
64+
else this.setOffset(this.width*0.4, this.height*0.72);
65+
}
66+
else if(this.currentState.name === "PlayerSlide" ){
67+
this.setSize(15, 15)
68+
if(this.flipX) this.setOffset(this.width*0.48, this.height*0.72)
69+
else this.setOffset(this.width*0.4, this.height*0.82);
70+
}
71+
else{
72+
this.setSize(15, 35)
73+
if(this.flipX) this.setOffset(this.width*0.48, this.height*0.55)
74+
else this.setOffset(this.width*0.4, this.height*0.55);
75+
}
76+
}
6577
addCollider(otherGameObject, callback){
6678
this.scene.physics.add.collider(this, otherGameObject, callback, null, this);
6779
}
6880

69-
setStatus(newStatus){
70-
this.status = newStatus;
71-
}
72-
7381
addCollider(otherGameObject, callback){
7482
this.scene.physics.add.collider(this, otherGameObject, callback, null, this);
7583
}
@@ -83,6 +91,7 @@ export class Player extends Phaser.Physics.Arcade.Sprite{
8391
this.decreaseHealth(enemy);
8492
this.playDamageTween(enemy);
8593
audio.play(audio.playerHitSound);
94+
8695
this.lastDirection === "left" ? this.setVelocityX(this.speedX) : this.setVelocityX(-this.speedX);
8796
}
8897
}
@@ -92,10 +101,11 @@ export class Player extends Phaser.Physics.Arcade.Sprite{
92101
this.scene.tweens.add({
93102
targets: this,
94103
health: this.health - source.damage,
95-
duration: 800,
104+
duration: 400,
96105
repeat: 0,
97106
onComplete: ()=>{
98107
this.hasBeenHit = false;
108+
this.setVelocity(0, 0);
99109
if(this.health <= 0 ){
100110
this.isDead = true;
101111
this.setVelocity(0, -200);
@@ -124,19 +134,6 @@ export class Player extends Phaser.Physics.Arcade.Sprite{
124134

125135
}
126136

127-
handleAnimations(){
128-
129-
if(this.body.onFloor()){
130-
this.body.velocity.x === 0 ?
131-
this.play("player-idle", true) : this.play("player-run", true);
132-
}
133-
else{
134-
this.body.velocity.y < 0 && this.play("player-jump", true);
135-
this.body.velocity.y > 0 && this.play("player-fall", true);
136-
}
137-
//on ladder
138-
this.onLadder && this.play('player-idle', true);
139-
}
140137

141138
shoot(key, anim){
142139
if(this.hasBeenHit) return;
@@ -175,12 +172,12 @@ export class Player extends Phaser.Physics.Arcade.Sprite{
175172

176173
update(time, delta){
177174
if(!this.body) return;
178-
super.update(time, delta)
175+
super.update(time, delta);
176+
179177
this.stateMachine.updateState(this.currentState, time, delta);
180178
this.healthbar.draw();
181-
this.handleAnimations();
182179
this.handleShooting();
183-
180+
this.updateBoundingBox()
184181
//SETTING PLAYER Hitbox
185182
this.lastDirection = this.flipX ? "left" : "right";
186183

src/groups/Doors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class Doors extends Phaser.GameObjects.Group{
99
createDoors() {
1010
if (!this.scene.mapLayers) return;
1111
this.scene.mapLayers.exit_zone.forEach(zone => {
12-
this.add(new Door(this.scene, zone.x, zone.y, "exitDoor"));
12+
this.add(new Door(this.scene, zone.x, zone.y, "exitSign"));
1313
})
1414
}
1515

src/hud/Status.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function drawStatus(entity){
2+
const x = entity.scene.config.topLeft.x;
3+
const y = entity.scene.config.topLeft.y;
4+
5+
let statusText;
6+
7+
statusText =entity.scene.add.text(0, 0, "", {
8+
font: "15px myOtherFont"
9+
})
10+
.setOrigin(0)
11+
.setDepth(20)
12+
.setScrollFactor(0)
13+
.setStyle({ fill: "white" })
14+
.setPosition(x, y)
15+
16+
statusText.setText("state: "+entity.currentState.name)
17+
}

src/myInput.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,54 @@ class Input{
5757
this.keypressed = false;
5858
}
5959
})
60+
//swipe
61+
window.addEventListener("touchstart", (e)=>{
62+
this.touchX = e.touches[0].clientX;
63+
this.touchY = e.touches[0].clientY;
64+
})
65+
window.addEventListener("touchmove", (e)=>{
66+
const dx = e.touches[0].clientX - this.touchX;
67+
const dy = e.touches[0].clientY - this.touchY;
68+
console.log (this.keys)
69+
if(dx < -this.touchThreshold){
70+
this.lastKey = "swipe left";
71+
if(this.keys.indexOf(this.lastKey) === -1){
72+
this.keys.unshift(this.lastKey);
73+
this.keypressed = true;
74+
}
75+
}
76+
else if(dx > this.touchThreshold){
77+
this.lastKey = "swipe right";
78+
if(this.keys.indexOf(this.lastKey) === -1){
79+
this.keys.unshift(this.lastKey);
80+
this.keypressed = true;
81+
}
82+
}
83+
else if(dy < -this.touchThreshold){
84+
this.lastKey = "swipe up";
85+
if (this.keys.indexOf(this.lastKey) === -1) {
86+
this.keys.unshift(this.lastKey);
87+
this.keypressed = true;
88+
}
89+
}
90+
else if(dy > this.touchThreshold){
91+
this.lastKey = "swipe down";
92+
if (this.keys.indexOf(this.lastKey) === -1) {
93+
this.keys.unshift(this.lastKey);
94+
this.keypressed = true;
95+
}
96+
97+
}
98+
})
99+
window.addEventListener("touchend", (e) => {
100+
if(this.keys.indexOf(this.lastKey) > -1){
101+
this.keys.splice(this.keys.indexOf(this.lastKey), 1);
102+
this.lastKey = "";
103+
this.keypressed = false;
104+
}
105+
})
60106
}
107+
61108
}
62109

63110
export const myInput = new Input();

0 commit comments

Comments
 (0)