]> git.eli173.com Git - pong_br/commitdiff
big commit cuz i should commit more
authorElijah Cohen <eli@eli173.com>
Wed, 24 Apr 2019 17:52:41 +0000 (12:52 -0500)
committerElijah Cohen <eli@eli173.com>
Wed, 24 Apr 2019 17:52:41 +0000 (12:52 -0500)
.gitignore
NOTES.org
server/basics.js [new file with mode: 0644]
server/field.js [new file with mode: 0644]
server/game.js
server/gamestate.js
server/matchmaker.js
server/paddles.js [new file with mode: 0644]
server/player.js

index 9a77fd5df8da46823191f010aa995c3fa2a0c5bd..e28b64b35b578a1e7cd81b52f47579f48eecc335 100644 (file)
@@ -22,3 +22,6 @@ server/node_modules/*
 /server/gamestate.js~
 /server/matchmaker.js~
 /server/player.js~
+/server/basics.js~
+/server/field.js~
+/server/paddles.js~
index d8ed4fa242a269013aa08d25a4d4bb376aae8779..5f9753e44c95740f1f0a8d7a2cafc57650a36ee7 100644 (file)
--- a/NOTES.org
+++ b/NOTES.org
@@ -1,15 +1,4 @@
 
-NEW PLAN: PUT THE PLAYER CLASS INIT STUFF INSIDE THE MATCHMAKER MANAGE_INCOMING PARTS! LETS ME GET AWAY WITH MORE STUFF SERVER-WISE I THINK
-
-
-
-Basic infrastructure for web work:
-have a player manager class thread which checks main game state and sends it out every so often (1/15 seconds?) (can also form ground work for computer players
-have a single game creator class which waits until there are ten connections, then spawns a new game thread
-game thread which manages game state and reads player logic
-
-sososo
-
 The general outline of the game is that we have some large number of players $n$, arranged in a $2n$-sided regular polygon, where the player has their pong-space, and is surrounded by two walls. The walls primarily serve the purpose of having the game end nicely when there are two players left: it becomes a regular game of pong.
 
 I'm going to limit the number of players to 10 for the time being, I think anything with more than 20 sides might be a bit too much. 20 might be pushing it actually.
@@ -18,9 +7,3 @@ I'm going to limit the number of players to 10 for the time being, I think anyth
 At the moment I think I've figured out basic matchmaking (the br format pretty much lets me ignore skill levels so I can just throw anyone with anyone), so the main concern is the actual pong gameplay. My biggest challenge is how to shrink the circle when someone dies.
 There's gotta be a decent transformation I can come up with? Probably mostly trig. I've gotta work it so multiple things can go away at the same time.
 
-
-
-Okay MM doesn't actually work yet: new strat tho.
-Have the recieving thingy (the start_server bit, where we recieve the new ws connections) pass along some info to an asynchronous matchmaking service. That recieving thingy will just wait until the match is made, at which point it'll recieve some game-interaction object, and will send and recieve updates from the game started in some separate thread.
-
-As far as dev, I think I'll try to do the networking then actually do game logic
diff --git a/server/basics.js b/server/basics.js
new file mode 100644 (file)
index 0000000..6f10481
--- /dev/null
@@ -0,0 +1,7 @@
+
+
+
+var Coord(x,y) {
+    this.x = x;
+    this.y = y;
+}
diff --git a/server/field.js b/server/field.js
new file mode 100644 (file)
index 0000000..fbdd17a
--- /dev/null
@@ -0,0 +1,55 @@
+
+const RADIUS = 10; // completely arbitrary actually...
+
+// for generating/using the actual playing field of the game, I guess it'll be newly generated on each frame? the math is simple enough...
+
+var Endpoints = function(f,s,a) {
+    // f,s are first, second coordinates, in increasing angle
+    // a is alive
+    // these endpoints enclose a paddle
+    this.f = f;
+    this.s = s;
+    this.isAlive = a;
+}
+
+var Coord(x,y) {
+    this.x = x;
+    this.y = y;
+}
+
+var genEndpoints = function(n ,dead) {
+    /**
+       /* takes the number of players total (that the game started with, should be NUM_PLAYERS),
+       /* and the array of the dead and dying
+    */
+    // so i'll start from a radius out a zero radians
+    var endpoints = [];
+    var players_length = n - dead.length;
+    for(var d in dead) {
+       players_length += d.time/DYING_TIME_IN_FRAMES;
+    }
+    var theta = 0;
+    var dtheta = players_length/(2*Math.PI);
+    var coord = new Coord(RADIUS,0);
+    for(var i=0; i<n; i++) {
+       var deadStatus = dead.find(e=>(e.id==i));
+       if((deadStatus !== undefined) && (deadStatus.time > 0)) {
+           var r = RADIUS;
+           theta += (deadStatus.time/DYING_TIME_IN_FRAMES)/2;
+           var pt1 = new Coord(r*Math.cos(theta), r*Math.sin(theta));
+           theta += (deadStatus.time/DYING_TIME_IN_FRAMES)/2;
+           var pt2 = new Coord(r*Math.cos(theta), r*Math.sin(theta));
+           endpoints.append(new Endpoints(pt1, pt2, false));
+       }
+       else {
+           theta += dtheta/2;
+           var pt1 = new Coord(r*Math.cos(theta), r*Math.sin(theta));
+           theta += dtheta/2;
+           var pt2 = new Coord(r*Math.cos(theta), r*Math.sin(theta));
+           endpoints.append(new Endpoints(pt1, pt2, true));
+       }
+    }
+    return endpoints;
+}
+
+var Field = function(endpoints, paddles)
index 451aca790cb2afefa253a8f85c3d7916b0bede69..70ed3ed154803fbaf96aff572391fedc70536e47 100644 (file)
@@ -3,7 +3,10 @@ const GameState = require('./gamestate.js');
 
 function Game(players) {
     this.players = players;
-    this.state = new GameState();
+    for(var i=0; i<players.length; i++) {
+       this.players[i].id = i;
+    }
+    this.state = new GameState(this.players.length);
     this.timeout = null;
 }
 
index 86c4f265240da5652cf654cd54d36846215d63f8..a72145ee29df0c612850df30efba0b25efbb3ada 100644 (file)
@@ -1,5 +1,14 @@
 
-function GameState() {
+const DYING_TIME_IN_FRAMES = 100;
+
+function Dead(id) {
+    this.id = id;
+    this.time = DYING_TIME_IN_FRAMES;
+}
+
+function GameState(n) {
+    this.numLiving = n;
+    this.dead = [];
     this.inputs = [];
 }
 
index 29f36a0824a9220b75c56acb8b4e69ed937855f5..a7d4766c4f440f394e1f0f88ac4e33538e385c04 100644 (file)
@@ -18,11 +18,8 @@ var manage_incoming = function(ws) {
     var new_player = new Player(ws);
     players.push(new_player);
     if(players.length >= NUM_PLAYERS) {
-       // is the slicing necessary? I'm not sure I understand js's mechanisms without threads
        game = new Game(players.slice(0, NUM_PLAYERS));
-       //
        game.start(MS_PER_FRAME);
-       //
        players = players.slice(NUM_PLAYERS);
     }
 }
diff --git a/server/paddles.js b/server/paddles.js
new file mode 100644 (file)
index 0000000..e16ccb3
--- /dev/null
@@ -0,0 +1,17 @@
+
+const DPADDLE = 0.1;
+
+
+var Paddle = function(id) {
+    // position is supposed to range between ±1
+    this.id = id;
+    this.position = 0;
+}
+
+Paddle.prototype.move(direction) {
+    // direction is either 'u', 'd', or 'x', passed along from the inputs gathered elsewhere
+    if((direction=='u') && (this.position < 1))
+       this.position += DPADDLE;
+    else if((direction=='d') && (this.position > -1))
+       this.position -= DPADDLE;
+}
index 48f0723b03480f800b2c2f9172327d37328cb300..a0d24fa94d50686c967f8a582a11ccce51173b18 100644 (file)
@@ -3,6 +3,7 @@
 function Player(ws) {
     this.status = 'x';
     this.socket = ws;
+    this.id = -1; // id just used for keeping track of deaths and whatnot
     var _this = this;
     var fn = function(msg) {
        _this.listener(msg);