Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Created August 15, 2013 19:38
Show Gist options
  • Select an option

  • Save Zolomon/6244064 to your computer and use it in GitHub Desktop.

Select an option

Save Zolomon/6244064 to your computer and use it in GitHub Desktop.
Artemis
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Artemis;
using Microsoft.Xna.Framework;
using Roguelike.components;
namespace Roguelike.utils
{
public class EntityFactory
{
public static void CreatePlayer(EntityWorld world)
{
Entity e = world.CreateEntity();
e.Group = "PLAYER";
var pos = new Position();
pos.Pos = new Vector2(30, 30);
e.AddComponent<Player>(new Player());
e.AddComponentFromPool<Position>();
e.AddComponentFromPool<Velocity>();
e.AddComponentFromPool<Acceleration>();
e.AddComponent(new Sprite("player") { Layer = Sprite.SpriteLayer.Actors1 });
e.IsEnabled = true;
e.GetComponent<Acceleration>().Acc = Vector2.Zero;
e.GetComponent<Velocity>().Vel = Vector2.Zero;
Debug.WriteLine(e.IsActive);
}
public static void CreateBoard(EntityWorld world)
{
for (int y = 0; y < 40; y++)
{
for (int x = 0; x < 40; x++)
{
Entity e = world.CreateEntity();
e.Group = "TILE";
e.AddComponent(new Tile() { TileType = TileType.Water });
e.AddComponentFromPool<Position>();
e.GetComponent<Position>().Pos = new Vector2(x * Tile.Width, y * Tile.Height);
e.AddComponent(new Sprite("water") { Layer = Sprite.SpriteLayer.Background });
e.IsEnabled = true;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment