Fix initial positions

This commit is contained in:
Neale Pickett 2010-07-14 16:37:24 -06:00
parent c0d0d2de74
commit 499aeb9455
2 changed files with 56 additions and 73 deletions

View File

@ -1,28 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Tank Game</title>
<script type="application/javascript" src="tanks.js"></script>
<style type="text/css">
body {
background-color: #444444;
color: white;
}
</style>
<script type="application/javascript">
function go() {
start(
// Start JSON data
divert(1)
// end JSON data
);
}
window.onload = go;
</script>
</head>
<body>
<div id="game_box"><canvas id="battlefield"></canvas></div>
<p><span id="fps">0</span> fps</p>
</body>
</html>
divert(0)

View File

@ -381,6 +381,59 @@ print_footer(FILE *f)
fprintf(f, "]]\n");
}
void
print_rounds(FILE *f,
struct tanks_game *game,
struct forftank *forftanks,
struct tank *tanks,
int ntanks)
{
int i;
int alive;
/* Run rounds */
alive = ntanks;
for (i = 0; (alive > 1) && (i < ROUNDS); i += 1) {
int j;
tanks_run_turn(&game, mytanks, ntanks);
fprintf(stdout, "[\n");
alive = ntanks;
for (j = 0; j < ntanks; j += 1) {
struct tank *t = &(mytanks[j]);
if (t->killer) {
alive -= 1;
fprintf(stdout, " 0,\n");
} else {
int k;
int flags = 0;
int sensors = 0;
for (k = 0; k < TANK_MAX_SENSORS; k += 1) {
if (t->sensors[k].triggered) {
sensors |= (1 << k);
}
}
if (t->turret.firing) {
flags |= 1;
}
if (t->led) {
flags |= 2;
}
fprintf(stdout, " [%d,%d,%.2f,%.2f,%d,%d],\n",
(int)(t->position[0]),
(int)(t->position[1]),
t->angle,
t->turret.current,
flags,
sensors);
}
}
fprintf(stdout, "],\n");
}
}
int
main(int argc, char *argv[])
{
@ -391,7 +444,6 @@ main(int argc, char *argv[])
int order[MAX_TANKS];
int ntanks = 0;
int i;
int alive;
lenv[0].name = NULL;
lenv[0].proc = NULL;
@ -457,8 +509,8 @@ main(int argc, char *argv[])
/* Position tanks */
{
int x = 50;
int y = 50;
int x = SPACING/2;
int y = SPACING/2;
for (i = 0; i < ntanks; i += 1) {
mytanks[i].position[0] = (float)x;
@ -475,48 +527,7 @@ main(int argc, char *argv[])
}
print_header(stdout, &game, myftanks, mytanks, ntanks);
/* Run rounds */
alive = ntanks;
for (i = 0; (alive > 1) && (i < ROUNDS); i += 1) {
int j;
tanks_run_turn(&game, mytanks, ntanks);
fprintf(stdout, "[\n");
alive = ntanks;
for (j = 0; j < ntanks; j += 1) {
struct tank *t = &(mytanks[j]);
if (t->killer) {
alive -= 1;
fprintf(stdout, " 0,\n");
} else {
int k;
int flags = 0;
int sensors = 0;
for (k = 0; k < TANK_MAX_SENSORS; k += 1) {
if (t->sensors[k].triggered) {
sensors |= (1 << k);
}
}
if (t->turret.firing) {
flags |= 1;
}
if (t->led) {
flags |= 2;
}
fprintf(stdout, " [%d,%d,%.2f,%.2f,%d,%d],\n",
(int)(t->position[0]),
(int)(t->position[1]),
t->angle,
t->turret.current,
flags,
sensors);
}
}
fprintf(stdout, "],\n");
}
print_rounds(stdout, &game, myftanks, mytanks, ntanks);
print_footer(stdout);