2007-02-16 01:23:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id: $
|
2007-02-16 06:57:49 +00:00
|
|
|
*
|
2007-02-16 01:23:48 +00:00
|
|
|
* Originally by Joshua Oreman, improved by Prashant Varanasi
|
|
|
|
* Ported to Rockbox by Ben Basha (Paprica)
|
2007-02-16 06:57:49 +00:00
|
|
|
*
|
2007-02-16 01:23:48 +00:00
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "xlcd.h"
|
|
|
|
#include "configfile.h"
|
2007-08-15 12:42:09 +00:00
|
|
|
#include "helper.h"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
PLUGIN_HEADER
|
|
|
|
|
|
|
|
/*Still To do:*/
|
|
|
|
/* - Make original speed and further increases in speed depend more on screen size*/
|
|
|
|
/* - attempt to make the tunnels get narrower as the game goes on*/
|
|
|
|
/* - make the chopper look better, maybe a picture, and scale according to screen size*/
|
|
|
|
/* - use textures for the color screens for background and terrain, eg stars on background*/
|
|
|
|
/* - allow choice of different levels [later: different screen themes]*/
|
|
|
|
/* - better high score handling, improved screen etc. */
|
|
|
|
|
|
|
|
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
|
|
|
|
|
|
|
#define QUIT BUTTON_OFF
|
|
|
|
#define ACTION BUTTON_UP
|
|
|
|
#define ACTION2 BUTTON_SELECT
|
2007-02-16 07:21:47 +00:00
|
|
|
#define ACTIONTEXT "SELECT"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
2007-07-27 09:57:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#define QUIT BUTTON_MENU
|
|
|
|
#define ACTION BUTTON_SELECT
|
2007-02-16 06:57:49 +00:00
|
|
|
#define ACTIONTEXT "SELECT"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD /* grayscale at the moment */
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#define QUIT BUTTON_POWER
|
2007-02-17 10:23:15 +00:00
|
|
|
#define ACTION BUTTON_UP
|
|
|
|
#define ACTION2 BUTTON_SELECT
|
2007-02-16 06:57:49 +00:00
|
|
|
#define ACTIONTEXT "SELECT"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define QUIT BUTTON_POWER
|
|
|
|
#define ACTION BUTTON_RIGHT
|
2007-02-16 06:57:49 +00:00
|
|
|
#define ACTIONTEXT "RIGHT"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == SANSA_E200_PAD
|
|
|
|
#define QUIT BUTTON_POWER
|
|
|
|
#define ACTION BUTTON_SELECT
|
2007-02-16 06:57:49 +00:00
|
|
|
#define ACTIONTEXT "SELECT"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
|
|
|
#define QUIT BUTTON_MENU
|
|
|
|
#define ACTION BUTTON_SELECT
|
2007-02-16 06:57:49 +00:00
|
|
|
#define ACTIONTEXT "SELECT"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define QUIT BUTTON_OFF
|
|
|
|
#define ACTION BUTTON_PLAY
|
2007-02-16 06:57:49 +00:00
|
|
|
#define ACTIONTEXT "PLAY"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2007-02-17 10:23:15 +00:00
|
|
|
#define QUIT BUTTON_OFF
|
|
|
|
#define ACTION BUTTON_UP
|
2007-02-17 10:32:19 +00:00
|
|
|
#define ACTION2 BUTTON_MENU
|
|
|
|
#define ACTIONTEXT "UP"
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#error Unsupported keypad
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct plugin_api* rb;
|
|
|
|
|
|
|
|
#define NUMBER_OF_BLOCKS 8
|
|
|
|
#define NUMBER_OF_PARTICLES 3
|
|
|
|
#define MAX_TERRAIN_NODES 15
|
|
|
|
|
|
|
|
#define LEVEL_MODE_NORMAL 0
|
|
|
|
#define LEVEL_MODE_STEEP 1
|
|
|
|
|
2007-02-20 00:40:21 +00:00
|
|
|
#if LCD_WIDTH <= 112
|
|
|
|
#define CYCLETIME 100
|
|
|
|
#define SCALE(x) ((x)==1 ? (x) : ((x) >> 1))
|
|
|
|
#define SIZE 2
|
|
|
|
#else
|
2007-02-16 01:23:48 +00:00
|
|
|
#define CYCLETIME 60
|
2007-02-20 00:40:21 +00:00
|
|
|
#define SCALE(x) (x)
|
|
|
|
#define SIZE 1
|
|
|
|
#endif
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
/*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 iLastBlockPlacedPosX;
|
|
|
|
static int iGravityTimerCountdown;
|
|
|
|
static int iPlayerAlive;
|
|
|
|
static int iLevelMode;
|
|
|
|
static int blockh,blockw;
|
|
|
|
static int highscore;
|
|
|
|
static int score;
|
|
|
|
|
|
|
|
#define CFG_FILE "chopper.cfg"
|
|
|
|
#define MAX_POINTS 50000
|
|
|
|
static struct configdata config[] =
|
|
|
|
{
|
|
|
|
{TYPE_INT, 0, MAX_POINTS, &highscore, "highscore", NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CBlock
|
|
|
|
{
|
|
|
|
int iWorldX;
|
|
|
|
int iWorldY;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int iSizeX;
|
|
|
|
int iSizeY;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int bIsActive;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CParticle
|
|
|
|
{
|
|
|
|
int iWorldX;
|
|
|
|
int iWorldY;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int iSpeedX;
|
|
|
|
int iSpeedY;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int bIsActive;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CTerrainNode
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CTerrain
|
|
|
|
{
|
|
|
|
struct CTerrainNode mNodes[MAX_TERRAIN_NODES];
|
|
|
|
int iNodesCount;
|
|
|
|
int iLastNodePlacedPosX;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CBlock mBlocks[NUMBER_OF_BLOCKS];
|
|
|
|
struct CParticle mParticles[NUMBER_OF_PARTICLES];
|
|
|
|
|
|
|
|
struct CTerrain mGround;
|
|
|
|
struct CTerrain mRoof;
|
|
|
|
|
|
|
|
/*Function declarations*/
|
|
|
|
static void chopDrawParticle(struct CParticle *mParticle);
|
|
|
|
static void chopDrawBlock(struct CBlock *mBlock);
|
|
|
|
static void chopRenderTerrain(struct CTerrain *ter);
|
|
|
|
void chopper_load(bool newgame);
|
|
|
|
void cleanup_chopper(void);
|
|
|
|
|
|
|
|
static void chopDrawPlayer(int x,int y) /* These are SCREEN coords, not world! */
|
|
|
|
{
|
|
|
|
|
|
|
|
#if LCD_DEPTH > 2
|
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(50,50,200));
|
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_DARKGRAY);
|
|
|
|
#endif
|
2007-02-20 00:40:21 +00:00
|
|
|
rb->lcd_fillrect(SCALE(x+6), SCALE(y+2), SCALE(12), SCALE(9));
|
|
|
|
rb->lcd_fillrect(SCALE(x-3), SCALE(y+6), SCALE(20), SCALE(3));
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
#if LCD_DEPTH > 2
|
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(50,50,50));
|
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_DARKGRAY);
|
|
|
|
#endif
|
2007-02-20 00:40:21 +00:00
|
|
|
rb->lcd_fillrect(SCALE(x+10), SCALE(y), SCALE(2), SCALE(3));
|
|
|
|
rb->lcd_fillrect(SCALE(x+10), SCALE(y), SCALE(1), SCALE(3));
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
#if LCD_DEPTH > 2
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(40,40,100));
|
2007-02-16 01:23:48 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
#endif
|
2007-02-20 00:40:21 +00:00
|
|
|
rb->lcd_drawline(SCALE(x), SCALE(y+iRotorOffset), SCALE(x+20), SCALE(y-iRotorOffset));
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
#if LCD_DEPTH > 2
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(20,20,50));
|
2007-02-16 01:23:48 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
#endif
|
2007-02-20 00:40:21 +00:00
|
|
|
rb->lcd_fillrect(SCALE(x - 2), SCALE(y + 5), SCALE(2), SCALE(5));
|
2007-02-16 01:23:48 +00:00
|
|
|
|
2007-02-16 06:57:49 +00:00
|
|
|
}
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
static void chopClearTerrain(struct CTerrain *ter)
|
|
|
|
{
|
2007-02-18 14:21:04 +00:00
|
|
|
ter->iNodesCount = 0;
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int iR(int low,int high)
|
|
|
|
{
|
|
|
|
return low+rb->rand()%(high-low+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopCopyTerrain(struct CTerrain *src, struct CTerrain *dest,
|
|
|
|
int xOffset,int yOffset)
|
|
|
|
{
|
|
|
|
int i=0;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while(i < src->iNodesCount)
|
|
|
|
{
|
|
|
|
dest->mNodes[i].x = src->mNodes[i].x + xOffset;
|
|
|
|
dest->mNodes[i].y = src->mNodes[i].y + yOffset;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
i++;
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
dest->iNodesCount = src->iNodesCount;
|
|
|
|
dest->iLastNodePlacedPosX = src->iLastNodePlacedPosX;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopAddTerrainNode(struct CTerrain *ter, int x, int y)
|
|
|
|
{
|
|
|
|
int i=0;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if(ter->iNodesCount + 1 >= MAX_TERRAIN_NODES)
|
|
|
|
{
|
|
|
|
/* DEBUGF("ERROR: Not enough nodes!\n"); */
|
|
|
|
return;
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
ter->iNodesCount++;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
i = ter->iNodesCount - 1;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
ter->mNodes[i].x = x;
|
|
|
|
ter->mNodes[i].y= y;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
ter->iLastNodePlacedPosX = x;
|
|
|
|
|
2007-02-16 06:57:49 +00:00
|
|
|
}
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
static void chopTerrainNodeDeleteAndShift(struct CTerrain *ter,int nodeIndex)
|
|
|
|
{
|
|
|
|
int i=nodeIndex;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while( i < ter->iNodesCount )
|
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
ter->mNodes[i - 1] = ter->mNodes[i];
|
2007-02-16 01:23:48 +00:00
|
|
|
i++;
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
ter->iNodesCount--;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int chopUpdateTerrainRecycling(struct CTerrain *ter)
|
|
|
|
{
|
|
|
|
int i=1;
|
|
|
|
int ret = 0;
|
|
|
|
int iNewNodePos,g,v;
|
|
|
|
while(i < ter->iNodesCount)
|
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if( iCameraPosX > ter->mNodes[i].x)
|
|
|
|
{
|
|
|
|
|
|
|
|
chopTerrainNodeDeleteAndShift(ter,i);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iNewNodePos = ter->iLastNodePlacedPosX + 50;
|
|
|
|
g = iScreenY - 10;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
v = 3*iPlayerSpeedX;
|
2007-02-16 06:57:49 +00:00
|
|
|
if(v>50)
|
2007-02-16 01:23:48 +00:00
|
|
|
v=50;
|
|
|
|
if(iLevelMode == LEVEL_MODE_STEEP)
|
|
|
|
v*=5;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
chopAddTerrainNode(ter,iNewNodePos,g - iR(-v,v));
|
|
|
|
ret=1;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int chopTerrainHeightAtPoint(struct CTerrain *ter, int pX)
|
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int iNodeIndexOne=0,iNodeIndexTwo=0, h, terY1, terY2, terX1, terX2, a, b;
|
|
|
|
float c,d;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int i=0;
|
|
|
|
for(i=1;i<MAX_TERRAIN_NODES;i++)
|
|
|
|
{
|
|
|
|
if(ter->mNodes[i].x > pX)
|
|
|
|
{
|
|
|
|
iNodeIndexOne = i - 1;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iNodeIndexTwo = iNodeIndexOne + 1;
|
|
|
|
terY1 = ter->mNodes[iNodeIndexOne].y;
|
|
|
|
terY2 = ter->mNodes[iNodeIndexTwo].y;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
terX1 = 0;
|
|
|
|
terX2 = ter->mNodes[iNodeIndexTwo].x - ter->mNodes[iNodeIndexOne].x;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
pX-= ter->mNodes[iNodeIndexOne].x;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
a = terY2 - terY1;
|
|
|
|
b = terX2;
|
|
|
|
c = pX;
|
|
|
|
d = (c/b) * a;
|
|
|
|
|
|
|
|
h = d + terY1;
|
|
|
|
|
|
|
|
return h;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int chopPointInTerrain(struct CTerrain *ter, int pX, int pY, int iTestType)
|
|
|
|
{
|
|
|
|
int h = chopTerrainHeightAtPoint(ter, pX);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if(iTestType == 0)
|
|
|
|
return (pY > h);
|
|
|
|
else
|
|
|
|
return (pY < h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopAddBlock(int x,int y,int sx,int sy, int indexOverride)
|
|
|
|
{
|
|
|
|
int i=0;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if(indexOverride < 0)
|
|
|
|
{
|
|
|
|
while(mBlocks[i].bIsActive && i < NUMBER_OF_BLOCKS)
|
2007-02-16 06:57:49 +00:00
|
|
|
i++;
|
2007-02-16 01:23:48 +00:00
|
|
|
if(i==NUMBER_OF_BLOCKS)
|
|
|
|
{
|
|
|
|
DEBUGF("No blocks!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i = indexOverride;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
mBlocks[i].bIsActive = 1;
|
|
|
|
mBlocks[i].iWorldX = x;
|
|
|
|
mBlocks[i].iWorldY = y;
|
|
|
|
mBlocks[i].iSizeX = sx;
|
|
|
|
mBlocks[i].iSizeY = sy;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iLastBlockPlacedPosX = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopAddParticle(int x,int y,int sx,int sy)
|
|
|
|
{
|
|
|
|
int i=0;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while(mParticles[i].bIsActive && i < NUMBER_OF_PARTICLES)
|
|
|
|
i++;
|
|
|
|
|
2007-02-18 14:21:04 +00:00
|
|
|
if(i==NUMBER_OF_PARTICLES)
|
2007-02-16 01:23:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
mParticles[i].bIsActive = 1;
|
|
|
|
mParticles[i].iWorldX = x;
|
|
|
|
mParticles[i].iWorldY = y;
|
|
|
|
mParticles[i].iSpeedX = sx;
|
|
|
|
mParticles[i].iSpeedY = sy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopGenerateBlockIfNeeded(void)
|
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
int DistSpeedX = iPlayerSpeedX * 5;
|
|
|
|
if(DistSpeedX<200) DistSpeedX = 200;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while(i < NUMBER_OF_BLOCKS)
|
|
|
|
{
|
|
|
|
if(!mBlocks[i].bIsActive)
|
|
|
|
{
|
|
|
|
int iX,iY,sX,sY;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iX = iLastBlockPlacedPosX + (350-DistSpeedX);
|
|
|
|
sX = blockw;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iY = iR(0,iScreenY);
|
|
|
|
sY = blockh + iR(1,blockh/3);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
chopAddBlock(iX,iY,sX,sY,i);
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
i++;
|
2007-02-16 06:57:49 +00:00
|
|
|
}
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chopBlockCollideWithPlayer(struct CBlock *mBlock)
|
|
|
|
{
|
|
|
|
int px = iPlayerPosX;
|
|
|
|
int py = iPlayerPosY;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int x = mBlock->iWorldX-17;
|
|
|
|
int y = mBlock->iWorldY-11;
|
|
|
|
|
|
|
|
int x2 = x + mBlock->iSizeX+17;
|
|
|
|
int y2 = y + mBlock->iSizeY+11;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if(px>x && px<x2)
|
|
|
|
{
|
|
|
|
if(py>y && py<y2)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
|
|
|
return 0;
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int chopBlockOffscreen(struct CBlock *mBlock)
|
|
|
|
{
|
|
|
|
if(mBlock->iWorldX + mBlock->iSizeX < iCameraPosX)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chopParticleOffscreen(struct CParticle *mParticle)
|
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
if (mParticle->iWorldX < iCameraPosX || mParticle->iWorldY < 0 ||
|
|
|
|
mParticle->iWorldY > iScreenY || mParticle->iWorldX > iCameraPosX +
|
2007-02-16 01:23:48 +00:00
|
|
|
iScreenX)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopKillPlayer(void)
|
|
|
|
{
|
2007-02-17 10:32:19 +00:00
|
|
|
int i, button;
|
2007-02-16 07:12:06 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
for (i = 0; i < NUMBER_OF_PARTICLES; i++) {
|
|
|
|
mParticles[i].bIsActive = 0;
|
2007-02-16 06:57:49 +00:00
|
|
|
chopAddParticle(iPlayerPosX + iR(0,20), iPlayerPosY + iR(0,20),
|
2007-02-16 01:23:48 +00:00
|
|
|
iR(-2,2), iR(-2,2));
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iPlayerAlive--;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if (iPlayerAlive == 0) {
|
|
|
|
rb->lcd_set_drawmode(DRMODE_FG);
|
|
|
|
#if LCD_DEPTH >= 2
|
2007-02-17 10:23:15 +00:00
|
|
|
rb->lcd_set_foreground(LCD_LIGHTGRAY);
|
2007-02-16 01:23:48 +00:00
|
|
|
#endif
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Game Over");
|
2007-02-17 10:23:15 +00:00
|
|
|
|
|
|
|
if (score > highscore) {
|
|
|
|
char scoretext[30];
|
|
|
|
highscore = score;
|
|
|
|
rb->snprintf(scoretext, sizeof(scoretext), "New High Score: %d",
|
|
|
|
highscore);
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*2, scoretext);
|
2007-02-17 10:23:15 +00:00
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ/4, "Press " ACTIONTEXT " to continue");
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->lcd_update();
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while (true) {
|
|
|
|
button = rb->button_get(true);
|
|
|
|
if (button == ACTION
|
|
|
|
#ifdef ACTION2
|
|
|
|
|| button == ACTION2
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
while (true) {
|
|
|
|
button = rb->button_get(true);
|
|
|
|
if (button == (ACTION | BUTTON_REL)
|
|
|
|
#ifdef ACTION2
|
|
|
|
|| button == (ACTION2 | BUTTON_REL)
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
chopper_load(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
|
|
|
} else
|
2007-02-16 01:23:48 +00:00
|
|
|
chopper_load(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopDrawTheWorld(void)
|
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
int i=0;
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while(i < NUMBER_OF_BLOCKS)
|
|
|
|
{
|
|
|
|
if(mBlocks[i].bIsActive)
|
|
|
|
{
|
|
|
|
if(chopBlockOffscreen(&mBlocks[i]) == 1)
|
|
|
|
mBlocks[i].bIsActive = 0;
|
|
|
|
else
|
|
|
|
chopDrawBlock(&mBlocks[i]);
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i=0;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while(i < NUMBER_OF_PARTICLES)
|
|
|
|
{
|
|
|
|
if(mParticles[i].bIsActive)
|
|
|
|
{
|
|
|
|
if(chopParticleOffscreen(&mParticles[i]) == 1)
|
|
|
|
mParticles[i].bIsActive = 0;
|
|
|
|
else
|
|
|
|
chopDrawParticle(&mParticles[i]);
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
i++;
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
chopRenderTerrain(&mGround);
|
|
|
|
chopRenderTerrain(&mRoof);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopDrawParticle(struct CParticle *mParticle)
|
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int iPosX = (mParticle->iWorldX - iCameraPosX);
|
|
|
|
int iPosY = (mParticle->iWorldY);
|
|
|
|
#if LCD_DEPTH > 2
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(192,192,192));
|
2007-02-16 01:23:48 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_LIGHTGRAY);
|
|
|
|
#endif
|
2007-02-20 00:40:21 +00:00
|
|
|
rb->lcd_fillrect(SCALE(iPosX), SCALE(iPosY), SCALE(3), SCALE(3));
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopDrawScene(void)
|
|
|
|
{
|
|
|
|
char s[30];
|
2007-07-25 10:21:54 +00:00
|
|
|
int w;
|
2007-02-16 01:23:48 +00:00
|
|
|
#if LCD_DEPTH > 2
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
2007-02-16 01:23:48 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_background(LCD_WHITE);
|
|
|
|
#endif
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
chopDrawTheWorld();
|
|
|
|
chopDrawPlayer(iPlayerPosX - iCameraPosX, iPlayerPosY);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
score = -20 + iPlayerPosX/3;
|
2007-02-20 00:40:21 +00:00
|
|
|
|
|
|
|
#if LCD_DEPTH == 1
|
|
|
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
|
|
|
#else
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_FG);
|
2007-02-20 00:40:21 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
#if LCD_DEPTH > 2
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
2007-02-16 01:23:48 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
#endif
|
2007-07-25 08:30:40 +00:00
|
|
|
|
2007-07-25 10:21:54 +00:00
|
|
|
#if LCD_WIDTH <= 128
|
|
|
|
rb->snprintf(s, sizeof(s), "Dist: %d", score);
|
|
|
|
#else
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->snprintf(s, sizeof(s), "Distance: %d", score);
|
2007-07-25 10:21:54 +00:00
|
|
|
#endif
|
|
|
|
rb->lcd_getstringsize(s, &w, NULL);
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->lcd_putsxy(2, 2, s);
|
2007-07-25 10:21:54 +00:00
|
|
|
if (score < highscore)
|
|
|
|
{
|
|
|
|
int w2;
|
|
|
|
#if LCD_WIDTH <= 128
|
|
|
|
rb->snprintf(s, sizeof(s), "Hi: %d", highscore);
|
|
|
|
#else
|
|
|
|
rb->snprintf(s, sizeof(s), "Best: %d", highscore);
|
|
|
|
#endif
|
|
|
|
rb->lcd_getstringsize(s, &w2, NULL);
|
|
|
|
if (LCD_WIDTH - 2 - w2 > w + 2)
|
|
|
|
rb->lcd_putsxy(LCD_WIDTH - 2 - w2, 2, s);
|
|
|
|
}
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chopMenu(int menunum)
|
|
|
|
{
|
2007-07-25 10:21:54 +00:00
|
|
|
int result = (menunum==0)?0:1;
|
2007-02-16 01:23:48 +00:00
|
|
|
int res = 0;
|
|
|
|
bool menu_quit = false;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
static const struct opt_items levels[2] = {
|
|
|
|
{ "Normal", -1 },
|
|
|
|
{ "Steep", -1 },
|
|
|
|
};
|
2007-04-03 20:22:04 +00:00
|
|
|
|
|
|
|
MENUITEM_STRINGLIST(menu,"Chopper Menu",NULL,"Start New Game","Resume Game",
|
|
|
|
"Level","Quit");
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-17 23:06:22 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
2007-02-17 10:23:15 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
rb->lcd_set_background(LCD_WHITE);
|
2007-02-16 06:57:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while (!menu_quit) {
|
2007-05-20 08:26:27 +00:00
|
|
|
switch(rb->do_menu(&menu, &result))
|
2007-02-16 01:23:48 +00:00
|
|
|
{
|
|
|
|
case 0: /* Start New Game */
|
|
|
|
menu_quit=true;
|
|
|
|
chopper_load(true);
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
case 1: /* Resume Game */
|
|
|
|
if(menunum==1) {
|
|
|
|
menu_quit=true;
|
|
|
|
res = -1;
|
|
|
|
} else if(menunum==0){
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "No game to resume");
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rb->set_option("Level", &iLevelMode, INT, levels, 2, NULL);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
menu_quit=true;
|
|
|
|
res = PLUGIN_OK;
|
|
|
|
break;
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
menu_quit=true;
|
|
|
|
res = PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chopGameLoop(void)
|
|
|
|
{
|
|
|
|
int move_button, ret;
|
|
|
|
bool exit=false;
|
|
|
|
int end, i=0, bdelay=0, last_button=BUTTON_NONE;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if (chopUpdateTerrainRecycling(&mGround) == 1)
|
|
|
|
/* mirror the sky if we've changed the ground */
|
2007-02-20 00:40:21 +00:00
|
|
|
chopCopyTerrain(&mGround, &mRoof, 0, - ( (iScreenY * 3) / 4));
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
ret = chopMenu(0);
|
|
|
|
if (ret != -1)
|
|
|
|
return PLUGIN_OK;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
|
|
|
chopDrawScene();
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
while (!exit) {
|
|
|
|
|
|
|
|
end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if(chopUpdateTerrainRecycling(&mGround) == 1)
|
|
|
|
/* mirror the sky if we've changed the ground */
|
2007-02-20 00:40:21 +00:00
|
|
|
chopCopyTerrain(&mGround, &mRoof, 0, - ( (iScreenY * 3) / 4));
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iRotorOffset = iR(-1,1);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
/* We need to have this here so particles move when we're dead */
|
|
|
|
|
|
|
|
for (i=0; i < NUMBER_OF_PARTICLES; i++)
|
|
|
|
if(mParticles[i].bIsActive == 1)
|
|
|
|
{
|
|
|
|
mParticles[i].iWorldX += mParticles[i].iSpeedX;
|
|
|
|
mParticles[i].iWorldY += mParticles[i].iSpeedY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw the main window: */
|
2007-02-16 06:57:49 +00:00
|
|
|
chopDrawScene();
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
iGravityTimerCountdown--;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if(iGravityTimerCountdown <= 0)
|
|
|
|
{
|
|
|
|
iGravityTimerCountdown = 3;
|
|
|
|
chopAddParticle(iPlayerPosX, iPlayerPosY+5, 0, 0);
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if(iLevelMode == LEVEL_MODE_NORMAL)
|
|
|
|
chopGenerateBlockIfNeeded();
|
|
|
|
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
move_button=rb->button_status();
|
|
|
|
if (rb->button_get(false) == QUIT) {
|
|
|
|
ret = chopMenu(1);
|
|
|
|
if (ret != -1)
|
|
|
|
return PLUGIN_OK;
|
|
|
|
bdelay = 0;
|
|
|
|
last_button = BUTTON_NONE;
|
|
|
|
move_button = BUTTON_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (move_button) {
|
|
|
|
case ACTION:
|
|
|
|
#ifdef ACTION2
|
|
|
|
case ACTION2:
|
|
|
|
#endif
|
|
|
|
if (last_button != ACTION
|
|
|
|
#ifdef ACTION2
|
|
|
|
&& last_button != ACTION2
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
bdelay = -2;
|
|
|
|
if (bdelay == 0)
|
|
|
|
iPlayerSpeedY = -3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (last_button == ACTION
|
|
|
|
#ifdef ACTION2
|
|
|
|
|| last_button == ACTION2
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
bdelay = 3;
|
|
|
|
if (bdelay == 0)
|
|
|
|
iPlayerSpeedY = 4;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if (rb->default_event_handler(move_button) == SYS_USB_CONNECTED)
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_button = move_button;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if (bdelay < 0) {
|
|
|
|
iPlayerSpeedY = bdelay;
|
|
|
|
bdelay++;
|
|
|
|
} else if (bdelay > 0) {
|
|
|
|
iPlayerSpeedY = bdelay;
|
|
|
|
bdelay--;
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
iCameraPosX = iPlayerPosX - 25;
|
|
|
|
iPlayerPosX += iPlayerSpeedX;
|
|
|
|
iPlayerPosY += iPlayerSpeedY;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
chopCounter++;
|
|
|
|
/* increase speed as we go along */
|
|
|
|
if (chopCounter == 100){
|
|
|
|
iPlayerSpeedX++;
|
|
|
|
chopCounter=0;
|
|
|
|
}
|
|
|
|
|
2007-02-16 06:57:49 +00:00
|
|
|
if (iPlayerPosY > iScreenY-10 || iPlayerPosY < -5 ||
|
|
|
|
chopPointInTerrain(&mGround, iPlayerPosX, iPlayerPosY + 10, 0) ||
|
2007-02-16 01:23:48 +00:00
|
|
|
chopPointInTerrain(&mRoof, iPlayerPosX ,iPlayerPosY, 1))
|
|
|
|
{
|
|
|
|
chopKillPlayer();
|
|
|
|
chopDrawScene();
|
|
|
|
ret = chopMenu(0);
|
|
|
|
if (ret != -1)
|
|
|
|
return ret;
|
|
|
|
}
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
for (i=0; i < NUMBER_OF_BLOCKS; i++)
|
|
|
|
if(mBlocks[i].bIsActive == 1)
|
|
|
|
if(chopBlockCollideWithPlayer(&mBlocks[i])) {
|
|
|
|
chopKillPlayer();
|
|
|
|
chopDrawScene();
|
|
|
|
ret = chopMenu(0);
|
|
|
|
if (ret != -1)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end > *rb->current_tick)
|
|
|
|
rb->sleep(end-*rb->current_tick);
|
|
|
|
else
|
|
|
|
rb->yield();
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chopDrawBlock(struct CBlock *mBlock)
|
2007-02-16 06:57:49 +00:00
|
|
|
{
|
2007-02-16 01:23:48 +00:00
|
|
|
int iPosX = (mBlock->iWorldX - iCameraPosX);
|
|
|
|
int iPosY = (mBlock->iWorldY);
|
|
|
|
#if LCD_DEPTH > 2
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(100,255,100));
|
2007-02-16 01:23:48 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_BLACK);
|
|
|
|
#endif
|
2007-02-20 00:40:21 +00:00
|
|
|
rb->lcd_fillrect(SCALE(iPosX), SCALE(iPosY), SCALE(mBlock->iSizeX),
|
|
|
|
SCALE(mBlock->iSizeY));
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void chopRenderTerrain(struct CTerrain *ter)
|
|
|
|
{
|
|
|
|
|
|
|
|
int i=1;
|
|
|
|
|
|
|
|
int oldx=0;
|
|
|
|
|
|
|
|
int ay=0;
|
2007-02-20 00:40:21 +00:00
|
|
|
if(ter->mNodes[0].y < (LCD_HEIGHT*SIZE)/2)
|
2007-02-16 01:23:48 +00:00
|
|
|
ay=0;
|
2007-02-16 06:57:49 +00:00
|
|
|
else
|
2007-02-20 00:40:21 +00:00
|
|
|
ay=(LCD_HEIGHT*SIZE);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-20 00:40:21 +00:00
|
|
|
while(i < ter->iNodesCount && oldx < iScreenX)
|
2007-02-16 01:23:48 +00:00
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int x = ter->mNodes[i-1].x - iCameraPosX;
|
|
|
|
int y = ter->mNodes[i-1].y;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int x2 = ter->mNodes[i].x - iCameraPosX;
|
|
|
|
int y2 = ter->mNodes[i].y;
|
|
|
|
#if LCD_DEPTH > 2
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_foreground(LCD_RGBPACK(100,255,100));
|
2007-02-16 01:23:48 +00:00
|
|
|
#elif LCD_DEPTH == 2
|
|
|
|
rb->lcd_set_foreground(LCD_DARKGRAY);
|
|
|
|
#endif
|
|
|
|
|
2007-02-20 00:40:21 +00:00
|
|
|
rb->lcd_drawline(SCALE(x), SCALE(y), SCALE(x2), SCALE(y2));
|
|
|
|
|
|
|
|
xlcd_filltriangle(SCALE(x), SCALE(y), SCALE(x2), SCALE(y2), SCALE(x2), SCALE(ay));
|
|
|
|
xlcd_filltriangle(SCALE(x), SCALE(ay), SCALE(x2), SCALE(y2), SCALE(x2), SCALE(ay));
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if (ay == 0)
|
2007-02-20 00:40:21 +00:00
|
|
|
xlcd_filltriangle(SCALE(x), SCALE(ay), SCALE(x), SCALE(y), SCALE(x2), SCALE(y2 / 2));
|
2007-02-16 01:23:48 +00:00
|
|
|
else
|
2007-02-20 00:40:21 +00:00
|
|
|
xlcd_filltriangle(SCALE(x), SCALE(ay), SCALE(x), SCALE(y), SCALE(x2), SCALE((LCD_HEIGHT*SIZE) - ((LCD_HEIGHT*SIZE) - y2) / 2));
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
oldx = x;
|
|
|
|
i++;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void chopper_load(bool newgame)
|
|
|
|
{
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
int i;
|
|
|
|
int g;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
if (newgame) {
|
2007-02-20 00:40:21 +00:00
|
|
|
iScreenX = LCD_WIDTH * SIZE;
|
|
|
|
iScreenY = LCD_HEIGHT * SIZE;
|
|
|
|
blockh = iScreenY / 5;
|
|
|
|
blockw = iScreenX / 20;
|
2007-02-16 01:23:48 +00:00
|
|
|
iPlayerAlive = 1;
|
|
|
|
score = 0;
|
|
|
|
}
|
|
|
|
iRotorOffset = 0;
|
|
|
|
iPlayerPosX = 60;
|
2007-02-20 00:40:21 +00:00
|
|
|
iPlayerPosY = (iScreenY * 4) / 10;
|
2007-02-16 01:23:48 +00:00
|
|
|
iLastBlockPlacedPosX = 0;
|
|
|
|
iGravityTimerCountdown = 2;
|
|
|
|
chopCounter = 0;
|
|
|
|
iPlayerSpeedX = 3;
|
|
|
|
iPlayerSpeedY = 0;
|
2007-02-16 06:57:49 +00:00
|
|
|
iCameraPosX = 30;
|
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
for (i=0; i < NUMBER_OF_PARTICLES; i++)
|
|
|
|
mParticles[i].bIsActive = 0;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
for (i=0; i < NUMBER_OF_BLOCKS; i++)
|
|
|
|
mBlocks[i].bIsActive = 0;
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
g = iScreenY - 10;
|
|
|
|
chopClearTerrain(&mGround);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
for (i=0; i < MAX_TERRAIN_NODES; i++)
|
|
|
|
chopAddTerrainNode(&mGround,i * 30,g - iR(0,20));
|
|
|
|
|
|
|
|
if (chopUpdateTerrainRecycling(&mGround) == 1)
|
|
|
|
/* mirror the sky if we've changed the ground */
|
2007-02-20 00:40:21 +00:00
|
|
|
chopCopyTerrain(&mGround, &mRoof, 0, - ( (iScreenY * 3) / 4));
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
iLevelMode = LEVEL_MODE_NORMAL;
|
|
|
|
if (iLevelMode == LEVEL_MODE_NORMAL)
|
|
|
|
/* make it a bit more exciting, cause it's easy terrain... */
|
|
|
|
iPlayerSpeedX *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the plugin entry point */
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
rb = api;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
2007-02-16 06:57:49 +00:00
|
|
|
#if LCD_DEPTH > 1
|
|
|
|
rb->lcd_set_backdrop(NULL);
|
|
|
|
#endif
|
2007-02-17 23:06:22 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2007-02-16 06:57:49 +00:00
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
#endif
|
|
|
|
|
2007-08-15 12:42:09 +00:00
|
|
|
/* Turn off backlight timeout */
|
2007-08-16 23:01:18 +00:00
|
|
|
backlight_force_on(rb); /* backlight control in lib/helper.c */
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
rb->srand( *rb->current_tick );
|
|
|
|
|
|
|
|
xlcd_init(rb);
|
|
|
|
configfile_init(rb);
|
|
|
|
configfile_load(CFG_FILE, config, 1, 0);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
chopper_load(true);
|
|
|
|
ret = chopGameLoop();
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
configfile_save(CFG_FILE, config, 1, 0);
|
2007-02-16 06:57:49 +00:00
|
|
|
|
2007-02-16 01:23:48 +00:00
|
|
|
rb->lcd_setfont(FONT_UI);
|
2007-08-15 12:42:09 +00:00
|
|
|
/* Turn on backlight timeout (revert to settings) */
|
2007-08-16 23:01:18 +00:00
|
|
|
backlight_use_settings(rb); /* backlight control in lib/helper.c */
|
2007-02-16 01:23:48 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|