Skip to content

Commit

Permalink
Start of warrior game
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanRegush committed Aug 3, 2024
1 parent 363202f commit aee0ee7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions allan_regush_sandbox/warrior/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="c" width="800" height="600"></canvas>
<script src="index.js"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions allan_regush_sandbox/warrior/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let height = 0;
let width = 0;
let tick = 0;
let ctx;

window.onload = function() {
const canvas = document.querySelector("#c");
if (!canvas) {
console.error("No Canvas Found");
return;
}
height = canvas.height;
width = canvas.width;
ctx = canvas.getContext("2d");
if (!ctx) {
console.error("Could Not Get Context");
return;
}
requestAnimationFrame(main);
}



function main(timeStamp) {
if (tick == 0) {
tick = timeStamp;
}
const dt = timeStamp - tick;
tick = timeStamp;
render();
requestAnimationFrame(main);
}

function blackoutCanvas() {
ctx.fillStyle = 'black';
ctx.fillRect(0,0, width, height);
}

function drawRectangle(x, y, width, height, color) {
ctx.fillStyle = color;
ctx.fillRect(x, y, width, height);
}

function render() {
blackoutCanvas();
drawRectangle(10, 10, 10, 10, 'blue');
}

0 comments on commit aee0ee7

Please sign in to comment.