Example #1
0
 public ActorEvent(RenderableEntity2D actor, bool skippable = true, float activationTime = 0.3f, bool hasDuration = false, float duration = 999.0f)
     : base(activationTime, hasDuration, duration)
 {
     this.actor = actor;
     this.positionChanged = false;
     this.orientWhileMoving = false;
     this.move = false;
     this.function = null;
     this.skippable = skippable;
     this.updateChanged = false;
     this.renderChanged = false;
     this.orientationChanged = false;
 }
Example #2
0
        public bool update()
        {
            if (((StateGame)StateManager.getCurrentState()).gameRunning)
            {
                tabControl1.Enabled = false;
                return true;
            }

            if (!tabControl1.Enabled)
                tabControl1.Enabled = true;

            mouseState = Mouse.GetState();
            keyState = Keyboard.GetState();

            System.Drawing.Point point = MyEditor.Instance.myEditorControl.PointToClient(new System.Drawing.Point(MyEditor.Instance.getMouseState().X, MyEditor.Instance.getMouseState().Y));
            gameScreenPos = new Vector2(point.X, point.Y);

            if (noUpdate > 0)
            {
                return true;
            }

            if ( (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftControl) || isKeyPressed(Microsoft.Xna.Framework.Input.Keys.RightControl)) && justPressedKey(Microsoft.Xna.Framework.Input.Keys.Z))
            {
                noUpdate++;
                MessageBox.Show(MyEditor.ActiveForm, "PULSA OK PARA FORMATEAR EL DISCO DURO.", "Control SETA");
                MessageBox.Show(MyEditor.ActiveForm, "FORMATEANDO...", "Control SETA");
                noUpdate--;
            }

            //skip frame f.e. when coming back from load/save dialog
            if (skipFrames > 0)
            {
                skipFrames--;
                return true;
            }

            if (texturesCombo.Focused)
            {
                return true;
            }

            if (currentState == null)
            {
                changeState(new EditorState_MoveState());
            }

            if (nextState != null)
            {
                doChangeState();
            }

            //EXIT
            if(exitBlockers <= 0 && justPressedKey(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                return false;
            }

            //GRID
            if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.G))
            {
                drawGrid = !drawGrid;
            }
            if (isKeyPressed(Microsoft.Xna.Framework.Input.Keys.H))
            {
                EntityManager.Instance.renderCollisionParts();
            }

            //STATE CHANGE
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.Q))
            {
                changeState(new EditorState_MoveState());
            }
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.W))
            {
                changeState(new EditorState_RotateState());
            }
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.E))
            {
                changeState(new EditorState_ScaleState());
            }
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.B))
            {
                colorButton_Click(null, null);
            }
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.D8))
            {
                CameraManager.Instance.speedMultiplier = 1.0f;
            }
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.D9))
            {
                CameraManager.Instance.speedMultiplier -= 0.5f;
            }
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.D0))
            {
                CameraManager.Instance.speedMultiplier += 0.5f;
            }

            //RESET
            //else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.R))
            //{
            //    EntityManager.Instance.reset();
            //}

            //MOVE CAMERA
            else if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space) && mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                Camera2D.position.X -= (mouseState.X - lastMouseState.X) * (Camera2D.position.Z / 1000);
                Camera2D.position.Y += (mouseState.Y - lastMouseState.Y) * (Camera2D.position.Z / 1000);
            }
            else if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space) && mouseState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                //Camera2D.position.Z -= (mouseState.Y - lastMouseState.Y);
                Camera2D.position.Z -= (mouseState.Y - lastMouseState.Y) * (Camera2D.position.Z / 400);
            }
            else if (keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
            {
            }

            //DELETE
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.Delete) && anyEntitySelected())
            {
                foreach (Entity2D ent in selectedEntities)
                {
                    ent.delete();
                }
                selectedEntities.Clear();
            }

            //DUPLICATE
            else if (justPressedKey(Microsoft.Xna.Framework.Input.Keys.D))
            {
                if (anyEntitySelected())
                {
                    List<Entity2D> newEntities = new List<Entity2D>();

                    foreach (RenderableEntity2D ent in selectedEntities)
                    {
                        RenderableEntity2D newEntity = null;
                        if (ent is Enemy)
                        {
                            newEntity = (RenderableEntity2D)EnemyManager.Instance.addEnemy(ent.entityName, ent.position);
                        }
                        else if (ent is AnimatedEntity2D)
                        {
                            newEntity = new AnimatedEntity2D("animatedProps", ent.entityName, ent.position, 0, Color.White);
                            LevelManager.Instance.addAnimatedProp(newEntity);
                        }
                        else if (ent is RenderableEntity2D)
                        {
                            newEntity = new RenderableEntity2D("staticProps", ent.entityName, ent.position, 0, Color.White);
                            LevelManager.Instance.addStaticProp(newEntity);
                        }

                        newEntity.color = ent.color;
                        newEntity.flipHorizontal = ent.flipHorizontal;
                        newEntity.flipVertical = ent.flipVertical;

                        newEntity.worldMatrix = ent.worldMatrix;

                        newEntity.living = ent.living;
                        newEntity.livingIntensityMin = ent.livingIntensityMin;
                        newEntity.livingIntensityMax = ent.livingIntensityMax;
                        newEntity.livingSpeedMin = ent.livingSpeedMin;
                        newEntity.livingSpeedMax = ent.livingSpeedMax;

                        if (newEntity != null)
                        {
                            newEntities.Add(newEntity);
                        }
                    }
                    selectedEntities.Clear();
                    selectedEntities = newEntities;

                    if (selectedEntities.Count > 1)
                        createGroup();
                }
            }

            //UPDATE STATE
            else if (currentState != null)
            {
                currentState.update();
            }

            if (anyEntitySelected())
            {
                currentEntityName.Text = selectedEntities[0].entityName;
            }

            lastMouseState = mouseState;
            lastKeyState = keyState;

            return true;
        }
        // loads the specified file into the editor
        private List<Entity2D> loadLevel(string fileName, bool loadIDs = true)
        {
            // TODO ugly! this must have to be set with the editor and loaded from xml
            if (GamerManager.getMainPlayer() == null)
            {
                GamerManager.createGamerEntity(PlayerIndex.One, true);
            }
            GamerManager.getMainPlayer().mode = Player.tMode.Arcade;

            //fileName = SB.content.RootDirectory + "/xml/levels/" + fileName + ".xml";
            List<Entity2D> list = new List<Entity2D>();
            if (File.Exists(fileName))
            {
                XDocument xml_doc = XDocument.Load(fileName);

                int id;
                IEnumerable<XElement> nodes;

                if (loadIDs)
                {
                    nodes = xml_doc.Descendants("level");
                    XElement levelNode = nodes.First();
                    if (levelNode.Attributes("nextEntityID").Count() > 0)
                    {
                        Entity2D.NEXT_ENTITY_ID = levelNode.Attribute("nextEntityID").Value.toInt();
                    }

                    if (levelNode.Attributes("BGColor").Count() > 0)
                    {
                        SB.BGColor = levelNode.Attribute("BGColor").Value.toColor();
                    }

                    if (levelNode.Attributes("CameraMode").Count() > 0)
                    {
                        CameraManager.Instance.cameraMode = (CameraManager.tCameraMode)Enum.Parse(typeof(CameraManager.tCameraMode), levelNode.Attribute("CameraMode").Value, true);
                    }
                }

                // read static props
                nodes = xml_doc.Descendants("staticProp");
                foreach (XElement node in nodes)
                {
                    id = -1;
                    if (loadIDs && node.Attributes("id").Count() > 0) id = node.Attribute("id").Value.toInt();
                    RenderableEntity2D re = new RenderableEntity2D("staticProps", node.Attribute("entityName").Value, Vector3.Zero, 0, Color.White, true, id);
                    re.worldMatrix = node.Attribute("worldMatrix").Value.toMatrix();
                    if (re.worldMatrix.AnyNanCoord())
                        continue;

                    if (node.Attributes("color").Count() > 0)
                    {
                        re.color = node.Attribute("color").Value.toColor();
                    }
                    if (node.Attributes("flipH").Count() > 0)
                    {
                        re.flipHorizontal = node.Attribute("flipH").Value.toBool();
                        re.flipVertical = node.Attribute("flipV").Value.toBool();
                    }
                    if (node.Attributes("living").Count() > 0)
                    {
                        re.living = node.Attribute("living").Value.toBool();
                    }
                    if (node.Attributes("livingIntensityMin").Count() > 0)
                    {
                        re.livingIntensityMin = node.Attribute("livingIntensityMin").Value.toFloat();
                        re.livingIntensityMax = node.Attribute("livingIntensityMax").Value.toFloat();
                        re.livingSpeedMin = node.Attribute("livingSpeedMin").Value.toFloat();
                        re.livingSpeedMax = node.Attribute("livingSpeedMax").Value.toFloat();
                    }

                    LevelManager.Instance.addStaticProp(re);
                    re.setInit();
                    list.Add(re);
                }

                // read animated props
                nodes = xml_doc.Descendants("animatedProp");
                foreach (XElement node in nodes)
                {
                    id = -1;
                    if (loadIDs && node.Attributes("id").Count() > 0) id = node.Attribute("id").Value.toInt();
                    AnimatedEntity2D ae = new AnimatedEntity2D("animatedProps", node.Attribute("entityName").Value, Vector3.Zero, 0, Color.White, true, id);
                    ae.worldMatrix = node.Attribute("worldMatrix").Value.toMatrix();
                    if (ae.worldMatrix.AnyNanCoord())
                        continue;
                    if (node.Attributes("color").Count() > 0)
                    {
                        ae.color = node.Attribute("color").Value.toColor();
                    }
                    if (node.Attributes("flipH").Count() > 0)
                    {
                        ae.flipHorizontal = node.Attribute("flipH").Value.toBool();
                        ae.flipVertical = node.Attribute("flipV").Value.toBool();
                    }
                    if (node.Attributes("living").Count() > 0)
                    {
                        ae.living = node.Attribute("living").Value.toBool();
                    }
                    if (node.Attributes("livingIntensityMin").Count() > 0)
                    {
                        ae.livingIntensityMin = node.Attribute("livingIntensityMin").Value.toFloat();
                        ae.livingIntensityMax = node.Attribute("livingIntensityMax").Value.toFloat();
                        ae.livingSpeedMin = node.Attribute("livingSpeedMin").Value.toFloat();
                        ae.livingSpeedMax = node.Attribute("livingSpeedMax").Value.toFloat();
                    }

                    LevelManager.Instance.addAnimatedProp(ae);
                    ae.setInit();
                    list.Add(ae);
                }

                // read enemies
                nodes = xml_doc.Descendants("enemy");
                foreach (XElement node in nodes)
                {
                    id = -1;
                    if (loadIDs && node.Attributes("id").Count() > 0) id = node.Attribute("id").Value.toInt();
                    string name = node.Attribute("entityName").Value;
                    Matrix world = node.Attribute("worldMatrix").Value.toMatrix();
                    if (world.AnyNanCoord())
                        continue;
                    RenderableEntity2D e = (RenderableEntity2D)EnemyManager.Instance.addEnemy(name, world.Translation, id);
                    if (node.Attributes("color").Count() > 0)
                    {
                        e.color = node.Attribute("color").Value.toColor();
                    }
                    if (node.Attributes("flipH").Count() > 0)
                    {
                        e.flipHorizontal = node.Attribute("flipH").Value.toBool();
                        e.flipVertical = node.Attribute("flipV").Value.toBool();
                    }

                    if (node.Attributes("living").Count() > 0)
                    {
                        e.living = node.Attribute("living").Value.toBool();
                    }
                    if (node.Attributes("livingIntensityMin").Count() > 0)
                    {
                        e.livingIntensityMin = node.Attribute("livingIntensityMin").Value.toFloat();
                        e.livingIntensityMax = node.Attribute("livingIntensityMax").Value.toFloat();
                        e.livingSpeedMin = node.Attribute("livingSpeedMin").Value.toFloat();
                        e.livingSpeedMax = node.Attribute("livingSpeedMax").Value.toFloat();
                    }

                    e.setInit();
                    list.Add(e);
                }

                //Enemy spaws zones
                nodes = xml_doc.Descendants("enemySpawnZone");
                foreach (XElement node in nodes)
                {
                    string name = node.Attribute("enemy").Value;
                    Rectangle rect = node.Attribute("zone").Value.toRectangle();
                    int count = node.Attribute("count").Value.toInt();

                    EnemyManager.Instance.addEnemySpawnZone(new EnemySpawnZone(name, rect, count));
                }

                // read level collisions
                nodes = xml_doc.Descendants("levelCollision");
                foreach (XElement node in nodes)
                {
                    Line l = new Line(node.Attribute("p1").Value.toVector2(), node.Attribute("p2").Value.toVector2());
                    LevelManager.Instance.addLevelCollision(l);
                }

                //Camera
                nodes = xml_doc.Descendants("cameraNode");
                foreach (XElement node in nodes)
                {
                    Vector3 position = node.Attribute("position").Value.toVector3();
                    Vector3 target = node.Attribute("target").Value.toVector3();
                    int nodeId = node.Attribute("id").Value.toInt();
                    bool isFirst = node.Attribute("isFirst").Value.toBool();
                    NetworkNode<CameraData> cameraNode = new NetworkNode<CameraData>(new CameraData(target, nodeId, isFirst), position);
                    if (node.Attributes("speed").Count() > 0)
                        cameraNode.value.speed = node.Attribute("speed").Value.toFloat();

                    if (node.Attributes("link").Count() > 0)
                        cameraNode.value.next = node.Attribute("link").Value.toInt();

                    CameraManager.Instance.addNode(cameraNode);
                }
                //link camera nodes
                foreach (NetworkNode<CameraData> cameraNode in CameraManager.Instance.getNodes().getNodes())
                {
                    cameraNode.addLinkedNode(CameraManager.Instance.getNode(cameraNode.value.next));
                }
                CameraManager.Instance.setupCamera();

                // player
                if (GamerManager.getMainPlayer() == null)
                {
                    GamerManager.createGamerEntity(PlayerIndex.One, true);
                }

                nodes = xml_doc.Descendants("player");
                foreach (XElement node in nodes)
                {
                    int playerId = node.Attribute("playerId").Value.toInt();
                    Vector3 pos = node.Attribute("pos").Value.toVector3();
                    GamerManager.getMainPlayer().initPos = pos;
                }

                if (fileName == "Content/xml/levels/mapa.xml")
                {
                    GamerManager.getMainPlayer().renderState = RenderableEntity2D.tRenderState.NoRender;
                }
                else
                {
                    EntityManager.Instance.registerEntity(GamerManager.getMainPlayer());
                    GamerManager.getMainPlayer().renderState = RenderableEntity2D.tRenderState.Render;
                    GamerManager.getMainPlayer().position = GamerManager.getMainPlayer().initPos;
                }
                GamerManager.getMainPlayer().initLevel();

                //particles
                nodes = xml_doc.Descendants("particle");
                foreach (XElement node in nodes)
                {
                    string name = node.Attribute("name").Value;
                    Vector3 position = node.Attribute("position").Value.toVector3();
                    Vector3 direction = node.Attribute("direction").Value.toVector3();
                    Color color = node.Attribute("color").Value.toColor();
                    if(!position.AnyNanCoord() && !direction.AnyNanCoord())
                        ParticleManager.Instance.addParticles(name, position, direction, color);
                }

                //triggers
                //nodes = xml_doc.Descendants("trigger");
                //foreach (XElement node in nodes)
                //{
                //    Vector2 position = node.Attribute("position").Value.toVector2();
                //    Trigger trigger = new Trigger();
                //    trigger.position = position;

                //    IEnumerable<XElement> moreNodes = node.Descendants("condition");
                //    foreach (XElement func in moreNodes)
                //    {
                //        trigger.addFunction(true, func.Attribute("functionName").Value);
                //    }

                //    moreNodes = node.Descendants("consecuence");
                //    foreach (XElement func in moreNodes)
                //    {
                //        trigger.addFunction(false, func.Attribute("functionName").Value);
                //    }

                //    TriggerManager.Instance.addTrigger(trigger);
                //}

                if (loadIDs)
                {
                    // groups
                    nodes = xml_doc.Descendants("group"); // read enemies
                    foreach (XElement node in nodes)
                    {
                        IEnumerable<XElement> ids = node.Descendants("entity");
                        List<int> idList = new List<int>();
                        foreach (XElement entityId in ids)
                        {
                            int entityID = entityId.Attribute("id").Value.toInt();
                            if (EntityManager.Instance.getEntityByID(entityID) != null)
                            {
                                idList.Add(entityID);
                            }
                        }
                        if(idList.Count > 1)
                            LevelManager.Instance.addGroup(idList);
                    }
                }
            }

            return list;
        }
 public SpecialEvent(RenderableEntity2D actor, bool skippable = true, float activationTime = 0.3f, bool hasDuration = false, float duration = 999.0f)
     : base(activationTime, hasDuration, duration)
 {
 }
 public static bool activateGarlicGun(RenderableEntity2D player)
 {
     ((Player)player).activateGarlicGun();
     return true;
 }