summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/boomshine.lua72
1 files changed, 30 insertions, 42 deletions
diff --git a/apps/plugins/boomshine.lua b/apps/plugins/boomshine.lua
index c9bd4a3ede..ab00c52e2b 100644
--- a/apps/plugins/boomshine.lua
+++ b/apps/plugins/boomshine.lua
@@ -25,27 +25,13 @@
25require "actions" 25require "actions"
26 26
27local CYCLETIME = rb.HZ / 50 27local CYCLETIME = rb.HZ / 50
28 28local HAS_TOUCHSCREEN = rb.action_get_touchscreen_press ~= nil
29if rb.action_get_touchscreen_press == nil then 29local DEFAULT_BALL_SIZE = rb.LCD_HEIGHT > rb.LCD_WIDTH and rb.LCD_WIDTH / 30
30 HAS_TOUCHSCREEN = false 30 or rb.LCD_HEIGHT / 30
31else 31local MAX_BALL_SPEED = DEFAULT_BALL_SIZE / 2
32 HAS_TOUCHSCREEN = true 32local DEFAULT_FOREGROUND_COLOR = rb.lcd_get_foreground ~= nil
33end 33 and rb.lcd_get_foreground()
34 34 or 0
35-- color used to write the text
36if rb.lcd_get_foreground ~= nil then
37 DEFAULT_FOREGROUND_COLOR = rb.lcd_get_foreground()
38else
39 DEFAULT_FOREGROUND_COLOR = 0
40end
41
42if rb.LCD_HEIGHT > rb.LCD_WIDTH then
43 DEFAULT_BALL_SIZE = rb.LCD_WIDTH/40
44else
45 DEFAULT_BALL_SIZE = rb.LCD_HEIGHT/40
46end
47
48MAX_BALL_SPEED = DEFAULT_BALL_SIZE/2
49 35
50local levels = { 36local levels = {
51 -- {GOAL, TOTAL_BALLS}, 37 -- {GOAL, TOTAL_BALLS},
@@ -77,7 +63,7 @@ function Ball:new(o)
77 color = random_color(), 63 color = random_color(),
78 up_speed = Ball:generateSpeed(), 64 up_speed = Ball:generateSpeed(),
79 right_speed = Ball:generateSpeed(), 65 right_speed = Ball:generateSpeed(),
80 explosion_size = math.random((3*self.size)/2, (5*self.size)/2), 66 explosion_size = math.random(2*self.size, 4*self.size),
81 life_duration = math.random(rb.HZ, rb.HZ*5) 67 life_duration = math.random(rb.HZ, rb.HZ*5)
82 } 68 }
83 end 69 end
@@ -89,8 +75,10 @@ end
89 75
90function Ball:generateSpeed() 76function Ball:generateSpeed()
91 local speed = math.random(-MAX_BALL_SPEED, MAX_BALL_SPEED) 77 local speed = math.random(-MAX_BALL_SPEED, MAX_BALL_SPEED)
92 -- Make sure all balls move 78 if speed == 0 then
93 if speed == 0 then speed = 1 end 79 speed = 1 -- Make sure all balls move
80 end
81
94 return speed 82 return speed
95end 83end
96 84
@@ -159,9 +147,7 @@ end
159 147
160function Cursor:do_action(action) 148function Cursor:do_action(action)
161 if action == rb.actions.ACTION_TOUCHSCREEN and HAS_TOUCHSCREEN then 149 if action == rb.actions.ACTION_TOUCHSCREEN and HAS_TOUCHSCREEN then
162 if HAS_TOUCHSCREEN then 150 _, self.x, self.y = rb.action_get_touchscreen_press()
163 _, self.x, self.y = rb.action_get_touchscreen_press()
164 end
165 return true 151 return true
166 elseif action == rb.actions.ACTION_KBD_SELECT then 152 elseif action == rb.actions.ACTION_KBD_SELECT then
167 return true 153 return true
@@ -174,21 +160,25 @@ function Cursor:do_action(action)
174 elseif (action == rb.actions.ACTION_KBD_DOWN) then 160 elseif (action == rb.actions.ACTION_KBD_DOWN) then
175 self.y = self.y + self.size 161 self.y = self.y + self.size
176 end 162 end
163
177 if self.x > rb.LCD_WIDTH then 164 if self.x > rb.LCD_WIDTH then
178 self.x = 0 165 self.x = 0
179 elseif self.x < 0 then 166 elseif self.x < 0 then
180 self.x = rb.LCD_WIDTH 167 self.x = rb.LCD_WIDTH
181 end 168 end
169
182 if self.y > rb.LCD_HEIGHT then 170 if self.y > rb.LCD_HEIGHT then
183 self.y = 0 171 self.y = 0
184 elseif self.y < 0 then 172 elseif self.y < 0 then
185 self.y = rb.LCD_HEIGHT 173 self.y = rb.LCD_HEIGHT
186 end 174 end
175
187 return false 176 return false
188end 177end
189 178
190function Cursor:draw() 179function Cursor:draw()
191 set_foreground(DEFAULT_FOREGROUND_COLOR) 180 set_foreground(DEFAULT_FOREGROUND_COLOR)
181
192 rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y - self.size/2) 182 rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y - self.size/2)
193 rb.lcd_hline(self.x + self.size/4, self.x + self.size/2, self.y - self.size/2) 183 rb.lcd_hline(self.x + self.size/4, self.x + self.size/2, self.y - self.size/2)
194 rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y + self.size/2) 184 rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y + self.size/2)
@@ -204,6 +194,7 @@ end
204 194
205function draw_positioned_string(bottom, right, str) 195function draw_positioned_string(bottom, right, str)
206 local _, w, h = rb.font_getstringsize(str, rb.FONT_UI) 196 local _, w, h = rb.font_getstringsize(str, rb.FONT_UI)
197
207 rb.lcd_putsxy((rb.LCD_WIDTH-w)*right, (rb.LCD_HEIGHT-h)*bottom, str) 198 rb.lcd_putsxy((rb.LCD_WIDTH-w)*right, (rb.LCD_HEIGHT-h)*bottom, str)
208end 199end
209 200
@@ -217,6 +208,7 @@ function random_color()
217 if rb.lcd_rgbpack ~= nil then --color target 208 if rb.lcd_rgbpack ~= nil then --color target
218 return rb.lcd_rgbpack(math.random(1,255), math.random(1,255), math.random(1,255)) 209 return rb.lcd_rgbpack(math.random(1,255), math.random(1,255), math.random(1,255))
219 end 210 end
211
220 return math.random(1, rb.LCD_DEPTH) 212 return math.random(1, rb.LCD_DEPTH)
221end 213end
222 214
@@ -287,6 +279,7 @@ function start_round(level, goal, nrBalls, total)
287 279
288 -- Drawing phase 280 -- Drawing phase
289 rb.lcd_clear_display() 281 rb.lcd_clear_display()
282
290 set_foreground(DEFAULT_FOREGROUND_COLOR) 283 set_foreground(DEFAULT_FOREGROUND_COLOR)
291 draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls)) 284 draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls))
292 draw_positioned_string(0, 1, string.format("Level %d", level)) 285 draw_positioned_string(0, 1, string.format("Level %d", level))
@@ -302,9 +295,12 @@ function start_round(level, goal, nrBalls, total)
302 explodedBall:step() 295 explodedBall:step()
303 explodedBall:draw() 296 explodedBall:draw()
304 end 297 end
298
305 if not HAS_TOUCHSCREEN and not player_added then 299 if not HAS_TOUCHSCREEN and not player_added then
306 cursor:draw() 300 cursor:draw()
307 end 301 end
302
303 -- Push framebuffer to the LCD
308 rb.lcd_update() 304 rb.lcd_update()
309 305
310 if rb.current_tick() < endtick then 306 if rb.current_tick() < endtick then
@@ -318,7 +314,8 @@ function start_round(level, goal, nrBalls, total)
318end 314end
319 315
320-- Helper function to display a message 316-- Helper function to display a message
321function display_message(message) 317function display_message(...)
318 local message = string.format(...)
322 local _, w, h = rb.font_getstringsize(message, rb.FONT_UI) 319 local _, w, h = rb.font_getstringsize(message, rb.FONT_UI)
323 local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2 320 local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2
324 321
@@ -342,18 +339,10 @@ end
342rb.backlight_force_on() 339rb.backlight_force_on()
343 340
344local idx, highscore = 1, 0 341local idx, highscore = 1, 0
345while true do 342while levels[idx] ~= nil do
346 local level = levels[idx] 343 local goal, nrBalls = levels[idx][1], levels[idx][2]
347 local goal, nrBalls
348
349 if level == nil then
350 break -- No more levels to play
351 end
352
353 goal = level[1]
354 nrBalls = level[2]
355 344
356 display_message(string.format("Level %d: get %d out of %d balls", idx, goal, nrBalls)) 345 display_message("Level %d: get %d out of %d balls", idx, goal, nrBalls)
357 346
358 local exit, score, nrExpandedBalls = start_round(idx, goal, nrBalls, highscore) 347 local exit, score, nrExpandedBalls = start_round(idx, goal, nrBalls, highscore)
359 if exit then 348 if exit then
@@ -370,11 +359,10 @@ while true do
370end 359end
371 360
372if idx > #levels then 361if idx > #levels then
373 display_message(string.format("You finished the game with %d points!", highscore)) 362 display_message("You finished the game with %d points!", highscore)
374else 363else
375 display_message(string.format("You made it till level %d with %d points!", idx, highscore)) 364 display_message("You made it till level %d with %d points!", idx, highscore)
376end 365end
377 366
378-- Restore user backlight settings 367-- Restore user backlight settings
379rb.backlight_use_settings() 368rb.backlight_use_settings()
380