mirror of https://github.com/dirtbags/tanks.git
Fix initial positions
This commit is contained in:
parent
c0d0d2de74
commit
499aeb9455
|
@ -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)
|
101
run-tanks.c
101
run-tanks.c
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue