Permalink
Browse files

sets up network events in processing.js

  • Loading branch information...
semmypurewal committed Nov 3, 2012
1 parent 81ec89a commit 1190562a8d62aeaf21b7e35e44a9d64fc93b294d
Showing with 34 additions and 0 deletions.
  1. +15 −0 game/game.pde
  2. +1 −0 index.html
  3. +18 −0 src/main.js
@@ -1,4 +1,6 @@
int radius;
int ballX;
int ballY;
ArrayList<Balloon> balloons;
void setup()
@@ -8,6 +10,9 @@ void setup()
balloons.add(new Balloon());
noStroke();
frameRate(30);
setupNetwork();
ballY = random(height);
ballX = random(width);
}
@@ -32,6 +37,16 @@ void draw(){
for(int i = 0; i < width; i=i+20) {
triangle(i, 0, i+10, 40, i+20, 0);
}
fill(255,255,255);
ellipse(ballX, ballY, 20, 20);
}
void onGamePacket(GamePacket p) {
println(p);
ballX = p;
}
class Balloon {
@@ -3,6 +3,7 @@
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="lib/processing-1.4.1.js"></script>
<script src="src/main.js"></script>
</head>
<body>
@@ -0,0 +1,18 @@
var main = function () {
if (window.Processing !== undefined) {
Processing.prototype.onGamePacket = function (packet) {
console.log("hello");
}
Processing.prototype.setupNetwork = function () {
var that = this;
console.log("setup network called!");
setInterval(function () {
that.onGamePacket(Math.round(Math.random()*400));
}, 1000);
}
}
}
$(document).ready(main);

0 comments on commit 1190562

Please sign in to comment.