mirror of
https://github.com/Sheldan/canvas.git
synced 2026-04-29 07:48:17 +00:00
survivors: only displaying the controls if we are on mobile
adding method to detect if mobile
This commit is contained in:
@@ -1,34 +1,44 @@
|
|||||||
import type {Drawable, DrawContainer, MouseInteracting, MouseInterActingContainer} from "./interfaces.ts";
|
import type {Drawable, DrawContainer, MouseInteracting, MouseInterActingContainer} from "./interfaces.ts";
|
||||||
import {World} from "./World.ts";
|
import {World} from "./World.ts";
|
||||||
import {Vector} from "./base.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 {
|
export class HUD implements DrawContainer {
|
||||||
private health: PlayerInfo;
|
private health: PlayerInfo;
|
||||||
private controls: Controls;
|
private controls: Controls | undefined;
|
||||||
private world: World;
|
private world: World;
|
||||||
|
|
||||||
constructor(world: World, keys: any) {
|
constructor(world: World, keys: any) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.health = new PlayerInfo(world);
|
this.health = new PlayerInfo(world);
|
||||||
this.controls = new Controls(world, keys);
|
if (isMobile()) {
|
||||||
|
this.controls = new Controls(world, keys);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(ctx: CanvasRenderingContext2D) {
|
draw(ctx: CanvasRenderingContext2D) {
|
||||||
this.health.draw(ctx)
|
this.health.draw(ctx)
|
||||||
this.controls.draw(ctx)
|
if(this.controls) {
|
||||||
|
this.controls.draw(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseDown(pos: Vector) {
|
mouseDown(pos: Vector) {
|
||||||
this.controls.mouseDown(pos)
|
if(this.controls) {
|
||||||
|
this.controls.mouseDown(pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseUp(pos: Vector) {
|
mouseUp(pos: Vector) {
|
||||||
this.controls.mouseUp(pos)
|
if(this.controls) {
|
||||||
|
this.controls.mouseUp(pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseMove(pos: Vector) {
|
mouseMove(pos: Vector) {
|
||||||
this.controls.mouseMove(pos)
|
if(this.controls) {
|
||||||
|
this.controls.mouseMove(pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ export function fillDot(position: Vector, size: number, color: string, ctx: Canv
|
|||||||
ctx.fill();
|
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) {
|
export function drawDot(position: Vector, size: number, color: string, ctx: CanvasRenderingContext2D) {
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.strokeStyle = color;
|
ctx.strokeStyle = color;
|
||||||
|
|||||||
Reference in New Issue
Block a user