Skip to content

Commit e7c9409

Browse files
committed
Added full Mobile Support
1 parent a0eaa07 commit e7c9409

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

src/app/classes/collectibles/potion/potion.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,13 @@ export class HealthPotion extends Potion {
4242
GameComponent.getCurrentLevel().getHealthPotions().splice(i, 1);
4343

4444
if (player.health + this.healAmount > player.maxHealth) {
45-
(async () => {
46-
const diff = player.maxHealth - player.health;
47-
let counter = 0;
48-
const interval = setInterval(() => {
49-
counter++;
50-
player.health += 1;
51-
if (counter >= diff || player.health === player.maxHealth) clearInterval(interval);
5245

53-
}, 75);
46+
player.health = player.maxHealth;
5447

55-
})();
5648

5749
} else {
58-
(async () => {
59-
let counter = 0;
60-
const interval = setInterval(() => {
61-
counter++;
62-
player.health += 1;
63-
if(counter >= this.healAmount || player.health === player.maxHealth) clearInterval(interval);
64-
65-
}, 75);
66-
})();
50+
player.health += this.healAmount;
51+
6752
}
6853

6954

src/app/classes/gui/window/mobile.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ export class Mobile {
2626
}, () => {
2727
setKeyPressed('w', false)
2828
}),
29-
new Button('../../../assets/gui/mobile/down.png', new Position(100, 0), new Scale(0.25), () => {
3029

30+
new Button('../../../assets/gui/mobile/a.png', new Position(650, 250), new Scale(0.4), () => {
31+
setKeyPressed('space', true);
32+
}, () => {
33+
setKeyPressed('space', false);
34+
}),
35+
new Button('../../../assets/gui/mobile/f.png', new Position(700, 0), new Scale(0.2), () => {
36+
setKeyPressed('f', true);
37+
}, () => {
38+
setKeyPressed('f', false);
3139
}),
3240
];
3341
Mobile.buttons = this.buttons;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {Mobile} from "../../classes/gui/window/mobile";
1515
})
1616
export class GameComponent implements AfterViewInit {
1717

18-
public static isMobile = window.innerWidth < 800 || window.innerHeight < 600;
18+
public static isMobile = window.innerWidth < 1000 || window.innerHeight < 800;
1919
public static canvasWidth = 64 * 16;
2020
public static canvasHeight = 64 * 9;
2121
public static player: Player;
@@ -121,6 +121,7 @@ export class GameComponent implements AfterViewInit {
121121
}
122122

123123
public touchEnd(event: TouchEvent): void {
124+
event.preventDefault();
124125

125126
if (GameComponent.isMobile) {
126127
setKeyPressed('a', false);
@@ -144,6 +145,8 @@ export class GameComponent implements AfterViewInit {
144145
}
145146

146147
touchStart(event: TouchEvent) {
148+
event.preventDefault();
149+
147150

148151
const {clientX, clientY} = event.touches[0];
149152
const canvasTouch = GameComponent.translateTouchToCanvasPosition(clientX, clientY, this.cameraCanvas!.nativeElement);

src/assets/gui/mobile/a.png

6 KB
Loading

src/assets/gui/mobile/f.png

2.5 KB
Loading

0 commit comments

Comments
 (0)