Merge branch 'shell'

This commit is contained in:
Richard Harrington 2013-08-21 19:33:30 -04:00
commit 17f913820a
3 changed files with 29 additions and 6 deletions

View File

@ -7,6 +7,8 @@
var ROBOT_COLORS = ["#6aea2a", "#380bfa", "#fa2d0b", "#0bfaf7", "#faf20b"];
var GUN_LENGTH = 14;
var GUN_WIDTH = 3;
var SHELL_RADIUS = 2;
var SHELL_COLOR = "#ffffff";
// TODO: This game info should probably come from the server
// in a preliminary ajax call.
@ -102,6 +104,7 @@
// scaleFactorY?
var robotDisplayRadius = scaleX(GAME_INFO.robotRadius);
var shellDisplayRadius = scaleX(SHELL_RADIUS);
var gunDisplayLength = scaleX(GUN_LENGTH);
var gunDisplayWidth = scaleY(GUN_WIDTH);
@ -131,12 +134,21 @@
drawCircle(x, y, robotDisplayRadius, color);
drawLinePolar(x, y, Geom.degreesToRadians(robot['aim']), gunDisplayLength, color);
}
var drawShell = function(shell) {
var x = scaleX(shell['pos-x']);
var y = scaleY(shell['pos-y']);
drawCircle(x, y, shellDisplayRadius, SHELL_COLOR);
}
var drawWorld = function(world) {
var drawWorld = function(previousWorld, currentWorld) {
ctx.clearRect(0, 0, width, height);
world.robots.forEach(function(robot, idx) {
currentWorld.robots.forEach(function(robot, idx) {
drawRobot(robot, ROBOT_COLORS[idx]);
});
currentWorld.shells.forEach(function(shell) {
drawShell(shell);
});
}
return {
@ -146,7 +158,7 @@
function loop(worlds, interval, callback) {
(function continueLoop(tick) {
if (worlds.isEmpty()) {
if (worlds.finished()) {
return;
}
callback();
@ -179,7 +191,7 @@
});
loop(worlds, frameDuration, function() {
debugAnimationCounter++;
canvas.drawWorld(worlds.getCurrentWorld());
canvas.drawWorld(worlds.getPreviousWorld(), worlds.getCurrentWorld());
});
loop(worlds, 1000, function() {
debugSecondsCounter++;

View File

@ -11,7 +11,8 @@
; TODO: have this source-code-picking be done in requests from the UI
; in the browser, not hard-coded here.
(def progs
(repeat 3 (:moving-to-spot source-programs/programs)))
(conj (repeat 3 (:moving-to-spot source-programs/programs))
(:shooter source-programs/programs)))
(defn add-game
"a function to update the games store agent state.

View File

@ -64,4 +64,14 @@
MOVEY
B - Y TO SPEEDY ; Take distance from destination in meters and use
; it to set SPEEDY, which is measured in decimeters/second.
ENDSUB "})
ENDSUB "
:shooter
"
90 TO AIM
Y TO RANDOM
RANDOM TO S
SHOOT
; S TO SHOT
GOTO SHOOT "
})