mirror of https://github.com/dirtbags/tanks.git
store/show cannon fire on the turn of death
This commit is contained in:
parent
601cf2b003
commit
223a068d34
47
forftanks.c
47
forftanks.c
|
@ -422,33 +422,32 @@ print_rounds(FILE *f,
|
|||
for (j = 0; j < ntanks; j += 1) {
|
||||
struct tank *t = &(tanks[j]);
|
||||
|
||||
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;
|
||||
}
|
||||
if (t->killer) {
|
||||
alive -= 1;
|
||||
fprintf(f, " 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(f, " [%d,%d,%.2f,%.2f,%d,%d],\n",
|
||||
(int)t->position[0],
|
||||
(int)(t->position[1]),
|
||||
t->angle,
|
||||
t->turret.current,
|
||||
flags,
|
||||
sensors);
|
||||
flags |= 4;
|
||||
}
|
||||
fprintf(f, " [%d,%d,%.2f,%.2f,%d,%d],\n",
|
||||
(int)t->position[0],
|
||||
(int)(t->position[1]),
|
||||
t->angle,
|
||||
t->turret.current,
|
||||
flags,
|
||||
sensors);
|
||||
}
|
||||
fprintf(f, "],\n");
|
||||
}
|
||||
|
|
36
jstanks.js
36
jstanks.js
|
@ -746,21 +746,6 @@ var resetTanks = function() {
|
|||
|
||||
var activeTanks = 0;
|
||||
for (var i = 0; i < ftanks.length; i++) {
|
||||
if (ftanks[i].killer) {
|
||||
tanks[i].draw_crater();
|
||||
} else {
|
||||
activeTanks++;
|
||||
}
|
||||
}
|
||||
if (activeTanks < 2) {
|
||||
clearInterval(interval);
|
||||
interval = null;
|
||||
}
|
||||
|
||||
for (var i = 0; i < ftanks.length; i++) {
|
||||
if (ftanks[i].killer) {
|
||||
continue;
|
||||
}
|
||||
var flags = 0;
|
||||
if (ftanks[i].turret.firing) {
|
||||
flags |= 1;
|
||||
|
@ -768,6 +753,11 @@ var resetTanks = function() {
|
|||
if (ftanks[i].led) {
|
||||
flags |= 2;
|
||||
}
|
||||
if (ftanks[i].killer) {
|
||||
flags |= 4;
|
||||
} else {
|
||||
activeTanks++;
|
||||
}
|
||||
var sensor_state = 0;
|
||||
for (var j = 0; j < ftanks[i].sensors.length; j++) {
|
||||
if (ftanks[i].sensors[j].triggered) {
|
||||
|
@ -775,13 +765,23 @@ var resetTanks = function() {
|
|||
}
|
||||
}
|
||||
tanks[i].set_state(ftanks[i].position[0], ftanks[i].position[1], ftanks[i].angle, ftanks[i].turret.current, flags, sensor_state);
|
||||
}
|
||||
|
||||
if (activeTanks < 2) {
|
||||
// we're done
|
||||
clearInterval(interval);
|
||||
interval = null;
|
||||
}
|
||||
|
||||
for (var i = 0; i < ftanks.length; i++) {
|
||||
tanks[i].draw_crater();
|
||||
}
|
||||
|
||||
for (var i = 0; i < tanks.length; i++) {
|
||||
tanks[i].draw_wrap_sensors();
|
||||
}
|
||||
|
||||
for (var i = 0; i < tanks.length; i++) {
|
||||
if (ftanks[i].killer) {
|
||||
continue;
|
||||
}
|
||||
tanks[i].draw_tank();
|
||||
}
|
||||
}
|
||||
|
|
50
tanks.js
50
tanks.js
|
@ -22,6 +22,8 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
this.rotation = 0;
|
||||
this.turret = 0;
|
||||
|
||||
this.dead = 0;
|
||||
|
||||
// Do all the yucky math up front
|
||||
this.sensors = new Array();
|
||||
for (i in sensors) {
|
||||
|
@ -52,10 +54,21 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
this.fire = 5;
|
||||
}
|
||||
this.led = flags & 2;
|
||||
if (flags & 4) {
|
||||
this.dead++;
|
||||
}
|
||||
this.sensor_state = sensor_state;
|
||||
}
|
||||
|
||||
this.draw_crater = function() {
|
||||
if (!this.dead) {
|
||||
return;
|
||||
}
|
||||
if (this.fire == 5) {
|
||||
// one frame of cannon fire
|
||||
this.draw_cannon();
|
||||
this.fire = 0;
|
||||
}
|
||||
var points = 7;
|
||||
var angle = Math.PI / points;
|
||||
|
||||
|
@ -82,6 +95,9 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
}
|
||||
|
||||
this.draw_sensors = function() {
|
||||
if (this.dead) {
|
||||
return;
|
||||
}
|
||||
ctx.save();
|
||||
ctx.translate(this.x, this.y);
|
||||
ctx.rotate(this.rotation);
|
||||
|
@ -108,6 +124,9 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
}
|
||||
|
||||
this.draw_tank = function() {
|
||||
if (this.dead) {
|
||||
return;
|
||||
}
|
||||
ctx.save();
|
||||
ctx.translate(this.x, this.y);
|
||||
ctx.rotate(this.rotation);
|
||||
|
@ -119,8 +138,7 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
ctx.fillRect(-7, 4, 15, 5);
|
||||
ctx.rotate(this.turret);
|
||||
if (this.fire) {
|
||||
ctx.fillStyle = ("rgba(255,255,64," + this.fire/5 + ")");
|
||||
ctx.fillRect(0, -1, 45, 2);
|
||||
this.draw_cannon();
|
||||
this.fire -= 1;
|
||||
} else {
|
||||
if (this.led) {
|
||||
|
@ -134,6 +152,11 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
ctx.restore();
|
||||
}
|
||||
|
||||
this.draw_cannon = function() {
|
||||
ctx.fillStyle = ("rgba(255,255,64," + this.fire/5 + ")");
|
||||
ctx.fillRect(0, -1, 45, 2);
|
||||
}
|
||||
|
||||
this.draw_wrap_sensors = function() {
|
||||
var orig_x = this.x;
|
||||
var orig_y = this.y;
|
||||
|
@ -190,28 +213,25 @@ function start(id, game) {
|
|||
canvas.width = canvas.width;
|
||||
turn = turns[idx];
|
||||
|
||||
// Draw craters first
|
||||
// Update and draw craters first
|
||||
for (i in turn) {
|
||||
t = turn[i];
|
||||
if (! t) {
|
||||
tanks[i].draw_crater();
|
||||
if (!t) {
|
||||
// old data, force-kill it
|
||||
tanks[i].fire = 0;
|
||||
tanks[i].dead = 5;
|
||||
} else {
|
||||
tanks[i].set_state(t[0], t[1], t[2], t[3], t[4], t[5]);
|
||||
}
|
||||
tanks[i].draw_crater();
|
||||
}
|
||||
// Then sensors
|
||||
for (i in turn) {
|
||||
t = turn[i];
|
||||
if (t) {
|
||||
// Surely there's a better way to do this.
|
||||
tanks[i].set_state(t[0], t[1], t[2], t[3], t[4], t[5]);
|
||||
tanks[i].draw_wrap_sensors();
|
||||
}
|
||||
tanks[i].draw_wrap_sensors();
|
||||
}
|
||||
// Then tanks
|
||||
for (i in turn) {
|
||||
t = turn[i];
|
||||
if (t) {
|
||||
tanks[i].draw_tank()
|
||||
}
|
||||
tanks[i].draw_tank()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue