Skip to content
noooway edited this page Mar 12, 2017 · 19 revisions
  1. Score display
local vector = require "vector"

local score_display = {}
score_display.position = vector( 680, 32 )
score_display.score = 0

function score_display.update( dt )
end

function score_display.draw()
   love.graphics.print( "Score: " .. tostring( score_display.score ),
                        score_display.position.x,
                        score_display.position.y )
end
  1. Reaction on collision
function score_display.add_score_for_simple_brick()
   score_display.score = score_display.score + 10
end

function score_display.add_score_for_cracked_brick()
   score_display.score = score_display.score + 30
end

function bricks.brick_hit_by_ball( i, brick, shift_ball, bonuses, score_display )
   if bricks.is_simple( brick ) then
      bonuses.generate_bonus(
         vector( brick.position.x + brick.width / 2,
                 brick.position.y + brick.height / 2 ),
         brick.bonustype )
      score_display.add_score_for_simple_brick()
      table.remove( bricks.current_level_bricks, i )
      simple_break_sound:play()
   elseif bricks.is_armored( brick ) then
      bricks.armored_to_scrathed( brick )
      armored_hit_sound:play()
   elseif bricks.is_scratched( brick ) then
      bricks.scrathed_to_cracked( brick )
      armored_hit_sound:play()
   elseif bricks.is_cracked( brick ) then
      bonuses.generate_bonus(
         vector( brick.position.x + brick.width / 2,
                 brick.position.y + brick.height / 2 ),
         brick.bonustype )
      score_display.add_score_for_cracked_brick()
      table.remove( bricks.current_level_bricks, i )
      armored_break_sound:play()
   elseif bricks.is_heavyarmored( brick ) then
      ball_heavyarmored_sound:play()
   end
end

function collisions.resolve_collisions( balls, platform,
                                        walls, bricks,
                                        bonuses, side_panel )
   collisions.balls_platform_collision( balls, platform )
   collisions.balls_walls_collision( balls, walls )
   collisions.balls_bricks_collision( balls, bricks, bonuses,
                                      side_panel.score_display )
   collisions.platform_walls_collision( platform, walls )
   collisions.platform_bonuses_collision( platform, bonuses,
                                          balls, walls,
                                          side_panel.lives_display )
end

function game.update( dt )
   balls.update( dt, platform )
   platform.update( dt )
   bricks.update( dt )
   bonuses.update( dt )
   walls.update( dt )
   side_panel.update( dt )
   collisions.resolve_collisions( balls, platform,
                                  walls, bricks,
                                  bonuses, side_panel )
   game.check_no_more_balls( balls, side_panel.lives_display )
   game.switch_to_next_level( bricks, levels )
end
  1. Modifications to side_panel
side_panel.lives_display = lives_display
side_panel.score_display = score_display

function side_panel.update( dt )
   side_panel.lives_display.update( dt )
   side_panel.score_display.update( dt )
end

function side_panel.draw()
   side_panel.draw_background()
   side_panel.lives_display.draw()
   side_panel.score_display.draw()
end

function side_panel.reset()
   side_panel.lives_display.reset()
   side_panel.score_display.reset()
end
  1. Modifications to "game"
function game.enter( prev_state, ... )
   local args = ...
   if prev_state == "gamepaused" then
      music:resume()
   end
   if prev_state == "gameover" or prev_state == "gamefinished" then
      side_panel.reset()
      music:rewind()
   end
   if args and args.current_level then
      bricks.clear_current_level_bricks()
      bonuses.clear_current_level_bonuses()
      levels.current_level = args.current_level
      local level = levels.require_current_level()
      bricks.construct_level( level )
      balls.reset()
      platform.remove_bonuses_effects()
      walls.remove_bonuses_effects()
   end      
end
  1. Add life if score milestone is reached.
function game.update( dt )
   .....
   side_panel.lives_display.add_life_if_score_reached(
      side_panel.score_display.score )
   game.check_no_more_balls( balls, side_panel.lives_display )
   .....
end

local lives_display = {}
lives_display.position = vector( 680, 500 )
lives_display.lives = 5
lives_display.lives_added_from_score = 0

function lives_display.add_life_if_score_reached( score )
   local score_milestone = (lives_display.lives_added_from_score + 1) * 3000
   if score >= score_milestone then
      lives_display.add_life()
      lives_display.lives_added_from_score = lives_display.lives_added_from_score + 1
   end
end
   
function lives_display.reset()
   lives_display.lives = 5
   lives_display.lives_added_from_score = 0
end

    Home
    Acknowledgements
    Todo

Chapter 1: Prototype

  1. The Ball, The Brick, The Platform
  2. Game Objects as Lua Tables
  3. Bricks and Walls
  4. Detecting Collisions
  5. Resolving Collisions
  6. Levels

    Appendix A: Storing Levels as Strings
    Appendix B: Optimized Collision Detection (draft)

Chapter 2: General Code Structure

  1. Splitting Code into Several Files
  2. Loading Levels from Files
  3. Straightforward Gamestates
  4. Advanced Gamestates
  5. Basic Tiles
  6. Different Brick Types
  7. Basic Sound
  8. Game Over

    Appendix C: Stricter Modules (draft)
    Appendix D-1: Intro to Classes (draft)
    Appendix D-2: Chapter 2 Using Classes.

Chapter 3 (deprecated): Details

  1. Improved Ball Rebounds
  2. Ball Launch From Platform (Two Objects Moving Together)
  3. Mouse Controls
  4. Spawning Bonuses
  5. Bonus Effects
  6. Glue Bonus
  7. Add New Ball Bonus
  8. Life and Next Level Bonuses
  9. Random Bonuses
  10. Menu Buttons
  11. Wall Tiles
  12. Side Panel
  13. Score
  14. Fonts
  15. More Sounds
  16. Final Screen
  17. Packaging

    Appendix D: GUI Layouts
    Appendix E: Love-release and Love.js

Beyond Programming:

  1. Game Design
  2. Minimal Marketing (draft)
  3. Finding a Team (draft)

Archive

Clone this wiki locally