dev-jakklu #5
20
survival/components/time_component.py
Normal file
20
survival/components/time_component.py
Normal file
@ -0,0 +1,20 @@
|
||||
class TimeComponent:
|
||||
def __init__(self, minute, hour, day, timer):
|
||||
self.minute = minute
|
||||
self.hour = hour
|
||||
self.day = day
|
||||
self.timer = timer
|
||||
|
||||
def add_time(self, minutes):
|
||||
self.minute += minutes
|
||||
if self.minute >= 60:
|
||||
temp = self.minute - 60
|
||||
self.hour += 1
|
||||
if self.hour >= 24:
|
||||
temp2 = self.hour - 24
|
||||
self.day += 1
|
||||
self.hour = temp2
|
||||
self.minute = temp
|
||||
|
||||
def __str__(self):
|
||||
return f'Day {self.day}, {self.hour}:{self.minute}'
|
@ -3,6 +3,7 @@ from survival.components.input_component import InputComponent
|
||||
from survival.components.movement_component import MovementComponent
|
||||
from survival.components.position_component import PositionComponent
|
||||
from survival.components.sprite_component import SpriteComponent
|
||||
from survival.components.time_component import TimeComponent
|
||||
|
||||
|
||||
class PlayerGenerator:
|
||||
@ -19,5 +20,6 @@ class PlayerGenerator:
|
||||
sprite = SpriteComponent('stevenson.png')
|
||||
sprite.set_scale(1)
|
||||
world.add_component(player, sprite)
|
||||
world.add_component(player, TimeComponent(0, 0, 0, 0))
|
||||
|
||||
return player
|
||||
|
12
survival/systems/time_system.py
Normal file
12
survival/systems/time_system.py
Normal file
@ -0,0 +1,12 @@
|
||||
from survival import esper
|
||||
from survival.components.time_component import TimeComponent
|
||||
|
||||
|
||||
class TimeSystem(esper.Processor):
|
||||
def process(self, dt):
|
||||
for ent, time in self.world.get_component(TimeComponent):
|
||||
time.timer += dt
|
||||
if time.timer > 1000:
|
||||
time.add_time(1)
|
||||
time.timer = 0
|
||||
print(time)
|
@ -4,6 +4,7 @@ from survival.systems.collision_system import CollisionSystem
|
||||
from survival.systems.draw_system import DrawSystem
|
||||
from survival.systems.input_system import InputSystem
|
||||
from survival.systems.movement_system import MovementSystem
|
||||
from survival.systems.time_system import TimeSystem
|
||||
|
||||
|
||||
class WorldGenerator:
|
||||
@ -15,5 +16,6 @@ class WorldGenerator:
|
||||
world.add_processor(MovementSystem(), priority=1)
|
||||
world.add_processor(CollisionSystem(game_map), priority=2)
|
||||
world.add_processor(DrawSystem(camera))
|
||||
world.add_processor(TimeSystem())
|
||||
|
||||
return world
|
||||
|
Loading…
Reference in New Issue
Block a user