diff --git a/data/models/fruit_1_1_scaled.svg b/data/models/fruit_1_1_scaled.svg index b0309c1..4a48ec5 100644 --- a/data/models/fruit_1_1_scaled.svg +++ b/data/models/fruit_1_1_scaled.svg @@ -8,7 +8,7 @@ version="1.1" id="svg1" xml:space="preserve" - inkscape:version="1.3.2 (091e20ef0f, 2023-11-25, custom)" + inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)" sodipodi:docname="fruit_1_1_scaled.svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" @@ -25,12 +25,12 @@ inkscape:deskcolor="#d1d1d1" inkscape:document-units="mm" inkscape:zoom="0.53718434" - inkscape:cx="782.78529" - inkscape:cy="191.74051" - inkscape:window-width="2560" - inkscape:window-height="1356" - inkscape:window-x="2560" - inkscape:window-y="0" + inkscape:cx="781.85451" + inkscape:cy="190.80973" + inkscape:window-width="1920" + inkscape:window-height="1009" + inkscape:window-x="-8" + inkscape:window-y="-8" inkscape:window-maximized="1" inkscape:current-layer="layer1" /> None: + def __init__(self, name: str, surface: pygame.Surface, surface_size: tuple, init_pos_x, init_pos_y, visibility: bool = True, rect_size:int = 10, color:tuple = (0,0,0), score_points = 0, sprite=str()) -> None: super().__init__(name, surface, surface_size, init_pos_x, init_pos_y, visibility) self.__score_points = score_points self.__rect:pygame.Rect self.__rect_size = rect_size self.__color = color + self.__image = pygame.image.load(sprite) def draw(self): - self.__rect = pygame.draw.rect(self._surface, self.__color, (self._position[0], self._position[1], self.__rect_size, self.__rect_size)) + #self.__rect = pygame.draw.rect(self._surface, self.__color, (self._position[0], self._position[1], self.__rect_size, self.__rect_size)) + self.__rect = self._surface.blit(self.__image, self.get_position()) + + + def get_rect(self) -> pygame.Rect: return self.__rect diff --git a/pygame-test.py b/pygame-test.py index b86e6f6..37a8258 100644 --- a/pygame-test.py +++ b/pygame-test.py @@ -89,12 +89,15 @@ def spawn_entities(x:int, list_of_objects:list): list_of_objects.append(Entity) count += 1 - +fruits = [ + "data/models/fruit_1_1_scaled_2_red.png", + "data/models/fruit_1_1_scaled_2_green.png", + "data/models/fruit_1_1_scaled_2_yellow.png", + "data/models/fruit_1_1_scaled_2_orange.png" +] background = pygame.surface.Surface((640,480)) -imageobj = GOIMAGE("TEST", PLAYGROUND, PLAYGROUND.get_size(), 50, 50, image="data/models/fruit_1_1_scaled_2.png", rect_size=(15,50)) - x = 3600 invert = False @@ -119,16 +122,20 @@ while active == True: elif (event.type == pygame.KEYDOWN): if (event.key == pygame.K_UP): game_started = True - player.change_direction("up") + if(player.get_playermovedirection()["down"] != True): + player.change_direction("up") elif (event.key == pygame.K_DOWN): game_started = True - player.change_direction("down") + if(player.get_playermovedirection()["up"] != True): + player.change_direction("down") elif (event.key == pygame.K_RIGHT): game_started = True - player.change_direction("right") + if(player.get_playermovedirection()["left"] != True): + player.change_direction("right") elif (event.key == pygame.K_LEFT): game_started = True - player.change_direction("left") + if(player.get_playermovedirection()["right"] != True): + player.change_direction("left") text_surface_score = my_font.render('Score: '+str(player.get_player_score()), True, (0, 0, 0)) text_surface_player = my_font.render("Player: " + User.getusername(), True, SCHWARZ, None) @@ -137,10 +144,8 @@ while active == True: MAINSCREEN.blit(text_surface_score, (MAINSCREEN_SIZE[0]/2-text_surface_score.get_size()[0]/2,0)) #Paints the Scoreboard in Top/Center MAINSCREEN.blit(text_surface_player, (10, 0)) - imageobj.draw() - if(spawn_fruit == True): - fruit = Fruit("Fruit", PLAYGROUND, PLAYGROUND.get_size(), init_pos_x=rand.randint(0, PLAYGROUND.get_size()[0]-40), init_pos_y=rand.randint(0, PLAYGROUND.get_size()[1]-40), color=ROT, rect_size=40, score_points=10) + fruit = Fruit("Fruit", PLAYGROUND, PLAYGROUND.get_size(), init_pos_x=rand.randint(0, PLAYGROUND.get_size()[0]-40), init_pos_y=rand.randint(0, PLAYGROUND.get_size()[1]-40), color=ROT, rect_size=40, score_points=10, sprite=fruits[rand.randint(0, len(fruits)-1)]) spawn_fruit = False if(fruit):