Merge branch 'master' into collision

This commit is contained in:
Richard Harrington 2013-08-30 00:17:11 -04:00
commit febad2b5f0
3 changed files with 31 additions and 26 deletions

View File

@ -5,8 +5,6 @@
var STARTING_FAST_FORWARD = 15;
var FPS = 60;
var ROBOT_COLORS = ["#fa2d0b", "#0bfaf7", "#faf20b", "#e312f0", "#4567fb"];
var GUN_LENGTH = 10;
var GUN_WIDTH = 3;
var SHELL_RADIUS = 2;
var SHELL_COLOR = "#ffffff";
@ -14,15 +12,6 @@
// TODO: Get rid of this.
var worlds;
// TODO: This game info should probably come from the server
// in a preliminary ajax call.
var GAME_INFO = {
robotRadius: 7,
robotXMax: 256.0,
robotYMax: 256.0,
gameSecondsPerTick: 0.0333333333333333333333333
}
var Geom = (function() {
var degreesToRadians = function(angle) {
return angle * Math.PI / 180;
@ -80,11 +69,16 @@
$.getJSON('init?programs=' + encodeURIComponent(programs))
.done(function(data) {
gameId = data['id'];
var gameInfo = data['game-info'];
fetch(function() {
currentWorld = queue.peek();
// TODO: Pass into this callback actual game info from the server.
// This returning of local constants is only temporary.
constructorCallback(GAME_INFO);
console.log(gameInfo)
constructorCallback({
robotRadius: gameInfo["ROBOT-RADIUS"],
robotRangeX: gameInfo["ROBOT-RANGE-X"],
robotRangeY: gameInfo["ROBOT-RANGE-Y"],
gameSecondsPerTick: gameInfo["*GAME-SECONDS-PER-TICK*"]
});
});
});
@ -100,9 +94,9 @@
var Animation = function(el, sounds, gameInfo) {
var width = parseInt(el.width);
var height = parseInt(el.height);
var roomForRobots = GAME_INFO.robotRadius * 2;
var arenaWidth = GAME_INFO.robotXMax + roomForRobots;
var arenaHeight = GAME_INFO.robotYMax + roomForRobots;
var roomForRobots = gameInfo.robotRadius * 2;
var arenaWidth = gameInfo.robotRangeX + roomForRobots;
var arenaHeight = gameInfo.robotRangeY + roomForRobots;
var scaleFactorX = width / arenaWidth;
var scaleFactorY = height / arenaHeight;
var scaleX = function(x) {
@ -112,10 +106,10 @@
return Math.round(y * scaleFactorY);
}
var offsetX = function(x) {
return scaleX(GAME_INFO.robotRadius + x);
return scaleX(gameInfo.robotRadius + x);
}
var offsetY = function(y) {
return scaleY(GAME_INFO.robotRadius + y);
return scaleY(gameInfo.robotRadius + y);
}
// TODO: regularize this here and on the server so that
@ -123,10 +117,10 @@
// like why are we using scaleFactorX here and don't need
// scaleFactorY?
var robotDisplayRadius = scaleX(GAME_INFO.robotRadius);
var shellDisplayRadius = scaleX(SHELL_RADIUS);
var gunDisplayLength = scaleX(GUN_LENGTH);
var gunDisplayWidth = scaleY(GUN_WIDTH);
var robotDisplayRadius = scaleX(gameInfo.robotRadius);
var shellDisplayRadius = scaleX(gameInfo.robotRadius * 0.3);
var gunDisplayLength = scaleX(gameInfo.robotRadius * 1.4);
var gunDisplayWidth = scaleY(gameInfo.robotRadius * 0.5);
var ctx = el.getContext('2d');
ctx.lineCap = 'square';
@ -298,6 +292,7 @@
setTimeout(function() {
$('#canvas').css({opacity: 1});
setTimeout(function() {
console.log(gameInfo);
startGame(gameInfo);
}, 500);
}, 500);

View File

@ -2,7 +2,7 @@
; MAX_ACCEL is in decimeters per second per second.
(def MAX-ACCEL 4.0)
(def ^:dynamic *GAME-SECONDS-PER-TICK* 0.03)
(def ^:dynamic *GAME-SECONDS-PER-TICK* 0.033)
; ROBOT-RANGE-X and -Y are in meters
(def ROBOT-RANGE-X 256.0)
@ -12,3 +12,6 @@
; SHELL-SPEED is in meters per second
(def SHELL-SPEED 25.0)
; Robot-radius is in meters.
(def ROBOT-RADIUS 7.0)

View File

@ -1,6 +1,7 @@
(ns robotwar.handler
(:use [compojure.core]
[clojure.string :only [split]])
[clojure.string :only [split]]
[robotwar.constants])
(:require [compojure.handler :as handler]
[ring.middleware.json :as middleware]
[ring.util.response :as response]
@ -9,6 +10,11 @@
[robotwar.world :as world]
[robotwar.browser :as browser]))
(def game-info {:ROBOT-RADIUS ROBOT-RADIUS
:ROBOT-RANGE-X ROBOT-RANGE-X
:ROBOT-RANGE-Y ROBOT-RANGE-Y
:*GAME-SECONDS-PER-TICK* *GAME-SECONDS-PER-TICK*})
(defn parse-program-names
"takes a string parameter from the browser and returns a seqence
of program keys"
@ -53,7 +59,8 @@
{:names (map name (keys source-programs/programs))}))
(GET "/init" [programs] (let [next-id (:next-id @games-store)]
(swap! games-store add-game programs)
(response/response {:id next-id})))
(response/response {:id next-id
:game-info game-info})))
(GET "/worlds/:id/:n" [id n] (response/response (take-drop-send
games-store
(Integer/parseInt id)