diff options
author | rodri <rgl@antares-labs.eu> | 2023-08-30 16:18:39 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-08-30 16:18:39 +0000 |
commit | 3d93e42d0e854a3bb7c3a380a0635cf927d59ab7 (patch) | |
tree | 98e528afec5ce056bda9d9273977f2840338ef91 /bts.c | |
parent | e0c574f246597d2ad865bea66073903b0e6d990a (diff) | |
download | battleship-3d93e42d0e854a3bb7c3a380a0635cf927d59ab7.tar.gz battleship-3d93e42d0e854a3bb7c3a380a0635cf927d59ab7.tar.bz2 battleship-3d93e42d0e854a3bb7c3a380a0635cf927d59ab7.zip |
added new cursors and their switching.
Diffstat (limited to 'bts.c')
-rw-r--r-- | bts.c | 99 |
1 files changed, 71 insertions, 28 deletions
@@ -11,6 +11,19 @@ int debug; +Cursor patrolcursor = { + {0, 0}, + { 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x03, 0x80, + 0x06, 0x80, 0x06, 0xc0, 0x0e, 0xe0, 0x1e, 0xf0, + 0x1f, 0xf8, 0x3f, 0x00, 0x01, 0x00, 0x41, 0x02, + 0x7f, 0xfe, 0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, + }, + { 0x03, 0x80, 0x06, 0x80, 0x04, 0xc0, 0x0c, 0x40, + 0x09, 0x60, 0x19, 0x30, 0x31, 0x18, 0x21, 0x0c, + 0x60, 0x04, 0x40, 0xfc, 0xfe, 0x87, 0xbe, 0xfd, + 0x80, 0x01, 0x80, 0x03, 0xc0, 0x06, 0x7f, 0xfc, + }, +}; Cursor waitcursor = { {0, 0}, { 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x07, 0xe0, @@ -24,21 +37,33 @@ Cursor waitcursor = { 0x0a, 0x50, 0x16, 0x68, 0x20, 0x04, 0x3f, 0xfc, } }; +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 + }, + { 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 = { {-7, -7}, - { 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, - 0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0x03, 0xC0, - 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, + { 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, 0xfb, 0xdf, + 0xf3, 0xcf, 0xe3, 0xc7, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xe3, 0xc7, 0xf3, 0xcf, + 0x7b, 0xdf, 0x7f, 0xfe, 0x3f, 0xfc, 0x1f, 0xf8, }, - { 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, - 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE, - 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, - 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, + { 0x00, 0x00, 0x0f, 0xf0, 0x31, 0x8c, 0x21, 0x84, + 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7f, 0xfe, + 0x7f, 0xfe, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82, + 0x21, 0x84, 0x31, 0x8c, 0x0f, 0xf0, 0x00, 0x00, } }; - char deffont[] = "/lib/font/bit/pelm/unicode.9.font"; char winspec[32]; Channel *drawchan; @@ -122,6 +147,17 @@ mkshipbbox(Point2 p, int o, int ncells) ); } +void +csetcursor(Mousectl *mc, Cursor *c) +{ + static Cursor *oc; + + if(c == oc) + return; + setcursor(mc, c); + oc = c; +} + Image * gettileimage(int type) { @@ -357,34 +393,34 @@ int confirmdone(Mousectl *mc) { /* thanks sigrid! */ - Cursor yousure = { + Cursor anchor = { {0, 0}, - { 0xf7, 0xfe, 0x15, 0x54, 0x1d, 0x54, 0x09, 0x54, - 0x09, 0xdc, 0x00, 0x00, 0x75, 0x77, 0x45, 0x54, - 0x75, 0x66, 0x15, 0x54, 0x77, 0x57, 0x00, 0x00, - 0x00, 0x02, 0x2a, 0x84, 0x11, 0x28, 0x2a, 0x90, + { 0x00, 0x00, 0x00, 0x1e, 0x01, 0x92, 0x30, 0xd2, + 0x70, 0x7e, 0x60, 0x70, 0x40, 0xf8, 0x41, 0xcc, + 0x43, 0x84, 0x47, 0x00, 0x4e, 0x00, 0x5c, 0x00, + 0x78, 0x18, 0x70, 0x38, 0x7f, 0xf0, 0x00, 0x00, + }, + { 0x00, 0x3f, 0x03, 0xe1, 0x7a, 0x6d, 0xcb, 0x2d, + 0x89, 0x81, 0x99, 0x8f, 0xb3, 0x07, 0xa6, 0x33, + 0xac, 0x7a, 0xb8, 0xce, 0xb1, 0x80, 0xa3, 0x3c, + 0x86, 0x64, 0x8f, 0xc4, 0x80, 0x0c, 0xff, 0xf8, }, - { 0xea, 0x2b, 0xea, 0xab, 0xe2, 0xab, 0xf6, 0xab, - 0xf6, 0x23, 0xff, 0xff, 0x8a, 0x88, 0xba, 0xab, - 0x8a, 0x99, 0xea, 0xab, 0x88, 0xa8, 0xff, 0xff, - 0xff, 0xfd, 0xd5, 0x7b, 0xee, 0xd7, 0xd5, 0x6f, - } }; - setcursor(mc, &yousure); + csetcursor(mc, &anchor); while(mc->buttons == 0) readmouse(mc); if(mc->buttons != 4){ - setcursor(mc, nil); + csetcursor(mc, nil); return 0; } while(mc->buttons){ if(mc->buttons != 4){ - setcursor(mc, nil); + csetcursor(mc, nil); return 0; } readmouse(mc); } - setcursor(mc, nil); + csetcursor(mc, nil); return 1; } @@ -524,6 +560,11 @@ mouse(Mousectl *mc) if(game.state == Outlaying && curship != nil){ newbbox = mkshipbbox(toboard(&localboard, mc->xy), curship->orient, curship->ncells); + if(ptinrect(mc->xy, localboard.bbox)) + csetcursor(mctl, &boxcursor); + else + csetcursor(mctl, nil); + if(rectinrect(newbbox, localboard.bbox) && !rectXarmada(newbbox)){ curship->p = toboard(&localboard, mc->xy); curship->bbox = newbbox; @@ -533,9 +574,9 @@ mouse(Mousectl *mc) if(game.state == Playing) if(ptinrect(mc->xy, alienboard.bbox)) - setcursor(mctl, &aimcursor); + csetcursor(mctl, &aimcursor); else - setcursor(mctl, nil); + csetcursor(mctl, nil); switch(mc->buttons){ case 1: @@ -647,18 +688,19 @@ processcmd(char *cmd) game.state = Outlaying; curship = &armada[0]; } + csetcursor(mctl, &patrolcursor); break; case Outlaying: if(strcmp(cmd, "wait") == 0){ game.state = Waiting; - setcursor(mctl, &waitcursor); + csetcursor(mctl, &waitcursor); }else if(strcmp(cmd, "play") == 0) game.state = Playing; break; case Playing: if(strcmp(cmd, "wait") == 0){ game.state = Waiting; - setcursor(mctl, &waitcursor); + csetcursor(mctl, &waitcursor); }else if(strcmp(cmd, "hit") == 0) settile(&alienboard, lastshot, Thit); else if(strcmp(cmd, "miss") == 0) @@ -667,7 +709,7 @@ processcmd(char *cmd) case Waiting: if(strcmp(cmd, "play") == 0){ game.state = Playing; - setcursor(mctl, nil); + csetcursor(mctl, nil); }else if(strncmp(cmd, "hit", 3) == 0){ cell = coords2cell(cmd+4); for(i = 0; i < nelem(armada); i++) @@ -788,6 +830,7 @@ threadmain(int argc, char *argv[]) initboards(); initarmada(); game.state = Waiting0; + csetcursor(mctl, &patrolcursor); drawchan = chancreate(sizeof(void*), 0); ingress = chancreate(sizeof(char*), 1); |