survivors: only displaying the controls if we are on mobile

adding method to detect if mobile
This commit is contained in:
Sheldan
2025-09-08 22:52:10 +02:00
parent 681ba1b632
commit add005d963
2 changed files with 21 additions and 7 deletions

View File

@@ -1,34 +1,44 @@
import type {Drawable, DrawContainer, MouseInteracting, MouseInterActingContainer} from "./interfaces.ts";
import {World} from "./World.ts";
import {Vector} from "./base.ts";
import {drawDot, fillDot, rectPointIntersection} from "./utils.ts";
import {drawDot, fillDot, isMobile, rectPointIntersection} from "./utils.ts";
export class HUD implements DrawContainer {
private health: PlayerInfo;
private controls: Controls;
private controls: Controls | undefined;
private world: World;
constructor(world: World, keys: any) {
this.world = world;
this.health = new PlayerInfo(world);
this.controls = new Controls(world, keys);
if (isMobile()) {
this.controls = new Controls(world, keys);
}
}
draw(ctx: CanvasRenderingContext2D) {
this.health.draw(ctx)
this.controls.draw(ctx)
if(this.controls) {
this.controls.draw(ctx)
}
}
mouseDown(pos: Vector) {
this.controls.mouseDown(pos)
if(this.controls) {
this.controls.mouseDown(pos)
}
}
mouseUp(pos: Vector) {
this.controls.mouseUp(pos)
if(this.controls) {
this.controls.mouseUp(pos)
}
}
mouseMove(pos: Vector) {
this.controls.mouseMove(pos)
if(this.controls) {
this.controls.mouseMove(pos)
}
}
}

View File

@@ -7,6 +7,10 @@ export function fillDot(position: Vector, size: number, color: string, ctx: Canv
ctx.fill();
}
export function isMobile() {
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
}
export function drawDot(position: Vector, size: number, color: string, ctx: CanvasRenderingContext2D) {
ctx.beginPath();
ctx.strokeStyle = color;