mirror of https://github.com/dirtbags/tanks.git
Fix all 3 known bugs
* Sensor sometimes triggers when tank directly behind it * Sensor range 0 screws up sensor order in canvas * Summary not sorted
This commit is contained in:
parent
a6a631e067
commit
adfc19fc4c
4
ctanks.c
4
ctanks.c
|
@ -131,7 +131,7 @@ tanks_fire_cannon(struct tanks_game *game,
|
|||
rpos[0] = vector[0];
|
||||
rpos[1] = vector[1];
|
||||
rotate_point(-theta, rpos);
|
||||
if (fabsf(rpos[1]) < TANK_RADIUS) {
|
||||
if ((rpos[0] > 0) && (fabsf(rpos[1]) < TANK_RADIUS)) {
|
||||
that->killer = this;
|
||||
that->cause_death = "shot";
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ tanks_sensor_calc(struct tanks_game *game,
|
|||
/* Now check if the edge of the arc intersects the tank. Do this
|
||||
just like with firing. */
|
||||
rotate_point(this->sensors[i].width / -2, rpos);
|
||||
if (fabsf(rpos[1]) < TANK_RADIUS) {
|
||||
if ((rpos[0] > 0) && (fabsf(rpos[1]) < TANK_RADIUS)) {
|
||||
this->sensors[i].triggered = 1;
|
||||
}
|
||||
}
|
||||
|
|
15
dump.h
15
dump.h
|
@ -1,6 +1,8 @@
|
|||
#ifndef __DUMP_H__
|
||||
|
||||
/* Debugging help */
|
||||
#include <stdio.h>
|
||||
|
||||
/* Debugging */
|
||||
#define DUMPf(fmt, args...) fprintf(stderr, "%s:%s:%d " fmt "\n", __FILE__, __FUNCTION__, __LINE__, ##args)
|
||||
#define DUMP() DUMPf("")
|
||||
#define DUMP_d(v) DUMPf("%s = %d", #v, v)
|
||||
|
@ -11,4 +13,15 @@
|
|||
#define DUMP_p(v) DUMPf("%s = %p", #v, v)
|
||||
#define DUMP_xy(v) DUMPf("%s = (%f, %f)", #v, v[0], v[1]);
|
||||
|
||||
/* Tektronix 4014 drawing */
|
||||
#define TEK_ENABLE "\033[?38h"
|
||||
#define TEK_DISABLE "\033\003"
|
||||
#define TEK(fmt, args...) fprintf(stderr, TEK_ENABLE fmt TEK_DISABLE, ##args)
|
||||
#define TEK_coord(x, y) ((int)y/32)+32,((int)y%32)+96,((int)x/32)+32,((int)x%32)+64
|
||||
|
||||
#define TEK_cls() TEK("\033\014")
|
||||
#define TEK_line(x1, y1, x2, y2) TEK("\035%c%c%c%c%c%c%c%c", TEK_coord(x1, y1), TEK_coord(x2, y2))
|
||||
#define TEK_point(x, y) TEK("\034%c%c%c%c", TEK_coord(x, y))
|
||||
#define TEK_text(x, y, s) TEK("\035%c%c%c%c\037%s", TEK_coord(x, y), s)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -361,14 +361,15 @@ print_header(FILE *f,
|
|||
struct sensor *s = &(tanks[i].sensors[j]);
|
||||
|
||||
if (! s->range) {
|
||||
continue;
|
||||
}
|
||||
fprintf(f, "0,");
|
||||
} else {
|
||||
fprintf(f, "[%d,%.2f,%.2f,%d],",
|
||||
(int)(s->range),
|
||||
s->angle,
|
||||
s->width,
|
||||
s->turret);
|
||||
}
|
||||
}
|
||||
fprintf(f, "]],\n");
|
||||
}
|
||||
fprintf(f, "],[\n");
|
||||
|
@ -535,6 +536,7 @@ main(int argc, char *argv[])
|
|||
mytanks[i].position[1] = (float)y;
|
||||
mytanks[i].angle = deg2rad(rand() % 360);
|
||||
mytanks[i].turret.current = deg2rad(rand() % 360);
|
||||
mytanks[i].turret.desired = mytanks[i].turret.current;
|
||||
|
||||
x += SPACING;
|
||||
if (x > game.size[0]) {
|
||||
|
|
|
@ -55,8 +55,8 @@ BEGIN {
|
|||
# Find highest score
|
||||
maxscore = -1;
|
||||
for (p in scores) {
|
||||
if (p > maxscore) {
|
||||
maxscore = p;
|
||||
if (int(p) > maxscore) {
|
||||
maxscore = int(p);
|
||||
}
|
||||
}
|
||||
if (maxscore == -1) {
|
||||
|
|
5
tanks.js
5
tanks.js
|
@ -26,6 +26,10 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
this.sensors = new Array();
|
||||
for (i in sensors) {
|
||||
var s = sensors[i];
|
||||
|
||||
if (! s) {
|
||||
this.sensors[i] = [0,0,0,0];
|
||||
} else {
|
||||
// r, angle, width, turret
|
||||
this.sensors[i] = new Array();
|
||||
this.sensors[i][0] = s[0];
|
||||
|
@ -36,6 +40,7 @@ function Tank(ctx, width, height, color, sensors) {
|
|||
maxlen = s[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set up our state, for later interleaved draw requests
|
||||
this.set_state = function(x, y, rotation, turret, flags, sensor_state) {
|
||||
|
|
Loading…
Reference in New Issue