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 #error No keymap defined!
180 #ifdef HAVE_TOUCHSCREEN
182 #define QUIT BUTTON_TOPLEFT
185 #define ACTION BUTTON_BOTTOMLEFT
188 #define ACTION2 BUTTON_BOTTOMRIGHT
191 #define ACTIONTEXT "BOTTOMRIGHT"
195 #define NUMBER_OF_BLOCKS 8
196 #define NUMBER_OF_PARTICLES 3
197 #define MAX_TERRAIN_NODES 15
199 #define LEVEL_MODE_NORMAL 0
200 #define LEVEL_MODE_STEEP 1
204 static inline int SCALE(int x
)
206 return x
== 1 ? x
: x
>> 1;
215 /* in 10 milisecond (ticks) */
216 #define CYCLETIME ((CYCLES*HZ)/1000)
218 /*Chopper's local variables to track the terrain position etc*/
219 static int chopCounter
;
220 static int iRotorOffset
;
223 static int iPlayerPosX
;
224 static int iPlayerPosY
;
225 static int iCameraPosX
;
226 static int iPlayerSpeedX
;
227 static int iPlayerSpeedY
;
228 static int iLastBlockPlacedPosX
;
229 static int iGravityTimerCountdown
;
230 static int iPlayerAlive
;
231 static int iLevelMode
, iCurrLevelMode
;
232 static int blockh
,blockw
;
233 static int highscore
;
236 #define CFG_FILE "chopper.cfg"
237 #define MAX_POINTS 50000
238 static struct configdata config
[] =
240 {TYPE_INT
, 0, MAX_POINTS
, { .int_p
= &highscore
}, "highscore", NULL
}
273 struct CTerrainNode mNodes
[MAX_TERRAIN_NODES
];
275 int iLastNodePlacedPosX
;
278 struct CBlock mBlocks
[NUMBER_OF_BLOCKS
];
279 struct CParticle mParticles
[NUMBER_OF_PARTICLES
];
281 struct CTerrain mGround
;
282 struct CTerrain mRoof
;
284 /*Function declarations*/
285 static void chopDrawParticle(struct CParticle
*mParticle
);
286 static void chopDrawBlock(struct CBlock
*mBlock
);
287 static void chopRenderTerrain(struct CTerrain
*ter
, bool isground
);
288 void chopper_load(bool newgame
);
289 void cleanup_chopper(void);
291 static void chopDrawPlayer(int x
,int y
) /* These are SCREEN coords, not world!*/
295 rb
->lcd_set_foreground(LCD_RGBPACK(50,50,200));
297 rb
->lcd_set_foreground(LCD_DARKGRAY
);
299 rb
->lcd_fillrect(SCALE(x
+6), SCALE(y
+2), SCALE(12), SCALE(9));
300 rb
->lcd_fillrect(SCALE(x
-3), SCALE(y
+6), SCALE(20), SCALE(3));
303 rb
->lcd_set_foreground(LCD_RGBPACK(50,50,50));
305 rb
->lcd_set_foreground(LCD_DARKGRAY
);
307 rb
->lcd_fillrect(SCALE(x
+10), SCALE(y
), SCALE(2), SCALE(3));
308 rb
->lcd_fillrect(SCALE(x
+10), SCALE(y
), SCALE(1), SCALE(3));
311 rb
->lcd_set_foreground(LCD_RGBPACK(40,40,100));
313 rb
->lcd_set_foreground(LCD_BLACK
);
315 rb
->lcd_drawline(SCALE(x
), SCALE(y
+iRotorOffset
), SCALE(x
+20),
316 SCALE(y
-iRotorOffset
));
319 rb
->lcd_set_foreground(LCD_RGBPACK(20,20,50));
321 rb
->lcd_set_foreground(LCD_BLACK
);
323 rb
->lcd_fillrect(SCALE(x
- 2), SCALE(y
+ 5), SCALE(2), SCALE(5));
327 static void chopClearTerrain(struct CTerrain
*ter
)
329 ter
->iNodesCount
= 0;
333 int iR(int low
,int high
)
335 return low
+rb
->rand()%(high
-low
+1);
338 static void chopCopyTerrain(struct CTerrain
*src
, struct CTerrain
*dest
,
339 int xOffset
,int yOffset
)
343 while(i
< src
->iNodesCount
)
345 dest
->mNodes
[i
].x
= src
->mNodes
[i
].x
+ xOffset
;
346 dest
->mNodes
[i
].y
= src
->mNodes
[i
].y
+ yOffset
;
351 dest
->iNodesCount
= src
->iNodesCount
;
352 dest
->iLastNodePlacedPosX
= src
->iLastNodePlacedPosX
;
356 static void chopAddTerrainNode(struct CTerrain
*ter
, int x
, int y
)
360 if(ter
->iNodesCount
+ 1 >= MAX_TERRAIN_NODES
)
362 /* DEBUGF("ERROR: Not enough nodes!\n"); */
368 i
= ter
->iNodesCount
- 1;
370 ter
->mNodes
[i
].x
= x
;
373 ter
->iLastNodePlacedPosX
= x
;
377 static void chopTerrainNodeDeleteAndShift(struct CTerrain
*ter
,int nodeIndex
)
381 while( i
< ter
->iNodesCount
)
383 ter
->mNodes
[i
- 1] = ter
->mNodes
[i
];
392 int chopUpdateTerrainRecycling(struct CTerrain
*ter
)
397 while(i
< ter
->iNodesCount
)
400 if( iCameraPosX
> ter
->mNodes
[i
].x
)
403 chopTerrainNodeDeleteAndShift(ter
,i
);
405 iNewNodePos
= ter
->iLastNodePlacedPosX
+ 50;
411 if(iCurrLevelMode
== LEVEL_MODE_STEEP
)
414 chopAddTerrainNode(ter
,iNewNodePos
,g
- iR(-v
,v
));
426 int chopTerrainHeightAtPoint(struct CTerrain
*ter
, int pX
)
429 int iNodeIndexOne
=0,iNodeIndexTwo
=0, h
, terY1
, terY2
, terX1
, terX2
, a
, b
;
433 for(i
=1;i
<MAX_TERRAIN_NODES
;i
++)
435 if(ter
->mNodes
[i
].x
> pX
)
437 iNodeIndexOne
= i
- 1;
443 iNodeIndexTwo
= iNodeIndexOne
+ 1;
444 terY1
= ter
->mNodes
[iNodeIndexOne
].y
;
445 terY2
= ter
->mNodes
[iNodeIndexTwo
].y
;
448 terX2
= ter
->mNodes
[iNodeIndexTwo
].x
- ter
->mNodes
[iNodeIndexOne
].x
;
450 pX
-= ter
->mNodes
[iNodeIndexOne
].x
;
463 int chopPointInTerrain(struct CTerrain
*ter
, int pX
, int pY
, int iTestType
)
465 int h
= chopTerrainHeightAtPoint(ter
, pX
);
473 static void chopAddBlock(int x
,int y
,int sx
,int sy
, int indexOverride
)
477 if(indexOverride
< 0)
479 while(mBlocks
[i
].bIsActive
&& i
< NUMBER_OF_BLOCKS
)
481 if(i
==NUMBER_OF_BLOCKS
)
483 DEBUGF("No blocks!\n");
490 mBlocks
[i
].bIsActive
= 1;
491 mBlocks
[i
].iWorldX
= x
;
492 mBlocks
[i
].iWorldY
= y
;
493 mBlocks
[i
].iSizeX
= sx
;
494 mBlocks
[i
].iSizeY
= sy
;
496 iLastBlockPlacedPosX
= x
;
499 static void chopAddParticle(int x
,int y
,int sx
,int sy
)
503 while(mParticles
[i
].bIsActive
&& i
< NUMBER_OF_PARTICLES
)
506 if(i
==NUMBER_OF_PARTICLES
)
509 mParticles
[i
].bIsActive
= 1;
510 mParticles
[i
].iWorldX
= x
;
511 mParticles
[i
].iWorldY
= y
;
512 mParticles
[i
].iSpeedX
= sx
;
513 mParticles
[i
].iSpeedY
= sy
;
516 static void chopGenerateBlockIfNeeded(void)
519 int DistSpeedX
= iPlayerSpeedX
* 5;
520 if(DistSpeedX
<200) DistSpeedX
= 200;
522 while(i
< NUMBER_OF_BLOCKS
)
524 if(!mBlocks
[i
].bIsActive
)
528 iX
= iLastBlockPlacedPosX
+ (350-DistSpeedX
);
532 sY
= blockh
+ iR(1,blockh
/3);
534 chopAddBlock(iX
,iY
,sX
,sY
,i
);
542 static int chopBlockCollideWithPlayer(struct CBlock
*mBlock
)
544 int px
= iPlayerPosX
;
545 int py
= iPlayerPosY
;
547 int x
= mBlock
->iWorldX
-17;
548 int y
= mBlock
->iWorldY
-11;
550 int x2
= x
+ mBlock
->iSizeX
+17;
551 int y2
= y
+ mBlock
->iSizeY
+11;
564 static int chopBlockOffscreen(struct CBlock
*mBlock
)
566 if(mBlock
->iWorldX
+ mBlock
->iSizeX
< iCameraPosX
)
572 static int chopParticleOffscreen(struct CParticle
*mParticle
)
574 if (mParticle
->iWorldX
< iCameraPosX
|| mParticle
->iWorldY
< 0 ||
575 mParticle
->iWorldY
> iScreenY
|| mParticle
->iWorldX
> iCameraPosX
+
584 static void chopKillPlayer(void)
588 for (i
= 0; i
< NUMBER_OF_PARTICLES
; i
++) {
589 mParticles
[i
].bIsActive
= 0;
590 chopAddParticle(iPlayerPosX
+ iR(0,20), iPlayerPosY
+ iR(0,20),
596 if (iPlayerAlive
== 0) {
597 rb
->splash(HZ
, "Game Over");
599 if (score
> highscore
) {
602 rb
->snprintf(scoretext
, sizeof(scoretext
), "New High Score: %d",
604 rb
->splash(HZ
*2, scoretext
);
610 static void chopDrawTheWorld(void)
614 while(i
< NUMBER_OF_BLOCKS
)
616 if(mBlocks
[i
].bIsActive
)
618 if(chopBlockOffscreen(&mBlocks
[i
]) == 1)
619 mBlocks
[i
].bIsActive
= 0;
621 chopDrawBlock(&mBlocks
[i
]);
629 while(i
< NUMBER_OF_PARTICLES
)
631 if(mParticles
[i
].bIsActive
)
633 if(chopParticleOffscreen(&mParticles
[i
]) == 1)
634 mParticles
[i
].bIsActive
= 0;
636 chopDrawParticle(&mParticles
[i
]);
642 chopRenderTerrain(&mGround
, true);
643 chopRenderTerrain(&mRoof
, false);
647 static void chopDrawParticle(struct CParticle
*mParticle
)
650 int iPosX
= (mParticle
->iWorldX
- iCameraPosX
);
651 int iPosY
= (mParticle
->iWorldY
);
653 rb
->lcd_set_foreground(LCD_RGBPACK(192,192,192));
655 rb
->lcd_set_foreground(LCD_LIGHTGRAY
);
657 rb
->lcd_fillrect(SCALE(iPosX
), SCALE(iPosY
), SCALE(3), SCALE(3));
661 static void chopDrawScene(void)
666 rb
->lcd_set_background(LCD_BLACK
);
668 rb
->lcd_set_background(LCD_WHITE
);
670 rb
->lcd_clear_display();
672 chopDrawPlayer(iPlayerPosX
- iCameraPosX
, iPlayerPosY
);
674 score
= -20 + iPlayerPosX
/3;
677 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
679 rb
->lcd_set_drawmode(DRMODE_FG
);
683 rb
->lcd_set_foreground(LCD_BLACK
);
685 rb
->lcd_set_foreground(LCD_WHITE
);
689 rb
->snprintf(s
, sizeof(s
), "Dist: %d", score
);
691 rb
->snprintf(s
, sizeof(s
), "Distance: %d", score
);
693 rb
->lcd_getstringsize(s
, &w
, NULL
);
694 rb
->lcd_putsxy(2, 2, s
);
695 if (score
< highscore
)
699 rb
->snprintf(s
, sizeof(s
), "Hi: %d", highscore
);
701 rb
->snprintf(s
, sizeof(s
), "Best: %d", highscore
);
703 rb
->lcd_getstringsize(s
, &w2
, NULL
);
704 if (LCD_WIDTH
- 2 - w2
> w
+ 2)
705 rb
->lcd_putsxy(LCD_WIDTH
- 2 - w2
, 2, s
);
707 rb
->lcd_set_drawmode(DRMODE_SOLID
);
713 static int chopMenuCb(int action
, const struct menu_item_ex
*this_item
)
715 if(action
== ACTION_REQUEST_MENUITEM
716 && !_ingame
&& ((intptr_t)this_item
)==0)
717 return ACTION_EXIT_MENUITEM
;
720 static int chopMenu(int menunum
)
724 bool menu_quit
= false;
726 static const struct opt_items levels
[2] = {
731 MENUITEM_STRINGLIST(menu
,"Chopper Menu",chopMenuCb
,
732 "Resume Game","Start New Game",
733 "Level","Playback Control","Quit");
734 _ingame
= (menunum
!=0);
736 #ifdef HAVE_LCD_COLOR
737 rb
->lcd_set_foreground(LCD_WHITE
);
738 rb
->lcd_set_background(LCD_BLACK
);
740 rb
->lcd_set_foreground(LCD_BLACK
);
741 rb
->lcd_set_background(LCD_WHITE
);
744 rb
->lcd_clear_display();
745 rb
->button_clear_queue();
748 switch(rb
->do_menu(&menu
, &result
, NULL
, false))
750 case 0: /* Resume Game */
754 case 1: /* Start New Game */
760 rb
->set_option("Level", &iLevelMode
, INT
, levels
, 2, NULL
);
763 playback_control(NULL
);
769 case MENU_ATTACHED_USB
:
771 res
= PLUGIN_USB_CONNECTED
;
775 rb
->lcd_clear_display();
779 static int chopGameLoop(void)
781 int move_button
, ret
;
783 int end
, i
=0, bdelay
=0, last_button
=BUTTON_NONE
;
785 if (chopUpdateTerrainRecycling(&mGround
) == 1)
786 /* mirror the sky if we've changed the ground */
787 chopCopyTerrain(&mGround
, &mRoof
, 0, - ( (iScreenY
* 3) / 4));
797 end
= *rb
->current_tick
+ CYCLETIME
;
799 if(chopUpdateTerrainRecycling(&mGround
) == 1)
800 /* mirror the sky if we've changed the ground */
801 chopCopyTerrain(&mGround
, &mRoof
, 0, - ( (iScreenY
* 3) / 4));
803 iRotorOffset
= iR(-1,1);
805 /* We need to have this here so particles move when we're dead */
807 for (i
=0; i
< NUMBER_OF_PARTICLES
; i
++)
808 if(mParticles
[i
].bIsActive
== 1)
810 mParticles
[i
].iWorldX
+= mParticles
[i
].iSpeedX
;
811 mParticles
[i
].iWorldY
+= mParticles
[i
].iSpeedY
;
814 /* Redraw the main window: */
818 iGravityTimerCountdown
--;
820 if(iGravityTimerCountdown
<= 0)
822 iGravityTimerCountdown
= 3;
823 chopAddParticle(iPlayerPosX
, iPlayerPosY
+5, 0, 0);
826 if(iCurrLevelMode
== LEVEL_MODE_NORMAL
)
827 chopGenerateBlockIfNeeded();
830 move_button
=rb
->button_status();
831 if (rb
->button_get(false) == QUIT
) {
836 last_button
= BUTTON_NONE
;
837 move_button
= BUTTON_NONE
;
840 switch (move_button
) {
845 if (last_button
!= ACTION
847 && last_button
!= ACTION2
856 if (last_button
== ACTION
858 || last_button
== ACTION2
865 if (rb
->default_event_handler(move_button
) == SYS_USB_CONNECTED
)
866 return PLUGIN_USB_CONNECTED
;
869 last_button
= move_button
;
872 iPlayerSpeedY
= bdelay
;
874 } else if (bdelay
> 0) {
875 iPlayerSpeedY
= bdelay
;
879 iCameraPosX
= iPlayerPosX
- 25;
880 iPlayerPosX
+= iPlayerSpeedX
;
881 iPlayerPosY
+= iPlayerSpeedY
;
884 /* increase speed as we go along */
885 if (chopCounter
== 100){
890 if (iPlayerPosY
> iScreenY
-10 || iPlayerPosY
< -5 ||
891 chopPointInTerrain(&mGround
, iPlayerPosX
, iPlayerPosY
+ 10, 0) ||
892 chopPointInTerrain(&mRoof
, iPlayerPosX
,iPlayerPosY
, 1))
901 for (i
=0; i
< NUMBER_OF_BLOCKS
; i
++)
902 if(mBlocks
[i
].bIsActive
== 1)
903 if(chopBlockCollideWithPlayer(&mBlocks
[i
])) {
911 if (TIME_BEFORE(*rb
->current_tick
, end
))
912 rb
->sleep(end
- *rb
->current_tick
); /* wait until time is over */
920 static void chopDrawBlock(struct CBlock
*mBlock
)
922 int iPosX
= (mBlock
->iWorldX
- iCameraPosX
);
923 int iPosY
= (mBlock
->iWorldY
);
925 rb
->lcd_set_foreground(LCD_RGBPACK(100,255,100));
927 rb
->lcd_set_foreground(LCD_BLACK
);
929 rb
->lcd_fillrect(SCALE(iPosX
), SCALE(iPosY
), SCALE(mBlock
->iSizeX
),
930 SCALE(mBlock
->iSizeY
));
934 static void chopRenderTerrain(struct CTerrain
*ter
, bool isground
)
941 while(i
< ter
->iNodesCount
&& oldx
< iScreenX
)
944 int x
= ter
->mNodes
[i
-1].x
- iCameraPosX
;
945 int y
= ter
->mNodes
[i
-1].y
;
947 int x2
= ter
->mNodes
[i
].x
- iCameraPosX
;
948 int y2
= ter
->mNodes
[i
].y
;
952 if ((y
< y2
) != isground
)
963 rb
->lcd_set_foreground(LCD_RGBPACK(100,255,100));
965 rb
->lcd_set_foreground(LCD_DARKGRAY
);
968 rb
->lcd_drawline(SCALE(x
), SCALE(y
), SCALE(x2
), SCALE(y2
));
970 xlcd_filltriangle(SCALE(x
), SCALE(y
), SCALE(x2
), SCALE(y2
),
971 SCALE(ax
), SCALE(ay
));
976 y2
= (LCD_HEIGHT
*SIZE
);
984 rb
->lcd_fillrect(SCALE(x
), SCALE(y
), SCALE(x2
-x
)+1, SCALE(y2
-y
)+1);
991 void chopper_load(bool newgame
)
998 iScreenX
= LCD_WIDTH
* SIZE
;
999 iScreenY
= LCD_HEIGHT
* SIZE
;
1000 blockh
= iScreenY
/ 5;
1001 blockw
= iScreenX
/ 20;
1003 iCurrLevelMode
= iLevelMode
;
1008 iPlayerPosY
= (iScreenY
* 4) / 10;
1009 iLastBlockPlacedPosX
= 0;
1010 iGravityTimerCountdown
= 2;
1016 for (i
=0; i
< NUMBER_OF_PARTICLES
; i
++)
1017 mParticles
[i
].bIsActive
= 0;
1019 for (i
=0; i
< NUMBER_OF_BLOCKS
; i
++)
1020 mBlocks
[i
].bIsActive
= 0;
1023 chopClearTerrain(&mGround
);
1025 for (i
=0; i
< MAX_TERRAIN_NODES
; i
++)
1026 chopAddTerrainNode(&mGround
,i
* 30,g
- iR(0,20));
1028 if (chopUpdateTerrainRecycling(&mGround
) == 1)
1029 /* mirror the sky if we've changed the ground */
1030 chopCopyTerrain(&mGround
, &mRoof
, 0, - ( (iScreenY
* 3) / 4));
1032 if (iCurrLevelMode
== LEVEL_MODE_NORMAL
)
1033 /* make it a bit more exciting, cause it's easy terrain... */
1037 /* this is the plugin entry point */
1038 enum plugin_status
plugin_start(const void* parameter
)
1043 rb
->lcd_setfont(FONT_SYSFIXED
);
1045 rb
->lcd_set_backdrop(NULL
);
1047 #ifdef HAVE_LCD_COLOR
1048 rb
->lcd_set_background(LCD_BLACK
);
1049 rb
->lcd_set_foreground(LCD_WHITE
);
1052 /* Turn off backlight timeout */
1053 backlight_force_on(); /* backlight control in lib/helper.c */
1055 rb
->srand( *rb
->current_tick
);
1057 configfile_load(CFG_FILE
, config
, 1, 0);
1060 ret
= chopGameLoop();
1062 configfile_save(CFG_FILE
, config
, 1, 0);
1064 rb
->lcd_setfont(FONT_UI
);
1065 /* Turn on backlight timeout (revert to settings) */
1066 backlight_use_settings(); /* backlight control in lib/helper.c */