1
0
Fork 0
forked from len0rd/rockbox

boomshine: improve collision detection.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25043 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2010-03-06 12:20:09 +00:00
parent a14f4acb0c
commit e726920bde

View file

@ -58,8 +58,8 @@ local Ball = {
function Ball:new(o) function Ball:new(o)
if o == nil then if o == nil then
o = { o = {
x = math.random(self.size, rb.LCD_WIDTH - self.size), x = math.random(0, rb.LCD_WIDTH - self.size),
y = math.random(self.size, rb.LCD_HEIGHT - self.size), y = math.random(0, rb.LCD_HEIGHT - self.size),
color = random_color(), color = random_color(),
up_speed = Ball:generateSpeed(), up_speed = Ball:generateSpeed(),
right_speed = Ball:generateSpeed(), right_speed = Ball:generateSpeed(),
@ -108,20 +108,19 @@ function Ball:step()
self.x = self.x + self.right_speed self.x = self.x + self.right_speed
self.y = self.y + self.up_speed self.y = self.y + self.up_speed
if (self.x + self.size) >= rb.LCD_WIDTH or self.x <= self.size then if (self.right_speed > 0 and self.x + self.size >= rb.LCD_WIDTH) or
self.right_speed = self.right_speed * (-1) (self.right_speed < 0 and self.x <= 0) then
elseif (self.y + self.size) >= rb.LCD_HEIGHT or self.y <= self.size then self.right_speed = -self.right_speed
self.up_speed = self.up_speed * (-1) end
if (self.up_speed > 0 and self.y + self.size >= rb.LCD_HEIGHT) or
(self.up_speed < 0 and self.y <= 0) then
self.up_speed = -self.up_speed
end end
end end
function Ball:checkHit(other) function Ball:checkHit(other)
local x_dist = math.abs(other.x - self.x) if (other.x + other.size >= self.x) and (self.x + self.size >= other.x) and
local y_dist = math.abs(other.y - self.y) (other.y + other.size >= self.y) and (self.y + self.size >= other.y) then
local x_size = self.x > other.x and other.size or self.size
local y_size = self.y > other.y and other.size or self.size
if (x_dist <= x_size) and (y_dist <= y_size) then
assert(not self.exploded) assert(not self.exploded)
self.exploded = true self.exploded = true
self.death_time = rb.current_tick() + self.life_duration self.death_time = rb.current_tick() + self.life_duration