diff options
Diffstat (limited to 'apps/plugins/snow.c')
-rw-r--r-- | apps/plugins/snow.c | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/apps/plugins/snow.c b/apps/plugins/snow.c index b9fc340e3f..a0725beefb 100644 --- a/apps/plugins/snow.c +++ b/apps/plugins/snow.c | |||
@@ -17,18 +17,32 @@ | |||
17 | * | 17 | * |
18 | **************************************************************************/ | 18 | **************************************************************************/ |
19 | #include "plugin.h" | 19 | #include "plugin.h" |
20 | #include "playergfx.h" | ||
20 | 21 | ||
21 | #ifdef HAVE_LCD_BITMAP | 22 | #ifdef HAVE_LCD_BITMAP |
22 | |||
23 | #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72) | 23 | #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72) |
24 | #define SNOW_HEIGHT LCD_HEIGHT | ||
25 | #define SNOW_WIDTH LCD_WIDTH | ||
26 | #else | ||
27 | #define NUM_PARTICLES 10 | ||
28 | #define SNOW_HEIGHT 14 | ||
29 | #define SNOW_WIDTH 20 | ||
30 | #endif | ||
31 | |||
32 | /* variable button definitions */ | ||
33 | #if CONFIG_KEYPAD == PLAYER_PAD | ||
34 | #define SNOW_QUIT BUTTON_STOP | ||
35 | #else | ||
36 | #define SNOW_QUIT BUTTON_OFF | ||
37 | #endif | ||
24 | 38 | ||
25 | static short particles[NUM_PARTICLES][2]; | 39 | static short particles[NUM_PARTICLES][2]; |
26 | static struct plugin_api* rb; | 40 | static struct plugin_api* rb; |
27 | 41 | ||
28 | static bool particle_exists(int particle) | 42 | static bool particle_exists(int particle) |
29 | { | 43 | { |
30 | if (particles[particle][0]>=0 && particles[particle][1]>=0 && | 44 | if (particles[particle][0]>=0 && particles[particle][1]>=0 && |
31 | particles[particle][0]<LCD_WIDTH && particles[particle][1]<LCD_HEIGHT) | 45 | particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT) |
32 | return true; | 46 | return true; |
33 | else | 47 | else |
34 | return false; | 48 | return false; |
@@ -40,7 +54,7 @@ static int create_particle(void) | |||
40 | 54 | ||
41 | for (i=0; i<NUM_PARTICLES; i++) { | 55 | for (i=0; i<NUM_PARTICLES; i++) { |
42 | if (!particle_exists(i)) { | 56 | if (!particle_exists(i)) { |
43 | particles[i][0]=(rb->rand()%LCD_WIDTH); | 57 | particles[i][0]=(rb->rand()%SNOW_WIDTH); |
44 | particles[i][1]=0; | 58 | particles[i][1]=0; |
45 | return i; | 59 | return i; |
46 | } | 60 | } |
@@ -57,7 +71,11 @@ static void snow_move(void) | |||
57 | 71 | ||
58 | for (i=0; i<NUM_PARTICLES; i++) { | 72 | for (i=0; i<NUM_PARTICLES; i++) { |
59 | if (particle_exists(i)) { | 73 | if (particle_exists(i)) { |
74 | #ifdef HAVE_LCD_BITMAP | ||
60 | rb->lcd_clearpixel(particles[i][0],particles[i][1]); | 75 | rb->lcd_clearpixel(particles[i][0],particles[i][1]); |
76 | #else | ||
77 | pgfx_clearpixel(particles[i][0],particles[i][1]); | ||
78 | #endif | ||
61 | switch ((rb->rand()%7)) { | 79 | switch ((rb->rand()%7)) { |
62 | case 0: | 80 | case 0: |
63 | particles[i][0]++; | 81 | particles[i][0]++; |
@@ -75,7 +93,11 @@ static void snow_move(void) | |||
75 | break; | 93 | break; |
76 | } | 94 | } |
77 | if (particle_exists(i)) | 95 | if (particle_exists(i)) |
96 | #ifdef HAVE_LCD_BITMAP | ||
78 | rb->lcd_drawpixel(particles[i][0],particles[i][1]); | 97 | rb->lcd_drawpixel(particles[i][0],particles[i][1]); |
98 | #else | ||
99 | pgfx_drawpixel(particles[i][0],particles[i][1]); | ||
100 | #endif | ||
79 | } | 101 | } |
80 | } | 102 | } |
81 | } | 103 | } |
@@ -88,7 +110,14 @@ static void snow_init(void) | |||
88 | particles[i][0]=-1; | 110 | particles[i][0]=-1; |
89 | particles[i][1]=-1; | 111 | particles[i][1]=-1; |
90 | } | 112 | } |
113 | #ifdef HAVE_LCD_BITMAP | ||
91 | rb->lcd_clear_display(); | 114 | rb->lcd_clear_display(); |
115 | #else | ||
116 | pgfx_display(0, 0); /* display three times */ | ||
117 | pgfx_display(4, 0); | ||
118 | pgfx_display(8, 0); | ||
119 | pgfx_clear_display(); | ||
120 | #endif | ||
92 | } | 121 | } |
93 | 122 | ||
94 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 123 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
@@ -98,20 +127,40 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
98 | (void)(parameter); | 127 | (void)(parameter); |
99 | rb = api; | 128 | rb = api; |
100 | 129 | ||
130 | #ifdef HAVE_LCD_CHARCELLS | ||
131 | if (!pgfx_init(rb, 4, 2)) | ||
132 | { | ||
133 | rb->splash(HZ*2, true, "Old LCD :("); | ||
134 | return PLUGIN_OK; | ||
135 | } | ||
136 | #endif | ||
101 | snow_init(); | 137 | snow_init(); |
102 | while (1) { | 138 | while (1) { |
103 | snow_move(); | 139 | snow_move(); |
140 | #ifdef HAVE_LCD_BITMAP | ||
104 | rb->lcd_update(); | 141 | rb->lcd_update(); |
142 | #else | ||
143 | pgfx_update(); | ||
144 | #endif | ||
105 | rb->sleep(HZ/20); | 145 | rb->sleep(HZ/20); |
106 | 146 | ||
107 | button = rb->button_get(false); | 147 | button = rb->button_get(false); |
108 | 148 | ||
109 | if (button == BUTTON_OFF) | 149 | if (button == SNOW_QUIT) |
150 | { | ||
151 | #ifdef HAVE_LCD_CHARCELLS | ||
152 | pgfx_release(); | ||
153 | #endif | ||
110 | return PLUGIN_OK; | 154 | return PLUGIN_OK; |
155 | } | ||
111 | else | 156 | else |
112 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 157 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
158 | { | ||
159 | #ifdef HAVE_LCD_CHARCELLS | ||
160 | pgfx_release(); | ||
161 | #endif | ||
113 | return PLUGIN_USB_CONNECTED; | 162 | return PLUGIN_USB_CONNECTED; |
163 | } | ||
114 | } | 164 | } |
115 | } | 165 | } |
116 | 166 | ||
117 | #endif | ||