mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-05-28 23:41:31 +00:00
loading gameInfo now from server, instead of hard-coding from browser
This commit is contained in:
parent
367aaa8c3f
commit
537d31b99b
|
@ -12,15 +12,6 @@
|
||||||
// TODO: Get rid of this.
|
// TODO: Get rid of this.
|
||||||
var worlds;
|
var worlds;
|
||||||
|
|
||||||
// TODO: This game info should probably come from the server
|
|
||||||
// in a preliminary ajax call.
|
|
||||||
var GAME_INFO = {
|
|
||||||
robotRadius: 7,
|
|
||||||
robotRangeX: 256.0,
|
|
||||||
robotRangeY: 256.0,
|
|
||||||
gameSecondsPerTick: 0.0333333333333333333333333
|
|
||||||
}
|
|
||||||
|
|
||||||
var Geom = (function() {
|
var Geom = (function() {
|
||||||
var degreesToRadians = function(angle) {
|
var degreesToRadians = function(angle) {
|
||||||
return angle * Math.PI / 180;
|
return angle * Math.PI / 180;
|
||||||
|
@ -78,11 +69,16 @@
|
||||||
$.getJSON('init?programs=' + encodeURIComponent(programs))
|
$.getJSON('init?programs=' + encodeURIComponent(programs))
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
gameId = data['id'];
|
gameId = data['id'];
|
||||||
|
var gameInfo = data['game-info'];
|
||||||
fetch(function() {
|
fetch(function() {
|
||||||
currentWorld = queue.peek();
|
currentWorld = queue.peek();
|
||||||
// TODO: Pass into this callback actual game info from the server.
|
console.log(gameInfo)
|
||||||
// This returning of local constants is only temporary.
|
constructorCallback({
|
||||||
constructorCallback(GAME_INFO);
|
robotRadius: gameInfo["ROBOT-RADIUS"],
|
||||||
|
robotRangeX: gameInfo["ROBOT-RANGE-X"],
|
||||||
|
robotRangeY: gameInfo["ROBOT-RANGE-Y"],
|
||||||
|
gameSecondsPerTick: gameInfo["*GAME-SECONDS-PER-TICK*"]
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -98,9 +94,9 @@
|
||||||
var Animation = function(el, sounds, gameInfo) {
|
var Animation = function(el, sounds, gameInfo) {
|
||||||
var width = parseInt(el.width);
|
var width = parseInt(el.width);
|
||||||
var height = parseInt(el.height);
|
var height = parseInt(el.height);
|
||||||
var roomForRobots = GAME_INFO.robotRadius * 2;
|
var roomForRobots = gameInfo.robotRadius * 2;
|
||||||
var arenaWidth = GAME_INFO.robotRangeX + roomForRobots;
|
var arenaWidth = gameInfo.robotRangeX + roomForRobots;
|
||||||
var arenaHeight = GAME_INFO.robotRangeY + roomForRobots;
|
var arenaHeight = gameInfo.robotRangeY + roomForRobots;
|
||||||
var scaleFactorX = width / arenaWidth;
|
var scaleFactorX = width / arenaWidth;
|
||||||
var scaleFactorY = height / arenaHeight;
|
var scaleFactorY = height / arenaHeight;
|
||||||
var scaleX = function(x) {
|
var scaleX = function(x) {
|
||||||
|
@ -110,10 +106,10 @@
|
||||||
return Math.round(y * scaleFactorY);
|
return Math.round(y * scaleFactorY);
|
||||||
}
|
}
|
||||||
var offsetX = function(x) {
|
var offsetX = function(x) {
|
||||||
return scaleX(GAME_INFO.robotRadius + x);
|
return scaleX(gameInfo.robotRadius + x);
|
||||||
}
|
}
|
||||||
var offsetY = function(y) {
|
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
|
// TODO: regularize this here and on the server so that
|
||||||
|
@ -121,10 +117,10 @@
|
||||||
// like why are we using scaleFactorX here and don't need
|
// like why are we using scaleFactorX here and don't need
|
||||||
// scaleFactorY?
|
// scaleFactorY?
|
||||||
|
|
||||||
var robotDisplayRadius = scaleX(GAME_INFO.robotRadius);
|
var robotDisplayRadius = scaleX(gameInfo.robotRadius);
|
||||||
var shellDisplayRadius = scaleX(GAME_INFO.robotRadius * 0.3);
|
var shellDisplayRadius = scaleX(gameInfo.robotRadius * 0.3);
|
||||||
var gunDisplayLength = scaleX(GAME_INFO.robotRadius * 1.4);
|
var gunDisplayLength = scaleX(gameInfo.robotRadius * 1.4);
|
||||||
var gunDisplayWidth = scaleY(GAME_INFO.robotRadius * 0.5);
|
var gunDisplayWidth = scaleY(gameInfo.robotRadius * 0.5);
|
||||||
|
|
||||||
var ctx = el.getContext('2d');
|
var ctx = el.getContext('2d');
|
||||||
ctx.lineCap = 'square';
|
ctx.lineCap = 'square';
|
||||||
|
@ -296,6 +292,7 @@
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$('#canvas').css({opacity: 1});
|
$('#canvas').css({opacity: 1});
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
console.log(gameInfo);
|
||||||
startGame(gameInfo);
|
startGame(gameInfo);
|
||||||
}, 500);
|
}, 500);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
; MAX_ACCEL is in decimeters per second per second.
|
; MAX_ACCEL is in decimeters per second per second.
|
||||||
(def MAX-ACCEL 4.0)
|
(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
|
; ROBOT-RANGE-X and -Y are in meters
|
||||||
(def ROBOT-RANGE-X 256.0)
|
(def ROBOT-RANGE-X 256.0)
|
||||||
|
@ -12,3 +12,6 @@
|
||||||
|
|
||||||
; SHELL-SPEED is in meters per second
|
; SHELL-SPEED is in meters per second
|
||||||
(def SHELL-SPEED 25.0)
|
(def SHELL-SPEED 25.0)
|
||||||
|
|
||||||
|
; Robot-radius is in meters.
|
||||||
|
(def ROBOT-RADIUS 7.0)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns robotwar.handler
|
(ns robotwar.handler
|
||||||
(:use [compojure.core]
|
(:use [compojure.core]
|
||||||
[clojure.string :only [split]])
|
[clojure.string :only [split]]
|
||||||
|
[robotwar.constants])
|
||||||
(:require [compojure.handler :as handler]
|
(:require [compojure.handler :as handler]
|
||||||
[ring.middleware.json :as middleware]
|
[ring.middleware.json :as middleware]
|
||||||
[ring.util.response :as response]
|
[ring.util.response :as response]
|
||||||
|
@ -9,6 +10,11 @@
|
||||||
[robotwar.world :as world]
|
[robotwar.world :as world]
|
||||||
[robotwar.browser :as browser]))
|
[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
|
(defn parse-program-names
|
||||||
"takes a string parameter from the browser and returns a seqence
|
"takes a string parameter from the browser and returns a seqence
|
||||||
of program keys"
|
of program keys"
|
||||||
|
@ -53,7 +59,8 @@
|
||||||
{:names (map name (keys source-programs/programs))}))
|
{:names (map name (keys source-programs/programs))}))
|
||||||
(GET "/init" [programs] (let [next-id (:next-id @games-store)]
|
(GET "/init" [programs] (let [next-id (:next-id @games-store)]
|
||||||
(swap! games-store add-game programs)
|
(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
|
(GET "/worlds/:id/:n" [id n] (response/response (take-drop-send
|
||||||
games-store
|
games-store
|
||||||
(Integer/parseInt id)
|
(Integer/parseInt id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user