1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Maurus Cuelenaere 2009-12-06 15:58:18 +00:00
parent 48114263d2
commit 51d89e2594

View file

@ -25,27 +25,13 @@
require "actions" require "actions"
local CYCLETIME = rb.HZ / 50 local CYCLETIME = rb.HZ / 50
local HAS_TOUCHSCREEN = rb.action_get_touchscreen_press ~= nil
if rb.action_get_touchscreen_press == nil then local DEFAULT_BALL_SIZE = rb.LCD_HEIGHT > rb.LCD_WIDTH and rb.LCD_WIDTH / 30
HAS_TOUCHSCREEN = false or rb.LCD_HEIGHT / 30
else local MAX_BALL_SPEED = DEFAULT_BALL_SIZE / 2
HAS_TOUCHSCREEN = true local DEFAULT_FOREGROUND_COLOR = rb.lcd_get_foreground ~= nil
end and rb.lcd_get_foreground()
or 0
-- color used to write the text
if rb.lcd_get_foreground ~= nil then
DEFAULT_FOREGROUND_COLOR = rb.lcd_get_foreground()
else
DEFAULT_FOREGROUND_COLOR = 0
end
if rb.LCD_HEIGHT > rb.LCD_WIDTH then
DEFAULT_BALL_SIZE = rb.LCD_WIDTH/40
else
DEFAULT_BALL_SIZE = rb.LCD_HEIGHT/40
end
MAX_BALL_SPEED = DEFAULT_BALL_SIZE/2
local levels = { local levels = {
-- {GOAL, TOTAL_BALLS}, -- {GOAL, TOTAL_BALLS},
@ -77,7 +63,7 @@ function Ball:new(o)
color = random_color(), color = random_color(),
up_speed = Ball:generateSpeed(), up_speed = Ball:generateSpeed(),
right_speed = Ball:generateSpeed(), right_speed = Ball:generateSpeed(),
explosion_size = math.random((3*self.size)/2, (5*self.size)/2), explosion_size = math.random(2*self.size, 4*self.size),
life_duration = math.random(rb.HZ, rb.HZ*5) life_duration = math.random(rb.HZ, rb.HZ*5)
} }
end end
@ -89,8 +75,10 @@ end
function Ball:generateSpeed() function Ball:generateSpeed()
local speed = math.random(-MAX_BALL_SPEED, MAX_BALL_SPEED) local speed = math.random(-MAX_BALL_SPEED, MAX_BALL_SPEED)
-- Make sure all balls move if speed == 0 then
if speed == 0 then speed = 1 end speed = 1 -- Make sure all balls move
end
return speed return speed
end end
@ -159,9 +147,7 @@ end
function Cursor:do_action(action) function Cursor:do_action(action)
if action == rb.actions.ACTION_TOUCHSCREEN and HAS_TOUCHSCREEN then if action == rb.actions.ACTION_TOUCHSCREEN and HAS_TOUCHSCREEN then
if HAS_TOUCHSCREEN then _, self.x, self.y = rb.action_get_touchscreen_press()
_, self.x, self.y = rb.action_get_touchscreen_press()
end
return true return true
elseif action == rb.actions.ACTION_KBD_SELECT then elseif action == rb.actions.ACTION_KBD_SELECT then
return true return true
@ -174,21 +160,25 @@ function Cursor:do_action(action)
elseif (action == rb.actions.ACTION_KBD_DOWN) then elseif (action == rb.actions.ACTION_KBD_DOWN) then
self.y = self.y + self.size self.y = self.y + self.size
end end
if self.x > rb.LCD_WIDTH then if self.x > rb.LCD_WIDTH then
self.x = 0 self.x = 0
elseif self.x < 0 then elseif self.x < 0 then
self.x = rb.LCD_WIDTH self.x = rb.LCD_WIDTH
end end
if self.y > rb.LCD_HEIGHT then if self.y > rb.LCD_HEIGHT then
self.y = 0 self.y = 0
elseif self.y < 0 then elseif self.y < 0 then
self.y = rb.LCD_HEIGHT self.y = rb.LCD_HEIGHT
end end
return false return false
end end
function Cursor:draw() function Cursor:draw()
set_foreground(DEFAULT_FOREGROUND_COLOR) set_foreground(DEFAULT_FOREGROUND_COLOR)
rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y - self.size/2) rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y - self.size/2)
rb.lcd_hline(self.x + self.size/4, self.x + self.size/2, self.y - self.size/2) rb.lcd_hline(self.x + self.size/4, self.x + self.size/2, self.y - self.size/2)
rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y + self.size/2) rb.lcd_hline(self.x - self.size/2, self.x - self.size/4, self.y + self.size/2)
@ -204,6 +194,7 @@ end
function draw_positioned_string(bottom, right, str) function draw_positioned_string(bottom, right, str)
local _, w, h = rb.font_getstringsize(str, rb.FONT_UI) local _, w, h = rb.font_getstringsize(str, rb.FONT_UI)
rb.lcd_putsxy((rb.LCD_WIDTH-w)*right, (rb.LCD_HEIGHT-h)*bottom, str) rb.lcd_putsxy((rb.LCD_WIDTH-w)*right, (rb.LCD_HEIGHT-h)*bottom, str)
end end
@ -217,6 +208,7 @@ function random_color()
if rb.lcd_rgbpack ~= nil then --color target if rb.lcd_rgbpack ~= nil then --color target
return rb.lcd_rgbpack(math.random(1,255), math.random(1,255), math.random(1,255)) return rb.lcd_rgbpack(math.random(1,255), math.random(1,255), math.random(1,255))
end end
return math.random(1, rb.LCD_DEPTH) return math.random(1, rb.LCD_DEPTH)
end end
@ -287,6 +279,7 @@ function start_round(level, goal, nrBalls, total)
-- Drawing phase -- Drawing phase
rb.lcd_clear_display() rb.lcd_clear_display()
set_foreground(DEFAULT_FOREGROUND_COLOR) set_foreground(DEFAULT_FOREGROUND_COLOR)
draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls)) draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpandedBalls))
draw_positioned_string(0, 1, string.format("Level %d", level)) draw_positioned_string(0, 1, string.format("Level %d", level))
@ -302,9 +295,12 @@ function start_round(level, goal, nrBalls, total)
explodedBall:step() explodedBall:step()
explodedBall:draw() explodedBall:draw()
end end
if not HAS_TOUCHSCREEN and not player_added then if not HAS_TOUCHSCREEN and not player_added then
cursor:draw() cursor:draw()
end end
-- Push framebuffer to the LCD
rb.lcd_update() rb.lcd_update()
if rb.current_tick() < endtick then if rb.current_tick() < endtick then
@ -318,7 +314,8 @@ function start_round(level, goal, nrBalls, total)
end end
-- Helper function to display a message -- Helper function to display a message
function display_message(message) function display_message(...)
local message = string.format(...)
local _, w, h = rb.font_getstringsize(message, rb.FONT_UI) local _, w, h = rb.font_getstringsize(message, rb.FONT_UI)
local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2 local x, y = (rb.LCD_WIDTH - w) / 2, (rb.LCD_HEIGHT - h) / 2
@ -342,18 +339,10 @@ end
rb.backlight_force_on() rb.backlight_force_on()
local idx, highscore = 1, 0 local idx, highscore = 1, 0
while true do while levels[idx] ~= nil do
local level = levels[idx] local goal, nrBalls = levels[idx][1], levels[idx][2]
local goal, nrBalls
if level == nil then display_message("Level %d: get %d out of %d balls", idx, goal, nrBalls)
break -- No more levels to play
end
goal = level[1]
nrBalls = level[2]
display_message(string.format("Level %d: get %d out of %d balls", idx, goal, nrBalls))
local exit, score, nrExpandedBalls = start_round(idx, goal, nrBalls, highscore) local exit, score, nrExpandedBalls = start_round(idx, goal, nrBalls, highscore)
if exit then if exit then
@ -370,11 +359,10 @@ while true do
end end
if idx > #levels then if idx > #levels then
display_message(string.format("You finished the game with %d points!", highscore)) display_message("You finished the game with %d points!", highscore)
else else
display_message(string.format("You made it till level %d with %d points!", idx, highscore)) display_message("You made it till level %d with %d points!", idx, highscore)
end end
-- Restore user backlight settings -- Restore user backlight settings
rb.backlight_use_settings() rb.backlight_use_settings()