aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-09-28 17:18:54 +0000
committerrodri <rgl@antares-labs.eu>2023-09-28 17:18:54 +0000
commit2834b114cfe13279b5742649cc655506c53dde8c (patch)
tree1119cbde5c64c09b311b27f25ab470dbd176044c
parent786f41cb2f7787933a0f939a221728b844776702 (diff)
downloadbattleship-2834b114cfe13279b5742649cc655506c53dde8c.tar.gz
battleship-2834b114cfe13279b5742649cc655506c53dde8c.tar.bz2
battleship-2834b114cfe13279b5742649cc655506c53dde8c.zip
added a border to the boards and corrected a bug when placing a ship.
the bug allowed the player to move the ship when the cursor was outside the board in the negative side of its rframe. by using floor(2) instead of a cast to int the problem is over.
-rw-r--r--bts.c19
-rw-r--r--dat.h10
-rw-r--r--fns.h2
-rw-r--r--util.c8
4 files changed, 23 insertions, 16 deletions
diff --git a/bts.c b/bts.c
index 6e5cd1d..9b036c1 100644
--- a/bts.c
+++ b/bts.c
@@ -19,6 +19,7 @@ enum {
PCBlue,
PCWater,
PCWaves,
+ PCBrown,
PCShadow,
NCOLORS
};
@@ -180,8 +181,8 @@ toboard(Board *b, Point p)
Point2 np;
np = rframexform(rframexform(Pt2(p.x,p.y,1), worldrf), *b);
- np.x = (int)np.x;
- np.y = (int)np.y;
+ np.x = floor(np.x);
+ np.y = floor(np.y);
return np;
}
@@ -308,6 +309,7 @@ drawboard(Image *dst, Board *b)
{
int i, j;
+ border(dst, b->bbox, -Borderwidth, pal[PCBrown], ZP);
for(i = 0; i < MAPW; i++)
for(j = 0; j < MAPH; j++)
drawtile(dst, b, Pt2(i,j,1), b->map[i][j]);
@@ -351,15 +353,15 @@ drawinfo(Image *dst)
string(dst, p, pal[PCWhite], ZP, font, s);
s = "TARGET";
- p = subpt(alienboard.bbox.min, Pt(font->width+2,0));
+ p = subpt(alienboard.bbox.min, Pt(font->width+2+Borderwidth,0));
vstring(dst, p, pal[PCWhite], ZP, font, s);
s = "LOCAL";
- p = Pt(localboard.bbox.max.x+2, localboard.bbox.min.y);
+ p = Pt(localboard.bbox.max.x+2+Borderwidth, localboard.bbox.min.y);
vstring(dst, p, pal[PCWhite], ZP, font, s);
- p = Pt(alienboard.bbox.max.x+2, alienboard.bbox.min.y);
+ p = Pt(alienboard.bbox.max.x+2+Borderwidth, alienboard.bbox.min.y);
vstring(dst, p, pal[PCWhite], ZP, font, game.state == Watching? match.pl[1].uid: oid);
- p = subpt(localboard.bbox.min, Pt(font->width+2,0));
+ p = subpt(localboard.bbox.min, Pt(font->width+2+Borderwidth,0));
vstring(dst, p, pal[PCWhite], ZP, font, game.state == Watching? match.pl[0].uid: uid);
/* TODO make this an info panel and show errors from bad transactions. */
@@ -462,6 +464,7 @@ initpalette(void)
pal[PCWater] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreyblue);
pal[PCWaves] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalebluegreen);
pal[PCBlue] = pal[PCWaves];
+ pal[PCBrown] = eallocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x806000FF);
pal[PCShadow] = eallocimage(display, Rect(0,0,1,1), RGBA32, 1, 0x0000007f);
}
@@ -508,13 +511,13 @@ void
initboards(void)
{
memset(alienboard.map, Twater, MAPW*MAPH);
- alienboard.p = Pt2(Boardmargin,Boardmargin,1);
+ alienboard.p = Pt2(Boardmargin+Borderwidth,Boardmargin+Borderwidth,1);
alienboard.bx = Vec2(TW,0);
alienboard.by = Vec2(0,TH);
alienboard.bbox = Rpt(fromworld(alienboard.p), fromworld(addpt2(alienboard.p, Pt2(TW*MAPW,TH*MAPH,1))));
memset(localboard.map, Twater, MAPW*MAPH);
- localboard.p = addpt2(alienboard.p, Vec2(0,MAPH*TH+TH));
+ localboard.p = addpt2(alienboard.p, Vec2(0,MAPH*TH+Borderwidth+TH+Borderwidth));
localboard.bx = Vec2(TW,0);
localboard.by = Vec2(0,TH);
localboard.bbox = Rpt(fromworld(localboard.p), fromworld(addpt2(localboard.p, Pt2(TW*MAPW,TH*MAPH,1))));
diff --git a/dat.h b/dat.h
index f53caf9..b7fa1f8 100644
--- a/dat.h
+++ b/dat.h
@@ -30,8 +30,12 @@ enum {
TH = TW,
MAPW = 17,
MAPH = MAPW,
- SCRW = Boardmargin+MAPW*TW+Boardmargin,
- SCRH = Boardmargin+MAPH*TH+TH+MAPH*TH+Boardmargin,
+ SCRW = Boardmargin + Borderwidth+MAPW*TW+Borderwidth + Boardmargin,
+ SCRH = Boardmargin+
+ Borderwidth+MAPH*TH+Borderwidth+
+ TH+
+ Borderwidth+MAPH*TH+Borderwidth+
+ Boardmargin,
KB = 1024,
BY2MAP = (TBITS*MAPW*MAPH+7)/8,
@@ -136,7 +140,7 @@ struct Mlist
{
Mentry *entries;
int nentries;
- int filling;
+ int filling; /* lock-alike */
};
struct Menulist
diff --git a/fns.h b/fns.h
index 58ba86e..eb9c5ba 100644
--- a/fns.h
+++ b/fns.h
@@ -21,8 +21,8 @@ int countshipcells(Map*);
int shiplen(int);
char *shipname(int);
char *statename(int);
-int max(int, int);
int min(int, int);
+int max(int, int);
int bitpackmap(uchar*, ulong, Map*);
int bitunpackmap(Map*, uchar*, ulong);
int chanvprint(Channel*, char*, va_list);
diff --git a/util.c b/util.c
index 585f81b..da5e8b0 100644
--- a/util.c
+++ b/util.c
@@ -146,15 +146,15 @@ statename(int state)
}
int
-max(int a, int b)
+min(int a, int b)
{
- return a > b? a: b;
+ return a < b? a: b;
}
int
-min(int a, int b)
+max(int a, int b)
{
- return a < b? a: b;
+ return a > b? a: b;
}
int