moveObjects :: GameWorld -> GameWorld
moveObjects world = world { player1 = newPlayer1 , player2 = newPlayer2
                          , lasersPlayer1 = newLasersPlayer1, lasersPlayer2 = newLasersPlayer2 , asteroids=newAsteroids
                          , player1Lives=newPlayer1Lives, player2Lives=newPlayer2Lives
                          , pointsPlayer1 = newPointsPlayer1, pointsPlayer2 = newPointsPlayer2
                          , player1Cooldown=newPlayer1Cooldown, player2Cooldown=newPlayer2Cooldown }
            where
                step = 1.5

                (player1X,player1Y) = getGameObjectCoordinates (player1 world)
                (player2X,player2Y) = getGameObjectCoordinates (player2 world)

                dx1 = if ((player1Left world) && (not $ player1X - 40 < -500)) then -step 
                      else if ((player1Right world) && (not $ player1X + 40 > 500)) then step              
                      else 0.0

                dx2 = if ((player2Left world) && (not $ player2X - 40 < -500)) then  - step
                      else if ((player2Right world) && (not $ player2X + 40 > 500)) then step  
                      else 0.0             
                      
                dy1 = if ((player1Up world) && (not $ player1Y + 40 > 350)) then step
                      else if ((player1Down world) && (not $ player1Y - 40 < -350)) then -step              
                      else 0.0

                dy2 = if ((player2Up world) && (not $ player2Y + 40 > 350)) then step
                      else if ((player2Down world) && (not $ player2Y - 40 < -350)) then -step              
                      else 0.0


                p1Cooldown=(player1Cooldown world)
                p1Lives = (player1Lives world)
                (newPlayer1Lives,newPlayer1Cooldown) = 
                  if((length p1Lives)>0 && (playerAsteroidCollision (player1 world) (asteroids world)) && (p1Cooldown==0)) 
                    then ((init p1Lives),600) 
                  else (p1Lives,updatePlayerCooldown p1Cooldown)
                
                p2Cooldown=(player2Cooldown world)
                p2Lives = (player2Lives world)
                (newPlayer2Lives,newPlayer2Cooldown) = 
                  if((length p2Lives)>0 && (playerAsteroidCollision (player2 world) (asteroids world)) && (p2Cooldown==0)) 
                    then ((init p2Lives),600) 
                  else (p2Lives,updatePlayerCooldown p2Cooldown)
   
                p1 =  moveGameObject (player1 world) dx1 dy1                                
                p2 =  moveGameObject (player2 world) dx2 dy2

                newPlayer1 = if (dx1 > 0 || (player1Right world)) then changeGameObjectImage p1 player1RightImg
                             else if (dx1 < 0 || (player1Left world)) then changeGameObjectImage p1 player1LeftImg
                             else changeGameObjectImage p1 player1BasicImg

                newPlayer2 = if (dx2 > 0 || (player2Right world)) then changeGameObjectImage p2 player2RightImg
                             else if (dx2 < 0 || (player2Left world)) then changeGameObjectImage p2 player2LeftImg
                             else changeGameObjectImage p2 player2BasicImg
                
                astep = 2.0

                movedLasersPlayer1 = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x 0 1.6) (lasersPlayer1 world)
                movedLasersPlayer2 = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x 0 1.6) (lasersPlayer2 world)
                movedAsteroids = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x (-1 * astep) (-0.7 * astep)) (asteroids world)

                (newLasersPlayer1, survivedAsteroids) =   laserAsteroidCollision (movedLasersPlayer1, movedAsteroids)
                newPointsPlayer1 = (pointsPlayer1 world) + if (asteroiDifference) < 0 then asteroiDifference + 4
                                                           else asteroiDifference
                                                           where asteroiDifference = length movedAsteroids - length survivedAsteroids


                (newLasersPlayer2, newAsteroids) = laserAsteroidCollision (movedLasersPlayer2, survivedAsteroids)
                newPointsPlayer2 = (pointsPlayer2 world) + if (asteroiDifference) < 0 then asteroiDifference + 4
                                                           else asteroiDifference
                                                           where asteroiDifference = length survivedAsteroids - length newAsteroids
moveObjects :: GameWorld -> GameWorld
moveObjects world = world { player1 = newPlayer1 , player2 = newPlayer2
                          , lasersPlayer1 = newLasersPlayer1, lasersPlayer2 = newLasersPlayer2 , asteroids=newAsteroids
                          , player1Lives=newPlayer1Lives, player2Lives=newPlayer2Lives
                          , pointsPlayer1 = newPointsPlayer1, pointsPlayer2 = newPointsPlayer2
                          , player1Cooldown=newPlayer1Cooldown, player2Cooldown=newPlayer2Cooldown }
            where
                step = 1.5

                (player1X,player1Y) = getGameObjectCoordinates (player1 world)
                (player2X,player2Y) = getGameObjectCoordinates (player2 world)

                dx1 = if ((player1Left world) && (not $ player1X - 40 < -500)) then -step 
                      else if ((player1Right world) && (not $ player1X + 40 > 500)) then step              
                      else 0.0

                dx2 = if ((player2Left world) && (not $ player2X - 40 < -500)) then  - step
                      else if ((player2Right world) && (not $ player2X + 40 > 500)) then step  
                      else 0.0             
                      
                dy1 = if ((player1Up world) && (not $ player1Y + 40 > 350)) then step
                      else if ((player1Down world) && (not $ player1Y - 40 < -350)) then -step              
                      else 0.0

                dy2 = if ((player2Up world) && (not $ player2Y + 40 > 350)) then step
                      else if ((player2Down world) && (not $ player2Y - 40 < -350)) then -step              
                      else 0.0


                p1Cooldown=(player1Cooldown world)
                p1Lives = (player1Lives world)
                (newPlayer1Lives,newPlayer1Cooldown) = 
                  if((length p1Lives)>0 && (playerAsteroidCollision (player1 world) (asteroids world)) && (p1Cooldown==0)) 
                    then ((init p1Lives),600) 
                  else (p1Lives,updatePlayerCooldown p1Cooldown)
                
                p2Cooldown=(player2Cooldown world)
                p2Lives = (player2Lives world)
                (newPlayer2Lives,newPlayer2Cooldown) = 
                  if((length p2Lives)>0 && (playerAsteroidCollision (player2 world) (asteroids world)) && (p2Cooldown==0)) 
                    then ((init p2Lives),600) 
                  else (p2Lives,updatePlayerCooldown p2Cooldown)
   
                p1 =  moveGameObject (player1 world) dx1 dy1                                
                p2 =  moveGameObject (player2 world) dx2 dy2

                newPlayer1 = if (dx1 > 0 || (player1Right world)) then changeGameObjectImage p1 player1RightImg
                             else if (dx1 < 0 || (player1Left world)) then changeGameObjectImage p1 player1LeftImg
                             else changeGameObjectImage p1 player1BasicImg

                newPlayer2 = if (dx2 > 0 || (player2Right world)) then changeGameObjectImage p2 player2RightImg
                             else if (dx2 < 0 || (player2Left world)) then changeGameObjectImage p2 player2LeftImg
                             else changeGameObjectImage p2 player2BasicImg
                
                astep = 2.0

                movedLasersPlayer1 = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x 0 1.6) (lasersPlayer1 world)
                movedLasersPlayer2 = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x 0 1.6) (lasersPlayer2 world)
                movedAsteroids = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x (-1 * astep) (-0.7 * astep)) (asteroids world)

                (newLasersPlayer1, survivedAsteroids) =   laserAsteroidCollision (movedLasersPlayer1, movedAsteroids)
                newPointsPlayer1 = (pointsPlayer1 world) + if (asteroiDifference) < 0 then asteroiDifference + 4
                                                           else asteroiDifference
                                                           where asteroiDifference = length movedAsteroids - length survivedAsteroids


                (newLasersPlayer2, newAsteroids) = laserAsteroidCollision (movedLasersPlayer2, survivedAsteroids)
                newPointsPlayer2 = (pointsPlayer2 world) + if (asteroiDifference) < 0 then asteroiDifference + 4
                                                           else asteroiDifference
                                                           where asteroiDifference = length survivedAsteroids - length newAsteroids
moveObjects world = world { player1 = newPlayer1 , player2 = newPlayer2
                          , lasersPlayer1 = newLasersPlayer1, lasersPlayer2 = newLasersPlayer2 , asteroids=newAsteroids
                          , player1Lives=newPlayer1Lives, player2Lives=newPlayer2Lives
                          , pointsPlayer1 = newPointsPlayer1, pointsPlayer2 = newPointsPlayer2
                          , player1Cooldown=newPlayer1Cooldown, player2Cooldown=newPlayer2Cooldown }
            where
                step = 1.5

                (player1X,player1Y) = getGameObjectCoordinates (player1 world)
                (player2X,player2Y) = getGameObjectCoordinates (player2 world)

                dx1 = if ((player1Left world) && (not $ player1X - 40 < -500)) then -step 
                      else if ((player1Right world) && (not $ player1X + 40 > 500)) then step              
                      else 0.0

                dx2 = if ((player2Left world) && (not $ player2X - 40 < -500)) then  - step
                      else if ((player2Right world) && (not $ player2X + 40 > 500)) then step  
                      else 0.0             
                      
                dy1 = if ((player1Up world) && (not $ player1Y + 40 > 350)) then step
                      else if ((player1Down world) && (not $ player1Y - 40 < -350)) then -step              
                      else 0.0

                dy2 = if ((player2Up world) && (not $ player2Y + 40 > 350)) then step
                      else if ((player2Down world) && (not $ player2Y - 40 < -350)) then -step              
                      else 0.0


                p1Cooldown=(player1Cooldown world)
                p1Lives = (player1Lives world)
                (newPlayer1Lives,newPlayer1Cooldown) = 
                  if((length p1Lives)>0 && (playerAsteroidCollision (player1 world) (asteroids world)) && (p1Cooldown==0)) 
                    then ((init p1Lives),600) 
                  else (p1Lives,updatePlayerCooldown p1Cooldown)
                
                p2Cooldown=(player2Cooldown world)
                p2Lives = (player2Lives world)
                (newPlayer2Lives,newPlayer2Cooldown) = 
                  if((length p2Lives)>0 && (playerAsteroidCollision (player2 world) (asteroids world)) && (p2Cooldown==0)) 
                    then ((init p2Lives),600) 
                  else (p2Lives,updatePlayerCooldown p2Cooldown)
   
                p1 =  moveGameObject (player1 world) dx1 dy1                                
                p2 =  moveGameObject (player2 world) dx2 dy2

                newPlayer1 = if (dx1 > 0 || (player1Right world)) then changeGameObjectImage p1 player1RightImg
                             else if (dx1 < 0 || (player1Left world)) then changeGameObjectImage p1 player1LeftImg
                             else changeGameObjectImage p1 player1BasicImg

                newPlayer2 = if (dx2 > 0 || (player2Right world)) then changeGameObjectImage p2 player2RightImg
                             else if (dx2 < 0 || (player2Left world)) then changeGameObjectImage p2 player2LeftImg
                             else changeGameObjectImage p2 player2BasicImg
                
                astep = 2.0

                movedLasersPlayer1 = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x 0 1.6) (lasersPlayer1 world)
                movedLasersPlayer2 = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x 0 1.6) (lasersPlayer2 world)
                movedAsteroids = laserOrAsteroidOutOfBound $ map (\x -> moveGameObject x (-1 * astep) (-0.7 * astep)) (asteroids world)

                (newLasersPlayer1, survivedAsteroids) =   laserAsteroidCollision (movedLasersPlayer1, movedAsteroids)
                newPointsPlayer1 = (pointsPlayer1 world) + if (asteroiDifference) < 0 then asteroiDifference + 4
                                                           else asteroiDifference
                                                           where asteroiDifference = length movedAsteroids - length survivedAsteroids


                (newLasersPlayer2, newAsteroids) = laserAsteroidCollision (movedLasersPlayer2, survivedAsteroids)
                newPointsPlayer2 = (pointsPlayer2 world) + if (asteroiDifference) < 0 then asteroiDifference + 4
                                                           else asteroiDifference
                                                           where asteroiDifference = length survivedAsteroids - length newAsteroids