diff options
author | Mark Powers <mark@marks.kitchen> | 2022-02-19 21:00:19 -0600 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2022-02-19 21:00:19 -0600 |
commit | 6867994e8a8742c78d38ee4b97c6632c305d9fc6 (patch) | |
tree | bea7685555d0ba5de3807135cc88918266bfed6e /main.js |
Initial commit
Diffstat (limited to 'main.js')
-rw-r--r-- | main.js | 70 |
1 files changed, 70 insertions, 0 deletions
@@ -0,0 +1,70 @@ +var canvas, ctx; +var t; // Frame counter +var gameInterval; +var components; + +var messages, username, currentMessageText, currentMessageParts, currentMessagePixels, mouseIsDown; + +window.onload = function () { + canvas = document.getElementById("canvas"); + ctx = canvas.getContext("2d"); + document.addEventListener("keydown", keyDown); + + document.addEventListener("mousedown", mouseDown) + document.addEventListener("mousemove", mouseMove) + document.addEventListener("mouseup", mouseUp) + window.addEventListener('resize', resizeCanvas, false); + window.addEventListener('orientationchange', resizeCanvas, false); + + init(); + resizeCanvas(); +} +function init() { + components = { + keyboard: typingMessageComponent, + mouse: drawMessageComponent, + draw: normalDraw, + update: normalUpdate + } + t = 0 + + username = "Mark" + messages = [] + messages.unshift({ + type: 0, + }) + messages.unshift({ + type: 1, + text: username + }) + currentMessageText = "" + currentMessagePixels = [] + gameInterval = setInterval(game, 1000 / FPS); +} +function resizeCanvas() { + canvas.width = WIDTH; + canvas.height = HEIGHT; +} +function keyDown(e) { + components.keyboard.keyDown(e); +} +function mouseDown(e){ + components.mouse.mouseDown(e); +} +function mouseUp(e){ + components.mouse.mouseUp(e); +} +function mouseMove(e){ + components.mouse.mouseMove(e); +} +function update() { + components.update.update() +} +function draw(){ + components.draw.draw() +} + +function game() { + update(); + draw(); +} |