aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-09-01 11:07:48 +0000
committerrodri <rgl@antares-labs.eu>2023-09-01 11:07:48 +0000
commit4f514003a8236aaeb9621b932c0f8329e03c1dd8 (patch)
tree98f02ef9ae95cb0e68a54341f1e2ba17bbc9fc7e
parent344e764a193a70807d429e54c36f4cf5a5d0e8c7 (diff)
downloadbattleship-4f514003a8236aaeb9621b932c0f8329e03c1dd8.tar.gz
battleship-4f514003a8236aaeb9621b932c0f8329e03c1dd8.tar.bz2
battleship-4f514003a8236aaeb9621b932c0f8329e03c1dd8.zip
change mmb to rotate the ship without presenting a menu.
-rw-r--r--bts.c77
-rw-r--r--readme.md13
2 files changed, 40 insertions, 50 deletions
diff --git a/bts.c b/bts.c
index 4706c23..a167f86 100644
--- a/bts.c
+++ b/bts.c
@@ -39,15 +39,15 @@ Cursor waitcursor = {
};
Cursor boxcursor = {
{-7, -7},
- { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F,
- 0xF8, 0x1F, 0xF8, 0x1F, 0xF8, 0x1F, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+ { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+ 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
},
- { 0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE,
- 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
- 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E, 0x70, 0x0E,
- 0x7F, 0xFE, 0x7F, 0xFE, 0x7F, 0xFE, 0x00, 0x00
+ { 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe,
+ 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e,
+ 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e,
+ 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x00, 0x00
}
};
Cursor aimcursor = {
@@ -500,47 +500,38 @@ lmb(Mousectl *mc)
void
mmb(Mousectl *mc)
{
- enum {
- ROTATE,
- };
- static char *items[] = {
- [ROTATE] "rotate ship",
- nil
- };
- static Menu menu = { .item = items };
-
if(game.state != Outlaying)
return;
- mc->xy = addpt(mc->xy, screen->r.min);
- switch(menuhit(2, mc, &menu, _screen)){
- case ROTATE:
- if(curship != nil){
- curship->orient = curship->orient == OH? OV: OH;
- curship->bbox = mkshipbbox(curship->p, curship->orient, curship->ncells);
-
- /* steer it, captain! don't let it go off-board! */
- if(!rectinrect(curship->bbox, localboard.bbox)){
- switch(curship->orient){
- case OH:
- curship->bbox.min.x -= curship->bbox.max.x-localboard.bbox.max.x;
- curship->bbox.max.x = localboard.bbox.max.x;
- break;
- case OV:
- curship->bbox.min.y -= curship->bbox.max.y-localboard.bbox.max.y;
- curship->bbox.max.y = localboard.bbox.max.y;
- break;
- }
- curship->p = toboard(&localboard, curship->bbox.min);
- moveto(mc, addpt(screen->r.min, curship->bbox.min));
+ if(curship != nil){
+ curship->orient = curship->orient == OH? OV: OH;
+ curship->bbox = mkshipbbox(curship->p, curship->orient, curship->ncells);
+
+ if(debug)
+ fprint(2, "curship orient %c\n", curship->orient == OH? 'h': 'v');
+
+ /* steer it, captain! don't let it go off-board! */
+ if(!rectinrect(curship->bbox, localboard.bbox)){
+ switch(curship->orient){
+ case OH:
+ curship->bbox.min.x -= curship->bbox.max.x-localboard.bbox.max.x;
+ curship->bbox.max.x = localboard.bbox.max.x;
+ break;
+ case OV:
+ curship->bbox.min.y -= curship->bbox.max.y-localboard.bbox.max.y;
+ curship->bbox.max.y = localboard.bbox.max.y;
+ break;
}
- /* …nor ram allied ships! */
- if(rectXarmada(curship->bbox))
- curship->bbox = ZR;
+ curship->p = toboard(&localboard, curship->bbox.min);
+ moveto(mc, addpt(screen->r.min, curship->bbox.min));
+ readmouse(mc); /* ignore mmb click triggered by moveto */
}
- break;
+ /* …nor ram allied ships! */
+ if(rectXarmada(curship->bbox))
+ curship->bbox = ZR;
+
+ send(drawchan, nil);
}
- send(drawchan, nil);
}
void
diff --git a/readme.md b/readme.md
index 99e346c..b8ae272 100644
--- a/readme.md
+++ b/readme.md
@@ -11,12 +11,11 @@ Join a server
Then wait for another player to show up (admire the velero). When
they do, you'll have to place your ships in the lower (local) board by
clicking LMB when the ship is at the right location; you can also
-change the orientation of the ship by pressing MMB and selecting
-“rotate ship”. If you are not happy with the current layout, press
-RMB and select “place ships” to start all over again (tip: if you
-don't want to move a ship, click LMB without moving the mouse.) Once
-you are done—a banner at the bottom will inform you—, press RMB and
-choose “done”.
+change the orientation of the ship by pressing MMB. If you are not
+happy with the current layout, press RMB and select “place ships” to
+start all over again (tip: if you don't want to move a ship, click LMB
+without moving the mouse.) Once you are done—a banner at the bottom
+will inform you—, press RMB and choose “done”.
At this moment the battle will begin. Each of you has a turn (read
[battleship.pdf](battleship.pdf)), and if you are the one shooting you
@@ -26,5 +25,5 @@ tile will show an X, otherwise a O. If you are the one waiting, well,
just do that.
There's no turn timeout so the battles can get as long as any of the
-players's will. If you quit or your connection is lost, your opponent
+players will. If you quit or your connection is lost, your opponent
wins.