diff --git a/Balle.py b/Balle.py index 744bc7308967b6d81950f2f20feb0783add3e6e0..c7ac147026bbbc33e0d1e3a3125c4899a10f1dd9 100644 --- a/Balle.py +++ b/Balle.py @@ -5,7 +5,7 @@ import os class Balle(pg.sprite.Sprite): - def __init__(self,x,y,barre,tiles): + def __init__(self,x,y,barre,tiles,orientation = pg.math.Vector2(0,-1),launched=False): super().__init__() self.screen = pg.display.get_surface() @@ -25,14 +25,13 @@ class Balle(pg.sprite.Sprite): self.compteur = 0 self.speed = 4 - self.launched = False + self.launched = launched def getSpeed(self): return self.speed - - + def launch(self): self.launched = True @@ -170,6 +169,9 @@ class Balle(pg.sprite.Sprite): self.speed = 4 + def isOffScreen(self): + return self.rect.y > DISPLAY_HEIGHT + def collision(self, tiles,direction): diff --git a/Barre.py b/Barre.py index 2e6723f1ededfe2b7ab24df596dd0e0f313cd97a..c6c764a83c08a9d316cf2416df46c8c535f59cba 100644 --- a/Barre.py +++ b/Barre.py @@ -100,9 +100,15 @@ class Barre(pg.sprite.Sprite): def receiveSignal(self,signal): if signal == 1: - self.sprites = self.expanded_sprites + if self.sprites == self.short_sprites: + self.sprites = self.normal_player_sprites + else: + self.sprites = self.expanded_sprites elif signal == 2: - self.sprites = self.short_sprites + if self.sprites == self.expanded_sprites: + self.sprites = self.normal_player_sprites + else: + self.sprites = self.short_sprites self.rect = self.sprites[0].get_rect(topleft = (self.rect.left,self.rect.top)) diff --git a/GamePhase.py b/GamePhase.py index 708ad0f8eeb9c67a43fc0fc09f1f740a40be3379..abab44188d21a09200d8fc4de1305143f1515383 100644 --- a/GamePhase.py +++ b/GamePhase.py @@ -28,6 +28,9 @@ class GamePhase: self._barre = Barre(self.display_width//2 - 60,self.display_height - 40) self._ball = Balle(self._barre.rect.x + self._barre.width//2 - 7,self.display_height - TILE_WIDTH - 4,self._barre,self._tiles) + + self._balls = [self._ball] + self._has_started = False self._score = 0 @@ -96,44 +99,61 @@ class GamePhase: collision_happened = False if self._has_started: - collision_happened_hor, hit_hor = self._ball.move("horizontal") - collision_happened_ver, hit_ver = self._ball.move("vertical") - - collision_happened = collision_happened_hor or collision_happened_ver - - if hit_hor : - if hit_hor.getLife() <= 0: - self._tiles.remove(hit_hor) - self._score += hit_hor.getType() + for ball in self._balls: + collision_happened_hor, hit_hor = ball.move("horizontal") + collision_happened_ver, hit_ver = ball.move("vertical") - if random.random() > 0.5: - self.spawnItemAtLocation(*hit_hor.getPosition()) - + collision_happened = collision_happened_hor or collision_happened_ver - elif hit_ver: - if hit_ver.getLife() <= 0: - self._tiles.remove(hit_ver) - self._score += hit_ver.getType() + if hit_hor : + if hit_hor.getLife() <= 0: + self._tiles.remove(hit_hor) + self._score += hit_hor.getType() + + if random.random() > 0.5: + self.spawnItemAtLocation(*hit_hor.getPosition()) + - if random.random() > 0.5: - self.spawnItemAtLocation(*hit_ver.getPosition()) + elif hit_ver: + if hit_ver.getLife() <= 0: + self._tiles.remove(hit_ver) + self._score += hit_ver.getType() + + if random.random() > 0.5: + self.spawnItemAtLocation(*hit_ver.getPosition()) - if collision_happened: - self.spawnParticlesAtBallLocation() - + if collision_happened: + self.spawnParticlesAtBallLocation() + for i in range(len(self._items)-1,-1,-1): if self._barre.isInCollisionWith(self._items[i]): self._barre.receiveSignal(self._items[i].getType()) + + if (self._items[i].getType() == 3): + orientation = pygame.math.Vector2(random.random(),random.random()) + orientation = pygame.math.Vector2.normalize(orientation) + print(orientation) + self._balls.append(Balle(self._balls[0].rect.x,self._balls[0].rect.y,self._barre,self._tiles,orientation,True)) + + orientation = pygame.math.Vector2(random.random(),random.random()) + print(orientation) + orientation = pygame.math.Vector2.normalize(orientation) + self._balls.append(Balle(self._balls[0].rect.x,self._balls[0].rect.y,self._barre,self._tiles,orientation,True)) + self._items.remove(self._items[i]) + + for ball in self._balls[::-1]: + if ball.isOffScreen(): + self._balls.remove(ball) else: - self._ball.rect.x = self._barre.rect.x + self._barre.rect.w // 2 - self._ball.rect.w // 2 + self._balls[0].rect.x = self._barre.rect.x + self._barre.rect.w // 2 - self._balls[0].rect.w // 2 self.updateEntities() def spawnItemAtLocation(self,x,y): - type = random.randint(1,2) + type = random.randint(1,3) self._items.append(Item(type,x,y)) @@ -142,7 +162,7 @@ class GamePhase: self._particle_array.append(Particle(2,*self._ball.get_pos())) def hasLost(self): - return self._ball.get_pos()[1] >= self.display_height + return len(self._balls) == 0 def loadLoseScreenAndExit(self): @@ -168,7 +188,10 @@ class GamePhase: def updateEntities(self): - self._ball.update() + + for ball in self._balls: + ball.update() + self._barre.update() for i in range(len(self._particle_array)-1,-1,-1): @@ -193,7 +216,9 @@ class GamePhase: tile.draw() - self._ball.draw() + for ball in self._balls: + ball.draw() + self._barre.draw() for particle in self._particle_array: diff --git a/LevelLoader.py b/LevelLoader.py index 0544d58a0535078ec2e652ecb0f010965ef6d4fb..249599167572fda0471218e8cb7a92038b34e375 100644 --- a/LevelLoader.py +++ b/LevelLoader.py @@ -65,7 +65,9 @@ class LevelLoader(State): def render(self): - self.game.draw_text(f"Score:{self.actualScore}",(DISPLAY_WIDTH-TILE_HEIGHT,DISPLAY_HEIGHT//2 - 50),(255,255,255),rot=90) + if self.actualScene != None: self.actualScene.render() + + self.game.draw_text(f"Score:{self.actualScore}",(DISPLAY_WIDTH-TILE_HEIGHT,DISPLAY_HEIGHT//2 - 50),(255,255,255),rot=90) \ No newline at end of file diff --git a/LevelSelectionState.py b/LevelSelectionState.py deleted file mode 100644 index 229b47d36e69b1905da48c6bcc4ba782531b6e91..0000000000000000000000000000000000000000 --- a/LevelSelectionState.py +++ /dev/null @@ -1,61 +0,0 @@ -import pygame -from State import State -import os -import platform -from constantes import * -from LevelLoader import LevelLoader -from Button import Button - -class LevelSelectionState(State): - - def __init__(self,game): - super().__init__(game) - level_filenames = [x[0].split() for x in os.walk("Levels")] - - self.levels = [] - - if platform.system() == "Linux" or platform.system() == "Darwin": - self.levels = [x[0].split("/")[1] for x in level_filenames[1:]] - elif platform.system() == "Windows": - self.levels = [x[0].split("\\")[1] for x in level_filenames[1:]] - self.selected = -1 - self.scene_index = 0 - - self.return_button = Button((0,DISPLAY_HEIGHT-40),"retour.png") - - def update(self,key_state): - if len(self.levels) == 0: - self.game.popStateStack() - - if key_state["left_click"][0] == True: - x,y = key_state["left_click"][1] - - selected = None - for i,level in enumerate(self.levels): - offset = len(level) * FONT_SIZE//2 - if x >= DISPLAY_WIDTH // 2 - offset and x <= DISPLAY_WIDTH//2 + offset: - if y >= i * TILE_HEIGHT and y <= (i+1) * TILE_HEIGHT: - selected = level - - if selected : - levelLoader = LevelLoader(self.game,selected) - - levelLoader.enter_stack() - - if self.return_button.rect.collidepoint((x,y)): - self.game.popStateStack() - - - - def render(self): - for i,level in enumerate(self.levels): - color = (255,0,0) - mouse_pos = pygame.mouse.get_pos() - offset = len(level)*FONT_SIZE//2 - if mouse_pos[0] >= DISPLAY_WIDTH//2 - offset and mouse_pos[0] <= DISPLAY_WIDTH // 2 + offset: - if mouse_pos[1] >= i * TILE_HEIGHT and mouse_pos[1] <= (i+1)* TILE_HEIGHT: - color = (0,0,0) - self.game.draw_text(level,(DISPLAY_WIDTH//2-offset,i*TILE_HEIGHT),color,True) - - self.return_button.render() - \ No newline at end of file diff --git a/Levels/Test/Test_1.pickle b/Levels/Test/Test_1.pickle new file mode 100644 index 0000000000000000000000000000000000000000..3658301fa0e28e5864b8cc81429bcdfd2885f7cd Binary files /dev/null and b/Levels/Test/Test_1.pickle differ diff --git a/Levels/Test/Test_2.pickle b/Levels/Test/Test_2.pickle new file mode 100644 index 0000000000000000000000000000000000000000..69eaef0b89f5d9240644ca51c31c4242a9ccf226 Binary files /dev/null and b/Levels/Test/Test_2.pickle differ diff --git a/Levels/Test/Test_3.pickle b/Levels/Test/Test_3.pickle new file mode 100644 index 0000000000000000000000000000000000000000..1cbb88d14f4d2c1f1f6d6917f29534814b6f4fbe Binary files /dev/null and b/Levels/Test/Test_3.pickle differ diff --git a/WayOfEditingState.py b/WayOfEditingState.py deleted file mode 100644 index 3c488a2f8fe480f9c7d356fad2426950ba0200e0..0000000000000000000000000000000000000000 --- a/WayOfEditingState.py +++ /dev/null @@ -1,38 +0,0 @@ -import pygame -from constantes import * -from State import State -from Button import Button -from LevelNamingState import LevelNamingState -from LevelSelectionToEditState import LevelSelectionToEditState - -class WayOfEditingState(State): - - def __init__(self, game): - super().__init__(game) - - self.return_button = Button((0,DISPLAY_HEIGHT-40),"retour.png") - self.nouveau_button = Button((DISPLAY_WIDTH//2-50,100),"nouveau.png") - self.reediter_button = Button((DISPLAY_WIDTH//2-50,225),"reediter.png") - - def update(self, key_state): - if key_state["quit"][0] == True: - self.game.popStateStack() - - elif key_state["left_click"][0] == True: - mouse_click = key_state["left_click"][1] - - if self.return_button.rect.collidepoint(mouse_click): - self.game.popStateStack() - - if self.nouveau_button.rect.collidepoint(mouse_click): - levelNaming = LevelNamingState(self.game) - levelNaming.enter_stack() - - if self.reediter_button.rect.collidepoint(mouse_click): - levelreed = LevelSelectionToEditState(self.game) - levelreed.enter_stack() - - def render(self): - self.return_button.render() - self.nouveau_button.render() - self.reediter_button.render() \ No newline at end of file diff --git a/__pycache__/Balle.cpython-38.pyc b/__pycache__/Balle.cpython-38.pyc index ec1085149dda1f31870c2fc8e32146b1864f24c1..54d1cf28b8bc3773cbea0cc02911d08274fd1f70 100644 Binary files a/__pycache__/Balle.cpython-38.pyc and b/__pycache__/Balle.cpython-38.pyc differ diff --git a/__pycache__/Barre.cpython-38.pyc b/__pycache__/Barre.cpython-38.pyc index 00d7449c11d1fc9d3a97188e111b011498c0f24c..ff344ea00be792b5a149f4df2da338088d31e100 100644 Binary files a/__pycache__/Barre.cpython-38.pyc and b/__pycache__/Barre.cpython-38.pyc differ diff --git a/__pycache__/GamePhase.cpython-38.pyc b/__pycache__/GamePhase.cpython-38.pyc index ce8a84c9e14a6813c939d34fc11e2d9acf2d580e..d9f3a9c388f303893e90c7f24c8d6b4fa5a16794 100644 Binary files a/__pycache__/GamePhase.cpython-38.pyc and b/__pycache__/GamePhase.cpython-38.pyc differ diff --git a/__pycache__/LevelLoader.cpython-38.pyc b/__pycache__/LevelLoader.cpython-38.pyc index bafe34eaed42ca0af3ff26c7856c5f25d0a22d74..601c605502da23c9f3572305dbd84181c43c6f60 100644 Binary files a/__pycache__/LevelLoader.cpython-38.pyc and b/__pycache__/LevelLoader.cpython-38.pyc differ diff --git a/__pycache__/constantes.cpython-38.pyc b/__pycache__/constantes.cpython-38.pyc index 4dd146760041743455c0e1a793c0618323a62652..a8080b280a1ac21039f83c68575e39acb525833f 100644 Binary files a/__pycache__/constantes.cpython-38.pyc and b/__pycache__/constantes.cpython-38.pyc differ diff --git a/assets/Items/laser.png b/assets/Items/laser.png new file mode 100644 index 0000000000000000000000000000000000000000..09e916f79155505983642f6abcb4855810a71a9e Binary files /dev/null and b/assets/Items/laser.png differ diff --git a/assets/Items/multipleBalls.png b/assets/Items/multipleBalls.png new file mode 100644 index 0000000000000000000000000000000000000000..27896b9262d63d0c933287b838210b001ab19e24 Binary files /dev/null and b/assets/Items/multipleBalls.png differ diff --git a/constantes.py b/constantes.py index d2e62b2ef5590616eba3a21eaf3cc3565561b5d4..cde87947fb54284fc63065583b54eead97c6fb08 100644 --- a/constantes.py +++ b/constantes.py @@ -54,4 +54,4 @@ SCENE_VICTORY = 1 SCENE_PAUSE = 4 -ITEM_SPRITES = {1:"expand.png",2:"shrink.png"} \ No newline at end of file +ITEM_SPRITES = {1:"expand.png",2:"shrink.png",3:"multipleBalls.png",4:"laser.png"} \ No newline at end of file