def initialize(self, app: engine.core.Application): super().initialize(app) engine.instantiate(engine.component.Event(self.close_event, "WINDOW"), id=False) app.window._master.title(f"Dinosaur") app.world.system(engine.ecs.systems.Render, True) app.world.add_system(PhysBodySystem(), "PHYSICS") app.world.add_system(engine.ecs.systems.FPS(), "POST") setting_collision = app.setting.collision() setting_collision.matrix.make( setting_collision.layers.set("Player", 10), setting_collision.layers.set("Enviroment", 11), setting_collision.layers.set("Obstacle", 12), ) setting_collision.matrix.compile() setting_render = app.setting.render() setting_render.layers["Player"] = 110 setting_render.compile() manager = StateManager() engine.instantiate(manager, ObstacleManager(), engine.component.Event(manager.restart)) engine.instantiate( # Player PlayerController(manager), PlayerControllerAI(manager) if self.AIState >= self.AIState.ACTIVE else PlayerControllerInput(), PhysBody(0.06), engine.component.Collider( engine.physics.collider.Rectangle, engine.component.Transform(scl=engine.Vector(50, 100)), "Player"), engine.component.Render(engine.render.Polygon.Quad(50, 100), layer="Player"), transform=engine.component.Transform( engine.Vector(GameApplication.width // 16, GameApplication.height // 2))) engine.instantiate( # Floor engine.component.Collider( engine.physics.collider.Rectangle, engine.component.Transform( scl=engine.Vector(GameApplication.width, 20)), "Enviroment"), engine.component.Render( engine.render.Polygon.Quad(GameApplication.width, 20)), transform=engine.component.Transform( engine.Vector(GameApplication.width // 2, FLOOR + 10))) engine.instantiate( # FPS engine.component.FPS(), engine.component.Render(engine.render.Text("FPS"), True), transform=engine.component.Transform( engine.Vector(GameApplication.width - 20, 8)))
def initialize(self): super().initialize() self.obstacle = self.Get(ObstacleManager) self._text_score = engine.render.Text(0) engine.instantiate(engine.component.Render(self._text_score, True), parent=self.entity, transform=engine.component.Transform( engine.Vector(GameApplication.width - 20, 32))) self._text_high = engine.render.Text(0) engine.instantiate(engine.component.Render(self._text_high, True), parent=self.entity, transform=engine.component.Transform( engine.Vector(GameApplication.width - 20, 20))) if engine.app().program.AIState >= GameApplication.AIState.ACTIVE: self._text_net_out = engine.render.Text([0, 0, 0]) engine.instantiate(engine.component.Render(self._text_net_out, True), parent=self.entity, transform=engine.component.Transform( engine.Vector(GameApplication.width - 300, 50))) self._text_net = engine.render.Text("NET") engine.instantiate(engine.component.Render(self._text_net, True), parent=self.entity, transform=engine.component.Transform( engine.Vector(GameApplication.width - 300, 70))) self.state = self.GameState.RUN
def add(self): self.dist = random.randint(self.__range, GameApplication.width) width = random.randint(*self.WIDTH) dim = engine.Vector(width, self.AREA // width) obstacle = Obstacle(*dim) engine.instantiate( obstacle, engine.component.Collider(engine.physics.collider.Rectangle, engine.component.Transform(scl=dim), "Obstacle"), engine.component.Render( engine.render.Polygon.Quad( *dim, col=self._colour_array[self._colour_count % len(self._colour_array)])), transform=engine.component.Transform( engine.Vector(self._spawn, FLOOR - 2 - dim[1] // 2))) self.children.append(obstacle) self._colour_count += 1
def initialize(self): app = engine.app() engine.instantiate(engine.component.Event(self.close_event, "WINDOW"), id=False) app.window._master.title(f"Pyrio") app.world.system(engine.ecs.systems.Render, True) app.world.add_system(PhysBodySystem(), "PHYSICS") app.world.add_system(engine.ecs.systems.FPS(50), "POST") # engine.ecs.World.active()._systems.insert(2, Collision()) # engine.ecs.World.active()._systems.insert(3, LandOnFloor()) engine.instantiate( # FPS Counter engine.component.FPS(), engine.component.Render(engine.render.Text("FPS"), True), transform=engine.component.Transform( engine.Vector(Game.width - 20, 10))) engine.instantiate( # Player Player(), PhysBody(), engine.component.Collider( engine.physics.collider.Rectangle, engine.component.Transform(scl=engine.Vector(50, 50))), engine.component.Render(engine.render.Polygon.Quad(50, 50)), transform=engine.component.Transform( engine.Vector(Game.width // 8, 3 * Game.height // 4)))
def initialize(self): app = engine.app() engine.instantiate(engine.component.Event(self.close, "WINDOW")) app.world.add_system(ScoreManager(), "RENDER") app.setting.collision().update({ 0: {1,}, }) scores = { "tally": Score(0), "left": Score(0), "right": Score(0) } engine.instantiate( # Ball (ball := Ball(scores)), engine.component.Event(ball.event_start), # Change collider to Circle once implemented engine.component.Collider(engine.physics.collider.Rectangle, engine.component.Transform(scl=engine.Vector(Ball.RADIUS, Ball.RADIUS)), 0), engine.component.Render(engine.render.Polygon.Circle(Ball.RADIUS, res=Ball.RESOLUTION)), transform=engine.component.Transform(engine.Vector(Game.width, Game.height) // 2) ) score_parent = engine.instantiate( transform=engine.component.Transform(engine.Vector(Game.width // 2, Game.height // 10)) ) engine.instantiate( scores["tally"], engine.component.Render(engine.render.Text("T"), True), parent=score_parent, transform=engine.component.Transform(engine.Vector(0, 10)) ) engine.instantiate( scores["left"], engine.component.Render(engine.render.Text("L"), True), parent=score_parent, transform=engine.component.Transform(engine.Vector(-10, 0)) ) engine.instantiate( scores["right"], engine.component.Render(engine.render.Text("R"), True), parent=score_parent, transform=engine.component.Transform(engine.Vector(10, 0)) ) engine.instantiate( # Left Paddle Paddle(0), # (ai := PaddleAI(ball, scores["tally"])), # engine.component.Event(ai.event), PaddlePlayer(engine.input.Key.W, engine.input.Key.S), engine.component.Collider(engine.physics.collider.Rectangle, engine.component.Transform(scl=Paddle.SIZE), 1), engine.component.Render(Paddle.QUAD), transform=engine.component.Transform(engine.Vector(Paddle.SIZE[0], Game.height // 2)) ) engine.instantiate( # Right Paddle Paddle(1), # (ai := PaddleAI(ball, scores["tally"])), # engine.component.Event(ai.event), PaddlePlayer(engine.input.Key.UP, engine.input.Key.DOWN), engine.component.Collider(engine.physics.collider.Rectangle, engine.component.Transform(scl=Paddle.SIZE), 1), engine.component.Render(Paddle.QUAD), transform=engine.component.Transform(engine.Vector(Game.width - Paddle.SIZE[0], Game.height // 2)) )