todo:
-- fix the robots
+- make sure files in the right place for server stuff
+maybe:
- paddle movement bump
-- fix collisions
- more balls
- fiddle with variables to optimize fun
+
+
+++ /dev/null
-list of things i should still do:
-- fix collisions
-
-sorta extra/for later/unsure:
-- fiddle with variables to optimize fun
-- make sure files are in the right place and urls are appropriate for server
-- double check all on-screen messages for fitting (look to the 'magic number...' comment)
-- fix game not ending with just robots (is this actually broken?)
-- polish
-- debug touch
// modifies ball's velocity if it encounters an actual collision
// wall is an endpoints
for(var wall of walls) {
+ var stretched = wall.elongate(1.2); // this is done to fix collision detection?
var next_spot = new Coord(ball.coord.x + ball.dx/c.FPS, ball.coord.y + ball.dy/c.FPS); // the next spot
- if(segments_intersect(wall, new Endpoints(ball.coord, next_spot))) {
+ var ball_ep = new Endpoints(ball.coord, next_spot)
+ if(segments_intersect(wall, ball_ep.elongate(1.2))) {
//there's a collision
var wall_normal = new Vec((wall.f.x+wall.s.x)/2, (wall.f.y+wall.s.y)/2); // given by the midpoint
wall_normal.normalize();
var c = {
// matchmaker
WS_PORT: 6789,
- NUM_PLAYERS: 4,
+ NUM_PLAYERS: 10,
FPS: 30,
WAIT_TIME: 60000, // 1 minute
MAX_GAMES: 100, // the most games allowed to go on at once, to be tweaked as needed for purposes
- ROBO_TIME: 5, // time in seconds before filling out with robots
+ ROBO_TIME: 30, // time in seconds before filling out with robots
// gamestate
DYING_TIME_IN_FRAMES: 100,
BOARD_RADIUS: 10,
// ball
MIN_INIT: 1,
MAX_INIT: 3, // initial speed constraints
- BALL_RADIUS: 0.5,
+ BALL_RADIUS: 0.3,
MAX_SPEED: 15,
SPEED_BUMP: 0.5,
// field
const c = require('./constants.js');
+const Coord = require('./coord.js');
+const Vec = Coord;
var Endpoints = function(f,s,id) {
// f,s are first, second coordinates, in increasing angle
}
return new AnglePair(fst-c.ANGLE_THRESH, snd+c.ANGLE_THRESH, this.id);
}
+Endpoints.prototype.elongate = function(v) {
+ // stretches the endpoints by multiple of v
+ var to_s = new Vec(v*(this.s.x-this.f.x), v*(this.s.y-this.f.y));
+ var to_f = new Vec(v*(this.f.x-this.s.x), v*(this.f.y-this.s.y));
+ // stretched vectors pointing in to s from f and vice versa
+ to_f.translate(this.s.x, this.s.y);
+ to_s.translate(this.f.x, this.f.y);
+ return new Endpoints(to_f, to_s)
+}
+
module.exports = Endpoints;
if(Math.abs(nearest_mod.x) < 0.2) this.status = 'x';
}
-
-
-
-Robot.prototype.bad_ai = function(data) {
- if(typeof data == "string")
- return;
- if(data.balls.length == 0)
- return;
- // this is where ALL the work needs to get done
- // i will start with a fairly naive approach, where i just move the paddle to the ball nearest to the region
- var me = data.id;
- var eps = field.genAllEndpoints(data.n, data.dead);
- var my_ep = eps.find(x => x.id == me);
- if(typeof my_ep == 'undefined') {
- this.status = 'x';
- return;
- }
- // recall that i strip out superfluous data... this is kinda tricky, just be careful
- var center = midpoint(my_ep.f, my_ep.s);
- var nearest = data.balls[0];
- var bdist2 = center.dist2(nearest);
- for(var ball of data.balls) {
- var newdist = center.dist2(ball);
- if(newdist < bdist2) {
- nearest = ball;
- bdist2 = newdist;
- }
- }
- // k now i've got the nearest... just move it in the direction of the nearest endpoint, yeah? yeah!
- // because the endpoints are given in increasing radians! Just have to do a check that
- if(nearest.dist2(my_ep.f) > nearest.dist2(my_ep.s)) {
- // double check which of 'u' or 'd' makes more sense, i think as is is probably fine but...
- this.status = 'u';
- }
- else {
- this.status = 'd';
- }
-}
-
var midpoint = function(a,b) {
return new Coord((a.x+b.x)/2, (a.y+b.y)/2);
}
var c = {
// matchmaker
WS_PORT: 6789,
- NUM_PLAYERS: 4,
+ NUM_PLAYERS: 10,
MS_PER_FRAME: 100,
WAIT_TIME: 60000, // 1 minute
MAX_GAMES: 5, // the most games allowed to go on at once, to be tweaked as needed for purposes
// ball
MIN_INIT: 3,
MAX_INIT: 5, // initial speed constraints
- BALL_RADIUS: 0.5,
+ BALL_RADIUS: 0.3,
MAX_SPEED: 15,
SPEED_BUMP: 0.2,
// field
}
// balls
for(var b of state.balls) {
- drawBall(ctx, bcolor, b);
+ drawBall(ctx, bcolor, b, state.dead.length, state.n);
}
// finally the paddles...
for(var eps of livingzones) {
return Math.sqrt((c1.x-c2.x)**2 + (c1.y-c2.y)**2);
}
-var drawBall = function(ctx, color, coord) {
+var drawBall = function(ctx, color, coord, nlive, nmax) {
ctx.save();
ctx.fillStyle = color;
ctx.beginPath();
- ctx.arc(coord.x, coord.y, c.BALL_RADIUS, 0, 2*Math.PI, false);
+ var rad = c.BALL_RADIUS;
+ ctx.arc(coord.x, coord.y, rad, 0, 2*Math.PI, false);
ctx.fill();
ctx.restore();
}
document.onclick = function(e) {location.reload()} // okay, outside of 'input' file...
document.onkeydown = function(e) {if(e.keyCode == '71') location.reload()};
drawWin(ctx);
- console.log("winner");
return;
}
else if(e.data == "l") {
drawOverlay(ctx,2); //second place
else
drawOverlay(ctx, place);
- console.log("loser");
return;
}
var state = JSON.parse(e.data);
+++ /dev/null
-
-var prefixurl = "ws://localhost:6789"
-
-var keystate = "";
-
-function doIt() {
- console.log("aaa")
- var ws = new WebSocket(prefixurl);
- ws.onopen = function(event) {
- ws.send("Hello World!");
- };
- ws.onmessage = function(event) {
- console.log(event.data);
- }
-}
-
-function onload() {
- var timer = 0;
- document.getElementById("play").addEventListener('click',e=>doIt());
- document.getElementById("stop").addEventListener('click',e=>clearInterval(timer));
- console.log("ssss");
-
- var ws = new WebSocket(prefixurl);
- ws.onmessage = function(event) {
- console.log("event.data")
- }
- timer = window.setInterval(function(){sendInput(ws);},1000);
- window.onkeydown = (e=>keypressHandler(e,true));
- window.onkeyup = (e=>keypressHandler(e,false));
-}
-
-window.addEventListener("DOMContentLoaded",e=> onload());
-
-
-function sendInput(ws) {
- if(keystate != '') {
- ws.send(keystate);
- }
-}
-
-function keypressHandler(evt,isdn) {
- if(evt.keyCode == '38') {
- if(isdn) {
- keystate = 'u';
- }
- else if(keystate=='u') {
- keystate = '';
- }
- }
- else if(evt.keyCode == '40') {
- if(isdn) {
- keystate = 'd';
- }
- else if(keystate=='d') {
- keystate = '';
- }
- }
-}
-
-function recievemessage(evt) {
-
-
-}
+++ /dev/null
-<!doctype html>
-<html>
- <head>
- <title>Pong Battle Royale</title>
- <script type="text/javascript" src="test.js"></script>
- </head>
- <body>
- Testing page for the websocket infrastructure I've drummed up
- <div id="buttons">
- <button id="connect" type="button" name="connect">
- connect
- </button>
- <button id="up" type="button" name="up">
- up
- </button>
- <button id="dn" type="button" name="dn">
- dn
- </button>
- </div>
- response from server:
- <div id="content">
- </div>
- </body>
-</html>
+++ /dev/null
-
-var prefixurl = "ws://localhost:6789"
-
-theSocket = null;
-
-
-function send(k, s) {
- // sends key k thru socket s
- theSocket.send(k);
-}
-
-function start() {
- // opens up a nice websocket
- theSocket = new WebSocket(prefixurl);
- theSocket.onmessage = function (e) {
- // newdiv = document.createElement('div')
- // newdiv.innerText = "data:" + e.data;
- // document.getElementById('content').appendChild(newdiv);
- }
-}
-
-
-
-function onload() {
- document.getElementById("connect").addEventListener('click', e=> start());
- document.getElementById("up").addEventListener('click', e=> send('u',theSocket));
- document.getElementById("dn").addEventListener('click', e=> send('d',theSocket));
-}
-window.addEventListener("DOMContentLoaded", e => onload());