diff options
Diffstat (limited to 'apps/plugins/bubbles.c')
-rw-r--r-- | apps/plugins/bubbles.c | 91 |
1 files changed, 14 insertions, 77 deletions
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c index dca3ede4e0..25fd4f3c63 100644 --- a/apps/plugins/bubbles.c +++ b/apps/plugins/bubbles.c | |||
@@ -20,11 +20,13 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include "plugin.h" | 22 | #include "plugin.h" |
23 | #include "xlcd.h" | ||
24 | #include "pluginlib_actions.h" | ||
25 | 23 | ||
26 | #ifdef HAVE_LCD_BITMAP | 24 | #ifdef HAVE_LCD_BITMAP |
27 | 25 | ||
26 | #include "xlcd.h" | ||
27 | #include "pluginlib_actions.h" | ||
28 | #include "fixedpoint.h" | ||
29 | |||
28 | PLUGIN_HEADER | 30 | PLUGIN_HEADER |
29 | 31 | ||
30 | /* files */ | 32 | /* files */ |
@@ -1278,71 +1280,6 @@ struct game_context { | |||
1278 | struct tile playboard[BB_HEIGHT][BB_WIDTH]; | 1280 | struct tile playboard[BB_HEIGHT][BB_WIDTH]; |
1279 | }; | 1281 | }; |
1280 | 1282 | ||
1281 | /* | ||
1282 | * Precalculated sine and cosine * 16384 (fixed point 18.14) | ||
1283 | * Borrowed from cube.c plugin | ||
1284 | */ | ||
1285 | static const short sin_table[91] = { | ||
1286 | 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, | ||
1287 | 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, | ||
1288 | 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, | ||
1289 | 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, | ||
1290 | 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, | ||
1291 | 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, | ||
1292 | 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, | ||
1293 | 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, | ||
1294 | 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, | ||
1295 | 16384 | ||
1296 | }; | ||
1297 | |||
1298 | static long sin(int val) { | ||
1299 | val = (val+360)%360; | ||
1300 | |||
1301 | if(val < 181) { | ||
1302 | if(val < 91) { | ||
1303 | /* phase 0-90 degree */ | ||
1304 | return (long)sin_table[val]; | ||
1305 | } else { | ||
1306 | /* phase 91-180 degree */ | ||
1307 | return (long)sin_table[180-val]; | ||
1308 | } | ||
1309 | } else { | ||
1310 | if(val < 271) { | ||
1311 | /* phase 181-270 degree */ | ||
1312 | return -(long)sin_table[val-180]; | ||
1313 | } else { | ||
1314 | /* phase 270-359 degree */ | ||
1315 | return -(long)sin_table[360-val]; | ||
1316 | } | ||
1317 | } | ||
1318 | return 0; | ||
1319 | } | ||
1320 | |||
1321 | static long cos(int val) { | ||
1322 | val = (val+360)%360; | ||
1323 | |||
1324 | if(val < 181) { | ||
1325 | if(val < 91) { | ||
1326 | /* phase 0-90 degree */ | ||
1327 | return (long)sin_table[90-val]; | ||
1328 | } else { | ||
1329 | /* phase 91-180 degree */ | ||
1330 | return -(long)sin_table[val-90]; | ||
1331 | } | ||
1332 | } else { | ||
1333 | if(val < 271) { | ||
1334 | /* phase 181-270 degree */ | ||
1335 | return -(long)sin_table[270-val]; | ||
1336 | } else { | ||
1337 | /* phase 270-359 degree */ | ||
1338 | return (long)sin_table[val-270]; | ||
1339 | } | ||
1340 | } | ||
1341 | return 0; | ||
1342 | } | ||
1343 | |||
1344 | |||
1345 | |||
1346 | static void bubbles_init(struct game_context* bb); | 1283 | static void bubbles_init(struct game_context* bb); |
1347 | static bool bubbles_nextlevel(struct game_context* bb); | 1284 | static bool bubbles_nextlevel(struct game_context* bb); |
1348 | static void bubbles_getonboard(struct game_context* bb); | 1285 | static void bubbles_getonboard(struct game_context* bb); |
@@ -1553,17 +1490,17 @@ static void bubbles_drawboard(struct game_context* bb) { | |||
1553 | ROW_HEIGHT*(BB_HEIGHT-2)+BUBBLE_HEIGHT); | 1490 | ROW_HEIGHT*(BB_HEIGHT-2)+BUBBLE_HEIGHT); |
1554 | 1491 | ||
1555 | /* draw arrow */ | 1492 | /* draw arrow */ |
1556 | tipx = SHOTX+BUBBLE_WIDTH/2+(((sin(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10); | 1493 | tipx = SHOTX+BUBBLE_WIDTH/2+(((sin_int(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10); |
1557 | tipy = SHOTY+BUBBLE_HEIGHT/2-(((cos(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10); | 1494 | tipy = SHOTY+BUBBLE_HEIGHT/2-(((cos_int(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10); |
1558 | 1495 | ||
1559 | rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((sin(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10), | 1496 | rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((sin_int(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10), |
1560 | SHOTY+BUBBLE_HEIGHT/2-(((cos(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10), | 1497 | SHOTY+BUBBLE_HEIGHT/2-(((cos_int(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10), |
1561 | tipx, tipy); | 1498 | tipx, tipy); |
1562 | xlcd_filltriangle(tipx, tipy, | 1499 | xlcd_filltriangle(tipx, tipy, |
1563 | tipx+(((sin(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10), | 1500 | tipx+(((sin_int(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10), |
1564 | tipy-(((cos(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10), | 1501 | tipy-(((cos_int(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10), |
1565 | tipx+(((sin(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10), | 1502 | tipx+(((sin_int(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10), |
1566 | tipy-(((cos(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10)); | 1503 | tipy-(((cos_int(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10)); |
1567 | 1504 | ||
1568 | /* draw text */ | 1505 | /* draw text */ |
1569 | rb->lcd_getstringsize(level, &w, &h); | 1506 | rb->lcd_getstringsize(level, &w, &h); |
@@ -1608,8 +1545,8 @@ static int bubbles_fire(struct game_context* bb) { | |||
1608 | 1545 | ||
1609 | /* get current bubble */ | 1546 | /* get current bubble */ |
1610 | bubblecur = bb->queue[bb->nextinq]; | 1547 | bubblecur = bb->queue[bb->nextinq]; |
1611 | shotxinc = ((sin(bb->angle)>>4)*BUBBLE_WIDTH)/3; | 1548 | shotxinc = ((sin_int(bb->angle)>>4)*BUBBLE_WIDTH)/3; |
1612 | shotyinc = ((-1*(cos(bb->angle)>>4))*BUBBLE_HEIGHT)/3; | 1549 | shotyinc = ((-1*(cos_int(bb->angle)>>4))*BUBBLE_HEIGHT)/3; |
1613 | shotxofs = shotyofs = 0; | 1550 | shotxofs = shotyofs = 0; |
1614 | 1551 | ||
1615 | /* advance the queue */ | 1552 | /* advance the queue */ |