-
Notifications
You must be signed in to change notification settings - Fork 20
Glue Bonus
noooway edited this page Mar 7, 2017
·
24 revisions
- Detect collision with 'glue' bonus
function bonuses.bonus_collected( i, bonus, ball, platform )
.....
elseif bonuses.is_glue( bonus ) then
platform.react_on_glue_bonus()
end
.....
end
function bonuses.is_glue( single_bonus )
local col = single_bonus.bonustype % 10
return ( col == 2 )
end
- When glue bonus is caught, platform tile is changed and
glued
flag is raised.
function platform.react_on_glue_bonus()
platform.glued = true
if platform.size == "small" then
platform.quad = love.graphics.newQuad(
platform.small_tile_x_pos + platfrom.glued_x_pos_shift,
platform.small_tile_y_pos,
platform.small_tile_width,
platform.small_tile_height,
platform.tileset_width,
platform.tileset_height )
elseif platform.size == "norm" then
platform.quad = love.graphics.newQuad(
platform.norm_tile_x_pos + platfrom.glued_x_pos_shift,
platform.norm_tile_y_pos,
platform.norm_tile_width,
platform.norm_tile_height,
platform.tileset_width,
platform.tileset_height )
elseif platform.size == "large" then
platform.quad = love.graphics.newQuad(
platform.large_tile_x_pos + platfrom.glued_x_pos_shift,
platform.large_tile_y_pos,
platform.large_tile_width,
platform.large_tile_height,
platform.tileset_width,
platform.tileset_height )
end
end
- Ball-platform collision depends on the value of the
glued
flag.
local first_launch_speed = vector( -150, -300 )
ball.platform_launch_speed = first_launch_speed:clone()
function ball.platform_rebound( shift_ball, platform )
ball.increase_collision_counter()
ball.increase_speed_after_collision()
if not platform.glued then
ball.normal_rebound( shift_ball )
ball.rotate_speed( shift_ball, platform )
else
ball.normal_rebound( shift_ball )
ball.rotate_speed( shift_ball, platform )
ball.platform_launch_speed = ball.speed:clone()
ball.stuck_to_platform = true
ball.speed = vector( 0, 0 )
local platform_center = vector(
platform.position.x + platform.width / 2,
platform.position.y + platform.height / 2 )
local ball_center = ball.position:clone()
ball.separation_from_platform_center =
ball_center - platform_center
print( ball.separation_from_platform_center )
end
end
function ball.launch_from_platform()
if ball.stuck_to_platform then
ball.stuck_to_platform = false
ball.speed = ball.platform_launch_speed:clone()
end
end
- The glued effect is removed if any other bonus is caught, the ball is lost, or the next level is reached. ...
function platform.remove_glued_effect()
platform.glued = false
if platform.size == "small" then
platform.quad = love.graphics.newQuad(
platform.small_tile_x_pos,
platform.small_tile_y_pos,
platform.small_tile_width,
platform.small_tile_height,
platform.tileset_width,
platform.tileset_height )
elseif platform.size == "norm" then
platform.quad = love.graphics.newQuad(
platform.norm_tile_x_pos,
platform.norm_tile_y_pos,
platform.norm_tile_width,
platform.norm_tile_height,
platform.tileset_width,
platform.tileset_height )
elseif platform.size == "large" then
platform.quad = love.graphics.newQuad(
platform.large_tile_x_pos,
platform.large_tile_y_pos,
platform.large_tile_width,
platform.large_tile_height,
platform.tileset_width,
platform.tileset_height )
end
end
Feedback is crucial to improve the tutorial!
Let me know if you have any questions, critique, suggestions or just any other ideas.
Chapter 1: Prototype
- The Ball, The Brick, The Platform
- Game Objects as Lua Tables
- Bricks and Walls
- Detecting Collisions
- Resolving Collisions
- Levels
Appendix A: Storing Levels as Strings
Appendix B: Optimized Collision Detection (draft)
Chapter 2: General Code Structure
- Splitting Code into Several Files
- Loading Levels from Files
- Straightforward Gamestates
- Advanced Gamestates
- Basic Tiles
- Different Brick Types
- Basic Sound
- 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
- Improved Ball Rebounds
- Ball Launch From Platform (Two Objects Moving Together)
- Mouse Controls
- Spawning Bonuses
- Bonus Effects
- Glue Bonus
- Add New Ball Bonus
- Life and Next Level Bonuses
- Random Bonuses
- Menu Buttons
- Wall Tiles
- Side Panel
- Score
- Fonts
- More Sounds
- Final Screen
- Packaging
Appendix D: GUI Layouts
Appendix E: Love-release and Love.js
Beyond Programming: