1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Originally by Joshua Oreman, improved by Prashant Varanasi
11 * Ported to Rockbox by Ben Basha (Paprica)
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
25 #include "lib/configfile.h"
26 #include "lib/helper.h"
27 #include "lib/playback_control.h"
33 - Make original speed and further increases in speed depend more on screen size
34 - attempt to make the tunnels get narrower as the game goes on
35 - make the chopper look better, maybe a picture, and scale according
37 - use textures for the color screens for background and terrain,
38 eg stars on background
39 - allow choice of different levels [later: different screen themes]
40 - better high score handling, improved screen etc.
43 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
45 #define QUIT BUTTON_OFF
46 #define ACTION BUTTON_UP
47 #define ACTION2 BUTTON_SELECT
48 #define ACTIONTEXT "SELECT"
50 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
51 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
52 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
54 #define QUIT BUTTON_MENU
55 #define ACTION BUTTON_SELECT
56 #define ACTIONTEXT "SELECT"
58 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD /* grayscale at the moment */
60 #define QUIT BUTTON_POWER
61 #define ACTION BUTTON_UP
62 #define ACTION2 BUTTON_SELECT
63 #define ACTIONTEXT "SELECT"
65 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
66 #define QUIT BUTTON_POWER
67 #define ACTION BUTTON_RIGHT
68 #define ACTIONTEXT "RIGHT"
70 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
71 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
72 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
73 (CONFIG_KEYPAD == SANSA_M200_PAD)
74 #define QUIT BUTTON_POWER
75 #define ACTION BUTTON_SELECT
76 #define ACTIONTEXT "SELECT"
78 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
79 #define QUIT BUTTON_HOME
80 #define ACTION BUTTON_SELECT
81 #define ACTIONTEXT "SELECT"
83 #elif CONFIG_KEYPAD == GIGABEAT_PAD
84 #define QUIT BUTTON_MENU
85 #define ACTION BUTTON_SELECT
86 #define ACTIONTEXT "SELECT"
88 #elif CONFIG_KEYPAD == RECORDER_PAD
89 #define QUIT BUTTON_OFF
90 #define ACTION BUTTON_PLAY
91 #define ACTIONTEXT "PLAY"
93 #elif CONFIG_KEYPAD == ONDIO_PAD
94 #define QUIT BUTTON_OFF
95 #define ACTION BUTTON_UP
96 #define ACTION2 BUTTON_MENU
97 #define ACTIONTEXT "UP"
99 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
100 #define QUIT BUTTON_BACK
101 #define ACTION BUTTON_SELECT
102 #define ACTION2 BUTTON_MENU
103 #define ACTIONTEXT "SELECT"
105 #elif CONFIG_KEYPAD == MROBE100_PAD
106 #define QUIT BUTTON_POWER
107 #define ACTION BUTTON_SELECT
108 #define ACTIONTEXT "SELECT"
110 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
111 #define QUIT BUTTON_RC_REC
112 #define ACTION BUTTON_RC_PLAY
113 #define ACTION2 BUTTON_RC_MODE
114 #define ACTIONTEXT "PLAY"
116 #elif CONFIG_KEYPAD == COWON_D2_PAD
117 #define QUIT BUTTON_POWER
118 #define ACTION2 BUTTON_PLUS
120 #elif CONFIG_KEYPAD == IAUDIO67_PAD
121 #define QUIT BUTTON_POWER
122 #define ACTION BUTTON_PLAY
123 #define ACTION2 BUTTON_STOP
124 #define ACTIONTEXT "PLAY"
126 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
127 #define QUIT BUTTON_BACK
128 #define ACTION BUTTON_UP
129 #define ACTION2 BUTTON_MENU
130 #define ACTIONTEXT "UP"
132 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
133 #define QUIT BUTTON_POWER
134 #define ACTION BUTTON_MENU
135 #define ACTION2 BUTTON_SELECT
136 #define ACTIONTEXT "MENU"
138 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
139 #define QUIT BUTTON_POWER
140 #define ACTION BUTTON_MENU
141 #define ACTION2 BUTTON_PLAY
142 #define ACTIONTEXT "MENU"
144 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
145 #define QUIT BUTTON_POWER
146 #define ACTION BUTTON_MENU
147 #define ACTION2 BUTTON_PLAY
148 #define ACTIONTEXT "MENU"
150 #elif CONFIG_KEYPAD == ONDAVX747_PAD || \
151 CONFIG_KEYPAD == ONDAVX777_PAD || \
152 CONFIG_KEYPAD == MROBE500_PAD
153 #define QUIT BUTTON_POWER
155 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
156 #define QUIT BUTTON_LEFT
157 #define ACTION BUTTON_RIGHT
158 #define ACTIONTEXT "RIGHT"
160 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
161 #define QUIT BUTTON_REC
162 #define ACTION BUTTON_PLAY
163 #define ACTION2 BUTTON_UP
164 #define ACTIONTEXT "PLAY"
166 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
167 #define QUIT (BUTTON_REC|BUTTON_PLAY)
168 #define ACTION BUTTON_FUNC
169 #define ACTIONTEXT "FUNC"
171 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
172 #define QUIT BUTTON_REC
173 #define ACTION BUTTON_ENTER
174 #define ACTIONTEXT "ENTER"
177 #elif !defined(HAVE_TOUCHSCREEN)
178 #error No keymap defined!
181 #ifdef HAVE_TOUCHSCREEN
183 #define QUIT BUTTON_TOPLEFT
186 #define ACTION BUTTON_BOTTOMLEFT
189 #define ACTION2 BUTTON_BOTTOMRIGHT
192 #define ACTIONTEXT "BOTTOMRIGHT"
196 #define NUMBER_OF_BLOCKS 8
197 #define NUMBER_OF_PARTICLES 3
198 #define MAX_TERRAIN_NODES 15
200 #define LEVEL_MODE_NORMAL 0
201 #define LEVEL_MODE_STEEP 1
205 static inline int SCALE(int x
)
207 return x
== 1 ? x
: x
>> 1;
216 /* in 10 milisecond (ticks) */
217 #define CYCLETIME ((CYCLES*HZ)/1000)
219 /*Chopper's local variables to track the terrain position etc*/
220 static int chopCounter
;
221 static int iRotorOffset
;
224 static int iPlayerPosX
;
225 static int iPlayerPosY
;
226 static int iCameraPosX
;
227 static int iPlayerSpeedX
;
228 static int iPlayerSpeedY
;
229 static int iLastBlockPlacedPosX
;
230 static int iGravityTimerCountdown
;
231 static int iPlayerAlive
;
232 static int iLevelMode
, iCurrLevelMode
;
233 static int blockh
,blockw
;
234 static int highscore
;
237 #define CFG_FILE "chopper.cfg"
238 #define MAX_POINTS 50000
239 static struct configdata config
[] =
241 {TYPE_INT
, 0, MAX_POINTS
, { .int_p
= &highscore
}, "highscore", NULL
}
274 struct CTerrainNode mNodes
[MAX_TERRAIN_NODES
];
276 int iLastNodePlacedPosX
;
279 struct CBlock mBlocks
[NUMBER_OF_BLOCKS
];
280 struct CParticle mParticles
[NUMBER_OF_PARTICLES
];
282 struct CTerrain mGround
;
283 struct CTerrain mRoof
;
285 /*Function declarations*/
286 static void chopDrawParticle(struct CParticle
*mParticle
);
287 static void chopDrawBlock(struct CBlock
*mBlock
);
288 static void chopRenderTerrain(struct CTerrain
*ter
, bool isground
);
289 void chopper_load(bool newgame
);
290 void cleanup_chopper(void);
292 static void chopDrawPlayer(int x
,int y
) /* These are SCREEN coords, not world!*/
296 rb
->lcd_set_foreground(LCD_RGBPACK(50,50,200));
298 rb
->lcd_set_foreground(LCD_DARKGRAY
);
300 rb
->lcd_fillrect(SCALE(x
+6), SCALE(y
+2), SCALE(12), SCALE(9));
301 rb
->lcd_fillrect(SCALE(x
-3), SCALE(y
+6), SCALE(20), SCALE(3));
304 rb
->lcd_set_foreground(LCD_RGBPACK(50,50,50));
306 rb
->lcd_set_foreground(LCD_DARKGRAY
);
308 rb
->lcd_fillrect(SCALE(x
+10), SCALE(y
), SCALE(2), SCALE(3));
309 rb
->lcd_fillrect(SCALE(x
+10), SCALE(y
), SCALE(1), SCALE(3));
312 rb
->lcd_set_foreground(LCD_RGBPACK(40,40,100));
314 rb
->lcd_set_foreground(LCD_BLACK
);
316 rb
->lcd_drawline(SCALE(x
), SCALE(y
+iRotorOffset
), SCALE(x
+20),
317 SCALE(y
-iRotorOffset
));
320 rb
->lcd_set_foreground(LCD_RGBPACK(20,20,50));
322 rb
->lcd_set_foreground(LCD_BLACK
);
324 rb
->lcd_fillrect(SCALE(x
- 2), SCALE(y
+ 5), SCALE(2), SCALE(5));
328 static void chopClearTerrain(struct CTerrain
*ter
)
330 ter
->iNodesCount
= 0;
334 int iR(int low
,int high
)
336 return low
+rb
->rand()%(high
-low
+1);
339 static void chopCopyTerrain(struct CTerrain
*src
, struct CTerrain
*dest
,
340 int xOffset
,int yOffset
)
344 while(i
< src
->iNodesCount
)
346 dest
->mNodes
[i
].x
= src
->mNodes
[i
].x
+ xOffset
;
347 dest
->mNodes
[i
].y
= src
->mNodes
[i
].y
+ yOffset
;
352 dest
->iNodesCount
= src
->iNodesCount
;
353 dest
->iLastNodePlacedPosX
= src
->iLastNodePlacedPosX
;
357 static void chopAddTerrainNode(struct CTerrain
*ter
, int x
, int y
)
361 if(ter
->iNodesCount
+ 1 >= MAX_TERRAIN_NODES
)
363 /* DEBUGF("ERROR: Not enough nodes!\n"); */
369 i
= ter
->iNodesCount
- 1;
371 ter
->mNodes
[i
].x
= x
;
374 ter
->iLastNodePlacedPosX
= x
;
378 static void chopTerrainNodeDeleteAndShift(struct CTerrain
*ter
,int nodeIndex
)
382 while( i
< ter
->iNodesCount
)
384 ter
->mNodes
[i
- 1] = ter
->mNodes
[i
];
393 int chopUpdateTerrainRecycling(struct CTerrain
*ter
)
398 while(i
< ter
->iNodesCount
)
401 if( iCameraPosX
> ter
->mNodes
[i
].x
)
404 chopTerrainNodeDeleteAndShift(ter
,i
);
406 iNewNodePos
= ter
->iLastNodePlacedPosX
+ 50;
412 if(iCurrLevelMode
== LEVEL_MODE_STEEP
)
415 chopAddTerrainNode(ter
,iNewNodePos
,g
- iR(-v
,v
));
427 int chopTerrainHeightAtPoint(struct CTerrain
*ter
, int pX
)
430 int iNodeIndexOne
=0,iNodeIndexTwo
=0, h
, terY1
, terY2
, terX1
, terX2
, a
, b
;
434 for(i
=1;i
<MAX_TERRAIN_NODES
;i
++)
436 if(ter
->mNodes
[i
].x
> pX
)
438 iNodeIndexOne
= i
- 1;
444 iNodeIndexTwo
= iNodeIndexOne
+ 1;
445 terY1
= ter
->mNodes
[iNodeIndexOne
].y
;
446 terY2
= ter
->mNodes
[iNodeIndexTwo
].y
;
449 terX2
= ter
->mNodes
[iNodeIndexTwo
].x
- ter
->mNodes
[iNodeIndexOne
].x
;
451 pX
-= ter
->mNodes
[iNodeIndexOne
].x
;
464 int chopPointInTerrain(struct CTerrain
*ter
, int pX
, int pY
, int iTestType
)
466 int h
= chopTerrainHeightAtPoint(ter
, pX
);
474 static void chopAddBlock(int x
,int y
,int sx
,int sy
, int indexOverride
)
478 if(indexOverride
< 0)
480 while(mBlocks
[i
].bIsActive
&& i
< NUMBER_OF_BLOCKS
)
482 if(i
==NUMBER_OF_BLOCKS
)
484 DEBUGF("No blocks!\n");
491 mBlocks
[i
].bIsActive
= 1;
492 mBlocks
[i
].iWorldX
= x
;
493 mBlocks
[i
].iWorldY
= y
;
494 mBlocks
[i
].iSizeX
= sx
;
495 mBlocks
[i
].iSizeY
= sy
;
497 iLastBlockPlacedPosX
= x
;
500 static void chopAddParticle(int x
,int y
,int sx
,int sy
)
504 while(mParticles
[i
].bIsActive
&& i
< NUMBER_OF_PARTICLES
)
507 if(i
==NUMBER_OF_PARTICLES
)
510 mParticles
[i
].bIsActive
= 1;
511 mParticles
[i
].iWorldX
= x
;
512 mParticles
[i
].iWorldY
= y
;
513 mParticles
[i
].iSpeedX
= sx
;
514 mParticles
[i
].iSpeedY
= sy
;
517 static void chopGenerateBlockIfNeeded(void)
520 int DistSpeedX
= iPlayerSpeedX
* 5;
521 if(DistSpeedX
<200) DistSpeedX
= 200;
523 while(i
< NUMBER_OF_BLOCKS
)
525 if(!mBlocks
[i
].bIsActive
)
529 iX
= iLastBlockPlacedPosX
+ (350-DistSpeedX
);
533 sY
= blockh
+ iR(1,blockh
/3);
535 chopAddBlock(iX
,iY
,sX
,sY
,i
);
543 static int chopBlockCollideWithPlayer(struct CBlock
*mBlock
)
545 int px
= iPlayerPosX
;
546 int py
= iPlayerPosY
;
548 int x
= mBlock
->iWorldX
-17;
549 int y
= mBlock
->iWorldY
-11;
551 int x2
= x
+ mBlock
->iSizeX
+17;
552 int y2
= y
+ mBlock
->iSizeY
+11;
565 static int chopBlockOffscreen(struct CBlock
*mBlock
)
567 if(mBlock
->iWorldX
+ mBlock
->iSizeX
< iCameraPosX
)
573 static int chopParticleOffscreen(struct CParticle
*mParticle
)
575 if (mParticle
->iWorldX
< iCameraPosX
|| mParticle
->iWorldY
< 0 ||
576 mParticle
->iWorldY
> iScreenY
|| mParticle
->iWorldX
> iCameraPosX
+
585 static void chopKillPlayer(void)
589 for (i
= 0; i
< NUMBER_OF_PARTICLES
; i
++) {
590 mParticles
[i
].bIsActive
= 0;
591 chopAddParticle(iPlayerPosX
+ iR(0,20), iPlayerPosY
+ iR(0,20),
597 if (iPlayerAlive
== 0) {
598 rb
->splash(HZ
, "Game Over");
600 if (score
> highscore
) {
603 rb
->snprintf(scoretext
, sizeof(scoretext
), "New High Score: %d",
605 rb
->splash(HZ
*2, scoretext
);
611 static void chopDrawTheWorld(void)
615 while(i
< NUMBER_OF_BLOCKS
)
617 if(mBlocks
[i
].bIsActive
)
619 if(chopBlockOffscreen(&mBlocks
[i
]) == 1)
620 mBlocks
[i
].bIsActive
= 0;
622 chopDrawBlock(&mBlocks
[i
]);
630 while(i
< NUMBER_OF_PARTICLES
)
632 if(mParticles
[i
].bIsActive
)
634 if(chopParticleOffscreen(&mParticles
[i
]) == 1)
635 mParticles
[i
].bIsActive
= 0;
637 chopDrawParticle(&mParticles
[i
]);
643 chopRenderTerrain(&mGround
, true);
644 chopRenderTerrain(&mRoof
, false);
648 static void chopDrawParticle(struct CParticle
*mParticle
)
651 int iPosX
= (mParticle
->iWorldX
- iCameraPosX
);
652 int iPosY
= (mParticle
->iWorldY
);
654 rb
->lcd_set_foreground(LCD_RGBPACK(192,192,192));
656 rb
->lcd_set_foreground(LCD_LIGHTGRAY
);
658 rb
->lcd_fillrect(SCALE(iPosX
), SCALE(iPosY
), SCALE(3), SCALE(3));
662 static void chopDrawScene(void)
667 rb
->lcd_set_background(LCD_BLACK
);
669 rb
->lcd_set_background(LCD_WHITE
);
671 rb
->lcd_clear_display();
673 chopDrawPlayer(iPlayerPosX
- iCameraPosX
, iPlayerPosY
);
675 score
= -20 + iPlayerPosX
/3;
678 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
680 rb
->lcd_set_drawmode(DRMODE_FG
);
684 rb
->lcd_set_foreground(LCD_BLACK
);
686 rb
->lcd_set_foreground(LCD_WHITE
);
690 rb
->snprintf(s
, sizeof(s
), "Dist: %d", score
);
692 rb
->snprintf(s
, sizeof(s
), "Distance: %d", score
);
694 rb
->lcd_getstringsize(s
, &w
, NULL
);
695 rb
->lcd_putsxy(2, 2, s
);
696 if (score
< highscore
)
700 rb
->snprintf(s
, sizeof(s
), "Hi: %d", highscore
);
702 rb
->snprintf(s
, sizeof(s
), "Best: %d", highscore
);
704 rb
->lcd_getstringsize(s
, &w2
, NULL
);
705 if (LCD_WIDTH
- 2 - w2
> w
+ 2)
706 rb
->lcd_putsxy(LCD_WIDTH
- 2 - w2
, 2, s
);
708 rb
->lcd_set_drawmode(DRMODE_SOLID
);
714 static int chopMenuCb(int action
, const struct menu_item_ex
*this_item
)
716 if(action
== ACTION_REQUEST_MENUITEM
717 && !_ingame
&& ((intptr_t)this_item
)==0)
718 return ACTION_EXIT_MENUITEM
;
721 static int chopMenu(int menunum
)
725 bool menu_quit
= false;
727 static const struct opt_items levels
[2] = {
732 MENUITEM_STRINGLIST(menu
,"Chopper Menu",chopMenuCb
,
733 "Resume Game","Start New Game",
734 "Level","Playback Control","Quit");
735 _ingame
= (menunum
!=0);
737 #ifdef HAVE_LCD_COLOR
738 rb
->lcd_set_foreground(LCD_WHITE
);
739 rb
->lcd_set_background(LCD_BLACK
);
741 rb
->lcd_set_foreground(LCD_BLACK
);
742 rb
->lcd_set_background(LCD_WHITE
);
745 rb
->lcd_clear_display();
746 rb
->button_clear_queue();
749 switch(rb
->do_menu(&menu
, &result
, NULL
, false))
751 case 0: /* Resume Game */
755 case 1: /* Start New Game */
761 rb
->set_option("Level", &iLevelMode
, INT
, levels
, 2, NULL
);
764 playback_control(NULL
);
770 case MENU_ATTACHED_USB
:
772 res
= PLUGIN_USB_CONNECTED
;
776 rb
->lcd_clear_display();
780 static int chopGameLoop(void)
782 int move_button
, ret
;
784 int end
, i
=0, bdelay
=0, last_button
=BUTTON_NONE
;
786 if (chopUpdateTerrainRecycling(&mGround
) == 1)
787 /* mirror the sky if we've changed the ground */
788 chopCopyTerrain(&mGround
, &mRoof
, 0, - ( (iScreenY
* 3) / 4));
798 end
= *rb
->current_tick
+ CYCLETIME
;
800 if(chopUpdateTerrainRecycling(&mGround
) == 1)
801 /* mirror the sky if we've changed the ground */
802 chopCopyTerrain(&mGround
, &mRoof
, 0, - ( (iScreenY
* 3) / 4));
804 iRotorOffset
= iR(-1,1);
806 /* We need to have this here so particles move when we're dead */
808 for (i
=0; i
< NUMBER_OF_PARTICLES
; i
++)
809 if(mParticles
[i
].bIsActive
== 1)
811 mParticles
[i
].iWorldX
+= mParticles
[i
].iSpeedX
;
812 mParticles
[i
].iWorldY
+= mParticles
[i
].iSpeedY
;
815 /* Redraw the main window: */
819 iGravityTimerCountdown
--;
821 if(iGravityTimerCountdown
<= 0)
823 iGravityTimerCountdown
= 3;
824 chopAddParticle(iPlayerPosX
, iPlayerPosY
+5, 0, 0);
827 if(iCurrLevelMode
== LEVEL_MODE_NORMAL
)
828 chopGenerateBlockIfNeeded();
831 move_button
=rb
->button_status();
832 if (rb
->button_get(false) == QUIT
) {
837 last_button
= BUTTON_NONE
;
838 move_button
= BUTTON_NONE
;
841 switch (move_button
) {
846 if (last_button
!= ACTION
848 && last_button
!= ACTION2
857 if (last_button
== ACTION
859 || last_button
== ACTION2
866 if (rb
->default_event_handler(move_button
) == SYS_USB_CONNECTED
)
867 return PLUGIN_USB_CONNECTED
;
870 last_button
= move_button
;
873 iPlayerSpeedY
= bdelay
;
875 } else if (bdelay
> 0) {
876 iPlayerSpeedY
= bdelay
;
880 iCameraPosX
= iPlayerPosX
- 25;
881 iPlayerPosX
+= iPlayerSpeedX
;
882 iPlayerPosY
+= iPlayerSpeedY
;
885 /* increase speed as we go along */
886 if (chopCounter
== 100){
891 if (iPlayerPosY
> iScreenY
-10 || iPlayerPosY
< -5 ||
892 chopPointInTerrain(&mGround
, iPlayerPosX
, iPlayerPosY
+ 10, 0) ||
893 chopPointInTerrain(&mRoof
, iPlayerPosX
,iPlayerPosY
, 1))
902 for (i
=0; i
< NUMBER_OF_BLOCKS
; i
++)
903 if(mBlocks
[i
].bIsActive
== 1)
904 if(chopBlockCollideWithPlayer(&mBlocks
[i
])) {
912 if (TIME_BEFORE(*rb
->current_tick
, end
))
913 rb
->sleep(end
- *rb
->current_tick
); /* wait until time is over */
921 static void chopDrawBlock(struct CBlock
*mBlock
)
923 int iPosX
= (mBlock
->iWorldX
- iCameraPosX
);
924 int iPosY
= (mBlock
->iWorldY
);
926 rb
->lcd_set_foreground(LCD_RGBPACK(100,255,100));
928 rb
->lcd_set_foreground(LCD_BLACK
);
930 rb
->lcd_fillrect(SCALE(iPosX
), SCALE(iPosY
), SCALE(mBlock
->iSizeX
),
931 SCALE(mBlock
->iSizeY
));
935 static void chopRenderTerrain(struct CTerrain
*ter
, bool isground
)
942 while(i
< ter
->iNodesCount
&& oldx
< iScreenX
)
945 int x
= ter
->mNodes
[i
-1].x
- iCameraPosX
;
946 int y
= ter
->mNodes
[i
-1].y
;
948 int x2
= ter
->mNodes
[i
].x
- iCameraPosX
;
949 int y2
= ter
->mNodes
[i
].y
;
953 if ((y
< y2
) != isground
)
964 rb
->lcd_set_foreground(LCD_RGBPACK(100,255,100));
966 rb
->lcd_set_foreground(LCD_DARKGRAY
);
969 rb
->lcd_drawline(SCALE(x
), SCALE(y
), SCALE(x2
), SCALE(y2
));
971 xlcd_filltriangle(SCALE(x
), SCALE(y
), SCALE(x2
), SCALE(y2
),
972 SCALE(ax
), SCALE(ay
));
977 y2
= (LCD_HEIGHT
*SIZE
);
985 rb
->lcd_fillrect(SCALE(x
), SCALE(y
), SCALE(x2
-x
)+1, SCALE(y2
-y
)+1);
992 void chopper_load(bool newgame
)
999 iScreenX
= LCD_WIDTH
* SIZE
;
1000 iScreenY
= LCD_HEIGHT
* SIZE
;
1001 blockh
= iScreenY
/ 5;
1002 blockw
= iScreenX
/ 20;
1004 iCurrLevelMode
= iLevelMode
;
1009 iPlayerPosY
= (iScreenY
* 4) / 10;
1010 iLastBlockPlacedPosX
= 0;
1011 iGravityTimerCountdown
= 2;
1017 for (i
=0; i
< NUMBER_OF_PARTICLES
; i
++)
1018 mParticles
[i
].bIsActive
= 0;
1020 for (i
=0; i
< NUMBER_OF_BLOCKS
; i
++)
1021 mBlocks
[i
].bIsActive
= 0;
1024 chopClearTerrain(&mGround
);
1026 for (i
=0; i
< MAX_TERRAIN_NODES
; i
++)
1027 chopAddTerrainNode(&mGround
,i
* 30,g
- iR(0,20));
1029 if (chopUpdateTerrainRecycling(&mGround
) == 1)
1030 /* mirror the sky if we've changed the ground */
1031 chopCopyTerrain(&mGround
, &mRoof
, 0, - ( (iScreenY
* 3) / 4));
1033 if (iCurrLevelMode
== LEVEL_MODE_NORMAL
)
1034 /* make it a bit more exciting, cause it's easy terrain... */
1038 /* this is the plugin entry point */
1039 enum plugin_status
plugin_start(const void* parameter
)
1044 rb
->lcd_setfont(FONT_SYSFIXED
);
1046 rb
->lcd_set_backdrop(NULL
);
1048 #ifdef HAVE_LCD_COLOR
1049 rb
->lcd_set_background(LCD_BLACK
);
1050 rb
->lcd_set_foreground(LCD_WHITE
);
1053 /* Turn off backlight timeout */
1054 backlight_force_on(); /* backlight control in lib/helper.c */
1056 rb
->srand( *rb
->current_tick
);
1058 configfile_load(CFG_FILE
, config
, 1, 0);
1061 ret
= chopGameLoop();
1063 configfile_save(CFG_FILE
, config
, 1, 0);
1065 rb
->lcd_setfont(FONT_UI
);
1066 /* Turn on backlight timeout (revert to settings) */
1067 backlight_use_settings(); /* backlight control in lib/helper.c */