ref: b555a1ad730994a42cfecf88bba15ece20d1e6f9
parent: 30ac819359e5d6de7f6622ba6c01e79457fe8277
author: rodri <rgl@antares-labs.eu>
date: Fri Nov 15 18:48:46 EST 2024
bts: add a little vfx for the buttons. add playvfx helper function.
binary files a/assets/vfx/battleship.png b/assets/vfx/battleship.png differ
binary files /dev/null b/assets/vfx/shining.png differ
--- a/bts.c
+++ b/bts.c
@@ -254,6 +254,15 @@
}
void
+playvfx(int idx, Point p, int times)
+{
+ if(idx < 0 || idx > NVFX)
+ return;
+
+ addvfx(&vfxqueue, newvfx(spritetab[idx]->clone(spritetab[idx]), p, times));
+}
+
+void
resetgame(void)
{
int i;
@@ -616,10 +625,14 @@
snprint(aux, sizeof aux, "%s/%s", assetdir, "vfx/battleship.png");
coverimg = readpngimage(aux);
+
snprint(aux, sizeof aux, "%s/%s", assetdir, "vfx/hit.png");
spritetab[VFXHit] = readpngsprite(aux, ZP, Rect(0, 0, 32, 32), 12, 100);
snprint(aux, sizeof aux, "%s/%s", assetdir, "vfx/miss.png");
spritetab[VFXMiss] = readpngsprite(aux, ZP, Rect(0, 0, 32, 32), 7, 150);
+ snprint(aux, sizeof aux, "%s/%s", assetdir, "vfx/shining.png");
+ spritetab[VFXShine] = readpngsprite(aux, ZP, Rect(0, 0, 50, 50), 11, 100);
+
initvfxq(&vfxqueue);
}
@@ -815,8 +828,14 @@
mc->xy = subpt(mc->xy, screen->r.min);
if(gamestate == Waiting0){
- for(b = mainbtns; b < mainbtns+nelem(mainbtns); b++)
- b->status = ptinrect(mc->xy, b->r)? BHover: BRest;
+ for(b = mainbtns; b < mainbtns+nelem(mainbtns); b++){
+ if(ptinrect(mc->xy, b->r)){
+ if(b->status == BRest)
+ playvfx(VFXShine, addpt(b->r.min, Pt(Btnborder, Btnborder)), 1);
+ b->status = BHover;
+ }else
+ b->status = BRest;
+ }
nbsend(drawchan, nil);
if((selmatch = matches->update(matches, mc, drawchan)) >= 0){
@@ -1030,17 +1049,13 @@
idx = strtoul(cb->f[1], nil, 10);
cell = coords2cell(cb->f[2]);
settile(match.bl[idx^1], cell, Thit);
- addvfx(&vfxqueue,
- newvfx(spritetab[VFXHit]->clone(spritetab[VFXHit]),
- addpt(fromboard(match.bl[idx^1], cell), Pt(TW/2, TH/2)), 1));
+ playvfx(VFXHit, addpt(fromboard(match.bl[idx^1], cell), Pt(TW/2, TH/2)), 1);
break;
case CMplayermiss:
idx = strtoul(cb->f[1], nil, 10);
cell = coords2cell(cb->f[2]);
settile(match.bl[idx^1], cell, Tmiss);
- addvfx(&vfxqueue,
- newvfx(spritetab[VFXMiss]->clone(spritetab[VFXMiss]),
- addpt(fromboard(match.bl[idx^1], cell), Pt(TW/2, TH/2)), 1));
+ playvfx(VFXMiss, addpt(fromboard(match.bl[idx^1], cell), Pt(TW/2, TH/2)), 1);
break;
case CMplayerplays:
idx = strtoul(cb->f[1], nil, 10);
@@ -1072,9 +1087,7 @@
break;
case CMwehit:
settile(&alienboard, lastshot, Thit);
- addvfx(&vfxqueue,
- newvfx(spritetab[VFXHit]->clone(spritetab[VFXHit]),
- addpt(fromboard(&alienboard, lastshot), Pt(TW/2, TH/2)), 1));
+ playvfx(VFXHit, addpt(fromboard(&alienboard, lastshot), Pt(TW/2, TH/2)), 1);
break;
case CMwemiss:
if(!silent)
@@ -1081,9 +1094,7 @@
playaudio(playlist[SWATER]);
settile(&alienboard, lastshot, Tmiss);
- addvfx(&vfxqueue,
- newvfx(spritetab[VFXMiss]->clone(spritetab[VFXMiss]),
- addpt(fromboard(&alienboard, lastshot), Pt(TW/2, TH/2)), 1));
+ playvfx(VFXMiss, addpt(fromboard(&alienboard, lastshot), Pt(TW/2, TH/2)), 1);
break;
}
break;
@@ -1097,9 +1108,7 @@
cell = coords2cell(cb->f[1]);
for(i = 0; i < nelem(armada); i++)
if(ptinrect(fromboard(&localboard, cell), armada[i].bbox)){
- addvfx(&vfxqueue,
- newvfx(spritetab[VFXHit]->clone(spritetab[VFXHit]),
- addpt(fromboard(&localboard, cell), Pt(TW/2, TH/2)), 1));
+ playvfx(VFXHit, addpt(fromboard(&localboard, cell), Pt(TW/2, TH/2)), 1);
cell = subpt2(cell, armada[i].p);
armada[i].hit[(int)vec2len(cell)] = 1;
break;
@@ -1108,9 +1117,7 @@
case CMtheymiss:
cell = coords2cell(cb->f[1]);
settile(&localboard, cell, Tmiss);
- addvfx(&vfxqueue,
- newvfx(spritetab[VFXMiss]->clone(spritetab[VFXMiss]),
- addpt(fromboard(&localboard, cell), Pt(TW/2, TH/2)), 1));
+ playvfx(VFXMiss, addpt(fromboard(&localboard, cell), Pt(TW/2, TH/2)), 1);
break;
}
break;
--- a/dat.h
+++ b/dat.h
@@ -19,6 +19,7 @@
VFXHit = 0,
VFXMiss,
+ VFXShine,
NVFX,
OH = 0, /* horizontal */