Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # FONTCION DE BASE
- from paddle import Paddle #import de la classe Paddle
- from paddle import Paddle #import de la classe Paddle
- from ball import Ball
- from Brick import Brick
- playingGame = False
- bricks = [] # création de la liste
- img = loadImage("back.png")
- def setup():
- global paddle, ball, img # on déclare les variables paddle et ball comme globale
- size(600,400)
- img=loadImage("back.png")
- image(img,0,0)
- paddle = Paddle() # on crée l'objet paddle
- ball = Ball()
- # appel de la fonction addBrick pour ajouter les briques
- for x in range(5, width - 80, 75):
- addBrick(x + 37.5, 50, 3)
- addBrick(x + 37.5, 70, 2)
- addBrick(x + 37.5, 90, 1)
- addBrick(x + 37.5, 110, 2)
- def draw():
- global playingGame
- background(0,0,0)
- image(img,0,0) # on affiche l'image
- #appel des méthodes pour le paddle
- paddle.display()
- if playingGame:
- paddle.checkEdges()
- paddle.update()
- #appel des méthodes pour la ball
- ball.display()
- if playingGame:
- ball.checkEdges()
- ball.update()
- if (ball.meets(paddle)):
- if (ball.dir.y > 0):
- ball.dir.y *= -1
- for i in range(len(bricks)):
- bricks[i].display()
- for i in range(len(bricks)-1,-1,-1):
- if (ball.meets(bricks[i])):
- bricks.pop(i)
- #del bricks[i]
- ball.dir.y*=-1
- if ball.pos.y>height-ball.r:
- playingGame=False
- background(0,0,0)
- fill(255)
- textSize(50)
- text("GAME OVER",160,220,500)
- if len(bircks)==0 :
- playing
- # détection des mouvements touches a et d
- def keyPressed():
- if key == "q" or key == "Q":
- paddle.isMovingLeft = True
- elif key == "d" or key == "D":
- paddle.isMovingRight = True
- #annulation des mouvements quand on relâche la touche
- def keyReleased():
- paddle.isMovingRight = False
- paddle.isMovingLeft = False
- def mousePressed():
- global playingGame
- playingGame = True
- def addBrick(x, y, hits):
- brick = Brick(x, y, hits)
- bricks.append(brick)
- def meets(self,brick):
- if (self.pos.y < brick.pos.y + brick.h and
- self.pos.y > brick.pos.y - self.r and
- self.pos.x > brick.pos.x - self.r and
- self.pos.x < brick.pos.x+ brick.w + self.r):
- return True
- else:
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement