2021-03-04 14:07:44 +01:00
|
|
|
import pygame
|
|
|
|
|
2021-03-15 13:31:25 +01:00
|
|
|
from settings import SCREEN_WIDTH, SCREEN_HEIGHT
|
2021-03-28 18:05:52 +02:00
|
|
|
from survival import esper
|
2021-03-15 13:31:25 +01:00
|
|
|
from survival.camera import Camera
|
2021-03-28 18:05:52 +02:00
|
|
|
from survival.components.camera_target_component import CameraTargetComponent
|
|
|
|
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
|
2021-03-04 15:02:42 +01:00
|
|
|
from survival.game_map import GameMap
|
2021-03-28 18:05:52 +02:00
|
|
|
from survival.systems.camera_system import CameraSystem
|
|
|
|
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
|
2021-03-04 14:07:44 +01:00
|
|
|
|
|
|
|
|
2021-03-14 20:23:38 +01:00
|
|
|
def draw_game(delta):
|
2021-03-15 13:31:25 +01:00
|
|
|
win.fill((0, 0, 0))
|
|
|
|
game_map.draw(camera)
|
2021-03-28 18:05:52 +02:00
|
|
|
world.process(delta)
|
2021-03-04 14:07:44 +01:00
|
|
|
pygame.display.update()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
pygame.init()
|
|
|
|
|
2021-03-15 13:31:25 +01:00
|
|
|
win = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
2021-03-04 14:07:44 +01:00
|
|
|
pygame.display.set_caption("AI Project")
|
|
|
|
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
|
2021-03-15 13:31:25 +01:00
|
|
|
game_map = GameMap(int(SCREEN_WIDTH / 32) * 2, 2 * int(SCREEN_HEIGHT / 32) + 1)
|
|
|
|
camera = Camera(game_map.width * 32, game_map.height * 32, win)
|
2021-03-28 18:05:52 +02:00
|
|
|
|
|
|
|
world = esper.World()
|
|
|
|
world.add_processor(InputSystem())
|
|
|
|
world.add_processor(CameraSystem(camera))
|
|
|
|
world.add_processor(MovementSystem(), priority=1)
|
|
|
|
world.add_processor(CollisionSystem(game_map), priority=2)
|
|
|
|
world.add_processor(DrawSystem(win, camera))
|
|
|
|
|
|
|
|
player = world.create_entity()
|
|
|
|
pos = PositionComponent([0, 0], [0, 0])
|
|
|
|
world.add_component(player, pos)
|
|
|
|
world.add_component(player, MovementComponent())
|
|
|
|
world.add_component(player, InputComponent())
|
|
|
|
camera_target = CameraTargetComponent(pos)
|
|
|
|
world.add_component(player, camera_target)
|
|
|
|
game_map.add_entity(player, pos)
|
|
|
|
sprite = SpriteComponent('stevenson.png')
|
|
|
|
sprite.set_scale(1)
|
|
|
|
world.add_component(player, sprite)
|
|
|
|
|
|
|
|
apple = world.create_entity()
|
|
|
|
pos = PositionComponent([96, 96], [3, 3])
|
|
|
|
world.add_component(apple, pos)
|
|
|
|
world.add_component(apple, SpriteComponent('apple.png'))
|
|
|
|
game_map.add_entity(apple, pos)
|
|
|
|
apple = world.create_entity()
|
|
|
|
pos = PositionComponent([128, 128], [4, 4])
|
|
|
|
world.add_component(apple, pos)
|
|
|
|
world.add_component(apple, SpriteComponent('apple.png'))
|
|
|
|
game_map.add_entity(apple, pos)
|
|
|
|
|
2021-03-04 14:07:44 +01:00
|
|
|
run = True
|
|
|
|
|
|
|
|
while run:
|
|
|
|
# Set the framerate
|
2021-03-14 20:23:38 +01:00
|
|
|
ms = clock.tick(60)
|
2021-03-04 14:07:44 +01:00
|
|
|
|
|
|
|
events = pygame.event.get()
|
|
|
|
|
|
|
|
for event in events:
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
run = False
|
|
|
|
|
|
|
|
keys = pygame.key.get_pressed()
|
|
|
|
|
2021-03-14 20:23:38 +01:00
|
|
|
draw_game(ms)
|