From 2cdf5ca5b03757e7ac1974f47ec0544cdf5a6d7e Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Fri, 9 Oct 2009 17:40:42 +0200 Subject: [PATCH] Convert chopper to do floating point math, allowing for more flexible game speeds in the future. --- apps/plugin.h | 1 + apps/plugins/chopper.c | 57 +++++++++++++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/apps/plugin.h b/apps/plugin.h index b06010437..2d8df6add 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -94,6 +94,7 @@ void* plugin_get_buffer(size_t *buffer_size); #include "ata_idle_notify.h" #include "settings_list.h" #include "timefuncs.h" +#include "fixedpoint.h" #ifdef HAVE_ALBUMART #include "albumart.h" diff --git a/apps/plugins/chopper.c b/apps/plugins/chopper.c index 5c4af3b11..76e1083a8 100644 --- a/apps/plugins/chopper.c +++ b/apps/plugins/chopper.c @@ -186,16 +186,31 @@ static inline int SCALE(int x) /* in 10 milisecond (ticks) */ #define CYCLETIME ((CYCLES*HZ)/1000) + + /* some fixed-point math for speed calculation + * based on brickmania after r22882 */ +#define FRAC_BITS 8 +#define TO_FIXED(x) ((x)<>FRAC_BITS) + + /*Chopper's local variables to track the terrain position etc*/ static int chopCounter; static int iRotorOffset; static int iScreenX; static int iScreenY; -static int iPlayerPosX; -static int iPlayerPosY; -static int iCameraPosX; -static int iPlayerSpeedX; -static int iPlayerSpeedY; +static int fPlayerPosX; +#define iPlayerPosX (TO_INT(fPlayerPosX)) +static int fPlayerPosY; +#define iPlayerPosY (TO_INT(fPlayerPosY)) +static int fCameraPosX; +#define iCameraPosX (TO_INT(fCameraPosX)) +static unsigned fPlayerSpeedX; +#define iPlayerSpeedX (TO_INT(fPlayerSpeedX)) +static unsigned fPlayerSpeedY; +#define iPlayerSpeedY (TO_INT(fPlayerSpeedY)) static int iLastBlockPlacedPosX; static int iGravityTimerCountdown; static int iPlayerAlive; @@ -378,7 +393,7 @@ int chopUpdateTerrainRecycling(struct CTerrain *ter) iNewNodePos = ter->iLastNodePlacedPosX + 50; g = iScreenY - 10; - v = 3*iPlayerSpeedX; + v = TO_INT(fPlayerSpeedX*3); if(v>50) v=50; if(iLevelMode == LEVEL_MODE_STEEP) @@ -489,7 +504,7 @@ static void chopAddParticle(int x,int y,int sx,int sy) static void chopGenerateBlockIfNeeded(void) { int i=0; - int DistSpeedX = iPlayerSpeedX * 5; + int DistSpeedX = TO_INT(fPlayerSpeedX * 5); if(DistSpeedX<200) DistSpeedX = 200; while(i < NUMBER_OF_BLOCKS) @@ -857,7 +872,7 @@ static int chopGameLoop(void) ) bdelay = -2; if (bdelay == 0) - iPlayerSpeedY = -3; + fPlayerSpeedY = TO_FIXED(-3); break; default: @@ -868,7 +883,7 @@ static int chopGameLoop(void) ) bdelay = 3; if (bdelay == 0) - iPlayerSpeedY = 4; + fPlayerSpeedY = TO_FIXED(4); if (rb->default_event_handler(move_button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; @@ -877,21 +892,21 @@ static int chopGameLoop(void) last_button = move_button; if (bdelay < 0) { - iPlayerSpeedY = bdelay; + fPlayerSpeedY = TO_FIXED(bdelay); bdelay++; } else if (bdelay > 0) { - iPlayerSpeedY = bdelay; + fPlayerSpeedY = TO_FIXED(bdelay); bdelay--; } - iCameraPosX = iPlayerPosX - 25; - iPlayerPosX += iPlayerSpeedX; - iPlayerPosY += iPlayerSpeedY; + fCameraPosX = fPlayerPosX - TO_FIXED(25); + fPlayerPosX += fPlayerSpeedX; + fPlayerPosY += fPlayerSpeedY; chopCounter++; /* increase speed as we go along */ if (chopCounter == 100){ - iPlayerSpeedX++; + fPlayerSpeedX += TO_FIXED(1); chopCounter=0; } @@ -1003,14 +1018,14 @@ void chopper_load(bool newgame) score = 0; } iRotorOffset = 0; - iPlayerPosX = 60; - iPlayerPosY = (iScreenY * 4) / 10; + fPlayerPosX = TO_FIXED(60); + fPlayerPosY = TO_FIXED(iScreenY * 4) / 10; iLastBlockPlacedPosX = 0; iGravityTimerCountdown = 2; chopCounter = 0; - iPlayerSpeedX = 3; - iPlayerSpeedY = 0; - iCameraPosX = 30; + fPlayerSpeedX = TO_FIXED(3); + fPlayerSpeedY = TO_FIXED(0); + fCameraPosX = TO_FIXED(30); for (i=0; i < NUMBER_OF_PARTICLES; i++) mParticles[i].bIsActive = 0; @@ -1030,7 +1045,7 @@ void chopper_load(bool newgame) if (iLevelMode == LEVEL_MODE_NORMAL) /* make it a bit more exciting, cause it's easy terrain... */ - iPlayerSpeedX *= 2; + fPlayerSpeedX *= 2; } /* this is the plugin entry point */ -- 2.11.4.GIT