Skip to content

Commit

Permalink
Use fullscreen for desktop and mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
edloper committed Dec 8, 2024
1 parent 2ee7a94 commit 7ce0f0d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
32 changes: 24 additions & 8 deletions game.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,40 @@
<script src="javascript/colorpicker.js"></script>
<script src="javascript/level_urls.js"></script>
<script>
const MIN_WIDTH = 500;
const MAX_WIDTH = Math.min(1000, window.innerHeight - 250);
var game;

$(function() {
var dw = 50;
var dh = 185;
var levelPickerContainer = document.getElementById('levelPicker');
var gameContainer = document.getElementById('game');

// Adjust size. Keep hight=width to preserve the aspect ratio of the game.
var naturalWidth = levelPickerContainer.offsetWidth - 50;
console.log("natural width", naturalWidth);
var width = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, naturalWidth));
var height = width;

var width = window.innerWidth - dw;
var height = window.innerHeight - dh;
game = new Game(gameContainer, width, height);
const levelPicker = new LevelPicker(levelPickerContainer, game, LEVEL_URLS);

window.addEventListener('resize', () => {
game.resize(window.innerWidth - dw, window.innerHeight - dh);
});
});
</script>
<style>
body {
overflow: hidden;
touch-action: none;
}
div.levelTitle {
position: absolute;
pointer-events: none;
top: 80px;
left: 50%;
width: 80%;
transform: translate(-50%, 0);
z-index: 100;
text-shadow: 0px 0px 2px white;
}
</style>

<!-- Uncomment this to debug touch input:
<script src="https://cdn.jsdelivr.net/gh/hammerjs/touchemulator@master/touch-emulator.js"></script>
Expand Down
16 changes: 14 additions & 2 deletions game_fullscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@
var levelPickerContainer = document.getElementById('levelPicker');
var gameContainer = document.getElementById('game');

// TODO: aspect ratio??
var width = window.innerWidth;
var height = window.innerHeight;

game = new Game(gameContainer, width, height);
const levelPicker = new LevelPicker(levelPickerContainer, game, LEVEL_URLS);

drawSplashscreen();
});

window.addEventListener('resize', () => {
game.resize(window.innerWidth, window.innerHeight);
});
</script>

<!-- Uncomment this to debug touch input:
Expand Down Expand Up @@ -84,6 +86,16 @@
div.controls #gameEasyMode {
pointer-events: auto;
}
div.levelTitle {
position: absolute;
pointer-events: none;
top: 25px;
left: 50%;
width: 80%;
transform: translate(-50%, 0);
z-index: 100;
text-shadow: 0px 0px 2px white;
}
</style>
</head>
<body class="fullscreen" style>
Expand Down
14 changes: 2 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
<tr>
<td>
<a href="game_fullscreen.html">
<img src="images/titles/missing_link_white.jpg">
</a>
</td>
<td>
<a href="game.html">
<img src="images/titles/missing_link_black.jpg"><br>
<img src="images/titles/missing_link_black.jpg">
</a>
</td>
<td>
Expand All @@ -32,12 +27,7 @@
<tr>
<td>
<a href="game_fullscreen.html">
Play<br>(mobile)
</a>
</td>
<td>
<a href="game.html">
Play<br>(desktop)
Play
</a>
</td>
<td>
Expand Down
5 changes: 3 additions & 2 deletions javascript/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ class LevelEditor {

addDot(x, y) {
const dot = this.graph.addDot(x, y);
dot.circle.on('mousedown', (e) => { this.mouseHandler.mouseDown(e, dot); });
dot.text.on('mousedown', (e) => { this.mouseHandler.mouseDown(e, dot); });
dot.on('mousedown', (e) => { this.mouseHandler.mouseDown(e, dot); });
dot.on('touchstart', (e) => { this.mouseHandler.mouseDown(e, dot); });
this.history.push(new EditorHistoryEvent('addDot', {x: x, y: y}));
return dot;
}
Expand All @@ -380,6 +380,7 @@ class LevelEditor {
addTri(corners, color) {
const tri = this.graph.addTri(corners, color, /*highlight=*/ false);
tri.polygon.on('mousedown', (e) => { this.mouseHandler.mouseDown(e, tri); });
tri.polygon.on('touchstart', (e) => { this.mouseHandler.mouseDown(e, tri); });
this.updateTriColor(tri);
this.history.push(new EditorHistoryEvent('addTri', {
corners: corners.map(c => ({x: c.x, y: c.y})), color: color}));
Expand Down
12 changes: 9 additions & 3 deletions javascript/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class Game {
this.$container = $(container)
this.$container.append($("<div class='levelTitle'></div>"));
this.$title = this.$container.find(".levelTitle");
this.width = width
this.height = height
this.width = width // used by mouse_controller.
this.height = height // used by mouse_controller.
this.draw = SVG().addTo(container).size(width, height);
$(container).addClass('missingLinkGame');
this.setBackgroundColor({h: 0, s: 0, l: 80});
Expand Down Expand Up @@ -179,7 +179,13 @@ class Game {
}
}
});
window.history.pushState({}, '');
window.history.pushState({}, '');
}

resize(width, height) {
console.log("Resize", width, height);
this.$container.find(".controls").css({width: width});
this.draw.size(width, height);
}

loadFromPng(dataUrl) {
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ h1 {
width: 12px;
}
.missingLinkTitle {
height: 80px;
width: 600px;
margin-bottom: 15px;
}
#game .youWon {
Expand Down

0 comments on commit 7ce0f0d

Please sign in to comment.