diff options
-rw-r--r-- | apps/plugins/SOURCES | 2 | ||||
-rw-r--r-- | apps/plugins/boomshine.lua | 129 | ||||
-rw-r--r-- | apps/plugins/lua/rocklib.c | 1 |
3 files changed, 108 insertions, 24 deletions
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 5dbdffd4ad..4b60562af4 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES | |||
@@ -173,7 +173,7 @@ md5sum.c | |||
173 | 173 | ||
174 | #if (PLUGIN_BUFFER_SIZE >= 0x80000) | 174 | #if (PLUGIN_BUFFER_SIZE >= 0x80000) |
175 | lua.c | 175 | lua.c |
176 | #ifdef HAVE_TOUCHSCREEN | 176 | #ifdef HAVE_LCD_BITMAP |
177 | boomshine.lua | 177 | boomshine.lua |
178 | #endif | 178 | #endif |
179 | #endif | 179 | #endif |
diff --git a/apps/plugins/boomshine.lua b/apps/plugins/boomshine.lua index 74f7f2a831..f7432ba16e 100644 --- a/apps/plugins/boomshine.lua +++ b/apps/plugins/boomshine.lua | |||
@@ -53,7 +53,7 @@ function Ball:new(o) | |||
53 | o = { | 53 | o = { |
54 | x = math.random(self.size, rb.LCD_WIDTH - self.size), | 54 | x = math.random(self.size, rb.LCD_WIDTH - self.size), |
55 | y = math.random(self.size, rb.LCD_HEIGHT - self.size), | 55 | y = math.random(self.size, rb.LCD_HEIGHT - self.size), |
56 | color = rb.lcd_rgbpack(math.random(0,255), math.random(0,255), math.random(0,255)), | 56 | color = random_color(), |
57 | up_speed = math.random(-3, 3), | 57 | up_speed = math.random(-3, 3), |
58 | right_speed = math.random(-3, 3), | 58 | right_speed = math.random(-3, 3), |
59 | explosion_size = math.random((3*self.size)/2, (5*self.size)/2), | 59 | explosion_size = math.random((3*self.size)/2, (5*self.size)/2), |
@@ -76,7 +76,7 @@ function Ball:draw() | |||
76 | implementation in Rockbox, rectangles will just do fine (drawing | 76 | implementation in Rockbox, rectangles will just do fine (drawing |
77 | circles from within Lua is far too slow). | 77 | circles from within Lua is far too slow). |
78 | ]]-- | 78 | ]]-- |
79 | rb.lcd_set_foreground(self.color) | 79 | set_foreground(self.color) |
80 | rb.lcd_fillrect(self.x, self.y, self.size, self.size) | 80 | rb.lcd_fillrect(self.x, self.y, self.size, self.size) |
81 | end | 81 | end |
82 | 82 | ||
@@ -123,14 +123,83 @@ function Ball:checkHit(other) | |||
123 | return false | 123 | return false |
124 | end | 124 | end |
125 | 125 | ||
126 | local Cursor = { | ||
127 | size = 20, | ||
128 | x = rb.LCD_WIDTH/2, | ||
129 | y = rb.LCD_HEIGHT/2 | ||
130 | } | ||
131 | |||
132 | function Cursor:new() | ||
133 | return self | ||
134 | end | ||
135 | |||
136 | function Cursor:do_action(action) | ||
137 | if action == rb.actions.ACTION_TOUCHSCREEN and hasTouchScreen then | ||
138 | if hasTouchScreen then | ||
139 | _, self.x, self.y = rb.action_get_touchscreen_press() | ||
140 | end | ||
141 | return true | ||
142 | elseif action == rb.actions.ACTION_KBD_SELECT then | ||
143 | return true | ||
144 | elseif (action == rb.actions.ACTION_KBD_RIGHT) then | ||
145 | self.x = self.x + self.size | ||
146 | elseif (action == rb.actions.ACTION_KBD_LEFT) then | ||
147 | self.x = self.x - self.size | ||
148 | elseif (action == rb.actions.ACTION_KBD_UP) then | ||
149 | self.y = self.y - self.size | ||
150 | elseif (action == rb.actions.ACTION_KBD_DOWN) then | ||
151 | self.y = self.y + self.size | ||
152 | end | ||
153 | if self.x > rb.LCD_WIDTH then | ||
154 | self.x = 0 | ||
155 | elseif self.x < 0 then | ||
156 | self.x = rb.LCD_WIDTH | ||
157 | end | ||
158 | if self.y > rb.LCD_HEIGHT then | ||
159 | self.y = 0 | ||
160 | elseif self.y < 0 then | ||
161 | self.y = rb.LCD_HEIGHT | ||
162 | end | ||
163 | return false | ||
164 | end | ||
165 | |||
166 | function Cursor:draw() | ||
167 | set_foreground(defaultForeGroundColor) | ||
168 | rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y - self.size/2) | ||
169 | rb.lcd_hline(self.x + self.size/4, self.x + self.size/2, self.y - self.size/2) | ||
170 | rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y + self.size/2) | ||
171 | rb.lcd_hline(self.x + self.size/4, self.x + self.size/2, self.y + self.size/2) | ||
172 | rb.lcd_vline(self.x - self.size/2, self.y - self.size/2, self.y - self.size/4) | ||
173 | rb.lcd_vline(self.x - self.size/2, self.y + self.size/4, self.y + self.size/2) | ||
174 | rb.lcd_vline(self.x + self.size/2, self.y - self.size/2, self.y - self.size/4) | ||
175 | rb.lcd_vline(self.x + self.size/2, self.y + self.size/4, self.y + self.size/2) | ||
176 | |||
177 | rb.lcd_hline(self.x - self.size/4, self.x + self.size/4, self.y) | ||
178 | rb.lcd_vline(self.x, self.y - self.size/4, self.y + self.size/4) | ||
179 | end | ||
180 | |||
126 | function draw_positioned_string(bottom, right, str) | 181 | function draw_positioned_string(bottom, right, str) |
127 | local _, w, h = rb.font_getstringsize(str, rb.FONT_UI) | 182 | local _, w, h = rb.font_getstringsize(str, rb.FONT_UI) |
128 | rb.lcd_putsxy((rb.LCD_WIDTH-w)*right, (rb.LCD_HEIGHT-h)*bottom, str) | 183 | rb.lcd_putsxy((rb.LCD_WIDTH-w)*right, (rb.LCD_HEIGHT-h)*bottom, str) |
129 | end | 184 | end |
130 | 185 | ||
186 | function set_foreground(color) | ||
187 | if rb.lcd_set_foreground ~= nil then | ||
188 | rb.lcd_set_foreground(color) | ||
189 | end | ||
190 | end | ||
191 | |||
192 | function random_color() | ||
193 | if rb.lcd_rgbpack ~= nil then --color target | ||
194 | return rb.lcd_rgbpack(math.random(1,255), math.random(1,255), math.random(1,255)) | ||
195 | end | ||
196 | return math.random(1, rb.LCD_DEPTH) | ||
197 | end | ||
198 | |||
131 | function start_round(level, goal, nrBalls, total) | 199 | function start_round(level, goal, nrBalls, total) |
132 | local player_added, score, exit, nrExpandedBalls = false, 0, false, 0 | 200 | local player_added, score, exit, nrExpandedBalls = false, 0, false, 0 |
133 | local balls, explodedBalls = {}, {} | 201 | local balls, explodedBalls = {}, {} |
202 | local cursor = Cursor:new() | ||
134 | 203 | ||
135 | -- Initialize the balls | 204 | -- Initialize the balls |
136 | for _=1,nrBalls do | 205 | for _=1,nrBalls do |
@@ -149,26 +218,24 @@ function start_round(level, goal, nrBalls, total) | |||
149 | end | 218 | end |
150 | 219 | ||
151 | -- Check for actions | 220 | -- Check for actions |
152 | local action = rb.get_action(rb.contexts.CONTEXT_STD, 0) | 221 | local action = rb.get_action(rb.contexts.CONTEXT_KEYBOARD, 0) |
153 | if (action == rb.actions.ACTION_TOUCHSCREEN) then | 222 | if(action == rb.actions.ACTION_KBD_ABORT) then |
154 | local _, x, y = rb.action_get_touchscreen_press() | ||
155 | if not player_added then | ||
156 | local player = Ball:new({ | ||
157 | x = x, | ||
158 | y = y, | ||
159 | color = rb.lcd_rgbpack(255, 255, 255), | ||
160 | size = 10, | ||
161 | explosion_size = 30, | ||
162 | exploded = true, | ||
163 | death_time = rb.current_tick() + rb.HZ * 3 | ||
164 | }) | ||
165 | table.insert(explodedBalls, player) | ||
166 | player_added = true | ||
167 | end | ||
168 | elseif(action == rb.actions.ACTION_STD_CANCEL) then | ||
169 | exit = true | 223 | exit = true |
170 | break | 224 | break |
171 | end | 225 | end |
226 | if not player_added and cursor:do_action(action) then | ||
227 | local player = Ball:new({ | ||
228 | x = cursor.x, | ||
229 | y = cursor.y, | ||
230 | color = defaultForeGroundColor, | ||
231 | size = 10, | ||
232 | explosion_size = 30, | ||
233 | exploded = true, | ||
234 | death_time = rb.current_tick() + rb.HZ * 3 | ||
235 | }) | ||
236 | table.insert(explodedBalls, player) | ||
237 | player_added = true | ||
238 | end | ||
172 | 239 | ||
173 | -- Check for hits | 240 | -- Check for hits |
174 | for i, ball in ipairs(balls) do | 241 | for i, ball in ipairs(balls) do |
@@ -196,7 +263,7 @@ function start_round(level, goal, nrBalls, total) | |||
196 | 263 | ||
197 | -- Drawing phase | 264 | -- Drawing phase |
198 | rb.lcd_clear_display() | 265 | rb.lcd_clear_display() |
199 | rb.lcd_set_foreground(rb.lcd_rgbpack(255, 255, 255)) | 266 | set_foreground(defaultForeGroundColor) |
200 | draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls)) | 267 | draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls)) |
201 | draw_positioned_string(0, 1, string.format("Level %d", level)) | 268 | draw_positioned_string(0, 1, string.format("Level %d", level)) |
202 | draw_positioned_string(1, 1, string.format("%d level points", score)) | 269 | draw_positioned_string(1, 1, string.format("%d level points", score)) |
@@ -211,7 +278,9 @@ function start_round(level, goal, nrBalls, total) | |||
211 | explodedBall:step() | 278 | explodedBall:step() |
212 | explodedBall:draw() | 279 | explodedBall:draw() |
213 | end | 280 | end |
214 | 281 | if not hasTouchScreen and not player_added then | |
282 | cursor:draw() | ||
283 | end | ||
215 | rb.lcd_update() | 284 | rb.lcd_update() |
216 | 285 | ||
217 | if rb.current_tick() < endtick then | 286 | if rb.current_tick() < endtick then |
@@ -230,7 +299,7 @@ function display_message(message) | |||
230 | local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2 | 299 | local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2 |
231 | 300 | ||
232 | rb.lcd_clear_display() | 301 | rb.lcd_clear_display() |
233 | rb.lcd_set_foreground(rb.lcd_rgbpack(255, 255, 255)) | 302 | set_foreground(defaultForeGroundColor) |
234 | if w > rb.LCD_WIDTH then | 303 | if w > rb.LCD_WIDTH then |
235 | rb.lcd_puts_scroll(x/w, y/h, message) | 304 | rb.lcd_puts_scroll(x/w, y/h, message) |
236 | else | 305 | else |
@@ -243,7 +312,21 @@ function display_message(message) | |||
243 | rb.lcd_stop_scroll() -- Stop our scrolling message | 312 | rb.lcd_stop_scroll() -- Stop our scrolling message |
244 | end | 313 | end |
245 | 314 | ||
246 | rb.touchscreen_set_mode(rb.TOUCHSCREEN_POINT) | 315 | if rb.action_get_touchscreen_press == nil then |
316 | hasTouchScreen = false | ||
317 | else | ||
318 | hasTouchScreen = true | ||
319 | end | ||
320 | -- color used to write the text | ||
321 | if rb.lcd_rgbpack ~= nil then | ||
322 | defaultForeGroundColor=rb.lcd_rgbpack(255, 255, 255) | ||
323 | else | ||
324 | defaultForeGroundColor=0 | ||
325 | end | ||
326 | |||
327 | if hasTouchScreen then | ||
328 | rb.touchscreen_set_mode(rb.TOUCHSCREEN_POINT) | ||
329 | end | ||
247 | rb.backlight_force_on() | 330 | rb.backlight_force_on() |
248 | 331 | ||
249 | local idx, highscore = 1, 0 | 332 | local idx, highscore = 1, 0 |
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 0b336b3784..ca77d5ea8f 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -674,6 +674,7 @@ LUALIB_API int luaopen_rock(lua_State *L) | |||
674 | 674 | ||
675 | RB_CONSTANT(LCD_WIDTH); | 675 | RB_CONSTANT(LCD_WIDTH); |
676 | RB_CONSTANT(LCD_HEIGHT); | 676 | RB_CONSTANT(LCD_HEIGHT); |
677 | RB_CONSTANT(LCD_DEPTH); | ||
677 | 678 | ||
678 | RB_CONSTANT(FONT_SYSFIXED); | 679 | RB_CONSTANT(FONT_SYSFIXED); |
679 | RB_CONSTANT(FONT_UI); | 680 | RB_CONSTANT(FONT_UI); |