Vous lisez 0 fil de discussion
  • Auteur
    Messages
    • #70038
      z0tman
      Participant

      ça y est, j’ai fait tous les exercices de la liste (sauf la traînée de balle, j’ai mis un changement de couleurs à la place).

      Voici mon code, pour le faire fonctionner, il faudra ôter les références audio, ou les remplacer par les votres.

      Par contre, je ne sais pas si au niveau de la durée de vie du jeu, comment ça se passe.

      J’ai mis 10 niveaux, et voilà.

      En principe, la condition de victoire fonctionne, mais si ce n’est pas le cas, c’est parce que je n’ai pas vérifié sur les 10 niveaux complets.

      Pour la jouabilité, j’ai laissé une fonctionnalité en suspend, cependant, le contrôle est nettement amélioré comparé à celui du cours.

      io.stdout:setvbuf('no')
      
      if arg[#arg] == "-debug" then require("mobdebug")end
      
      local player = {}
      player.lives = 5
      player.level = 1
      player.score = 0
      player.bStart = false
      player.bLost = false
      player.bLevelUp = false
      
      local pad = {}
      pad.img = nil
      pad.health = 50
      pad.vx = 0
      pad.vy = 0
      pad.bMoveLeft = false
      pad.bMoveRight = false
      
      local ball = {}
      ball.radius = 7  
      ball.x = 0
      ball.y = 0
      ball.vx = 0
      ball.vy = 0
      ball.angle = 0
      ball.bBorderCollision = false
      ball.bPadCollision = false
      ball.bBrickCollision = false
      
      local bricks = {}
      bricks.height = 0
      bricks.width = 0
      bricks.number = 0
      bricks.points = 10
      
      brickTex ={}
      
      local gridBricks = {}
      gridBricks.x = 112
      gridBricks.y = 99
      gridBricks.width = 576
      gridBricks.height = 115
      gridBricks.gridName = "grid_"
      gridBricks.levels = {}
      gridBricks.bGridLevelStart = false
      gridBricks.bGridLevelPlaying = false
      gridBricks.bGridLevelEnd = false
      
      gridBricks.grid_1 = {
                             {0,0,0,0,0,1,1,0,0,0,0,0},
                             {0,0,0,0,1,1,1,1,0,0,0,0},
                             {0,0,0,1,1,0,0,1,1,0,0,0},
                             {0,0,1,1,0,0,0,0,1,1,0,0},
                             {0,1,1,0,0,0,0,0,0,1,1,0}
                            }
      
      gridBricks.grid_2 = {
                            {0,0,0,1,1,0,0,1,1,0,0,0}
                            ,{1,1,0,0,1,1,1,1,0,0,1,1}
                            ,{1,0,0,0,1,1,1,1,0,0,0,1}
                            ,{1,0,0,0,0,1,1,0,0,0,0,1}
                            ,{1,1,0,0,0,0,0,0,0,0,1,1}
                            }
                          
      gridBricks.grid_3 = {
                             {1,1,1,0,0,0,0,0,0,1,1,1},
                             {0,1,1,1,0,0,0,0,1,1,1,0},
                             {0,0,1,1,1,0,0,1,1,1,0,0},
                             {0,0,0,1,1,1,1,1,1,0,0,0},
                             {0,1,0,0,1,1,1,1,0,0,1,0}
                            }
                            
      gridBricks.grid_4 = {
                             {1,1,1,1,0,0,0,0,1,1,1,1},
                             {0,1,1,1,1,0,0,1,1,1,1,0},
                             {1,1,1,1,1,0,0,1,1,1,1,1},
                             {0,0,1,1,1,1,1,1,1,1,0,0},
                             {1,0,0,1,1,1,1,1,1,0,0,1}
                            }
                            
      gridBricks.grid_5 = {
                             {1,0,0,1,0,1,0,0,1,0,0,1},
                             {1,0,0,1,0,0,1,0,1,0,0,1},
                             {1,0,0,1,0,1,0,0,1,0,0,1},
                             {1,0,0,1,0,0,1,0,1,0,0,1},
                             {1,0,0,1,0,1,0,0,1,0,0,1}
                            }
                            
      gridBricks.grid_6 = {
                             {1,0,1,0,0,1,1,0,0,1,0,1},
                             {0,1,0,1,0,1,1,0,1,0,1,0},
                             {1,0,1,0,0,1,1,0,0,1,0,1},
                             {0,1,0,1,0,1,1,0,1,0,1,0},
                             {1,0,1,0,0,1,1,0,0,1,0,1}
                            }
                            
      gridBricks.grid_7 = {
                             {1,0,0,1,1,1,1,1,1,0,0,1},
                             {0,0,1,0,1,0,0,0,0,1,0,0},
                             {1,0,0,0,0,0,1,0,0,0,0,1},
                             {0,0,1,0,1,0,0,1,0,1,0,0},
                             {1,0,0,1,0,0,1,0,0,0,0,1}
                            }
                            
      gridBricks.grid_8 = {
                             {1,0,0,1,1,1,1,1,0,0,0,1},
                             {0,0,0,1,0,0,0,0,1,0,0,0},
                             {1,0,0,0,1,1,1,1,1,0,0,1},
                             {0,0,0,1,0,0,0,0,1,0,0,0},
                             {1,0,0,1,1,1,1,1,0,0,0,1}
                            }
                            
      gridBricks.grid_9 = {
                             {0,1,1,1,1,1,1,1,1,1,0,1},
                             {1,0,0,1,0,1,0,1,0,0,0,0},
                             {0,0,0,0,0,1,0,0,0,0,0,1},
                             {1,0,0,1,0,1,0,1,0,1,0,0},
                             {0,0,0,1,1,1,1,1,0,0,0,1}
                            }
                            
      gridBricks.grid_10 = {
                              {1,0,1,1,1,1,1,0,0,1,0,1},
                              {0,0,1,0,0,1,1,0,0,1,0,0},
                              {1,0,1,0,0,1,1,1,1,1,0,1},
                              {0,0,1,0,0,1,1,0,0,1,0,0},
                              {1,0,1,1,1,1,1,1,1,1,0,1}
                             }
      local hud = {}
      
      hud.font = nil
      hud.title = "CASSE-BRIQUE"
      hud.lives = {label="Lives: ", value = player.lives}
      hud.level = {label="Level: ", value = player.level}
      hud.score = {label = "Score: ", value = player.score}
      hud.remainingBricks = {label = "Bricks: ", value = bricks.number}
      hud.looseMsg = "You loose !"
      hud.lvlCompleteMsg = "Level complete !"
      hud.winMsg = "Congratulations ! You won it !!!"
      
      ----------------TIME LAUNCH CONTROL ANGLE---------------
      ----NON UTILISE - 
      -----------------pour faire varier l'angle de la balle ----------------en fonction de la vitesse du pad-----
      local timer = 0
      local padMoveLeftTrigger = 0
      local padMoveRightTrigger = 0
      local launchBallTrigger = 0
      
      function setTimer(deltaTime)
          timer = timer + deltaTime
      end
      
      function setPadMoveLeftTimeTrigger(timer)
        padMoveLeftTrigger = timer
      end
      
      function setPadMoveRightTimeTrigger(timer)
        padMoveRightTrigger = timer
      end
      
      function setLaunchBallTrigger(timer)
        launchBallTrigger = timer
      end
      
      function getPadSpeedAtLaunchTrigger(deltaTime,timePadMoveStart)
        local padInstant_Vx_AtLaunch = ((pad.vx/deltaTime)-pad.vx/timer)/(deltaTime - timePadMoveStart)
        return padInstant_Vx_AtLaunch
      end
      
      function setBallSpeedAtLaunchTrigger(launchTime, timePadMoveStart)
        if(getPadSpeedAtLaunchTrigger(launchTime, timePadMoveStart) > 0) then
          ball.vx = 200
        elseif(getPadSpeedAtLaunchTrigger(launchTime,timePadMoveStart)<0) then
          ball.vx = -200
        end
        return ball.vx
      end
      ------------------GAME OBJECTS SETTINGS-----------------
      function setPad()
        pad.img = love.graphics.newImage("images/Racket.png")
        pad.width = pad.img:getWidth()
        pad.height = pad.img:getHeight()
        pad.health = 100
        pad.x = screenWidth/2
        pad.y = screenHeight - pad.height
      end
      
      function setPadSpeed(deltaTime)
        if love.keyboard.isDown('left') then
          pad.bMoveRight = false
          pad.bMoveLeft = true
          setPadMoveLeftTimeTrigger(deltaTime)
          pad.x = pad.x -pad.x*3*deltaTime
        end
        if love.keyboard.isDown('right') then
          pad.bMoveLeft = false
          pad.bMoveRight = true
          setPadMoveRightTimeTrigger(deltaTime)
          pad.x = pad.x +pad.x*3*deltaTime
        end
      end
      
      function setBallLaunchPosition()
        ball.x = pad.x
        ball.y = pad.y - pad.height/2 - ball.radius
      end
      
      function setBallSpeed(deltaTime)
        ball.x = ball.x + ball.vx*deltaTime
        ball.y = ball.y + ball.vy*deltaTime
      end
      
      function BallLaunchImpulse()
        if love.keyboard.isDown('space') then
          if ball.bStackOnPad == true then
            ball.bStackOnPad = false
            bStart = true
            gridBricks.bGridLevelEnd = false
            gridBricks.bGridLevelStart = false
            gridBricks.bGridLevelPlaying = true
            if(pad.bMoveLeft == true and pad.bMoveRight == false) then
              ball.vx = -200
            ball.vy = -200
            elseif(pad.bMoveRight == true and pad.bMoveLeft == false) then
              ball.vx = 200
              ball.vy = -200
            end
          end
        end
      end
      
      function setBallColorCollisionIndex(bPad,bBorder,bBrick)
        local index = 0
        bBorder = ball.bBorderCollision
        bPad = ball.bPadCollision
        bBrick = ball.bBrickCollision
        if(bBorder == true and bPad == false and bBrick == false) then
          index = 1 -- border ball collision
        elseif(bPad == true and bBorder == false and bBrick == false) then
          index = 2 -- pad ball collision
        elseif(bBrick == true and bPad == false and bBorder == false) then
          index = 3 -- brick ball collision
        elseif(bBrick == false and bPad == false and bBorder == false) then
          index = 4 -- game lost
        end
        return index
      end
      
      function getBallColorCollisionIndex()
        return setBallColorCollisionIndex(ball.bBorderCollision,ball.bPadCollision, ball.bBrickCollision)
      end
      
      function setBallColorBorderCollision()
        ball.bBorderCollision = true
        ball.bPadCollision = false
        ball.bBrickCollision = false
      end
      
      function setBallColorPadCollision()
        ball.bPadCollision = true
        ball.bBorderCollision = false
        ball.bBrickCollision = false
      end
      
      function setBallColorBrickCollision()
        ball.bBrickCollision = true
        ball.bPadCollision = false
        ball.bBorderCollision = false
      end
      
      function setBallColorBrickCollision()
        ball.bBrickCollision = false
        ball.bPadCollision = false
        ball.bBorderCollision = false
      end
      
      function updateBallColor(r,g,b)
        love.graphics.setColor(r,g,b)
          love.graphics.circle("fill",ball.x, ball.y,ball.radius)
      end
      
      function setBrick()
        bricks.height = (gridBricks.height)/5
        bricks.width = (gridBricks.width)/12
      end
      
      function setGridNames()
        local index = 0
        for index = 1, 10 do
          gridBricks.levels[index] = gridBricks.gridName..index
        end
      end
      
      function getGridLevelName(index)
        return gridBricks.levels[index]
      end
      
      function loadBrickGridStart()
        if(player.level == 1) then
          gridBricks.levels[player.level] = {
                             {0,0,0,0,0,1,1,0,0,0,0,0},
                             {0,0,0,0,1,1,1,1,0,0,0,0},
                             {0,0,0,1,1,0,0,1,1,0,0,0},
                             {0,0,1,1,0,0,0,0,1,1,0,0},
                             {0,1,1,0,0,0,0,0,0,1,1,0}
                            }
        end
        return gridBricks.levels[player.level]
      end
      
      function resetBrickGrid()
        if(gridBricks.bGridLevelEnd == true) then
          gridBricks.levels[player.level] = {
                             {0,0,0,0,0,0,0,0,0,0,0,0},
                             {0,0,0,0,0,0,0,0,0,0,0,0},
                             {0,0,0,0,0,0,0,0,0,0,0,0},
                             {0,0,0,0,0,0,0,0,0,0,0,0},
                             {0,0,0,0,0,0,0,0,0,0,0,0}
                            }
        end
      end
      
      function updateBrickGrid(updatedLevel)
        if(player.level ~= 1)then
          updatedLevel = player.level
          if(gridBricks.bGridLevelEnd == true) then
            gridBricks.bGridLevelEnd = false;
            gridBricks.bGridLevelStart = true;
            gridBricks.bGridLevelPlaying = false;
            if(player.level == 2)then
            gridBricks.levels[updatedLevel] = {
                            {0,0,0,1,1,0,0,1,1,0,0,0}
                            ,{1,1,0,0,1,1,1,1,0,0,1,1}
                            ,{1,0,0,0,1,1,1,1,0,0,0,1}
                            ,{1,0,0,0,0,1,1,0,0,0,0,1}
                            ,{1,1,0,0,0,0,0,0,0,0,1,1}
                            }
            elseif(player.level == 3) then
              gridBricks.levels[updatedLevel] = {
                               {1,1,1,0,0,0,0,0,0,1,1,1},
                               {0,1,1,1,0,0,0,0,1,1,1,0},
                               {0,0,1,1,1,0,0,1,1,1,0,0},
                               {0,0,0,1,1,1,1,1,1,0,0,0},
                               {0,1,0,0,1,1,1,1,0,0,1,0}
                              }
            elseif(player.level == 4) then
              gridBricks.levels[updatedLevel] = {
                                     {1,1,1,1,0,0,0,0,1,1,1,1},
                                     {0,1,1,1,1,0,0,1,1,1,1,0},
                                     {1,1,1,1,1,0,0,1,1,1,1,1},
                                     {0,0,1,1,1,1,1,1,1,1,0,0},
                                     {1,0,0,1,1,1,1,1,1,0,0,1}
                                    }
            elseif(player.level == 5) then
              gridBricks.levels[updatedLevel] = {
                                     {1,0,0,1,0,1,0,0,1,0,0,1},
                                     {1,0,0,1,0,0,1,0,1,0,0,1},
                                     {1,0,0,1,0,1,0,0,1,0,0,1},
                                     {1,0,0,1,0,0,1,0,1,0,0,1},
                                     {1,0,0,1,0,1,0,0,1,0,0,1}
                                    }
            elseif(player.level == 6) then
              gridBricks.levels[updatedLevel] = {
                                     {1,0,1,0,0,1,1,0,0,1,0,1},
                                     {0,1,0,1,0,1,1,0,1,0,1,0},
                                     {1,0,1,0,0,1,1,0,0,1,0,1},
                                     {0,1,0,1,0,1,1,0,1,0,1,0},
                                     {1,0,1,0,0,1,1,0,0,1,0,1}
                                    }
            elseif(player.level == 7) then
              gridBricks.levels[updatedLevel] = {
                                     {1,0,0,1,1,1,1,1,1,0,0,1},
                                     {0,0,1,0,1,0,0,0,0,1,0,0},
                                     {1,0,0,0,0,0,1,0,0,0,0,1},
                                     {0,0,1,0,1,0,0,1,0,1,0,0},
                                     {1,0,0,1,0,0,1,0,0,0,0,1}
                                    }
            elseif(player.level == 8) then
              gridBricks.levels[updatedLevel] = {
                                     {1,0,0,1,1,1,1,1,0,0,0,1},
                                     {0,0,0,1,0,0,0,0,1,0,0,0},
                                     {1,0,0,0,1,1,1,1,1,0,0,1},
                                     {0,0,0,1,0,0,0,0,1,0,0,0},
                                     {1,0,0,1,1,1,1,1,0,0,0,1}
                                    }
            elseif(player.level == 9) then
              gridBricks.levels[updatedLevel] = {
                                     {0,1,1,1,1,1,1,1,1,1,0,1},
                                     {1,0,0,1,0,1,0,1,0,0,0,0},
                                     {0,0,0,0,0,1,0,0,0,0,0,1},
                                     {1,0,0,1,0,1,0,1,0,1,0,0},
                                     {0,0,0,1,1,1,1,1,0,0,0,1}
                                    }
            elseif(player.level == 10) then
              gridBricks.levels[updatedLevel] = {
                                      {1,0,1,1,1,1,1,0,0,1,0,1},
                                      {0,0,1,0,0,1,1,0,0,1,0,0},
                                      {1,0,1,0,0,1,1,1,1,1,0,1},
                                      {0,0,1,0,0,1,1,0,0,1,0,0},
                                      {1,0,1,1,1,1,1,1,1,1,0,1}
                                     }
            end
          end
        end
      end
      
      function setBricksNumber()
        local l,c
        local count = 0
        local grid = {}
        grid = loadBrickGridStart()
        if(gridBricks.levels[player.level] ~= nil) then
          for l = 1, 5 do
            for c = 1, 12 do
              if(grid[l][c] == 1) then
                count = count + 1
              end
            end
          end
        end
        bricks.number = count
        hud.remainingBricks.value = count
      end
      
      function getBricksNumber()
        return hud.remainingBricks.value
      end
      
      function setSoundTracks()
        sndLoose = love.audio.newSource("sound/ball_miss_event_sound.wav", "static")
        sndBorderCollision = love.audio.newSource("sound/border_collision_sound.wav", "static")
        sndBrickBreaking = love.audio.newSource("sound/brick_breaking_sound.wav", "static")
        sndLevelComplete = love.audio.newSource("sound/level_clear_sound.wav", "static")
        sndLifeUp = love.audio.newSource("sound/life_up_sound.wav", "static")
        sndPadCollision = love.audio.newSource("sound/pad_collision_sound.wav", "static")
        
        sndLoose:setVolume(1)
        sndBorderCollision:setVolume(0.54)
        sndBrickBreaking:setVolume(0.88)
        sndLevelComplete:setVolume(0.93)
        sndLifeUp:setVolume(1)
        sndPadCollision:setVolume(1)
      end
      
      function setHUD()
        love.graphics.newFont("font/Inconsolata.ttf",36)
        
      end
      ---------------------GAME WIN CONDITION----------------
      function start()
        ball.bStackOnPad = true
        setBallColorPadCollision()
        loadBrickGridStart()
        setBricksNumber()
        gridBricks.bGridLevelStart = true
        gridBricks.bGridLevelEnd = false
        gridBricks.bGridLevelPlaying = false
        
        --to modify
        
        brickTexture = love.graphics.newImage("textures/Blue_brick.png")
        
        brickTex[1] = love.graphics.newImage("textures/Blue_brick.png")
        brickTex[2] = love.graphics.newImage("textures/Red_brick.png")
        brickTex[3] = love.graphics.newImage("textures/Green_brick.png")
        brickTex[4] = love.graphics.newImage("textures/Orange_brick.png")
        brickTex[5] = love.graphics.newImage("textures/Yellow_brick.png")
        brickTex[6] = love.graphics.newImage("textures/Pink_brick.png")
        brickTex[7] = love.graphics.newImage("textures/Lightblue_brick.png")
        brickTex[8] = love.graphics.newImage("textures/Purple_brick.png")
        brickTex[9] = love.graphics.newImage("textures/Metal_brick.png")
        brickTex[10] = love.graphics.newImage("textures/Metal_brick.png")
      end
      
      function update()
        ball.bStackOnPad = true
        setBallColorPadCollision()
        if(bricks.number == 0 and player.level ~= 10) then
          gridBricks.bGridLevelEnd = true
          gridBricks.bGridLevelPlaying = false;
          resetBrickGrid();
          gridBricks.bGridLevelStart = false
          player.level = player.level + 1
          updateBrickGrid(player.level)
          hud.level.value = player.level
          setBricksNumber()
        end
      end
      
      function BonusGame()
        if((hud.score.value >= 100 and hud.score.value <109.99)or
          (hud.score.value >= 300 and hud.score.value <309.99)or
          (hud.score.value >= 600 and hud.score.value < 609.99)or
          (hud.score.value >= 1000 and hud.score.value <1009.99)or
          (hud.score.value >= 1500 and hud.score.value < 1509.99)or
          (hud.score.value >= 2000 and hud.score.value < 2009.99)) then
          player.lives = player.lives + 1
          hud.lives.value = player.lives
        end
      end
      
      function GameLost()
        if(player.lives == 0) then
          gridBricks.bGridLevelPlaying = false
          gridBricks.bGridLevelStart = false
          gridBricks.bGridLevelEnd = true
          hud.lives.value = player.lives
          player.bLost = true
          sndLoose:play()
        else
          player.bLost = false
          gridBricks.bGridLevelPlaying = true
          gridBricks.bGridLevelStart = false
          gridBricks.bGridLevelEnd = false
        end
        return player.bLost
      end
      
      function GameWin()
        if(player.level ==10 and bricks.number == 0) then
          hud.level.value = player.level
          player.bLost = false
          gridBricks.bGridLevelPlaying = false
          gridBricks.bGridLevelStart = false
          gridBricks.bGridLevelEnd = true
        end
      end
      
      function winEnd()
        pad.vx = 0
        pad.vy = 0
        ball.vx = 0
        ball.vy = 0
        player.bLost = false
        gridBricks.bGridLevelPlaying = false
        gridBricks.bGridLevelStart = false
        gridBricks.bGridLevelEnd = true
      end
      ----------------------TIME SYSTEM ---------------------
      function sleep(n)
        os.execute("sleep " .. tonumber(n))
      end
      
      function love.load()
        screenWidth = love.graphics.getWidth()
        screenHeight = love.graphics.getHeight()
        setHUD()
        setPad()
        setBallLaunchPosition()
        setBrick()
        setSoundTracks()
        
        start()
      end
      
      function love.update(dt)
        setTimer(dt)
        setPadSpeed(dt)
        BallLaunchImpulse()
        
        ----------------COLLISION SYSTEM BEGIN-----------------
        --collision pad - borders and control mouse setting
        if pad.x<(112+pad.width/2) then
          pad.x = 112 + pad.width/2
        end
        if pad.x>(screenWidth-112-pad.width/2) then
          pad.x = screenWidth-112-pad.width/2
        end
        if ball.bStackOnPad == true then
          setBallLaunchPosition()
        else
          setBallSpeed(dt)
        end
        
        --collision ball - screen borders
        if ball.x > screenWidth - 112 then
          --play border collision sound function
          sndBorderCollision:play()
          ball.vx = -ball.vx
          
          setBallColorBorderCollision()
          setBallColorCollisionIndex(false,true,false)
          print(getBallColorCollisionIndex())
        end
        
        if ball.x <= ball.radius +112 then
          --play border collision sound function
          sndBorderCollision:play()
          ball.vx = - ball.vx
          setBallColorBorderCollision()
          setBallColorCollisionIndex(false,true,false)
          print(getBallColorCollisionIndex())
        end
        
        if ball.y <= ball.radius + 52 then
          --play border collision sound function
          sndBorderCollision:play()
          ball.vy = -ball.vy
          setBallColorBorderCollision()
          setBallColorCollisionIndex(false,true,false)
          print(getBallColorCollisionIndex())
        end
        
        if ball.y >= screenHeight then
          
          if(GameLost() == true) then
            bStart = false
            winEnd()
            print("Game Lost")
          else
            --play sound life lost
            sndLoose:play()
            setBallColorCollisionIndex(false,false,false)
            print(getBallColorCollisionIndex())
            player.lives = player.lives - 1
            player.score = player.score / 2
            hud.score.value = player.score
            hud.lives.value = player.lives
            sleep(3)
            --play start sound after time sleep of 3 seconds
            ball.bStackOnPad = true
            setBallColorPadCollision()
          end
        end
        --collision balle - pad
        if (((pad.width/2 >= math.abs(pad.x - ball.x))) and (ball.y >= (pad.y - pad.height/2 - ball.radius))) then
          ball.vy = -ball.vy
          setBallColorPadCollision()
          setBallColorCollisionIndex(true,false,false)
          print(getBallColorCollisionIndex())
          --play racket collision sound
          sndPadCollision:play()
        end
        --collision balle - brique
        local currentBricksNum = getBricksNumber()
        
        local x_offset = gridBricks.x
        local y_offset = gridBricks.y
        local detection_x = math.floor((ball.x -x_offset)/bricks.width) + 1
        local detection_y = math.floor((ball.y - y_offset)/bricks.height) + 1
        
        if(detection_y > 0 and detection_y <=#gridBricks.levels[player.level] and detection_x<=12 and detection_x >= 1) then
          if(gridBricks.levels[player.level][detection_y][detection_x] == 1) then
            gridBricks.levels[player.level][detection_y][detection_x] = 0
            ball.vy = - ball.vy
            sndBrickBreaking:play()
            setBallColorBrickCollision()
            setBallColorCollisionIndex(false, false, true)
            currentBricksNum = currentBricksNum - 1
            bricks.number = currentBricksNum
            hud.remainingBricks.value = currentBricksNum
            player.score = player.score + bricks.points
            hud.score.value = player.score
            BonusGame()
          end
        end
      -----------------FIN GESTION COLLISIONS------------------
      
      ----------------CHANGEMENT DE NIVEAU---------------------
        if bricks.number == 0 then
          update()
        end
      -----------------CONDITIONS DE VICTOIRE-----------------
      --win condition
        if(player.level ==10) then
          if(bricks.number == 0) then
            winEnd()
          end
        end
      end
      
      function love.draw()
        --set ball color
        if(getBallColorCollisionIndex() == 1) then
          updateBallColor(1,0.64,0)
        elseif(getBallColorCollisionIndex() == 2) then
          updateBallColor(0,0.5,0.5)
        elseif(getBallColorCollisionIndex() == 3) then
          updateBallColor(1,0,0)
        elseif(getBallColorCollisionIndex() == 4) then
          updateBallColor(0,1,0)
        end
        --display pad
          love.graphics.setColor(1,1,1)
          love.graphics.draw(pad.img, pad.x, pad.y,0,1,1,pad.width/2,pad.height/2)
          
          --display container - pour débogage uniquement
          --love.graphics.setColor(1,0.8,0.6,0.3)
      --love.graphics.rectangle("fill",gridBricks.x,gridBricks.y,gridBricks.width,gridBricks.height)
          --display brick for first level
          love.graphics.setColor(0.2,0.6,0.4,1)
          local line, column
          local bx_offset, by_offset = gridBricks.x, gridBricks.y
          local bx = bx_offset
          local by = by_offset
      
          for line =1,5 do
            bx = bx_offset
            for column = 1, 12 do
              if gridBricks.levels[player.level][line][column] == 1 then
                love.graphics.draw(brickTex[player.level],bx+ bx_offset/2,by+ by_offset/2 - 3,0,1,1,bricks.width - 2, bricks.width - 2)
              end
              bx = bx + bricks.width
            end
            by = by + bricks.height
          end
          
          
          --draw hud base containers
          --borders side
          love.graphics.setColor(0.3,0.3,0.3)
          love.graphics.rectangle("fill",0,52,112,548)
          love.graphics.rectangle("fill",688,52,112,548)
          --Game Title Area
          love.graphics.setColor(0.6,0,0.24)
          love.graphics.rectangle("fill",0,0,screenWidth,22)
          --Game Infos area
          love.graphics.setColor(0,0.36,0.36)
          love.graphics.rectangle("fill",0,22,screenWidth,30)
          --display text
          love.graphics.setColor(1,1,1)
          love.graphics.print(hud.lives.label,5,24)
          love.graphics.print(hud.lives.value, 42,24)
          love.graphics.print(hud.level.label,screenWidth/2,24)
          love.graphics.print(hud.level.value, (screenWidth/2)+42,24)
          love.graphics.print(hud.score.label,screenWidth-123,24)
          love.graphics.print(hud.score.value, screenWidth - 82,24)
          --display bricks
          love.graphics.setColor(1,1,1)
          love.graphics.print(hud.remainingBricks.label, 18, 250)
          love.graphics.print(hud.remainingBricks.value, 63,250)
          --display game title
          love.graphics.setColor(1,0.647,0)
          love.graphics.print(hud.title, screenWidth/2-20, 5)
          --display loose message
          local alphaLoose = 0
          if(hud.lives.value == 0) then
            alphaLoose = 1
            love.graphics.setColor(0,0.5,1,alphaLoose)
            love.graphics.print(hud.looseMsg, screenWidth/2, screenHeight/2)
          else
            alphaLoose = 0
            love.graphics.setColor(0,0.5,1,alphaLoose)
            love.graphics.print(hud.looseMsg, screenWidth/2, screenHeight/2)
          end
          --display win message
          local alphaWin = 0
          if(hud.remainingBricks.value == 0)then
            alphaWin = 1
            love.graphics.setColor(1,1,0,alphaWin)
            love.graphics.print(hud.winMsg, screenWidth/2,screenHeight/3)
          else
            alphaWin = 0
            love.graphics.setColor(1,1,0,alphaWin)
            love.graphics.print(hud.winMsg, screenWidth/2,screenHeight/3)
          end
      
      end
      
      function love.keypressed()
        
        if(player.bLost == false) then
          if love.keyboard.isDown('r') then
            start()
          end
        end
      end
Vous lisez 0 fil de discussion
  • Vous devez être connecté pour répondre à ce sujet.