From 273b8f45ffdc7cacfc814c849f414e2d9ca0e6ae Mon Sep 17 00:00:00 2001 From: Zentae <42480921+Zentae@users.noreply.github.com> Date: Fri, 2 Dec 2022 11:35:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20refactor=20=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.py | 8 +++++++- main.py | 6 ------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/game.py b/game.py index 40031cd..8348890 100644 --- a/game.py +++ b/game.py @@ -1,11 +1,14 @@ import pygame import sys -from event_listener import EventListener from player import Player from element import Element from window import Window +from event_listener import EventListener +from drag_event_listener import DragEventListener +from ball_release_event_listener import BallReleaseEventListener + class Game(): def __init__(self, screen:pygame.Surface, img_location:str, sound_location:str) -> None: # get the actual display screen. @@ -38,6 +41,9 @@ def __init__(self, screen:pygame.Surface, img_location:str, sound_location:str) self.__window.register_element("ball", Element(ball, 200, 400)) # register the placeholder ball. self.__window.register_element("placeholder_ball", Element(placeholder_ball, 200, 400)) + # listen to events. + self.listen(pygame.MOUSEMOTION, DragEventListener()) + self.listen(pygame.MOUSEBUTTONUP, BallReleaseEventListener()) def get_window(self) -> Window: """ :return: the game's window. diff --git a/main.py b/main.py index 1b0951f..4665246 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,5 @@ import pygame - from game import Game -from drag_event_listener import DragEventListener -from ball_release_event_listener import BallReleaseEventListener # init pygame. pygame.init() @@ -16,9 +13,6 @@ screen = pygame.display.set_mode((1024,640)) # create a new instance of the Game. game = Game(screen, "img/", None) -# listen to events. -game.listen(pygame.MOUSEMOTION, DragEventListener()) -game.listen(pygame.MOUSEBUTTONUP, BallReleaseEventListener()) # register dummy player. game.register_player("Yanis") # setup the game. From c7e14dac38c30fd604d342059b9d4aeaccb445f5 Mon Sep 17 00:00:00 2001 From: Zentae <42480921+Zentae@users.noreply.github.com> Date: Fri, 2 Dec 2022 11:38:13 +0100 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20refactor=20=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ball_release_event_listener.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ball_release_event_listener.py b/ball_release_event_listener.py index 12313d3..f66a165 100644 --- a/ball_release_event_listener.py +++ b/ball_release_event_listener.py @@ -2,7 +2,7 @@ from game import Game from stoppable_thread import StoppableThread from vector import Vector -from math import (ceil, atan, pi, cos, sin) +from math import (ceil, atan, cos, sin) import pygame class BallReleaseEventListener(EventListener):