Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rdragon committed Dec 30, 2011
1 parent 5aa733c commit 467bb93
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
9 changes: 6 additions & 3 deletions client/config.js
Expand Up @@ -2,9 +2,12 @@ var enableSound = true; // this is not constant! may change during execution of
var keyCodeLeft = 37; // left arrow button
var keyCodeRight = 39; // right arrow button
var chatSendKeyCode = 13; // enter
var serverURL = (location.href.indexOf('localhost') != -1) ?
"ws://localhost:" + location.href.substr(location.href.lastIndexOf(':') + 1) :
"ws://marcusklaas.nl:7681"; // websocket game server

var serverURL = "ws://marcusklaas.nl:7681"; // websocket game server
if(location.href.indexOf('localhost') != -1)
serverURL = "ws://localhost:" + location.href.substr(location.href.lastIndexOf(':') + 1);
else if(location.href.indexOf('82.161') != -1)
serverURL = "ws://82.161.20.2:7681";

var gapAlpha = 0.2;
var lineWidth = 3; // only visual, does not influence collisions
Expand Down
19 changes: 12 additions & 7 deletions client/game.js
Expand Up @@ -382,10 +382,12 @@ GameEngine.prototype.syncWithServer = function() {
GameEngine.prototype.doTick = function() {
var player = this.players[0];

this.tick++;

if(!player.alive)
return;

player.simulate(this.tick, ++this.tick, player.context, null);
player.simulate(this.tick - 1, this.tick, player.context, null);

if(pencilGame)
this.pencil.doTick();
Expand Down Expand Up @@ -491,11 +493,11 @@ GameEngine.prototype.realStart = function() {
this.baseContext.clearRect(0, 0, this.width, this.height);
this.audioController.playSound('gameStart');
this.gameState = 'playing';
var tellert = 0;

var self = this;
var gameloop = function() {
var timeOut;
var tellert = 0;

do {
if(self.gameState != 'playing' && self.gameState != 'watching')
Expand Down Expand Up @@ -599,6 +601,7 @@ function Player(color, local) {
this.lca = 0; // last confirmed angle
this.lctick = 0; // game tick of last confirmed location
this.lcturn = 0;
this.lvelocity = 0;
this.color = color;
this.turn = 0; // -1 is turn left, 0 is straight, 1 is turn right
this.game = null; // to which game does this player belong
Expand Down Expand Up @@ -650,13 +653,15 @@ Player.prototype.steer = function(obj) {
this.y = this.lcy;
this.angle = this.lca;
this.turn = this.lcturn;
this.velocity = this.lvelocity;
this.simulate(this.lctick, obj.tick, this.game.baseContext, this.baseQueue);
this.turn = obj.turn;
this.baseQueue = [];
this.lcx = this.x;
this.lcy = this.y;
this.lca = this.angle;
this.lcturn = this.turn;
this.lcturn = this.turn;
this.lvelocity = this.velocity;
this.lctick = obj.tick;

/* clear this players canvas and run extrapolation on this player's
Expand Down Expand Up @@ -723,13 +728,13 @@ Player.prototype.simulate = function(startTick, endTick, ctx, queue) {
this.x += this.velocity * step * cos;
this.y += this.velocity * step * sin;

/* zo weer weg -- ff uitgezet want bron van syncproblemen
// zo weer weg -- ff uitgezet want bron van syncproblemen
var a = 70/2;
this.velocity += Math.cos(this.angle) * a / 1000 * simStep;
if(this.velocity < 70)
this.velocity = 70;
else if(this.velocity > 140)
this.velocity = 140; */
else if(this.velocity > 105)
this.velocity = 105;

ctx.lineTo(this.x, this.y);
}
Expand All @@ -738,7 +743,7 @@ Player.prototype.simulate = function(startTick, endTick, ctx, queue) {
}

Player.prototype.initialise = function(x, y, angle, holeStart) {
this.velocity = this.game.velocity;
this.lvelocity = this.velocity = this.game.velocity;
this.turnSpeed = this.game.turnSpeed;
this.holeStart = holeStart;
this.holeSize = this.game.holeSize;
Expand Down
32 changes: 19 additions & 13 deletions test-server/game.c
Expand Up @@ -323,7 +323,7 @@ int lineboxcollision(struct seg *seg, int left, int bottom, int right, int top)
// returns 1 in case of collision, 0 other wise
// TODO: it would be super nice if we would cut of the latter part of the segment
// if it intersects an existing segment
int addsegment(struct game *gm, struct seg *seg) {
int addsegment(struct game *gm, struct seg *seg, int checkcollision) {
int left_tile, right_tile, bottom_tile, top_tile, swap, collision = 0;
struct seg *current, *copy;

Expand Down Expand Up @@ -354,14 +354,15 @@ int addsegment(struct game *gm, struct seg *seg) {
(i + 1) * gm->tilew, (j + 1) * gm->tileh))
continue;

for(current = gm->seg[gm->htiles * j + i]; current; current = current->nxt)
if(segcollision(current, seg)) {
if(DEBUG_MODE) {
printseg(current);printf(" collided with ");printseg(seg);printf("\n");
if(checkcollision)
for(current = gm->seg[gm->htiles * j + i]; current; current = current->nxt)
if(segcollision(current, seg)) {
if(DEBUG_MODE) {
printseg(current);printf(" collided with ");printseg(seg);printf("\n");
}
collision = 1;
break;
}
collision = 1;
break;
}

copy = smalloc(sizeof(struct seg));
memcpy(copy, seg, sizeof(struct seg));
Expand Down Expand Up @@ -402,12 +403,12 @@ int simuser(struct user *usr, int tick) {
usr->y += sin(usr->angle) * usr->v * TICK_LENGTH / 1000.0;

// zo weer weg
/*float a = 70.0/2;
float a = 70.0/2;
usr->v += cos(usr->angle) * a / 1000.0 * TICK_LENGTH;
if(usr->v < 70)
usr->v = 70;
else if(usr->v > 140)
usr->v = 140;*/
else if(usr->v > 105)
usr->v = 105;

// check if usr in a hole. hole starts _AFTER_ hstart
if(tick > usr->hstart
Expand All @@ -421,7 +422,7 @@ int simuser(struct user *usr, int tick) {
newseg->x2 = usr->x;
newseg->y2 = usr->y;

return addsegment(usr->gm, newseg);
return addsegment(usr->gm, newseg, 1);
}

// send message to group: this player died
Expand Down Expand Up @@ -571,6 +572,7 @@ static void resetGameChatCounters(struct game *gm) {
void mainloop() {
int sleepuntil, resetChat = !(serverticks % SPAM_CHECK_INTERVAL);
struct game *gm, *nxtgm;
static int lastheavyloadmsg;

while(1) {
for(gm = headgame; gm; gm = nxtgm) {
Expand All @@ -586,6 +588,10 @@ void mainloop() {
resetGameChatCounters(lobby);

sleepuntil = ++serverticks * TICK_LENGTH;
if(sleepuntil < servermsecs() - 5 * TICK_LENGTH && servermsecs() - lastheavyloadmsg > 1000){
printf("server is under heavy load! %d msec behind on schedule!\n", -sleepuntil);
lastheavyloadmsg = servermsecs();
}
do{
libwebsocket_service(ctx, max(0, sleepuntil - servermsecs()));
}while(sleepuntil - servermsecs() > 0);
Expand Down Expand Up @@ -778,7 +784,7 @@ struct seg *copyseg(struct seg *a) {
void simpencil(struct pencil *p) {
if(p->psegtail && p->psegtail->tick == p->usr->gm->tick) {
struct pencilseg *tail = p->psegtail;
addsegment(p->usr->gm, copyseg(&tail->seg));
addsegment(p->usr->gm, copyseg(&tail->seg), 0);
if(tail->prev) {
tail->prev->nxt = 0;
p->psegtail = tail->prev;
Expand Down

0 comments on commit 467bb93

Please sign in to comment.