Advertisement
Guest User

Untitled

a guest
Jan 13th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. # FONTCION DE BASE
  2.  
  3.  
  4. from paddle import Paddle #import de la classe Paddle
  5. from paddle import Paddle #import de la classe Paddle
  6. from ball import Ball
  7. from Brick import Brick
  8.  
  9. playingGame = False
  10. bricks = [] # création de la liste
  11. img = loadImage("back.png")
  12.  
  13. def setup():
  14. global paddle, ball, img # on déclare les variables paddle et ball comme globale
  15. size(600,400)
  16. img=loadImage("back.png")
  17. image(img,0,0)
  18. paddle = Paddle() # on crée l'objet paddle
  19. ball = Ball()
  20. # appel de la fonction addBrick pour ajouter les briques
  21. for x in range(5, width - 80, 75):
  22. addBrick(x + 37.5, 50, 3)
  23. addBrick(x + 37.5, 70, 2)
  24. addBrick(x + 37.5, 90, 1)
  25. addBrick(x + 37.5, 110, 2)
  26.  
  27. def draw():
  28. global playingGame
  29. background(0,0,0)
  30. image(img,0,0) # on affiche l'image
  31. #appel des méthodes pour le paddle
  32. paddle.display()
  33. if playingGame:
  34. paddle.checkEdges()
  35. paddle.update()
  36. #appel des méthodes pour la ball
  37. ball.display()
  38. if playingGame:
  39. ball.checkEdges()
  40. ball.update()
  41. if (ball.meets(paddle)):
  42. if (ball.dir.y > 0):
  43. ball.dir.y *= -1
  44. for i in range(len(bricks)):
  45. bricks[i].display()
  46. for i in range(len(bricks)-1,-1,-1):
  47. if (ball.meets(bricks[i])):
  48. bricks.pop(i)
  49. #del bricks[i]
  50. ball.dir.y*=-1
  51. if ball.pos.y>height-ball.r:
  52. playingGame=False
  53. background(0,0,0)
  54. fill(255)
  55. textSize(50)
  56. text("GAME OVER",160,220,500)
  57. if len(bircks)==0 :
  58. playing
  59.  
  60.  
  61. # détection des mouvements touches a et d
  62. def keyPressed():
  63. if key == "q" or key == "Q":
  64. paddle.isMovingLeft = True
  65. elif key == "d" or key == "D":
  66. paddle.isMovingRight = True
  67.  
  68. #annulation des mouvements quand on relâche la touche
  69. def keyReleased():
  70. paddle.isMovingRight = False
  71. paddle.isMovingLeft = False
  72.  
  73. def mousePressed():
  74. global playingGame
  75. playingGame = True
  76.  
  77. def addBrick(x, y, hits):
  78. brick = Brick(x, y, hits)
  79. bricks.append(brick)
  80.  
  81. def meets(self,brick):
  82. if (self.pos.y < brick.pos.y + brick.h and
  83. self.pos.y > brick.pos.y - self.r and
  84. self.pos.x > brick.pos.x - self.r and
  85. self.pos.x < brick.pos.x+ brick.w + self.r):
  86. return True
  87. else:
  88. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement