Example #1
0
    public void SwitchItem(Vector2 mousepos, EntityType et, string asset, int boundingy = 0)
    {
        //check selected entity
        Vector2      vpos   = GridPosition(mousepos + new Vector2(0, cellHeight / 2));
        Point        pos    = new Point((int)vpos.X, (int)vpos.Y);
        EditorEntity entity = Get(pos.X, pos.Y) as EditorEntity;

        //replace entity
        if (entity != null)
        {
            Remove(entity.Id, pos.X, pos.Y);
            EditorEntity newentity = new EditorEntity(pos, asset, boundingy, et);
            if (et == EntityType.Enemy)
            {
                //get additional information from the mouse
                EditorMouse mouse = GameWorld.GetObject("mouse") as EditorMouse;
                newentity.EnemyType = mouse.EnemyType;
            }
            else if (et == EntityType.AnimatedItem || et == EntityType.SpriteItem)
            {
                //get additional information from the mouse
                EditorMouse mouse = GameWorld.GetObject("mouse") as EditorMouse;
                newentity.ItemType = mouse.ItemType;
            }
            Add(newentity, pos.X, pos.Y);
            newentity.InitializeTile();
        }
    }