/server/gamestate.js~
/server/matchmaker.js~
/server/player.js~
+/server/basics.js~
+/server/field.js~
+/server/paddles.js~
-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.
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
--- /dev/null
+
+
+
+var Coord(x,y) {
+ this.x = x;
+ this.y = y;
+}
--- /dev/null
+
+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)
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;
}
-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 = [];
}
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);
}
}
--- /dev/null
+
+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;
+}
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);