diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-12-06 15:58:18 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-12-06 15:58:18 +0000 |
commit | 51d89e25940a79401b71c3a4d2e23bba88c2647f (patch) | |
tree | 7486ee7d476755cb97bf1e00b0349146424ec39c /apps | |
parent | 48114263d243040da3c78217d9fde519c14f3a95 (diff) | |
download | rockbox-51d89e25940a79401b71c3a4d2e23bba88c2647f.tar.gz rockbox-51d89e25940a79401b71c3a4d2e23bba88c2647f.zip |
Boomshine:
* simplify some things (no functional changes)
* increase default and exploded ball size a bit to be more compliant with the original game (and make beating it on big screens a bit easier)
* whitespace cleanups
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23876 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/boomshine.lua | 72 |
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 @@ | |||
25 | require "actions" | 25 | require "actions" |
26 | 26 | ||
27 | local CYCLETIME = rb.HZ / 50 | 27 | local CYCLETIME = rb.HZ / 50 |
28 | 28 | local HAS_TOUCHSCREEN = rb.action_get_touchscreen_press ~= nil | |
29 | if rb.action_get_touchscreen_press == nil then | 29 | local DEFAULT_BALL_SIZE = rb.LCD_HEIGHT > rb.LCD_WIDTH and rb.LCD_WIDTH / 30 |
30 | HAS_TOUCHSCREEN = false | 30 | or rb.LCD_HEIGHT / 30 |
31 | else | 31 | local MAX_BALL_SPEED = DEFAULT_BALL_SIZE / 2 |
32 | HAS_TOUCHSCREEN = true | 32 | local DEFAULT_FOREGROUND_COLOR = rb.lcd_get_foreground ~= nil |
33 | end | 33 | and rb.lcd_get_foreground() |
34 | 34 | or 0 | |
35 | -- color used to write the text | ||
36 | if rb.lcd_get_foreground ~= nil then | ||
37 | DEFAULT_FOREGROUND_COLOR = rb.lcd_get_foreground() | ||
38 | else | ||
39 | DEFAULT_FOREGROUND_COLOR = 0 | ||
40 | end | ||
41 | |||
42 | if rb.LCD_HEIGHT > rb.LCD_WIDTH then | ||
43 | DEFAULT_BALL_SIZE = rb.LCD_WIDTH/40 | ||
44 | else | ||
45 | DEFAULT_BALL_SIZE = rb.LCD_HEIGHT/40 | ||
46 | end | ||
47 | |||
48 | MAX_BALL_SPEED = DEFAULT_BALL_SIZE/2 | ||
49 | 35 | ||
50 | local levels = { | 36 | local 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 | ||
90 | function Ball:generateSpeed() | 76 | function 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 |
95 | end | 83 | end |
96 | 84 | ||
@@ -159,9 +147,7 @@ end | |||
159 | 147 | ||
160 | function Cursor:do_action(action) | 148 | function 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 |
188 | end | 177 | end |
189 | 178 | ||
190 | function Cursor:draw() | 179 | function 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 | ||
205 | function draw_positioned_string(bottom, right, str) | 195 | function 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) |
208 | end | 199 | end |
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) |
221 | end | 213 | end |
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) | |||
318 | end | 314 | end |
319 | 315 | ||
320 | -- Helper function to display a message | 316 | -- Helper function to display a message |
321 | function display_message(message) | 317 | function 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 | |||
342 | rb.backlight_force_on() | 339 | rb.backlight_force_on() |
343 | 340 | ||
344 | local idx, highscore = 1, 0 | 341 | local idx, highscore = 1, 0 |
345 | while true do | 342 | while 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 | |||
370 | end | 359 | end |
371 | 360 | ||
372 | if idx > #levels then | 361 | if 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) |
374 | else | 363 | else |
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) |
376 | end | 365 | end |
377 | 366 | ||
378 | -- Restore user backlight settings | 367 | -- Restore user backlight settings |
379 | rb.backlight_use_settings() | 368 | rb.backlight_use_settings() |
380 | |||