Skip to content

Commit

Permalink
git status! Its working, baby
Browse files Browse the repository at this point in the history
  • Loading branch information
stepiiik committed Apr 29, 2012
1 parent cee7bad commit bf71dec
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
30 changes: 17 additions & 13 deletions client/Arena.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@ class Arena {
ball.setAsOut();

if (this.websocket != null) {

PongMessage msg = new PongMessage();
msg.type = 1;
msg.speed = ball.speed;
msg.direction = ball.direction;
msg.x = ball.x;
msg.y = ball.y;
var msg = {};
msg['type'] = 2;
msg['speed'] = ball.speed;
msg['direction'] = ball.direction;
msg['x'] = ball.x;
msg['y'] = ball.y;

this.websocket.send(JSON.stringify(msg));
}

}

teleportBallIn(PongMessage msg) {
teleportBallIn(msg) {print(msg);
print('Teleport IN');
ball.x = this.getWidth() - ball.x;
ball.y = msg.y;
ball.speed = msg.speed;
ball.direction = msg.direction;
if (msg['x'] > 300) {
ball.x = 40.0;
} else {
ball.x = 560.0;
}

ball.y = msg['y'];
ball.speed = msg['speed'];
ball.direction = Math.PI - msg['direction'];

ball.setAsIn();

}
Expand Down Expand Up @@ -75,7 +79,7 @@ class Arena {

// v tuto chvili jen u micku
changePositions() {
if (ball.available) ball.changePosition();
if (ball.available == true) ball.changePosition();
}

}
2 changes: 1 addition & 1 deletion client/DartPong.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class DartPong {



arena = new Arena( map, ball );
arena = new Arena( map, ball, ws );

handler.arena = arena;

Expand Down
16 changes: 11 additions & 5 deletions client/MessageReceiver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class MessageReceiver {

onMessage(e) {
var data = JSON.parse(e.data);

print(data['type']);
if (data['type'] == 1) {
fetchNumberOfPlayers(data);
}

if (data['type'] == 2) {
fetchNumberOfPlayers(data);
showBall(data);
}
}

Expand All @@ -31,14 +31,20 @@ class MessageReceiver {
}

fetchNumberOfPlayers(data) {
dartPong.prepareGameForMultiplayer(data['numberOfClients'] > 1 ? 2 : 1);

if (data['numberOfClients'] > 1 && dartPong.multiplayerId == 1) {
dartPong.arena.ball.setAsIn();
} else {
dartPong.prepareGameForMultiplayer(data['numberOfClients'] > 1 ? 2 : 1);
}
}

showBall(data) {
//dartPong.arena.
if (data['x'] > 500 && dartPong.multiplayerId == 1) {
dartPong.arena.teleportBallIn(data);
}

if (data['x'] < 100 && dartPong.multiplayerId == 2) {
dartPong.arena.teleportBallIn(data);
}
}
}
2 changes: 1 addition & 1 deletion server/DartPongServer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() {
if (parsedMsg['type'] == 2) {
print('Ball crosses the teleport zone with x = ' + parsedMsg['x'] + ', y = ' + parsedMsg['y']);
conns.forEach((c) {
c.send(message);
c.send(JSON.stringify(parsedMsg));
});
}

Expand Down

0 comments on commit bf71dec

Please sign in to comment.