update
This commit is contained in:
parent
534e9813ef
commit
f49ef8559d
@ -9,6 +9,7 @@ from survival.components.movement_component import MovementComponent
|
||||
from survival.components.position_component import PositionComponent
|
||||
from survival.components.sprite_component import SpriteComponent
|
||||
from survival.game_map import GameMap
|
||||
from survival.player_generator import PlayerGenerator
|
||||
from survival.resource_generator import ResourceGenerator
|
||||
from survival.systems.camera_system import CameraSystem
|
||||
from survival.systems.collision_system import CollisionSystem
|
||||
@ -29,18 +30,7 @@ if __name__ == '__main__':
|
||||
camera = Camera(game_map.width * 32, game_map.height * 32, win)
|
||||
|
||||
world = WorldGenerator().create_world(camera, game_map)
|
||||
|
||||
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)
|
||||
player = PlayerGenerator().create_player(world, game_map)
|
||||
|
||||
ResourceGenerator(world, game_map).generate_resources()
|
||||
|
||||
|
23
survival/player_generator.py
Normal file
23
survival/player_generator.py
Normal file
@ -0,0 +1,23 @@
|
||||
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
|
||||
|
||||
|
||||
class PlayerGenerator:
|
||||
|
||||
def create_player(self, world, game_map):
|
||||
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)
|
||||
|
||||
return player
|
@ -2,6 +2,7 @@ import random
|
||||
|
||||
from survival.components.position_component import PositionComponent
|
||||
from survival.components.sprite_component import SpriteComponent
|
||||
from survival.settings import RESOURCES_AMOUNT
|
||||
|
||||
|
||||
class ResourceGenerator:
|
||||
@ -10,7 +11,7 @@ class ResourceGenerator:
|
||||
self.map = game_map
|
||||
|
||||
def generate_resources(self):
|
||||
for x in range(50):
|
||||
for x in range(RESOURCES_AMOUNT):
|
||||
obj = self.world.create_entity()
|
||||
sprites = ['apple.png', 'water.png', 'wood.png', 'stone.png']
|
||||
|
||||
|
@ -1,2 +1,3 @@
|
||||
SCREEN_WIDTH = 1920
|
||||
SCREEN_HEIGHT = 1080
|
||||
RESOURCES_AMOUNT = 300
|
||||
|
@ -12,6 +12,9 @@ class TileLayer:
|
||||
def draw(self, camera, visible_area):
|
||||
for y in range(int(visible_area.top / 32), int(visible_area.height / 32) + 1):
|
||||
for x in range(int(visible_area.left / 32), int(visible_area.width / 32) + 1):
|
||||
if y >= self.height or x >= self.width:
|
||||
continue
|
||||
|
||||
self.image.pos = (x * 32, y * 32)
|
||||
self.image.origin = self.tiles[y][x].origin
|
||||
camera.draw(self.image)
|
||||
|
Loading…
Reference in New Issue
Block a user