This repository has been archived by the owner on Oct 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
75 lines (65 loc) · 2.1 KB
/
sketch.js
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
71
72
73
74
75
var cnv;
var gameManager;
var dataManager;
var chat;
var userInterface;
var computer;
var playOffline = false;
function setup() {
cnv = createCanvas(700, 700); //eigentliche größe 600, 550
cnv.position((windowWidth - 600)/2, 0);
gameManager = new GameManager();
dataManager = new DataManager();
if(playOffline){
computer = new Computer();
}
chat = new Chat(285, 20, 250, 200);
userInterface = new UserInterface(260, 310);
dataManager.setup(gameManager, chat, computer);
gameManager.setup(dataManager, playOffline);
chat.setup();
if(computer != null)
computer.setup(dataManager);
userInterface.setup(gameManager);
}
function draw() {
background(0);
gameManager.show();
chat.show();
if(computer != null)
computer.show();
if(!gameManager.gameStarted)
userInterface.show();
}
//die Methode callInput gibt true zurück wenn sie mit "KeyPressed" aufgerufen wurde
//dadruch wird sichergestellt, dass wenn man was in den chat schreibt man keine
//Tastenkombination vom GameManager aufrufen möchte
//wird ggf. noch entfernt falls wir uns für buttons entscheiden
function keyPressed(){
if(!chat.callInput("KeyPressed", [key, keyCode])){
gameManager.callInput("KeyPressed", key);
}
if(this.playOffline){
computer.callInput("KeyPressed", [key, keyCode]);
}
}
function mousePressed(){
gameManager.callInput("MousePressed", createVector(mouseX, mouseY));
chat.callInput("MousePressed", createVector(mouseX, mouseY));
userInterface.mousePressed();
}
function mouseReleased(){
gameManager.callInput("MouseReleased", createVector(mouseX, mouseY));
userInterface.mouserReleased();
}
function windowResized(){
cnv.position((windowWidth - 600)/2, 0);
}
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = 'Do you really want to leave the game?';
if (gameManager.gameEnd) {
return undefined;
}
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
});