diff options
author | Kevin Ferrare <kevin@rockbox.org> | 2009-10-29 08:40:08 +0000 |
---|---|---|
committer | Kevin Ferrare <kevin@rockbox.org> | 2009-10-29 08:40:08 +0000 |
commit | 8d376d03be0a8267dea722fa70c954dbea286bde (patch) | |
tree | 6ef9e268417d34489000ebe3227745c5148d92d9 /apps/plugins/boomshine.lua | |
parent | 19c3e77fa06cca129c4be9b404297f0ab485ee77 (diff) | |
download | rockbox-8d376d03be0a8267dea722fa70c954dbea286bde.tar.gz rockbox-8d376d03be0a8267dea722fa70c954dbea286bde.zip |
Boomshine plugin : make speed and ball sizes adapt to the target screen size to get a constant gameplay
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23398 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/boomshine.lua')
-rw-r--r-- | apps/plugins/boomshine.lua | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/apps/plugins/boomshine.lua b/apps/plugins/boomshine.lua index f7432ba16e..53ea4f3598 100644 --- a/apps/plugins/boomshine.lua +++ b/apps/plugins/boomshine.lua | |||
@@ -26,6 +26,27 @@ require "actions" | |||
26 | 26 | ||
27 | local CYCLETIME = rb.HZ / 50 | 27 | local CYCLETIME = rb.HZ / 50 |
28 | 28 | ||
29 | if rb.action_get_touchscreen_press == nil then | ||
30 | HAS_TOUCHSCREEN = false | ||
31 | else | ||
32 | HAS_TOUCHSCREEN = true | ||
33 | end | ||
34 | |||
35 | -- color used to write the text | ||
36 | if rb.lcd_rgbpack ~= nil then | ||
37 | DEFAULT_FOREGROUND_COLOR = rb.lcd_rgbpack(255, 255, 255) | ||
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 | |||
29 | local levels = { | 50 | local levels = { |
30 | -- {GOAL, TOTAL_BALLS}, | 51 | -- {GOAL, TOTAL_BALLS}, |
31 | {1, 5}, | 52 | {1, 5}, |
@@ -43,7 +64,7 @@ local levels = { | |||
43 | } | 64 | } |
44 | 65 | ||
45 | local Ball = { | 66 | local Ball = { |
46 | size = 10, | 67 | size = DEFAULT_BALL_SIZE, |
47 | exploded = false, | 68 | exploded = false, |
48 | implosion = false | 69 | implosion = false |
49 | } | 70 | } |
@@ -54,15 +75,11 @@ function Ball:new(o) | |||
54 | x = math.random(self.size, rb.LCD_WIDTH - self.size), | 75 | x = math.random(self.size, rb.LCD_WIDTH - self.size), |
55 | y = math.random(self.size, rb.LCD_HEIGHT - self.size), | 76 | y = math.random(self.size, rb.LCD_HEIGHT - self.size), |
56 | color = random_color(), | 77 | color = random_color(), |
57 | up_speed = math.random(-3, 3), | 78 | up_speed = Ball:generateSpeed(), |
58 | right_speed = math.random(-3, 3), | 79 | right_speed = Ball:generateSpeed(), |
59 | explosion_size = math.random((3*self.size)/2, (5*self.size)/2), | 80 | explosion_size = math.random((3*self.size)/2, (5*self.size)/2), |
60 | life_duration = math.random(rb.HZ, rb.HZ*5) | 81 | life_duration = math.random(rb.HZ, rb.HZ*5) |
61 | } | 82 | } |
62 | |||
63 | -- Make sure all balls move | ||
64 | if o.up_speed == 0 then o.up_speed = 1 end | ||
65 | if o.right_speed == 0 then o.right_speed = 1 end | ||
66 | end | 83 | end |
67 | 84 | ||
68 | setmetatable(o, self) | 85 | setmetatable(o, self) |
@@ -70,6 +87,13 @@ function Ball:new(o) | |||
70 | return o | 87 | return o |
71 | end | 88 | end |
72 | 89 | ||
90 | function Ball:generateSpeed() | ||
91 | local speed = math.random(-MAX_BALL_SPEED, MAX_BALL_SPEED) | ||
92 | -- Make sure all balls move | ||
93 | if speed == 0 then speed = 1 end | ||
94 | return speed | ||
95 | end | ||
96 | |||
73 | function Ball:draw() | 97 | function Ball:draw() |
74 | --[[ | 98 | --[[ |
75 | I know these aren't circles, but as there's no current circle | 99 | I know these aren't circles, but as there's no current circle |
@@ -124,7 +148,7 @@ function Ball:checkHit(other) | |||
124 | end | 148 | end |
125 | 149 | ||
126 | local Cursor = { | 150 | local Cursor = { |
127 | size = 20, | 151 | size = DEFAULT_BALL_SIZE*2, |
128 | x = rb.LCD_WIDTH/2, | 152 | x = rb.LCD_WIDTH/2, |
129 | y = rb.LCD_HEIGHT/2 | 153 | y = rb.LCD_HEIGHT/2 |
130 | } | 154 | } |
@@ -134,8 +158,8 @@ function Cursor:new() | |||
134 | end | 158 | end |
135 | 159 | ||
136 | function Cursor:do_action(action) | 160 | function Cursor:do_action(action) |
137 | if action == rb.actions.ACTION_TOUCHSCREEN and hasTouchScreen then | 161 | if action == rb.actions.ACTION_TOUCHSCREEN and HAS_TOUCHSCREEN then |
138 | if hasTouchScreen then | 162 | if HAS_TOUCHSCREEN then |
139 | _, self.x, self.y = rb.action_get_touchscreen_press() | 163 | _, self.x, self.y = rb.action_get_touchscreen_press() |
140 | end | 164 | end |
141 | return true | 165 | return true |
@@ -164,7 +188,7 @@ function Cursor:do_action(action) | |||
164 | end | 188 | end |
165 | 189 | ||
166 | function Cursor:draw() | 190 | function Cursor:draw() |
167 | set_foreground(defaultForeGroundColor) | 191 | set_foreground(DEFAULT_FOREGROUND_COLOR) |
168 | rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y - self.size/2) | 192 | 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) | 193 | 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) | 194 | rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y + self.size/2) |
@@ -227,9 +251,9 @@ function start_round(level, goal, nrBalls, total) | |||
227 | local player = Ball:new({ | 251 | local player = Ball:new({ |
228 | x = cursor.x, | 252 | x = cursor.x, |
229 | y = cursor.y, | 253 | y = cursor.y, |
230 | color = defaultForeGroundColor, | 254 | color = DEFAULT_FOREGROUND_COLOR, |
231 | size = 10, | 255 | size = 10, |
232 | explosion_size = 30, | 256 | explosion_size = 3*DEFAULT_BALL_SIZE, |
233 | exploded = true, | 257 | exploded = true, |
234 | death_time = rb.current_tick() + rb.HZ * 3 | 258 | death_time = rb.current_tick() + rb.HZ * 3 |
235 | }) | 259 | }) |
@@ -263,7 +287,7 @@ function start_round(level, goal, nrBalls, total) | |||
263 | 287 | ||
264 | -- Drawing phase | 288 | -- Drawing phase |
265 | rb.lcd_clear_display() | 289 | rb.lcd_clear_display() |
266 | set_foreground(defaultForeGroundColor) | 290 | set_foreground(DEFAULT_FOREGROUND_COLOR) |
267 | draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls)) | 291 | draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls)) |
268 | draw_positioned_string(0, 1, string.format("Level %d", level)) | 292 | draw_positioned_string(0, 1, string.format("Level %d", level)) |
269 | draw_positioned_string(1, 1, string.format("%d level points", score)) | 293 | draw_positioned_string(1, 1, string.format("%d level points", score)) |
@@ -278,7 +302,7 @@ function start_round(level, goal, nrBalls, total) | |||
278 | explodedBall:step() | 302 | explodedBall:step() |
279 | explodedBall:draw() | 303 | explodedBall:draw() |
280 | end | 304 | end |
281 | if not hasTouchScreen and not player_added then | 305 | if not HAS_TOUCHSCREEN and not player_added then |
282 | cursor:draw() | 306 | cursor:draw() |
283 | end | 307 | end |
284 | rb.lcd_update() | 308 | rb.lcd_update() |
@@ -299,7 +323,7 @@ function display_message(message) | |||
299 | local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2 | 323 | local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2 |
300 | 324 | ||
301 | rb.lcd_clear_display() | 325 | rb.lcd_clear_display() |
302 | set_foreground(defaultForeGroundColor) | 326 | set_foreground(DEFAULT_FOREGROUND_COLOR) |
303 | if w > rb.LCD_WIDTH then | 327 | if w > rb.LCD_WIDTH then |
304 | rb.lcd_puts_scroll(x/w, y/h, message) | 328 | rb.lcd_puts_scroll(x/w, y/h, message) |
305 | else | 329 | else |
@@ -312,19 +336,7 @@ function display_message(message) | |||
312 | rb.lcd_stop_scroll() -- Stop our scrolling message | 336 | rb.lcd_stop_scroll() -- Stop our scrolling message |
313 | end | 337 | end |
314 | 338 | ||
315 | if rb.action_get_touchscreen_press == nil then | 339 | if HAS_TOUCHSCREEN 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) | 340 | rb.touchscreen_set_mode(rb.TOUCHSCREEN_POINT) |
329 | end | 341 | end |
330 | rb.backlight_force_on() | 342 | rb.backlight_force_on() |