Minor corrections to the .colours file editing; added .colours to the list of support...
[kugel-rb.git] / apps / plugins / rockblox1d.c
blobd7779fadd6d3fc37d26b734706ea01e5f178d0c0
1 /*****************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 - 2008 Alexander Papst
11 * Idea from http://www.tetris1d.org
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 ****************************************************************************/
23 #include "plugin.h"
25 PLUGIN_HEADER
28 #ifdef HAVE_LCD_BITMAP
30 #if CONFIG_KEYPAD == RECORDER_PAD
31 #define ONEDROCKBLOX_DOWN BUTTON_PLAY
32 #define ONEDROCKBLOX_QUIT BUTTON_OFF
34 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
35 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
36 #define ONEDROCKBLOX_QUIT BUTTON_OFF
38 #elif CONFIG_KEYPAD == ONDIO_PAD
39 #define ONEDROCKBLOX_DOWN BUTTON_RIGHT
40 #define ONEDROCKBLOX_QUIT BUTTON_OFF
42 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
43 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
44 #define ONEDROCKBLOX_QUIT BUTTON_POWER
46 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
47 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
48 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
49 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
50 #define ONEDROCKBLOX_QUIT (BUTTON_SELECT | BUTTON_MENU)
52 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
53 (CONFIG_KEYPAD == IRIVER_H300_PAD)
54 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
55 #define ONEDROCKBLOX_QUIT BUTTON_OFF
57 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
58 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
59 #define ONEDROCKBLOX_QUIT BUTTON_POWER
61 #elif CONFIG_KEYPAD == SANSA_E200_PAD || \
62 CONFIG_KEYPAD == SANSA_C200_PAD || \
63 CONFIG_KEYPAD == SANSA_CLIP_PAD || \
64 CONFIG_KEYPAD == SANSA_M200_PAD || \
65 CONFIG_KEYPAD == SANSA_FUZE_PAD
66 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
67 #define ONEDROCKBLOX_QUIT BUTTON_POWER
69 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
70 #define ONEDROCKBLOX_DOWN BUTTON_PLAY
71 #define ONEDROCKBLOX_QUIT BUTTON_POWER
73 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
74 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
75 #define ONEDROCKBLOX_QUIT BUTTON_BACK
77 #elif (CONFIG_KEYPAD == MROBE100_PAD)
78 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
79 #define ONEDROCKBLOX_QUIT BUTTON_POWER
81 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
82 #define ONEDROCKBLOX_DOWN BUTTON_RC_PLAY
83 #define ONEDROCKBLOX_QUIT BUTTON_RC_REC
85 #elif (CONFIG_KEYPAD == COWOND2_PAD)
86 #define ONEDROCKBLOX_DOWN BUTTON_MENU
87 #define ONEDROCKBLOX_QUIT BUTTON_POWER
89 #elif CONFIG_KEYPAD == IAUDIO67_PAD
90 #define ONEDROCKBLOX_DOWN BUTTON_MENU
91 #define ONEDROCKBLOX_QUIT BUTTON_POWER
93 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
94 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
95 #define ONEDROCKBLOX_QUIT BUTTON_BACK
97 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
98 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
99 #define ONEDROCKBLOX_QUIT BUTTON_POWER
101 #else
102 #error No keymap defined!
103 #endif
105 #define mrand(max) (short)(rb->rand()%max)
107 #define TILES 11
109 /**********
110 ** Lots of defines for the drawing stuff :-)
111 ** The most ugly way i could think of...
114 #if (LCD_WIDTH > LCD_HEIGHT)
115 /* Any screens larger than the minis LCD */
116 #if (LCD_WIDTH > 132)
117 /* Max size of one block */
118 # define WIDTH (int)((LCD_HEIGHT * 0.85) / TILES)
119 /* Align the playing filed centered */
120 # define CENTER_X (int)(LCD_WIDTH/2-(WIDTH/2))
121 # define CENTER_Y (int)(LCD_HEIGHT/2-((WIDTH*TILES+TILES)/2))
122 /* Score box */
123 # define SCORE_X (int)(((CENTER_X+WIDTH+4) + (LCD_WIDTH-(CENTER_X+WIDTH+4))/2)-(f_width/2))
124 # define SCORE_Y (int)((LCD_HEIGHT/2)-(f_height/2))
125 /* Max. size of bricks is 4 blocks */
126 # define NEXT_H (WIDTH*4+3)
127 # define NEXT_X (int)(CENTER_X/2-WIDTH/2)
128 # define NEXT_Y (int)(LCD_HEIGHT/2-NEXT_H/2)
129 #else
130 /* Max size of one block */
131 # define WIDTH (int)((LCD_HEIGHT * 0.85) / TILES)
132 /* Align the playing left centered */
133 # define CENTER_X (int)(LCD_WIDTH*0.2)
134 # define CENTER_Y (int)(LCD_HEIGHT/2-((WIDTH*TILES+TILES)/2))
135 /* Score box */
136 # define SCORE_X (int)(((CENTER_X+WIDTH+4) + (LCD_WIDTH-(CENTER_X+WIDTH+4))/2)-(f_width/2))
137 # define SCORE_Y 16
138 /* Max. size of bricks is 4 blocks */
139 # define NEXT_H (WIDTH*4+3)
140 # define NEXT_X (score_x+f_width+7)
141 # define NEXT_Y (int)(LCD_HEIGHT-((4*WIDTH)+13))
142 #endif
143 #else
144 /* Max size of one block */
145 # define WIDTH (int)((LCD_HEIGHT * 0.8) / TILES)
146 /* Align the playing filed centered */
147 # define CENTER_X (int)(LCD_WIDTH/2-(WIDTH/2))
148 # define CENTER_Y 2
149 /* Score box */
150 # define SCORE_X (int)((LCD_WIDTH/2)-(f_width/2))
151 # define SCORE_Y (LCD_HEIGHT-(f_height+2))
152 /* Max. size of bricks is 4 blocks */
153 # define NEXT_H (WIDTH*4+3)
154 # define NEXT_X (int)(CENTER_X/2-WIDTH/2)
155 # define NEXT_Y (int)((LCD_HEIGHT * 0.8)/2-NEXT_H/2)
156 #endif
158 void draw_brick(int pos, int length) {
159 int i = pos;
160 rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID);
161 rb->lcd_fillrect(CENTER_X, CENTER_Y, WIDTH, WIDTH * TILES + TILES);
162 rb->lcd_set_drawmode(DRMODE_SOLID);
164 for (i = pos; i < length + pos; ++i) {
165 if (i >= 0) rb->lcd_fillrect(CENTER_X, CENTER_Y+i+(WIDTH*i), WIDTH, WIDTH);
169 enum plugin_status plugin_start(const void* parameter)
171 int i;
172 int f_width, f_height;
173 int score_x;
175 bool quit = false;
176 int button;
178 int cycletime = 300;
179 int end;
181 int pos_cur_brick = 0;
182 int type_cur_brick = 0;
183 int type_next_brick = 0;
185 unsigned long int score = 34126;
186 char score_buf[10];
188 (void)parameter;
190 #if LCD_DEPTH > 1
191 rb->lcd_set_backdrop(NULL);
192 rb->lcd_set_background(LCD_BLACK);
193 rb->lcd_set_foreground(LCD_WHITE);
194 #endif
196 rb->lcd_setfont(FONT_SYSFIXED);
198 rb->lcd_getstringsize("100000000", &f_width, &f_height);
200 rb->lcd_clear_display();
202 /***********
203 ** Draw EVERYTHING
206 /* Playing filed box */
207 rb->lcd_vline(CENTER_X-2, CENTER_Y, CENTER_Y + (WIDTH*TILES+TILES));
208 rb->lcd_vline(CENTER_X + WIDTH + 1, CENTER_Y,
209 CENTER_Y + (WIDTH*TILES+TILES));
210 rb->lcd_hline(CENTER_X-2, CENTER_X + WIDTH + 1,
211 CENTER_Y + (WIDTH*TILES+TILES));
213 /* Score box */
214 #if (LCD_WIDTH > LCD_HEIGHT)
215 rb->lcd_drawrect(SCORE_X-4, SCORE_Y-5, f_width+8, f_height+9);
216 rb->lcd_putsxy(SCORE_X-4, SCORE_Y-6-f_height, "score");
217 #else
218 rb->lcd_hline(0, LCD_WIDTH, SCORE_Y-5);
219 rb->lcd_putsxy(2, SCORE_Y-6-f_height, "score");
220 #endif
221 score_x = SCORE_X;
223 /* Next box */
224 rb->lcd_getstringsize("next", &f_width, NULL);
225 #if (LCD_WIDTH > LCD_HEIGHT) && !(LCD_WIDTH > 132)
226 rb->lcd_drawrect(NEXT_X-5, NEXT_Y-5, WIDTH+10, NEXT_H+10);
227 rb->lcd_putsxy(score_x-4, NEXT_Y-5, "next");
228 #else
229 rb->lcd_drawrect(NEXT_X-5, NEXT_Y-5, WIDTH+10, NEXT_H+10);
230 rb->lcd_putsxy(NEXT_X-5, NEXT_Y-5-f_height-1, "next");
231 #endif
233 /***********
234 ** GAMELOOP
236 rb->srand( *rb->current_tick );
238 type_cur_brick = 2 + mrand(3);
239 type_next_brick = 2 + mrand(3);
241 do {
242 end = *rb->current_tick + (cycletime * HZ) / 1000;
244 draw_brick(pos_cur_brick, type_cur_brick);
246 /* Draw next brick */
247 rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID);
248 rb->lcd_fillrect(NEXT_X, NEXT_Y, WIDTH, WIDTH * 4 + 4);
249 rb->lcd_set_drawmode(DRMODE_SOLID);
251 for (i = 0; i < type_next_brick; ++i) {
252 rb->lcd_fillrect(NEXT_X,
253 NEXT_Y + ((type_next_brick % 2) ? (int)(WIDTH/2) : ((type_next_brick == 2) ? (WIDTH+1) : 0)) + (WIDTH*i) + i,
254 WIDTH, WIDTH);
257 /* Score box */
258 rb->snprintf(score_buf, sizeof(score_buf), "%8ld0", score);
259 rb->lcd_putsxy(score_x, SCORE_Y, score_buf);
261 rb->lcd_update();
263 button = rb->button_status();
265 switch(button) {
266 case ONEDROCKBLOX_DOWN:
267 case (ONEDROCKBLOX_DOWN|BUTTON_REPEAT):
268 cycletime = 100;
269 break;
270 case ONEDROCKBLOX_QUIT:
271 quit = true;
272 break;
273 default:
274 cycletime = 300;
275 if(rb->default_event_handler(button) == SYS_USB_CONNECTED) {
276 quit = true;
280 if ((pos_cur_brick + type_cur_brick) > 10) {
281 type_cur_brick = type_next_brick;
282 type_next_brick = 2 + mrand(3);
283 score += (type_cur_brick - 1) * 2;
284 pos_cur_brick = 1 - type_cur_brick;
285 } else {
286 ++pos_cur_brick;
289 if (end > *rb->current_tick)
290 rb->sleep(end-*rb->current_tick);
291 else
292 rb->yield();
294 } while (!quit);
296 return PLUGIN_OK;
298 #endif