Advertisement
Guest User

Untitled

a guest
Apr 8th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.63 KB | None | 0 0
  1. diff --git a/apps/plugins/boomshine.lua b/apps/plugins/boomshine.lua
  2. index 2eb43de..cc3f5a6 100644
  3. --- a/apps/plugins/boomshine.lua
  4. +++ b/apps/plugins/boomshine.lua
  5. @@ -63,7 +63,7 @@ function Ball:new(o)
  6.                  color = random_color(),
  7.                  up_speed = Ball:generateSpeed(),
  8.                  right_speed = Ball:generateSpeed(),
  9. -                explosion_size = math.random(2*self.size, 4*self.size),
  10. +                explosion_size = math.random(2*self.size, 4*self.size) * 4/3,
  11.                  life_duration = math.random(rb.HZ, rb.HZ*5)
  12.              }
  13.      end
  14. @@ -82,6 +82,26 @@ function Ball:generateSpeed()
  15.      return speed
  16.  end
  17.  
  18. +function drawCircle(x0, y0, radius)
  19. +  x = radius
  20. +  y = 0
  21. +  radiusError = 1 - x
  22. +  step = 0
  23. +
  24. +  while x >= y do
  25. +    y = y + 1
  26. +    if radiusError < 0 then
  27. +      radiusError = radiusError + 2 * y + 1
  28. +    else
  29. +      rb.lcd_fillrect(x0 - x, y0 - y, 1, 2 * y)
  30. +      rb.lcd_fillrect(x0 + x, y0 - y, 1, 2 * y)
  31. +      rb.lcd_fillrect(x0 - y, y0 - x, 2 * y, 2 * x)
  32. +      x = x - 1
  33. +      radiusError = radiusError + (y - x) + 1
  34. +    end
  35. +  end
  36. +end
  37. +
  38.  function Ball:draw()
  39.      --[[
  40.           I know these aren't circles, but as there's no current circle
  41. @@ -89,7 +109,13 @@ function Ball:draw()
  42.           circles from within Lua is far too slow).
  43.      ]]--
  44.      set_foreground(self.color)
  45. -    rb.lcd_fillrect(self.x, self.y, self.size, self.size)
  46. +
  47. +    xm = math.floor(self.x + self.size / 2)
  48. +    ym = math.floor(self.y + self.size / 2)
  49. +
  50. +    drawCircle(xm, ym, math.ceil(self.size / 2))
  51. +
  52. +    --[[ rb.lcd_fillrect(self.x, self.y, self.size, self.size) ]]--
  53.  end
  54.  
  55.  function Ball:step()
  56. @@ -119,8 +145,12 @@ function Ball:step()
  57.  end
  58.  
  59.  function Ball:checkHit(other)
  60. -    if (other.x + other.size >= self.x) and (self.x + self.size >= other.x) and
  61. -       (other.y + other.size >= self.y) and (self.y + self.size >= other.y) the
  62. +    dx = (other.x + other.size / 2) - (self.x + self.size / 2)
  63. +    dy = (other.y + other.size / 2) - (self.y + self.size / 2)
  64. +    ds = (other.size / 2 + self.size / 2)
  65. +    if dx*dx + dy*dy   -- Distance between centers, squared
  66. +       <=
  67. +       ds * ds then    -- Sizes, squared
  68.          assert(not self.exploded)
  69.          self.exploded = true
  70.          self.death_time = rb.current_tick() + self.life_duration
  71. @@ -212,7 +242,7 @@ function random_color()
  72.  end
  73.  
  74.  function start_round(level, goal, nrBalls, total)
  75. -    local player_added, score, exit, nrExpandedBalls = false, 0, false, 0
  76. +    local player_added, score, exit, nrExpendedBalls = false, 0, false, 0
  77.      local balls, explodedBalls = {}, {}
  78.      local cursor = Cursor:new()
  79.  
  80. @@ -257,7 +287,7 @@ function start_round(level, goal, nrBalls, total)
  81.              for _, explodedBall in ipairs(explodedBalls) do
  82.                  if ball:checkHit(explodedBall) then
  83.                      score = score + 100*level
  84. -                    nrExpandedBalls = nrExpandedBalls + 1
  85. +                    nrExpendedBalls = nrExpendedBalls + 1
  86.                      table.insert(explodedBalls, ball)
  87.                      table.remove(balls, i)
  88.                      break
  89. @@ -280,7 +310,7 @@ function start_round(level, goal, nrBalls, total)
  90.          rb.lcd_clear_display()
  91.  
  92.          set_foreground(DEFAULT_FOREGROUND_COLOR)
  93. -        draw_positioned_string(0, 0, string.format("%d balls expanded", nrExpan
  94. +        draw_positioned_string(0, 0, string.format("%d balls expended", nrExpen
  95.          draw_positioned_string(0, 1, string.format("Level %d", level))
  96.          draw_positioned_string(1, 1, string.format("%d level points", score))
  97.          draw_positioned_string(1, 0, string.format("%d total points", total+sco
  98. @@ -309,7 +339,7 @@ function start_round(level, goal, nrBalls, total)
  99.          end
  100.      end
  101.  
  102. -    return exit, score, nrExpandedBalls
  103. +    return exit, score, nrExpendedBalls
  104.  end
  105.  
  106.  -- Helper function to display a message
  107. @@ -353,17 +383,19 @@ if HAS_TOUCHSCREEN then
  108.  end
  109.  rb.backlight_force_on()
  110.  
  111. +math.randomseed(os.time())
  112. +
  113.  local idx, highscore = 1, 0
  114.  while levels[idx] ~= nil do
  115.      local goal, nrBalls = levels[idx][1], levels[idx][2]
  116.  
  117.      display_message(rb.HZ*2, "Level %d: get %d out of %d balls", idx, goal, nrB
  118.  
  119. -    local exit, score, nrExpandedBalls = start_round(idx, goal, nrBalls, highsc
  120. +    local exit, score, nrExpendedBalls = start_round(idx, goal, nrBalls, highsc
  121.      if exit then
  122.          break -- Exiting..
  123.      else
  124. -        if nrExpandedBalls >= goal then
  125. +        if nrExpendedBalls >= goal then
  126.              display_message(rb.HZ*2, "You won!")
  127.              idx = idx + 1
  128.              highscore = highscore + score
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement