public override void Load() { SpriteSheet sheet = SpriteSheet.Get("textures1"); SpriteFrame frame = sheet.Frames["TheAlchemist_Idle_1"]; Sprite sprite = new Sprite(frame); int player = ECS.CreateEntity(); ECS.AddComponent(player, new CSpriteRenderer()); ECS.AddComponent(player, new CPhysics()); ECS.GetComponent <CSpriteRenderer>(player).sprite = sprite; ECS.GetComponent <CPhysics>(player).position = new Pos(1, 1); ECS.GetComponent <CPhysics>(player).playerControlled = true; int npc = ECS.CreateEntity(); ECS.AddComponent(npc, new CSpriteRenderer()); ECS.AddComponent(npc, new CPhysics()); ECS.AddComponent(npc, new CSimpleAI()); ECS.GetComponent <CSpriteRenderer>(npc).sprite = sprite; ECS.GetComponent <CPhysics>(npc).position = new Pos(5, 1); AddSystem(new SimpleAISystem()); AddSystem(new PhysicsSystem()); AddSystem(new RenderSystem()); }
public override void Draw(float delta) { foreach (int entity in ECS.Entities) { CSpriteRenderer renderer = ECS.GetComponent <CSpriteRenderer>(entity); CPhysics physics = ECS.GetComponent <CPhysics>(entity); if (renderer == null || physics == null) { continue; } renderer.sprite.position = physics.position; if (physics.isMoving) { Point move = physics.queuedMovement; move.X = (int)(move.X * physics.moveDelta * Pos.TileSize); move.Y = (int)(move.Y * physics.moveDelta * Pos.TileSize); renderer.sprite.position += move; } renderer.sprite.Draw(); } }
public override void Update(float delta) { foreach (int entity in ECS.GetEntitiesWithComponent <CPhysics>()) { CPhysics physics = ECS.GetComponent <CPhysics>(entity); if (physics.isMoving) { HandleMovement(delta, physics); } if (physics.isMoving) { continue; } int x = 0, y = 0; if (physics.playerControlled) { if (Input.IsKeyDown(Keys.Down)) { y++; } if (Input.IsKeyDown(Keys.Up)) { y--; } if (Input.IsKeyDown(Keys.Left)) { x--; } if (Input.IsKeyDown(Keys.Right)) { x++; } } else { x = physics.queuedMovement.X; y = physics.queuedMovement.Y; } if (x != 0 || y != 0) { physics.queuedMovement = new Point(x, y); physics.isMoving = true; } if (physics.isMoving) { HandleMovement(delta, physics); } } }
public override void Update(float delta) { foreach (int entity in ECS.GetEntitiesWithComponent <CSimpleAI>()) { CSimpleAI ai = ECS.GetComponent <CSimpleAI>(entity); CPhysics physics = ECS.GetComponent <CPhysics>(entity); if (physics == null) { continue; } if (physics.isMoving) { continue; } physics.isMoving = true; physics.queuedMovement = new Point(1, 0); } }