From 6867994e8a8742c78d38ee4b97c6632c305d9fc6 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sat, 19 Feb 2022 21:00:19 -0600 Subject: Initial commit --- main.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 main.js (limited to 'main.js') diff --git a/main.js b/main.js new file mode 100644 index 0000000..6e387be --- /dev/null +++ b/main.js @@ -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(); +} -- cgit v1.2.3