Update Fruit class

Added multiplie fruitcolors and spawn them random
This commit is contained in:
2024-02-04 18:33:16 +01:00
parent cbcf1e6bbd
commit d312fa3308
8 changed files with 36 additions and 23 deletions

View File

@@ -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):