From 6d7702b959926ddbbc83c6126c3bac14f86b06dd Mon Sep 17 00:00:00 2001 From: Elijah Cohen Date: Wed, 24 Apr 2019 12:52:41 -0500 Subject: [PATCH] big commit cuz i should commit more --- .gitignore | 3 +++ NOTES.org | 17 -------------- server/basics.js | 7 ++++++ server/field.js | 55 ++++++++++++++++++++++++++++++++++++++++++++ server/game.js | 5 +++- server/gamestate.js | 11 ++++++++- server/matchmaker.js | 3 --- server/paddles.js | 17 ++++++++++++++ server/player.js | 1 + 9 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 server/basics.js create mode 100644 server/field.js create mode 100644 server/paddles.js diff --git a/.gitignore b/.gitignore index 9a77fd5..e28b64b 100644 --- a/.gitignore +++ b/.gitignore @@ -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~ diff --git a/NOTES.org b/NOTES.org index d8ed4fa..5f9753e 100644 --- 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 index 0000000..6f10481 --- /dev/null +++ b/server/basics.js @@ -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 index 0000000..fbdd17a --- /dev/null +++ b/server/field.js @@ -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(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) diff --git a/server/game.js b/server/game.js index 451aca7..70ed3ed 100644 --- a/server/game.js +++ b/server/game.js @@ -3,7 +3,10 @@ const GameState = require('./gamestate.js'); function Game(players) { this.players = players; - this.state = new GameState(); + for(var i=0; i= 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 index 0000000..e16ccb3 --- /dev/null +++ b/server/paddles.js @@ -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; +} diff --git a/server/player.js b/server/player.js index 48f0723..a0d24fa 100644 --- a/server/player.js +++ b/server/player.js @@ -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); -- 2.39.2