summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2010-03-06 12:20:09 +0000
committerTeruaki Kawashima <teru@rockbox.org>2010-03-06 12:20:09 +0000
commite726920bde78dbbf9b3b85d6e344dbb068ecc144 (patch)
tree3042646e29eeba8c9d210e2e9756424635a5959d
parenta14f4acb0c9ecdb11845a84e6d83b1a7bdbd5c7b (diff)
downloadrockbox-e726920bde78dbbf9b3b85d6e344dbb068ecc144.tar.gz
rockbox-e726920bde78dbbf9b3b85d6e344dbb068ecc144.zip
boomshine: improve collision detection.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25043 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/boomshine.lua23
1 files changed, 11 insertions, 12 deletions
diff --git a/apps/plugins/boomshine.lua b/apps/plugins/boomshine.lua
index ab00c52e2b..c160fddf0d 100644
--- a/apps/plugins/boomshine.lua
+++ b/apps/plugins/boomshine.lua
@@ -58,8 +58,8 @@ local Ball = {
58function Ball:new(o) 58function Ball:new(o)
59 if o == nil then 59 if o == nil then
60 o = { 60 o = {
61 x = math.random(self.size, rb.LCD_WIDTH - self.size), 61 x = math.random(0, rb.LCD_WIDTH - self.size),
62 y = math.random(self.size, rb.LCD_HEIGHT - self.size), 62 y = math.random(0, rb.LCD_HEIGHT - self.size),
63 color = random_color(), 63 color = random_color(),
64 up_speed = Ball:generateSpeed(), 64 up_speed = Ball:generateSpeed(),
65 right_speed = Ball:generateSpeed(), 65 right_speed = Ball:generateSpeed(),
@@ -108,20 +108,19 @@ function Ball:step()
108 108
109 self.x = self.x + self.right_speed 109 self.x = self.x + self.right_speed
110 self.y = self.y + self.up_speed 110 self.y = self.y + self.up_speed
111 if (self.x + self.size) >= rb.LCD_WIDTH or self.x <= self.size then 111 if (self.right_speed > 0 and self.x + self.size >= rb.LCD_WIDTH) or
112 self.right_speed = self.right_speed * (-1) 112 (self.right_speed < 0 and self.x <= 0) then
113 elseif (self.y + self.size) >= rb.LCD_HEIGHT or self.y <= self.size then 113 self.right_speed = -self.right_speed
114 self.up_speed = self.up_speed * (-1) 114 end
115 if (self.up_speed > 0 and self.y + self.size >= rb.LCD_HEIGHT) or
116 (self.up_speed < 0 and self.y <= 0) then
117 self.up_speed = -self.up_speed
115 end 118 end
116end 119end
117 120
118function Ball:checkHit(other) 121function Ball:checkHit(other)
119 local x_dist = math.abs(other.x - self.x) 122 if (other.x + other.size >= self.x) and (self.x + self.size >= other.x) and
120 local y_dist = math.abs(other.y - self.y) 123 (other.y + other.size >= self.y) and (self.y + self.size >= other.y) then
121 local x_size = self.x > other.x and other.size or self.size
122 local y_size = self.y > other.y and other.size or self.size
123
124 if (x_dist <= x_size) and (y_dist <= y_size) then
125 assert(not self.exploded) 124 assert(not self.exploded)
126 self.exploded = true 125 self.exploded = true
127 self.death_time = rb.current_tick() + self.life_duration 126 self.death_time = rb.current_tick() + self.life_duration