Add AI to the pong plugin, to allow single-player operation.
[kugel-rb.git] / apps / plugins / mosaique.c
blobc3f6fc34cd1e846626b65ff6865832a2f7f1f6b4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Itai Shaked
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 **************************************************************************/
21 #include "plugin.h"
22 #include "lib/playergfx.h"
23 #include "lib/mylcd.h"
27 #ifdef HAVE_LCD_BITMAP
28 #define GFX_X (LCD_WIDTH/2-1)
29 #define GFX_Y (LCD_HEIGHT/2-1)
30 #if LCD_WIDTH != LCD_HEIGHT
31 #define GFX_WIDTH GFX_X
32 #define GFX_HEIGHT GFX_Y
33 #else
34 #define GFX_WIDTH GFX_X
35 #define GFX_HEIGHT (4*GFX_Y/5)
36 #endif
37 #else
38 #define GFX_X 9
39 #define GFX_Y 6
40 #define GFX_WIDTH 9
41 #define GFX_HEIGHT 6
42 #endif
44 /* variable button definitions */
45 #if CONFIG_KEYPAD == RECORDER_PAD
46 #define MOSAIQUE_QUIT BUTTON_OFF
47 #define MOSAIQUE_SPEED BUTTON_F1
48 #define MOSAIQUE_RESTART BUTTON_PLAY
50 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
51 #define MOSAIQUE_QUIT BUTTON_OFF
52 #define MOSAIQUE_SPEED BUTTON_F1
53 #define MOSAIQUE_RESTART BUTTON_SELECT
55 #elif CONFIG_KEYPAD == PLAYER_PAD
56 #define MOSAIQUE_QUIT BUTTON_STOP
57 #define MOSAIQUE_SPEED BUTTON_MENU
58 #define MOSAIQUE_RESTART BUTTON_PLAY
60 #elif CONFIG_KEYPAD == ONDIO_PAD
61 #define MOSAIQUE_QUIT BUTTON_OFF
62 #define MOSAIQUE_SPEED BUTTON_MENU
63 #define MOSAIQUE_RESTART BUTTON_RIGHT
65 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
66 (CONFIG_KEYPAD == IRIVER_H300_PAD)
67 #define MOSAIQUE_QUIT BUTTON_OFF
68 #define MOSAIQUE_SPEED BUTTON_MODE
69 #define MOSAIQUE_RESTART BUTTON_ON
71 #define MOSAIQUE_RC_QUIT BUTTON_RC_STOP
73 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
74 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
75 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
76 #define MOSAIQUE_QUIT BUTTON_MENU
77 #define MOSAIQUE_SPEED BUTTON_SELECT
78 #define MOSAIQUE_RESTART BUTTON_PLAY
80 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
81 #define MOSAIQUE_QUIT BUTTON_PLAY
82 #define MOSAIQUE_SPEED BUTTON_MODE
83 #define MOSAIQUE_RESTART BUTTON_SELECT
85 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
86 #define MOSAIQUE_QUIT BUTTON_POWER
87 #define MOSAIQUE_SPEED BUTTON_SELECT
88 #define MOSAIQUE_RESTART BUTTON_PLAY
90 #elif CONFIG_KEYPAD == GIGABEAT_PAD
91 #define MOSAIQUE_QUIT BUTTON_POWER
92 #define MOSAIQUE_SPEED BUTTON_A
93 #define MOSAIQUE_RESTART BUTTON_SELECT
95 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
96 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
97 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
98 (CONFIG_KEYPAD == SANSA_M200_PAD)
99 #define MOSAIQUE_QUIT BUTTON_POWER
100 #define MOSAIQUE_SPEED BUTTON_DOWN
101 #define MOSAIQUE_RESTART BUTTON_SELECT
103 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
104 #define MOSAIQUE_QUIT (BUTTON_HOME|BUTTON_REPEAT)
105 #define MOSAIQUE_SPEED BUTTON_DOWN
106 #define MOSAIQUE_RESTART BUTTON_SELECT
108 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
109 #define MOSAIQUE_QUIT BUTTON_POWER
110 #define MOSAIQUE_SPEED BUTTON_FF
111 #define MOSAIQUE_RESTART BUTTON_PLAY
113 #elif CONFIG_KEYPAD == MROBE500_PAD
114 #define MOSAIQUE_QUIT BUTTON_POWER
116 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
117 #define MOSAIQUE_QUIT BUTTON_BACK
118 #define MOSAIQUE_SPEED BUTTON_SELECT
119 #define MOSAIQUE_RESTART BUTTON_MENU
121 #elif CONFIG_KEYPAD == MROBE100_PAD
122 #define MOSAIQUE_QUIT BUTTON_POWER
123 #define MOSAIQUE_SPEED BUTTON_DISPLAY
124 #define MOSAIQUE_RESTART BUTTON_SELECT
126 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
127 #define MOSAIQUE_QUIT BUTTON_RC_REC
128 #define MOSAIQUE_SPEED BUTTON_RC_MENU
129 #define MOSAIQUE_RESTART BUTTON_RC_PLAY
131 #elif CONFIG_KEYPAD == COWON_D2_PAD
132 #define MOSAIQUE_QUIT BUTTON_POWER
133 #define MOSAIQUE_SPEED BUTTON_MINUS
134 #define MOSAIQUE_RESTART BUTTON_MENU
136 #elif CONFIG_KEYPAD == IAUDIO67_PAD
137 #define MOSAIQUE_QUIT BUTTON_POWER
138 #define MOSAIQUE_SPEED BUTTON_PLAY
139 #define MOSAIQUE_RESTART BUTTON_MENU
141 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
142 #define MOSAIQUE_QUIT BUTTON_BACK
143 #define MOSAIQUE_SPEED BUTTON_SELECT
144 #define MOSAIQUE_RESTART BUTTON_PLAY
146 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
147 #define MOSAIQUE_QUIT BUTTON_POWER
148 #define MOSAIQUE_SPEED BUTTON_VIEW
149 #define MOSAIQUE_RESTART BUTTON_MENU
151 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
152 #define MOSAIQUE_QUIT BUTTON_POWER
153 #define MOSAIQUE_SPEED BUTTON_RIGHT
154 #define MOSAIQUE_RESTART BUTTON_MENU
156 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
157 #define MOSAIQUE_QUIT BUTTON_POWER
158 #define MOSAIQUE_SPEED BUTTON_RIGHT
159 #define MOSAIQUE_RESTART BUTTON_MENU
161 #elif CONFIG_KEYPAD == ONDAVX747_PAD
162 #define MOSAIQUE_QUIT BUTTON_POWER
163 #elif CONFIG_KEYPAD == ONDAVX777_PAD
164 #define MOSAIQUE_QUIT BUTTON_POWER
166 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
167 #define MOSAIQUE_QUIT BUTTON_PLAY
168 #define MOSAIQUE_SPEED BUTTON_UP
169 #define MOSAIQUE_RESTART BUTTON_DOWN
171 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
172 #define MOSAIQUE_QUIT BUTTON_REC
173 #define MOSAIQUE_SPEED BUTTON_PLAY
174 #define MOSAIQUE_RESTART BUTTON_MENU
176 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
177 #define MOSAIQUE_QUIT (BUTTON_REC | BUTTON_PLAY)
178 #define MOSAIQUE_SPEED BUTTON_FUNC
179 #define MOSAIQUE_RESTART BUTTON_PLAY
181 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
182 #define MOSAIQUE_QUIT (BUTTON_REC | BUTTON_REPEAT)
183 #define MOSAIQUE_SPEED BUTTON_ENTER
184 #define MOSAIQUE_RESTART BUTTON_PLAY
186 #else
187 #error No keymap defined!
188 #endif
190 #ifdef HAVE_TOUCHSCREEN
191 #ifndef MOSAIQUE_QUIT
192 #define MOSAIQUE_QUIT BUTTON_TOPLEFT
193 #endif
194 #ifndef MOSAIQUE_SPEED
195 #define MOSAIQUE_SPEED BUTTON_MIDRIGHT
196 #endif
197 #ifndef MOSAIQUE_RESTART
198 #define MOSAIQUE_RESTART BUTTON_CENTER
199 #endif
200 #endif
202 enum plugin_status plugin_start(const void* parameter)
204 int button;
205 int timer = 10;
206 int x=0;
207 int y=0;
208 int sx = 3;
209 int sy = 3;
210 (void)parameter;
212 #ifdef HAVE_LCD_CHARCELLS
213 if (!pgfx_init(4, 2))
215 rb->splash(HZ*2, "Old LCD :(");
216 return PLUGIN_OK;
218 pgfx_display(3, 0);
219 #endif
220 mylcd_clear_display();
221 mylcd_set_drawmode(DRMODE_COMPLEMENT);
222 while (1) {
224 x+=sx;
225 if (x>GFX_WIDTH)
227 x = 2*GFX_WIDTH-x;
228 sx=-sx;
231 if (x<0)
233 x = -x;
234 sx = -sx;
237 y+=sy;
238 if (y>GFX_HEIGHT)
240 y = 2*GFX_HEIGHT-y;
241 sy=-sy;
244 if (y<0)
246 y = -y;
247 sy = -sy;
250 mylcd_fillrect(GFX_X-x, GFX_Y-y, 2*x+1, 1);
251 mylcd_fillrect(GFX_X-x, GFX_Y+y, 2*x+1, 1);
252 mylcd_fillrect(GFX_X-x, GFX_Y-y+1, 1, 2*y-1);
253 mylcd_fillrect(GFX_X+x, GFX_Y-y+1, 1, 2*y-1);
254 mylcd_update();
256 rb->sleep(HZ/timer);
258 button = rb->button_get(false);
259 switch (button)
261 #ifdef MOSAIQUE_RC_QUIT
262 case MOSAIQUE_RC_QUIT:
263 #endif
264 case MOSAIQUE_QUIT:
265 mylcd_set_drawmode(DRMODE_SOLID);
266 #ifdef HAVE_LCD_CHARCELLS
267 pgfx_release();
268 #endif
269 return PLUGIN_OK;
271 case MOSAIQUE_SPEED:
272 timer = timer+5;
273 if (timer>20)
274 timer=5;
275 break;
277 case MOSAIQUE_RESTART:
279 sx = rb->rand() % (GFX_HEIGHT/2) + 1;
280 sy = rb->rand() % (GFX_HEIGHT/2) + 1;
281 x=0;
282 y=0;
283 mylcd_clear_display();
284 break;
287 default:
288 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
290 mylcd_set_drawmode(DRMODE_SOLID);
291 #ifdef HAVE_LCD_CHARCELLS
292 pgfx_release();
293 #endif
294 return PLUGIN_USB_CONNECTED;
296 break;