Ejemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="gw">Gameworld reference this entity is in</param>
 /// <param name="et">The entity type</param>
 /// <param name="x">x coordinate in meters</param>
 /// <param name="y">y coordinate in meters</param>
 public Entity(GameWorld gw, EntityType et)
 {
     type       = et;
     gameWorld  = gw;
     game       = gameWorld.getGame();
     myPowerBar = gameWorld.bar;
     eventList  = new List <Event>();
     sourceRect = new Rectangle(0, 0, 1, 1);
     origin     = Vector2.Zero;
     isPlayer   = false;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a distance joint between two bodies
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected Entity loadEntity(XmlTextReader reader)
        {
            Entity newEntity;
            String type   = reader.GetAttribute("type");
            String color  = reader.GetAttribute("color");
            String noGrav = reader.GetAttribute("noGrav");
            String xLoc   = reader.GetAttribute("locationX");
            String aiArgs = reader.GetAttribute("aiArgs");
            String angle  = reader.GetAttribute("angle");
            float  xPos   = float.Parse(xLoc);
            float  yPos   = float.Parse(reader.GetAttribute("locationY"));
            String id     = reader.GetAttribute("id");

            if (id == null)
            {
                id = "NoId";
            }
            String aiName = reader.GetAttribute("aiName");
            String aiFile = reader.GetAttribute("aiFile");
            Body   body   = null;

            if (type.Contains("Player"))
            {
                id = "Player";
                if (entityManager.player == null)
                {
                    newEntity = new Player.Player(this, entityManager.getType(type));
                    entityManager.addPlayer(newEntity as Player.Player);
                }
                else
                {
                    newEntity = entityManager.player;
                }
                newEntity.type.type = TypeOfThing.PLAYER;
                body = AddBody(new Vector2(xPos, yPos), entityManager.getType(type), newEntity);
                (newEntity as Player.Player).addBody(body, name);
                (newEntity as Player.Player).addType(entityManager.getType(type), name);
                bodyDict.Add(id, body);
                if (angle != null)
                {
                    body.Rotation = (float.Parse(angle) / 180) * 3.14f;
                }
                AIBase pai = null;
                if (aiName != null)
                {
                    pai = loadAI(newEntity, aiName, aiFile);
                    pai.init();
                }
                (newEntity as Player.Player).addAI(pai, name);
            }
            else if (type.Contains("Character"))//Is anyone who can be talked to
            {
                newEntity = new Character(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.NPC }, animation = "Standing Down"
                };                                                                             //This is kind of cool, not really useful, but still cool.
            }
            else if (type.Contains("BuildingEnemy"))
            {
                newEntity = new Character(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.BUILDING_ENEMY }, animation = "Standing Down"
                };
            }
            else if (type.Contains("ChopTree"))
            {
                newEntity = new ChopTree(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.CHOPTREE }, animation = "full"
                };
                navStuff.addRectangle(new Rectangle((int)(xPos * 64), (int)(yPos * 64), (int)newEntity.type.size.X, (int)newEntity.type.size.Y));
            }
            else if (type.Contains("Bar"))
            {
                newEntity = new PowerBar(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.BAR }, animation = "_"
                };
                bar = (PowerBar)newEntity;
            }
            else if (type.Contains("Cannon"))
            {
                newEntity = new Cannon(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.CANNON }, animation = "_"
                };
                cannon = (Cannon)newEntity;
            }
            else if (type.Contains("Building") || type.Contains("BallPlatform"))
            {
                newEntity = new Building(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.BUILDING }, animation = "_"
                };
                navStuff.addRectangle(new Rectangle((int)(xPos * 64), (int)(yPos * 64), (int)newEntity.type.size.X, (int)newEntity.type.size.Y));
            }
            else if (type.Contains("Block"))//Block is anything that can be pushed around
            {
                newEntity = new Entity(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.BUILDING }, animation = "_"
                };
            }
            else if (type.Contains("Item"))//Item is anything that can be picked up
            {
                newEntity = new Item(this, entityManager.getType(type), type.Replace("Item", string.Empty))
                {
                    type = { type = TypeOfThing.ITEM }, animation = "_"
                };
            }
            else if (type.Contains("Enemy"))
            {
                newEntity = new Character(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.ENEMY }, animation = "Standing Down"
                };
            }
            else if (type.Contains("Explosive"))
            {
                newEntity = new Explosive(this, entityManager.getType(type))
                {
                    type = { type = TypeOfThing.EXPLOSIVE }, animation = "_"
                };
            }
            else
            {
                throw new Exception("Invalid Entity Type: " + type);
            }

            if (id == null || !id.Equals("Player"))
            {
                body = AddBody(new Vector2(xPos, yPos), newEntity);

                body.SetLinearVelocity(Vector2.Zero);
                newEntity.my_Body = body;
                addEntity(newEntity, id);
                if (aiName != null)
                {
                    newEntity.ai = loadAI(newEntity, aiName, aiFile);
                    if (aiArgs != null)
                    {
                        newEntity.ai.aiArgs = aiArgs;
                    }
                    newEntity.ai.init();
                }
                if (angle != null)
                {
                    newEntity.my_Body.Rotation = (float.Parse(angle) / 180) * 3.14f;
                }
            }
            newEntity.id = id;
            if (noGrav == null || noGrav == "false")
            {
                body.noGravity = false;
            }
            else if (noGrav == "true")
            {
                body.noGravity = true;
            }
            switch (color)
            {
            case ("Green"):
            {
                newEntity.color = Color.Green;
                break;
            }

            case ("Purple"):
            {
                newEntity.color = Color.Purple;
                break;
            }

            case ("Red"):
            {
                newEntity.color = Color.Red;
                break;
            }

            default:
            {
                newEntity.color = Color.White;
                break;
            }
            }

            if (name == "Main")
            {
                if (id != null && newEntity.ai != null && id != "NoId")
                {
                    aiDict.Add(id, newEntity.ai);
                }
            }
            return(newEntity);
        }