User Tools

Site Tools


love:interacting_with_boundaries

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revisionBoth sides next revision
love:interacting_with_boundaries [2021/10/05 02:42] – created mithatlove: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 
-     
---    -- "clip" the motion 
---    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
-        if circleX < (love.graphics.getWidth() - CIRCLE_SIZE) then  -- moving right, not reached the edgee +        isMoveRight = circleX < (love.graphics.getWidth() - CIRCLE_SIZE)
-            isMoveRight = true +
-        else                                                        -- moving right, reached the edge +
-            isMoveRight = false +
-        end+
     else     else
-        if circleX > (CIRCLE_SIZE) then                             -- moving left, not reached the edgee +        isMoveRight = not (circleX > CIRCLE_SIZE)
-            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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki