love:interacting_with_boundaries
Differences
This shows you the differences between two versions of the page.
Next revisionBoth sides next revision | |||
love:interacting_with_boundaries [2021/10/05 02:42] – created mithat | love:interacting_with_boundaries [2021/10/05 02:46] – [Bounce] mithat | ||
---|---|---|---|
Line 231: | Line 231: | ||
--[[ Update values of game parameters. ]]-- | --[[ Update values of game parameters. ]]-- | ||
function love.update(dt) | function love.update(dt) | ||
- | -- -- wrap around | ||
- | -- circleX = circleX + CIRCLE_SPEED * dt | ||
- | -- if circleX > (love.graphics.getWidth() + CIRCLE_SIZE) then | ||
- | -- circleX = -CIRCLE_SIZE | ||
- | -- end | ||
- | | ||
- | -- -- " | ||
- | -- circleX = circleX + CIRCLE_SPEED * dt | ||
- | -- if circleX > (love.graphics.getWidth() - CIRCLE_SIZE) then | ||
- | -- circleX = love.graphics.getWidth() - CIRCLE_SIZE | ||
- | -- end | ||
- | | ||
-- -- bounce | -- -- bounce | ||
-- -- four possible cases: | -- -- four possible cases: | ||
Line 249: | Line 237: | ||
-- -- moving left, not reached the edge -> keep moving left | -- -- moving left, not reached the edge -> keep moving left | ||
-- -- moving left, reached the edge -> move right | -- -- moving left, reached the edge -> move right | ||
- | -- if isMoveRight and circleX < (love.graphics.getWidth() - CIRCLE_SIZE) then -- moving right, not reached the edgee | ||
- | -- isMoveRight = true | ||
- | -- elseif isMoveRight and circleX >= (love.graphics.getWidth() - CIRCLE_SIZE) then -- moving right, reached the edge | ||
- | -- isMoveRight = false | ||
- | -- elseif not isMoveRight and circleX > (CIRCLE_SIZE) then -- moving left, not reached the edgee | ||
- | -- isMoveRight = false | ||
- | -- elseif not isMoveRight and circleX <= (CIRCLE_SIZE) then -- moving right, reached the edge | ||
- | -- isMoveRight = true | ||
- | -- end | ||
| | ||
-- bounce improved | -- bounce improved | ||
if isMoveRight then | if isMoveRight then | ||
- | | + | |
- | isMoveRight = true | + | |
- | else -- moving right, reached the edge | + | |
- | isMoveRight = false | + | |
- | end | + | |
else | else | ||
- | | + | |
- | isMoveRight = false | + | |
- | else -- moving right, reached the edge | + | |
- | isMoveRight = true | + | |
- | end | + | |
end | end | ||
| |
love/interacting_with_boundaries.txt · Last modified: 2021/10/05 02:53 by mithat