summaryrefslogtreecommitdiff
path: root/main.js
blob: 6e387becb361f3f4d18fd31b2779c5df9458cd46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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();
}