Skip to content

Life and Next Level Bonuses

noooway edited this page Mar 9, 2017 · 10 revisions
  1. Recognize Life and Next Level bonuses.
function bonuses.bonus_collected( i, bonus, balls, platform )
   .....
   elseif bonuses.is_life( bonus ) then
      .....
   elseif bonuses.is_next_level( bonus ) then
      .....
   end
   .....
end

function bonuses.is_life( single_bonus )
   local col = single_bonus.bonustype % 10
   return ( col == 8 )
end

function bonuses.is_next_level( single_bonus )
   local col = single_bonus.bonustype % 10
   return ( col == 7 )
end
  1. Reaction on life: it is necessary to add new life to the counter.
function game.update( dt )
   .....
   collisions.resolve_collisions( balls, platform,
                                  walls, bricks,
                                  bonuses, lives_display )
   .....
end

function collisions.resolve_collisions( balls, platform,
                                        walls, bricks,
                                        bonuses, lives_display )
   .....
   collisions.platform_bonuses_collision( platform, bonuses,
                                          balls, lives_display )
end

function collisions.platform_bonuses_collision( platform, bonuses,
                                                balls, lives_display )
   .....
      if overlap then
         bonuses.bonus_collected( i, bonus, balls, platform, lives_display )
      end
   .....
end

function bonuses.bonus_collected( i, bonus, balls, platform, lives_display )
   .....
   elseif bonuses.is_life( bonus ) then
      lives_display.add_life()
   elseif
   .....
end

function lives_display.add_life()
   lives_display.lives = lives_display.lives + 1
end
  1. Reaction on next level bonus:

3.1) In the right wall, the flag is activated if the bonus is caught.

function collisions.resolve_collisions( balls, platform,
                                        walls, bricks,
                                        bonuses, lives_display )
   .....
   collisions.platform_bonuses_collision( platform, bonuses,
                                          balls, walls,
                                          lives_display )
end


function collisions.platform_bonuses_collision( platform, bonuses,
                                                balls, walls,
                                                lives_display )
   .....
      if overlap then
         bonuses.bonus_collected( i, bonus,
                                  balls, platform,
                                  walls, lives_display )
      end
   .....
end

function bonuses.bonus_collected( i, bonus,
                                  balls, platform,
                                  walls, lives_display )
   .....
   elseif bonuses.is_next_level( bonus ) then
      walls.current_level_walls["right"].next_level_bonus = true
   end
   .....
end

3.2) The display of the wall is changed.

function walls.draw_wall( single_wall ) ..... love.graphics.setColor( 255, 0, 0, 100 ) if single_wall.next_level_bonus then love.graphics.setColor( 0, 0, 255, 100 ) end love.graphics.rectangle( 'fill', single_wall.position.x, single_wall.position.y, single_wall.width, single_wall.height ) ..... end


3.3) If the platform touches the right wall, the game switches
to the next level. It is more convenient to raise one more flag in the
platform object and check it.
```lua
function collisions.platform_walls_collision( platform, walls )
   .....
      if overlap then    
         platform.bounce_from_wall( shift_platform, wall )
      end
   .....
end

function platform.bounce_from_wall( shift_platform, wall )
   platform.position.x = platform.position.x + shift_platform.x
   if wall.next_level_bonus then
      platform.activated_next_level_bonus = true
   end
end

function game.switch_to_next_level( bricks, levels )
   if bricks.no_more_bricks or platform.activated_next_level_bonus then
      bricks.clear_current_level_bricks()
      bonuses.clear_current_level_bonuses()
      if levels.current_level < #levels.sequence then
         gamestates.set_state(
            "game", { current_level = levels.current_level + 1 } )
      else
         gamestates.set_state( "gamefinished" )
      end
   end
end

3.4) The effect of the bonus is lost if next level is reached or all the balls are lost

function game.enter( prev_state, ... )
   .....
   if args and args.current_level then
      .....
      platform.remove_bonuses_effects()
      walls.remove_bonuses_effects()
   end      
end

function game.check_no_more_balls( balls, lives_display )
   if balls.no_more_balls then
       .....
         platform.remove_bonuses_effects()
         walls.remove_bonuses_effects()
       .....
   end
end

function platform.remove_bonuses_effects()
   platform.remove_glued_effect()
   platform.reset_size_to_norm()
   platform.activated_next_level_bonus = false
end

function walls.remove_bonuses_effects()
   walls.current_level_walls["right"].next_level_bonus = false
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