Skip to content

Commit 55d305e

Browse files
committed
Save name into localStorage
1 parent b51fb9b commit 55d305e

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

src/app/classes/entitiy/player/player.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class Player extends Sprite {
198198
GameComponent.player.preventInput = false;
199199
destinationDoor.play();
200200

201-
GameComponent.player.setPosition(destinationDoor.getDestination().getPosition());
201+
GameComponent.player.setPosition(destinationDoor.getPosition());
202202
}
203203
}
204204

src/app/classes/level/level.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,28 @@ export class Level extends Sprite {
322322
this.getDoors().forEach(door => {
323323
if(this.getFinalDoor() === door) return;
324324

325-
if (door.checkCollision(GameComponent.player) && isKeyPressed('w') && GameComponent.player.collectedKeys >= 1 && GameComponent.player.isOnGround && !GameComponent.player.isReceivingDamage) {
325+
if (door.checkCollision(GameComponent.player) && isKeyPressed('w') && GameComponent.player.isOnGround && !GameComponent.player.isReceivingDamage) {
326326

327327
if (GameComponent.player.isAttacking) return;
328328

329-
if(!door.isLocked()) return;
329+
if(!door.isLocked()){
330+
GameComponent.player.getVelocity().setY(0);
331+
GameComponent.player.getVelocity().setX(0);
332+
GameComponent.player.preventInput = true;
333+
334+
this.doors.forEach(destination => {
335+
if(destination.getDestination() === door) {
336+
GameComponent.player.switchSprite('enterIntermediateDoor', destination);
337+
}else {
338+
GameComponent.player.switchSprite('enterIntermediateDoor', door.getDestination());
339+
}
340+
})
341+
342+
343+
return;
344+
}
345+
346+
if(GameComponent.player.collectedKeys < 1) return;
330347

331348
door.setLocked(false);
332349

src/app/components/game/game.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class GameComponent implements AfterViewInit {
4545
GameComponent.player = new Player();
4646
initializeSounds();
4747
this.registerGuiListener();
48+
49+
if(localStorage.getItem('name')) {
50+
this.leaderboard.name = localStorage.getItem('name')!;
51+
}
4852
}
4953

5054
public static getPlayer(): Player {

src/app/components/intro/intro.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ export class IntroComponent {
1919
public readonly router: Router) {
2020

2121

22+
2223
}
2324

2425
public redirect(): void {
26+
localStorage.setItem('name', this.leaderboardService.name);
2527
this.router.navigate(['/game']).then(r => console.log(r));
2628
}
2729

src/app/services/leaderboard.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export class LeaderboardService {
88

99
public name: string = 'Anonymous';
1010
public time: number = 0;
11-
constructor() { }
11+
constructor() {
12+
if(localStorage.getItem('name')) {
13+
this.name = localStorage.getItem('name') ?? 'Anonymous';
14+
}
15+
}
1216

1317

1418
}

0 commit comments

Comments
 (0)