-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
92 lines (79 loc) · 2.17 KB
/
test.js
File metadata and controls
92 lines (79 loc) · 2.17 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// all the processing code goes in the function
// which gets passed in a processing instance p
var p_code = function(p) {
var sm, t1, c1, c2;
p.setup = function() {
p.size(700, 600);
// deal with console issues
// TODO move this code
if (!window.console) {
console = { log: function() {} };
}
Processing.logger = console;
var f = new p.loadFont("_sans");
p.textFont(f, 14);
sm = state_manager(p);
p.frameRate(30);
};
update_counter = 0;
// draw is called repeatedly
p.draw = function() {
update_counter += 1;
if (update_counter === 30) {
//console.log("frame "+p.millis());
//console.log(p.__frameRate);
update_counter = 0;
}
sm.update(); // Also renders
};
//Mouse and Keyboard input
p.keyPressed = function() {
sm.key_pressed(p.key);
};
p.mousePressed = function() {
sm.mouse_click(p.mouseX, p.mouseY);
};
p.mouseMoved = function() {
sm.mouse_moved(p.mouseX, p.mouseY);
};
};
// want this to be global
var sketch;
var start_game = function() {
// attaches the processing code to the canvas
// note that we need to do this AFTER the canvas element is created
var canvas = document.getElementById("test_canvas");
sketch = new Processing.Sketch(p_code);
//sketch.options.isTransparent = true;
var pInstance = new Processing(canvas, sketch);
};
window.onload = start_game;
/*
var back_code = function(p) {
var tiles = [];
p.setup = function() {
p.size(700, 600);
p.frameRate(30);
tiles.push(background(p, {
pos: new p.PVector(0, 0)
}));
tiles.push(background(p, {
pos: new p.PVector(700, 0)
}));
};
p.draw = function() {
p.background(200);
for_each(tiles, function(tile) {
tile.update();
tile.scroll(1);
tile.draw();
});
};
};
*/
//var back_canvas = document.getElementById("back_canvas");
//var backInstance = new Processing(back_canvas, back_code);
// Make spacebar not move the window down
window.onkeydown = function(e) {
return !(e.keyCode == 32);
};