-
Notifications
You must be signed in to change notification settings - Fork 3
/
seedSpawner.py
34 lines (28 loc) · 1.1 KB
/
seedSpawner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import random
from gameobject import GameObject
from item import Item, SeedItem
from report import Report
from vector2 import Vector2
import gamemanager
class SeedSpawner(GameObject):
def __init__(self, v2_pos):
super().__init__(v2_pos, Vector2(16, 16) * gamemanager.GameManager.scale, False)
self.temporizador = 0
self.lastItem = None
self.spawnRandomSeed()
def loop(self):
if self.lastItem == None or (self.lastItem != None and self.lastItem not in Item.all_itens):
self.lastItem = None
self.temporizador += gamemanager.GameManager.deltaTime
if self.temporizador >= 5:
self.spawnRandomSeed()
self.temporizador = 0
def spawnRandomSeed(self):
item_nome = "Cenoura"
keys = list(Report.getCurrentHarvestGoal().keys())
for x in range(5):
rnd = random.randint(0, len(keys)-1)
if Report.getCurrentHarvestGoal()[keys[rnd]] > 0:
item_nome = keys[rnd]
break
self.lastItem = SeedItem(self.v2_pos, item_nome)