Exemplo n.º 1
0
 public void addEntity(Entity2D entity)
 {
     if (selectedEntities.IndexOf(entity) == -1)
         selectedEntities.Add(entity);
     else
         selectedEntities.Remove(entity);
 }
        public void loadEntity(int index)
        {
            #if EDITOR
            var textures = SB.content.LoadContent("xml/enemies");
            currentIndex = (index + textures.Count) % textures.Count;
            Vector3 position = new Vector3(Camera2D.position.X, Camera2D.position.Y, 0.0f);

            entity = EnemyManager.Instance.addEnemy(textures[currentIndex], position);
            #endif
        }
 public void loadEntity(int index)
 {
     #if EDITOR
     var textures = SB.content.LoadContent("textures/staticProps");
     currentIndex = (index + textures.Count) % textures.Count;
     Texture2D texture = TextureManager.Instance.getTexture("staticProps", textures[currentIndex]);
     Vector3 position = Camera2D.position;
     position.Z = 0.0f;
     staticEntity = new RenderableEntity2D("staticProps", textures[currentIndex], position, 0, Color.White);
     LevelManager.Instance.addStaticProp(staticEntity);
     #endif
 }
 public void loadEntity(int index)
 {
     #if EDITOR
     var textures = SB.content.LoadContent("xml/animatedProps");
     currentIndex = (index + textures.Count) % textures.Count;
     Vector3 position = Camera2D.position;
     position.Z = 0.0f;
     AnimatedEntity2D ent = new AnimatedEntity2D("animatedProps", textures[currentIndex], position, 0, Color.White);
     LevelManager.Instance.addAnimatedProp(ent);
     entity = ent;
     #endif
 }
Exemplo n.º 5
0
        public Lifebar(string name, Entity2D reference, Vector2 scale, Vector2 offset, Color color)
        {
            back = TextureManager.Instance.getTexture("GUI/ingame/" + name + "Back");
            backScale.X = back.Width * scale.X;
            backScale.Y = back.Height * scale.Y;
            front = TextureManager.Instance.getTexture("GUI/ingame/" + name + "Front");
            frontScale.X = front.Width * scale.X;
            frontScale.Y = front.Height * scale.Y;

            this.color = color;

            this.reference = reference;
            this.offset = offset;
            lifePercentage = 1.0f;
            Viewport viewport = GraphicsManager.Instance.graphicsDevice.Viewport;
        }
Exemplo n.º 6
0
        // updates the position of an entity within the level lines passed as parameter and in the playable zone
        public void updateEntityPosition(Entity2D entity, Vector2 newPosition, List<Line> levelLines, bool keepInPlayableZone = false, bool arcadeLimitation = false)
        {
            float distanceToLine = 0.0f;

            // set the new position
            entity.position2D = newPosition;

            // update the position controlling the collisions with all the scene and camera lines
            for (int i = 0; i < levelLines.Count; ++i)
            {
                Vector2 v = levelLines[i].vectorToPoint(newPosition);
                distanceToLine = Vector2.Distance(newPosition, v) - entity.getRadius();
                if (distanceToLine < 0)
                {
                    entity.position2D -= Vector2.Normalize(entity.position2D - v) * distanceToLine;
                }
            }
            if (keepInPlayableZone)
            {
                Line[] cameraLines = Camera2D.playableZoneCollisions;
                if (arcadeLimitation)
                {
                    float newTop = Camera2D.position.Y + (Camera2D.screen.Height * 0.2f);
                    cameraLines[0].p1.Y = newTop;
                    cameraLines[0].p2.Y = newTop;
                }

                for (int i = 0; i < 4; ++i)
                {
                    Vector2 v = cameraLines[i].vectorToPoint(newPosition);
                    distanceToLine = Vector2.Distance(newPosition, v) - entity.getRadius();
                    if (distanceToLine < 0)
                    {
                        entity.position2D -= Vector2.Normalize(entity.position2D - v) * distanceToLine;
                    }
                }
            }
        }
Exemplo n.º 7
0
 public void addStaticProp(Entity2D re)
 {
     staticProps.Add(re);
 }
Exemplo n.º 8
0
 void writeEntity(XmlTextWriter writer, Entity2D entity2D, string element)
 {
     writer.WriteStartElement(element);
     writer.WriteAttributeString("entityName", entity2D.entityName);
     writer.WriteAttributeString("worldMatrix", entity2D.worldMatrix.toXML());
     writer.WriteAttributeString("id", entity2D.id.ToString());
     RenderableEntity2D ent = (RenderableEntity2D) entity2D;
     writer.WriteAttributeString("color", ent.color.toXML());
     writer.WriteAttributeString("flipH", ent.flipHorizontal.ToString());
     writer.WriteAttributeString("flipV", ent.flipVertical.ToString());
     writer.WriteAttributeString("living", ent.living.ToString());
     writer.WriteAttributeString("livingIntensityMin", ent.livingIntensityMin.ToString());
     writer.WriteAttributeString("livingIntensityMax", ent.livingIntensityMax.ToString());
     writer.WriteAttributeString("livingSpeedMin", ent.livingSpeedMin.ToString());
     writer.WriteAttributeString("livingSpeedMax", ent.livingSpeedMax.ToString());
     writer.WriteEndElement();
 }
Exemplo n.º 9
0
 public void selectEntity(Entity2D entity)
 {
     selectedEntities.Clear();
     selectedEntities.Add(entity);
 }
Exemplo n.º 10
0
 // renders the border lines of the quad representing this entity
 public void renderEntityQuad(Entity2D entity)
 {
     Vector3[] quad = getEntityQuad(entity);
     DebugManager.Instance.addLine(quad[0], quad[1], Color.Green);
     DebugManager.Instance.addLine(quad[1], quad[2], Color.Green);
     DebugManager.Instance.addLine(quad[2], quad[3], Color.Green);
     DebugManager.Instance.addLine(quad[3], quad[0], Color.Green);
 }
Exemplo n.º 11
0
        // returns the 4 points that conforms the quad of this entity in order: up-right, up-left, bottom-left, bottom-right
        Vector3[] getEntityQuad(Entity2D entity)
        {
            Matrix world = entity.worldMatrix;

            Vector3[] quad = new Vector3[4];
            Vector3 point = new Vector3(0.5f, 0.5f, 0.0f);
            Vector3.Transform(ref point, ref world, out quad[0]);
            point = new Vector3(-0.5f, 0.5f, 0.0f);
            Vector3.Transform(ref point, ref world, out quad[1]);
            point = new Vector3(-0.5f, -0.5f, 0.0f);
            Vector3.Transform(ref point, ref world, out quad[2]);
            point = new Vector3(0.5f, -0.5f, 0.0f);
            Vector3.Transform(ref point, ref world, out quad[3]);
            return quad;
        }
Exemplo n.º 12
0
 public void removeProjectile(Entity2D p)
 {
     EntityManager.Instance.removeEntity(p);
     projectiles.Remove(p);
 }
Exemplo n.º 13
0
        // returns true if the ray collides with the quad representing this entity
        public bool rayVsEntity(Ray ray, Entity2D entity)
        {
            Vector3[] vertexs = getEntityQuad(entity);

            return ray.intersectsTriangle(vertexs[0], vertexs[1], vertexs[2])
                || ray.intersectsTriangle(vertexs[0], vertexs[2], vertexs[3]);
        }
        public override void update()
        {
            base.update();

            if (justPressedKey(Keys.PageDown) || justPressedKey(Keys.O))
            {
                LevelManager.Instance.removeAnimatedProp(entity);
                loadEntity(currentIndex + 1);
                MyEditor.Instance.texturesCombo.SelectedIndex = currentIndex;
                MyEditor.Instance.myEditorControl.Focus();
            }
            else if (justPressedKey(Keys.PageUp) || justPressedKey(Keys.I))
            {
                LevelManager.Instance.removeAnimatedProp(entity);
                loadEntity(currentIndex - 1);
                MyEditor.Instance.texturesCombo.SelectedIndex = currentIndex;
                MyEditor.Instance.myEditorControl.Focus();
            }
            else if (justPressedLeftButton() && isPosInScreen(gameScreenPos))
            {
                entity = null;
                MyEditor.Instance.changeState(new EditorState_AddAnimated(currentIndex));
            }

            if (entity != null)
            {
                entity.position2D = new Vector2(mouseInSetaZero.X, mouseInSetaZero.Y);
            }
        }
Exemplo n.º 15
0
 public void removeAnimatedProp(Entity2D ae)
 {
     EntityManager.Instance.removeEntity(ae);
     animatedProps.Remove(ae);
 }
Exemplo n.º 16
0
 public void addAnimatedProp(Entity2D ae)
 {
     animatedProps.Add(ae);
 }
Exemplo n.º 17
0
 public void removeStaticProp(Entity2D re)
 {
     EntityManager.Instance.removeEntity(re);
     staticProps.Remove(re);
 }
Exemplo n.º 18
0
 public void removeEntity(Entity2D ent)
 {
     if (animatedProps.IndexOf(ent) >= 0)
         removeAnimatedProp(ent);
     else if (staticProps.IndexOf(ent) >= 0)
         removeStaticProp(ent);
 }
Exemplo n.º 19
0
 public void removeEnemy(Entity2D e)
 {
     EntityManager.Instance.removeEntity(e);
     if (enemies.Contains(e))
     {
         enemies.Remove(e);
     }
     else
     {
         activeEnemies.Remove(e);
     }
 }
Exemplo n.º 20
0
 // returns the entity from the lits that collides with a ray or null if none collides
 public Entity2D rayVsEntities(Ray ray, List<Entity2D> entities, Entity2D ent = null, List<Entity2D> ignoreEntities = null)
 {
     float currentSeta = ent != null ? ent.position.Z : float.MinValue;
     foreach (Entity2D e in entities)
     {
         if (ignoreEntities.IndexOf(e) == -1 &&  rayVsEntity(ray, e))
         {
             if (ent == null || e.position.Z > currentSeta)
             {
                 currentSeta = e.position.Z;
                 ent = e;
             }
         }
     }
     return ent;
 }