public MapEditor(GameWindow window, ClientNetworking client, CannonManager cannonManager, List<CannonGroups> cannonGroups)
        {
            factory = GameObjectFactory.Instance;

            this.window = window;
            this.client = client;
            this.cannonManager = cannonManager;
            this.cannonGroups = cannonGroups;
        }
Exemple #2
0
        public GameObjectFactory ShootDoggy(GameObjectFactory factory, CannonGroups cannonGroup)
        {
            List <int> temp = new List <int>();
            //figure out which cannon to shoot from
            //replace once just pass which cannon
            //endreplace



            //dog
            int dog = factory.Create(
                (int)RaginRovers.GameObjectTypes.DOG,
                factory.Objects[cannonGroup.cannonKey].sprite.Location + new Vector2(30, 0),
                "spritesheet",
                Vector2.Zero,
                cannonGroup.Rotation,
                0,
                0);

            factory.Objects[dog].sprite.OnCollision += new OnCollisionEventHandler(CollisionEvents.dog_OnCollision);

            if (factory.Objects[cannonGroup.cannonKey].sprite.Location.X > 6000)
            {
                factory.Objects[dog].sprite.PlayerNumber = 2;
            }
            if (factory.Objects[cannonGroup.cannonKey].sprite.Location.X < 6000)
            {
                factory.Objects[dog].sprite.PlayerNumber = 1;
            }

            if (cannonGroup.isFlipped)
            {
                factory.Objects[dog].sprite.flipType = Sprite.FlipType.VERTICAL;
            }

            factory.Objects[dog].sprite.PhysicsBody.LinearVelocity = new Vector2(
                cannonPower * (float)Math.Cos((double)cannonGroup.Rotation),
                cannonPower * (float)Math.Sin((double)cannonGroup.Rotation));

            //chaning magnitude depending on power bar
            factory.Objects[dog].sprite.PhysicsBody.LinearVelocity *= cannonGroup.Power;     // ((factory.Objects[cannonGroup.tabKey].sprite.Location.X - factory.Objects[cannonGroup.barKey].sprite.Location.X) / factory.Objects[cannonGroup.barKey].sprite.BoundingBoxRect.Width) + 1;

            factory.Objects[cannonGroup.boomKey].sprite.Dead = false;
            cannonGroup.boomTime = 0f;

            factory.Objects[dog].sprite.PhysicsBody.Mass        = 30;
            factory.Objects[dog].sprite.PhysicsBody.Restitution = 0.4f;

            //factory.Objects[cannonGroup.boomKey].sprite.Rotation = factory.Objects[cannonGroup.cannonKey].sprite.Rotation;
            factory.Objects[cannonGroup.boomKey].sprite.Location = factory.Objects[cannonGroup.cannonKey].sprite.Location - factory.Objects[cannonGroup.boomKey].sprite.Origin + new Vector2(0, -150) + factory.Objects[dog].sprite.PhysicsBody.LinearVelocity / factory.Objects[dog].sprite.PhysicsBody.LinearVelocity.Length() * 200;


            return(factory);
        }
Exemple #3
0
        private SunManager()
        {
            factory = GameObjectFactory.Instance;

            rand = new Random(System.Environment.TickCount);

            this.sun = factory.Create((int)GameObjectTypes.SUN, new Vector2(GameWorld.WorldWidth / 2, -800), "sun", Vector2.Zero, 0f, 0f, 0f, 256);
            factory.Objects[sun].sprite.Location -= new Vector2(factory.Objects[sun].sprite.BoundingBoxRect.Width / 2, 0);
            defaultLocation = factory.Objects[sun].sprite.Location;
            factory.Objects[sun].saveable = false;
        }
        public void Update(GameTime gameTime, GameObjectFactory factory, List <CannonGroups> cannonGroup)
        {
            for (int i = 0; i < cannonGroup.Count; i++)
            {
                if (factory.Objects[cannonGroup[i].boomKey].sprite.Frame == 12)
                {
                    factory.Objects[cannonGroup[i].boomKey].sprite.Dead = true;

                    factory.Objects[cannonGroup[i].boomKey].sprite.Frame = 0;
                }
            }
        }
Exemple #5
0
        public MapEditor(GameWindow window, ClientNetworking client, CannonManager cannonManager, List<CannonGroups> cannonGroups, int screenconfiguration)
        {
            
            factory = GameObjectFactory.Instance;

            this.window = window;
            this.client = client;
            this.cannonManager = cannonManager;
            this.cannonGroups = cannonGroups;
            this.screenconfiguration = screenconfiguration;
            
        }
 public CannonGroups(int cannonKey,
                     int wheelKey,
                     int barKey,
                     int tabKey,
                     int boomKey,
                     bool isFlipped)
 {
     this.factory = GameObjectFactory.Instance;
     this.cannonKey = cannonKey;
     this.wheelKey = wheelKey;
     this.barKey = barKey;
     this.tabKey = tabKey;
     this.boomKey = boomKey;
     this.isFlipped = isFlipped;
     cannonState = CannonState.ROTATE;
 }
        public GameObjectFactory ManipulateCannons(GameObjectFactory factory, CannonGroups cannonGroups)
        {
            if (cannonGroups.cannonState == CannonState.ROTATE)
                {
                            //decide whether to rotate one way or back
                    if (factory.Objects[cannonGroups.cannonKey].sprite.Rotation >= factory.Objects[cannonGroups.cannonKey].sprite.LowerRotationBounds)
                        factory.Objects[cannonGroups.cannonKey].sprite.rotationDirection = -1;
                    if (factory.Objects[cannonGroups.cannonKey].sprite.Rotation <= factory.Objects[cannonGroups.cannonKey].sprite.UpperRotationBounds)
                        factory.Objects[cannonGroups.cannonKey].sprite.rotationDirection = 1;

                 

                    factory.Objects[cannonGroups.cannonKey].sprite.Rotation += ((MathHelper.PiOver4 / 16) * factory.Objects[cannonGroups.cannonKey].sprite.rotationDirection);
                        

                }
            if (cannonGroups.cannonState == CannonState.POWER)
                {

                    if (factory.Objects[cannonGroups.barKey].sprite.Location.X > factory.Objects[cannonGroups.tabKey].sprite.Location.X)
                    {
                        Direction = 1;
                    }
                    else if (factory.Objects[cannonGroups.barKey].sprite.Location.X + factory.Objects[cannonGroups.barKey].sprite.BoundingBoxRect.Width - factory.Objects[cannonGroups.tabKey].sprite.BoundingBoxRect.Width < factory.Objects[cannonGroups.tabKey].sprite.Location.X)
                    {
                        Direction = -1;
                    }
                    factory.Objects[cannonGroups.tabKey].sprite.Location += new Vector2(10 * Direction, 0);
                        
                }
            if (cannonGroups.cannonState == CannonState.SHOOT)
                {
                    ShootDoggy(factory, cannonGroups);
                    ChangeCannonState(cannonGroups);
                }

            if (cannonGroups.cannonState == CannonState.COOLDOWN)
            {
                if (factory.Objects[cannonGroups.boomKey].sprite.Dead)
                {
                    ChangeCannonState(cannonGroups); 
                }
            }

            return factory;
        }
        public GameObjectFactory ManipulateCannons(GameObjectFactory factory, CannonGroups cannonGroups)
        {
            if (cannonGroups.cannonState == CannonState.ROTATE)
            {
                //decide whether to rotate one way or back
                if (factory.Objects[cannonGroups.cannonKey].sprite.Rotation >= factory.Objects[cannonGroups.cannonKey].sprite.LowerRotationBounds)
                {
                    factory.Objects[cannonGroups.cannonKey].sprite.rotationDirection = -1;
                }
                if (factory.Objects[cannonGroups.cannonKey].sprite.Rotation <= factory.Objects[cannonGroups.cannonKey].sprite.UpperRotationBounds)
                {
                    factory.Objects[cannonGroups.cannonKey].sprite.rotationDirection = 1;
                }



                factory.Objects[cannonGroups.cannonKey].sprite.Rotation += ((MathHelper.PiOver4 / 16) * factory.Objects[cannonGroups.cannonKey].sprite.rotationDirection);
            }
            if (cannonGroups.cannonState == CannonState.POWER)
            {
                if (factory.Objects[cannonGroups.barKey].sprite.Location.X > factory.Objects[cannonGroups.tabKey].sprite.Location.X)
                {
                    Direction = 1;
                }
                else if (factory.Objects[cannonGroups.barKey].sprite.Location.X + factory.Objects[cannonGroups.barKey].sprite.BoundingBoxRect.Width - factory.Objects[cannonGroups.tabKey].sprite.BoundingBoxRect.Width < factory.Objects[cannonGroups.tabKey].sprite.Location.X)
                {
                    Direction = -1;
                }
                factory.Objects[cannonGroups.tabKey].sprite.Location += new Vector2(10 * Direction, 0);
            }
            if (cannonGroups.cannonState == CannonState.SHOOT)
            {
                ShootDoggy(factory, cannonGroups);
                ChangeCannonState(cannonGroups);
            }

            if (cannonGroups.cannonState == CannonState.COOLDOWN)
            {
                if (factory.Objects[cannonGroups.boomKey].sprite.Dead)
                {
                    ChangeCannonState(cannonGroups);
                }
            }

            return(factory);
        }
        public CloudManager()
        {
            rand = new Random(10); // We have to make sure all systems follow the same random pattern
            factory = GameObjectFactory.Instance;
            clouds = new List<int>();
/*
            if (Game1.ScreenConfiguration == 1)
            {
                for (int i = 0; i < 15; i++)
                {
                    Vector2 v = new Vector2(rand.Next(-1024, GameWorld.WorldWidth + 1024), rand.Next(-800, 0));
                    Vector2 velocity = new Vector2(5 + rand.Next(0, 15), 0);

                    client.SendMessage("action=createother;gotype=" + (int)RaginRovers.GameObjectTypes.CLOUD1 + rand.Next(0, 5) + ";textureassetname=clouds;location.x=" + v.X + ";location.y=" + v.Y + ";rotation=0;upperBounds=0;lowerBounds=0;velocity.x=" + velocity.X + ";velocity.y=" + velocity.Y);
    
                    
                    int cloud = factory.Create(
                             (int)RaginRovers.GameObjectTypes.CLOUD1 + rand.Next(0, 5),
                             new Vector2(
                                 rand.Next(-1024, GameWorld.WorldWidth + 1024),
                                 rand.Next(-800, 0)),
                             "clouds",
                             new Vector2(5 + rand.Next(0, 15), 0),
                             0,
                             0f,
                             0f, 100);

                    clouds.Add(
                                    cloud
                        );

                    factory.Objects[cloud].saveable = false;
                  
                }
            }  */
        }
Exemple #10
0
 public PlaneManager()
 {
     factory = GameObjectFactory.Instance;
 }
        public GameObjectFactory CreateCannonStuff(GameObjectFactory factory, Vector2 location, Camera camera, bool isReversed, ref List <CannonGroups> cannonGroups)
        {
            int icannon;

            if (!isReversed)
            {
                icannon = factory.Create(
                    (int)RaginRovers.GameObjectTypes.CANNON,
                    new Vector2((int)location.X - 95, (int)location.Y - 80),
                    "spritesheet",
                    new Vector2(0, 0),
                    0,
                    -MathHelper.PiOver2,
                    0,
                    32);
            }
            else
            {
                icannon = factory.Create((int)RaginRovers.GameObjectTypes.CANNON, new Vector2(location.X - 95, location.Y - 80), "spritesheet", new Vector2(0, 0), -MathHelper.Pi, -MathHelper.Pi, -MathHelper.PiOver2, 32);
            }

            //factory.Objects[icannon].sprite.Origin = new Vector2(120, 103);
            factory.Objects[icannon].sprite.Origin = new Vector2((factory.Objects[icannon].sprite.BoundingBoxRect.Width / 2) - 40, factory.Objects[icannon].sprite.BoundingBoxRect.Height / 2);

            int iwheel = factory.Create(
                (int)RaginRovers.GameObjectTypes.CANNONWHEEL,
                //new Vector2((int)location.X  - 30, (int)location.Y - 120),
                factory.Objects[icannon].sprite.Origin,
                "spritesheet",
                new Vector2(0, 0),
                0,
                0f,
                0f, 31);
            int ibar = factory.Create(
                (int)RaginRovers.GameObjectTypes.POWERMETERBAR,
                new Vector2(
                    factory.Objects[icannon].sprite.Location.X,
                    factory.Objects[icannon].sprite.Location.Y + factory.Objects[icannon].sprite.BoundingBoxRect.Height + 50),
                "background",
                new Vector2(0, 0),
                0,
                0f,
                0f, 30);
            int itab = factory.Create(
                (int)RaginRovers.GameObjectTypes.POWERMETERTAB,
                new Vector2(
                    factory.Objects[ibar].sprite.Location.X,
                    factory.Objects[ibar].sprite.Location.Y + factory.Objects[ibar].sprite.Origin.Y),
                "background",
                new Vector2(0, 0),
                0,
                0f,
                0f, 30);

            //had to put after because cant access origin before sprite is created
            factory.Objects[itab].sprite.Location -= new Vector2(0, factory.Objects[itab].sprite.Origin.Y);


            //putting them all in a group
            //factory.Objects[icannon].sprite.groupNumber = groupNumber;
            //factory.Objects[iwheel].sprite.groupNumber = groupNumber;
            //factory.Objects[ibar].sprite.groupNumber = groupNumber;
            //factory.Objects[itab].sprite.groupNumber = groupNumber;

            //Sprite cannon = factory.Objects[icannon].sprite;
            //Sprite wheel = factory.Objects[iwheel].sprite;//boom

            int boom = factory.Create(
                (int)RaginRovers.GameObjectTypes.BOOM,
                factory.Objects[icannon].sprite.Location,
                "boom",
                Vector2.Zero,
                factory.Objects[icannon].sprite.Rotation,
                0,
                0, 5);

            factory.Objects[icannon].saveable = false;
            factory.Objects[iwheel].saveable  = false;
            factory.Objects[itab].saveable    = false;
            factory.Objects[ibar].saveable    = false;
            factory.Objects[boom].saveable    = false;


            //changing location so that origins equal
            factory.Objects[boom].sprite.Location += factory.Objects[icannon].sprite.Origin - factory.Objects[boom].sprite.Origin;

            factory.Objects[boom].sprite.Scale = 2.0f;
            if (isReversed)
            {
                factory.Objects[boom].sprite.flipType = Sprite.FlipType.BOTH;
            }
            factory.Objects[boom].sprite.Dead = true;


            cannonGroups.Add(new CannonGroups(icannon, iwheel, ibar, itab, boom, isReversed));

            factory.Objects[iwheel].sprite.Location = factory.Objects[icannon].sprite.Location + factory.Objects[icannon].sprite.Origin - new Vector2(109 - 20, 113); // factory.Objects[iwheel].sprite.Origin;
            //groupNumber++;
            return(factory);
        }
Exemple #12
0
        public void Update(GameTime gameTime, Camera camera)
        {
            KeyboardState kb = Keyboard.GetState();
            MouseState msState = Mouse.GetState();

            Vector2 ms = Vector2.Transform(new Vector2(msState.X, msState.Y), Matrix.Invert(camera.GetViewMatrix(Vector2.One)));
            window.Title = "Local Mouse> X: " + msState.X + " Y: " + msState.Y + ", World Mouse> X: " + ms.X + ", Y: " + ms.Y + ", Zoom: " + camera.Zoom;

            DetectKeyPress(kb, Keys.OemTilde);
            DetectKeyPress(kb, Keys.D1);  // Record if this key is pressed
            DetectKeyPress(kb, Keys.D2);  // Record if this key is pressed
            DetectKeyPress(kb, Keys.D3);
            DetectKeyPress(kb, Keys.D4);
            DetectKeyPress(kb, Keys.D5);
            DetectKeyPress(kb, Keys.D6);
            DetectKeyPress(kb, Keys.D7);
            DetectKeyPress(kb, Keys.D8);
            DetectKeyPress(kb, Keys.D9);
            DetectKeyPress(kb, Keys.D0);
            DetectKeyPress(kb, Keys.P);
            DetectKeyPress(kb, Keys.R);
            DetectKeyPress(kb, Keys.B);
            DetectKeyPress(kb, Keys.Delete);
            DetectKeyPress(kb, Keys.M);
            DetectKeyPress(kb, Keys.L);
            DetectKeyPress(kb, Keys.U);
            DetectKeyPress(kb, Keys.Enter);
            DetectKeyPress(kb, Keys.Space);
            DetectKeyPress(kb, Keys.N);
            DetectKeyPress(kb, Keys.J);
            DetectKeyPress(kb, Keys.Q);


            if (KeyDown)
            {
                if (kb.IsKeyUp(Key))
                {
                    switch (Key)
                    {
                        ////////////////////////////////////////////////////
                        case Keys.Space:
                            if (!EditMode)
                            { 
                                //probably will get annoying when working on project and testing bugs
                                if (screenconfiguration == 1) // put in "|| screenconfiguration == 2" to test stuff
                                {
                                    cannonManager.ChangeCannonState(cannonGroups[1]);

                                    if (cannonGroups[1].cannonState == CannonState.WAITING)
                                    {
                                        client.SendMessage("action=shoot;cannonGroup=1;rotation=" + cannonGroups[1].Rotation + ";power=" + cannonGroups[1].Power + ";Screen=" + Game1.ScreenConfiguration);
                                        SunManager.Instance.Mood = SunMood.OPENSMILE;
                                        camera.Shake(10, 1);
                                    }
                                }
                                if (screenconfiguration == 3)
                                {
                                    cannonManager.ChangeCannonState(cannonGroups[0]);

                                    if (cannonGroups[0].cannonState == CannonState.WAITING)
                                    {
                                        client.SendMessage("action=shoot;cannonGroup=0;rotation=" + cannonGroups[0].Rotation + ";power=" + cannonGroups[0].Power + ";Screen=" + Game1.ScreenConfiguration);
                                        SunManager.Instance.Mood = SunMood.OPENSMILE;
                                        camera.Shake(10, 1);
                                    }
                                }
                                
                            }
                            break;

                            /*
                        case Keys.OemTilde:
                            if (screenconfiguration == 2)
                                EditMode = !EditMode;
                            //camera.Zoom = 1f;
                            
                            //window.Title = "Ragin Rovers " + (EditMode ? " | EDITING MODE" : "");
                            break;

                        case Keys.Q:

                            if (EditMode && screenconfiguration == 2)
                            {
                                int puff = factory.Create((int)GameObjectTypes.PUFF, new Vector2((int)ms.X /*+ camera.Position.X*/// - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                              /*  factory.Objects[puff].sprite.PhysicsBody.Mass = 30;
                                factory.Objects[puff].sprite.PhysicsBody.Restitution = 0.4f;
                                factory.Objects[puff].saveable = false;
                            }

                            break;*/
                        
                        case Keys.D1:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                int dog = factory.Create((int)GameObjectTypes.DOG, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                                factory.Objects[dog].sprite.PhysicsBody.Mass = 30;
                                factory.Objects[dog].sprite.PhysicsBody.Restitution = 0.4f;
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 1);
                                LoadPlanesandClouds();
                            }

                            break;

                        case Keys.D2:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                int cat = factory.Create((int)GameObjectTypes.CAT, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                                factory.Objects[cat].sprite.PhysicsBody.Mass = 30;
                                factory.Objects[cat].sprite.PhysicsBody.Restitution = 0.8f;
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 2);

                                LoadPlanesandClouds();
                            }
                            break;

                        case Keys.D3:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD1, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);

                                factory.Objects[board].sprite.OnCollision += new OnCollisionEventHandler(CollisionEvents.wood_OnCollision);
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 3);

                                LoadPlanesandClouds();
                            }

                            break;

                        case Keys.D4:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD2, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                                factory.Objects[board].sprite.OnCollision += new OnCollisionEventHandler(CollisionEvents.wood_OnCollision);
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 4);

                                LoadPlanesandClouds();
                            }

                            break;

                        case Keys.D5:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD3, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                                factory.Objects[board].sprite.OnCollision += new OnCollisionEventHandler(CollisionEvents.wood_OnCollision);
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 5);

                                LoadPlanesandClouds();
                            }

                            break;

                        case Keys.D6:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD4, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                                factory.Objects[board].sprite.OnCollision += new OnCollisionEventHandler(CollisionEvents.wood_OnCollision);
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 6);

                                LoadPlanesandClouds();
                            }

                            break;

                        case Keys.D7:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                factory.Create((int)GameObjectTypes.PLATFORM_LEFT, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 7);

                                LoadPlanesandClouds();
                            }

                            break;

                        case Keys.D8:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                factory.Create((int)GameObjectTypes.PLATFORM_MIDDLE, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 8);

                                LoadPlanesandClouds();
                            }

                            break;

                        case Keys.D9:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                factory.Create((int)GameObjectTypes.PLATFORM_RIGHT, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 0);

                                LoadPlanesandClouds();
                            }

                            break;
                        case Keys.D0:

                            if (screenconfiguration != 2 && EditMode)
                            {
                                factory = cannonManager.CreateCannonStuff(factory, new Vector2(ms.X /*+ camera.Position.X*/ - 95, ms.Y - 80), camera, false, ref cannonGroups);

                            }
                            if (screenconfiguration == 2)
                            {
                                client.SendMessage("action=reset;map=" + 0);

                                LoadPlanesandClouds();
                            }

                            break;


                        /*case Keys.P:

                            if (EditMode && screenconfiguration == 2)
                            {
                                factory = cannonManager.CreateCannonStuff(factory, new Vector2(ms.X, ms.Y), camera, true, ref cannonGroups);

                            }

                            break;
                        case Keys.J:
                            if (screenconfiguration == 2)
                            {
                                cannonManager.CreateCannonStuff(factory, new Vector2(0, 500), camera, true, ref cannonGroups); //need how to figure out location
                                cannonManager.CreateCannonStuff(factory, new Vector2(500, 500), camera, false, ref cannonGroups); //need how to figure out location
                            }
                            break;

                        case Keys.B:
                                int boom = factory.Create((int)GameObjectTypes.BOOM, new Vector2((int)ms.X + camera.Position.X - 95, (int)ms.Y - 80), "boom", new Vector2(0, 0), 0, 0f, 0f);

                            break;

                        case Keys.R:

                            if (EditMode && MouseDown && DragSprite != -1)
                            {
                                if (factory.Objects[DragSprite].sprite.Rotation == 0)
                                    factory.Objects[DragSprite].sprite.Rotation = MathHelper.PiOver2;
                                else
                                    factory.Objects[DragSprite].sprite.Rotation = 0;
                            }

                            break;
                            
                        case Keys.Delete:

                            if (EditMode && MouseDown && DragSprite != -1)
                            {
                                factory.Remove(DragSprite);
                                DragSprite = -1;
                            }

                            break;
                        case Keys.L:
                            if (screenconfiguration == 2)
                            {
                                

                            }

                            break;
                            */

                            //done with saving maps for now
                        /*case Keys.M:

                            string objlist = factory.Serialize();

                            using (StreamWriter outfile = new StreamWriter(@"map.txt"))
                            {
                                outfile.Write(objlist);
                            }

                            break;*/
                    }

                    KeyDown = false;
                    Key = Keys.None;
                }
            }

            if (!EditMode)
            {
                for (int i = 0; i < cannonGroups.Count; i++)
                {
                    factory = cannonManager.ManipulateCannons(factory, cannonGroups[i]);
                }
            }

            cannonManager.Update(gameTime, factory, cannonGroups);

            if (EditMode)
            {
                if (msState.LeftButton == ButtonState.Pressed && !MouseDown)
                {
                    MouseDown = true;

                    foreach (int key in factory.Objects.Keys)
                    {
                        Sprite sprite = factory.Objects[key].sprite;
                        if (sprite.IsBoxColliding(new Rectangle((int)ms.X /*+ (int)camera.Position.X*/, (int)ms.Y, 1, 1)))
                        {
                            DragSprite = key;
                            DragOffset = new Vector2(ms.X, ms.Y) - sprite.Location;
                        }
                    }
                }

                if (MouseDown && DragSprite != -1)
                {
                    factory.Objects[DragSprite].sprite.Location = new Vector2(ms.X, ms.Y) - DragOffset;
                }

                if (msState.LeftButton == ButtonState.Released)
                {
                    MouseDown = false;
                    DragSprite = -1;
                }
            }
        }
 public void Update(GameTime gameTime, GameObjectFactory factory, List<CannonGroups> cannonGroup)
 {
     for (int i = 0; i < cannonGroup.Count; i++)
     {
         if (factory.Objects[cannonGroup[i].boomKey].sprite.Frame == 12)
         {
             factory.Objects[cannonGroup[i].boomKey].sprite.Dead = true;
             
             factory.Objects[cannonGroup[i].boomKey].sprite.Frame = 0;
         }
     }
 }
Exemple #14
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            GameWorld.Initialize(0, 12234 - ( 1080 * 2), this.Window.ClientBounds.Width, this.Window.ClientBounds.Height, new Vector2(0, 9.8f));
            GameWorld.ViewPortXOffset = 0;

            SpriteCreators.Load("Content\\spritesheet.txt");

            MapLoaded = false;

            // Create the texture manager
            textureManager = new TextureManager(Content);

            //Create the audio manager
            AudioManager.Instance.Initialize(Content);


            // Now load the sprite creator factory helper
            factory = GameObjectFactory.Instance;
            factory.Initialize(textureManager);

            cannonManager = new CannonManager();
            cannonGroups = new List<CannonGroups>();


            client = new ClientNetworking();
            client.Connect();
            client.ActionHandler["shoot"] = new EventHandler(this.HandleNetworkShoot);
            client.ActionHandler["create"] = new EventHandler(this.HandleNetworkCreate);
            client.ActionHandler["plane"] = new EventHandler(this.HandleNetworkPlane);
            client.ActionHandler["createother"] = new EventHandler(this.HandleNetworkCreateOtherStuff);
            client.ActionHandler["reset"] = new EventHandler(this.HandleReset);
            client.ActionHandler["endgame"] = new EventHandler(this.HandleEndGame);
            client.ActionHandler["sendpoints"] = new EventHandler(this.HandleSendPoints);

            // Add a few sprite creators
            factory.AddCreator((int)GameObjectTypes.CAT, SpriteCreators.CreateCat);
            factory.AddCreator((int)GameObjectTypes.DOG, SpriteCreators.CreateDog);
            factory.AddCreator((int)GameObjectTypes.SUN, SpriteCreators.CreateSun);
            factory.AddCreator((int)GameObjectTypes.BOOM, SpriteCreators.CreateBoom);
            factory.AddCreator((int)GameObjectTypes.PUFF, SpriteCreators.CreatePuff);
            factory.AddCreator((int)GameObjectTypes.DINO, SpriteCreators.CreateDino);
            factory.AddCreator((int)GameObjectTypes.CLOUD1, SpriteCreators.CreateCloud1);
            factory.AddCreator((int)GameObjectTypes.CLOUD2, SpriteCreators.CreateCloud2);
            factory.AddCreator((int)GameObjectTypes.CLOUD3, SpriteCreators.CreateCloud3);
            factory.AddCreator((int)GameObjectTypes.CLOUD4, SpriteCreators.CreateCloud4);
            factory.AddCreator((int)GameObjectTypes.CLOUD5, SpriteCreators.CreateCloud5);
            factory.AddCreator((int)GameObjectTypes.CLOUD6, SpriteCreators.CreateCloud6);
            factory.AddCreator((int)GameObjectTypes.WOOD1, SpriteCreators.CreateWood1);
            factory.AddCreator((int)GameObjectTypes.WOOD2, SpriteCreators.CreateWood2);
            factory.AddCreator((int)GameObjectTypes.WOOD3, SpriteCreators.CreateWood3);
            factory.AddCreator((int)GameObjectTypes.WOOD4, SpriteCreators.CreateWood4);
            factory.AddCreator((int)GameObjectTypes.PLATFORM_LEFT, SpriteCreators.CreatePlatformLeft);
            factory.AddCreator((int)GameObjectTypes.PLATFORM_MIDDLE, SpriteCreators.CreatePlatformMiddle);
            factory.AddCreator((int)GameObjectTypes.PLATFORM_RIGHT, SpriteCreators.CreatePlatformRight);
            factory.AddCreator((int)GameObjectTypes.CANNON, SpriteCreators.CreateCannon);
            factory.AddCreator((int)GameObjectTypes.CANNONWHEEL, SpriteCreators.CreateCannonWheel);
            factory.AddCreator((int)GameObjectTypes.POWERMETERBAR, SpriteCreators.CreatePowerMeterBar);
            factory.AddCreator((int)GameObjectTypes.POWERMETERTAB, SpriteCreators.CreatePowerMeterTab);
            factory.AddCreator((int)GameObjectTypes.EXPLOSION1, SpriteCreators.CreateExplosion1);
            factory.AddCreator((int)GameObjectTypes.EXPLOSION1, SpriteCreators.CreateExplosion2);
            factory.AddCreator((int)GameObjectTypes.PLANE, SpriteCreators.CreatePlane);
            factory.AddCreator((int)GameObjectTypes.CATSPLODE, SpriteCreators.CreateCatsplode);
            factory.AddCreator((int)GameObjectTypes.DUSTSPLODE, SpriteCreators.CreateDustsplode);
            factory.AddCreator((int)GameObjectTypes.YOULOSE, SpriteCreators.CreateYouLose);
            factory.AddCreator((int)GameObjectTypes.YOUWIN, SpriteCreators.CreateYouWin);
            factory.AddCreator((int)GameObjectTypes.SCOREPLUS50, SpriteCreators.CreatePlus50);
            factory.AddCreator((int)GameObjectTypes.SCOREPLUS100, SpriteCreators.CreatePlus100);
            factory.AddCreator((int)GameObjectTypes.SCOREPLUS250, SpriteCreators.CreatePlus250);

            //factory.AddCreator((int)GameObjectTypes.EAHSCSLOGO, SpriteCreators.CreateEAHSCSLogo);

            mapEditor = new MapEditor(Window, client, cannonManager, cannonGroups, ScreenConfiguration);

            base.Initialize();
        }
        public GameObjectFactory CreateCannonStuff(GameObjectFactory factory, Vector2 location, Camera camera, bool isReversed, ref List<CannonGroups> cannonGroups)
        {
            int icannon;
            if (!isReversed)
            {
                icannon = factory.Create(
                                        (int)RaginRovers.GameObjectTypes.CANNON,
                                        new Vector2((int)location.X, (int)location.Y),
                                        "spritesheet",
                                        new Vector2(0, 0),
                                        0,
                                        -MathHelper.PiOver2,
                                        0,
                                        32);
            }
            else
            {
                icannon = factory.Create((int)RaginRovers.GameObjectTypes.CANNON, new Vector2(location.X - 20, location.Y - 20), "spritesheet", new Vector2(0, 0), -MathHelper.Pi, -MathHelper.Pi, -MathHelper.PiOver2, 32);
            }
            factory.Objects[icannon].sprite.Location -= new Vector2(0, factory.Objects[icannon].sprite.BoundingBoxRect.Height);

            //factory.Objects[icannon].sprite.Origin = new Vector2(120, 103);
            factory.Objects[icannon].sprite.Origin = new Vector2((factory.Objects[icannon].sprite.BoundingBoxRect.Width / 2) - 40, factory.Objects[icannon].sprite.BoundingBoxRect.Height / 2);

            int iwheel = factory.Create(
                (int)RaginRovers.GameObjectTypes.CANNONWHEEL,
                //new Vector2((int)location.X  - 30, (int)location.Y - 120),
                factory.Objects[icannon].sprite.Origin,
                "spritesheet",
                new Vector2(0, 0),
                0,
                0f,
                0f, 31);
            int ibar = factory.Create(
                 (int)RaginRovers.GameObjectTypes.POWERMETERBAR,
                 new Vector2(
                     factory.Objects[icannon].sprite.Location.X,
                     factory.Objects[icannon].sprite.Location.Y + factory.Objects[icannon].sprite.BoundingBoxRect.Height + 20),
                 "spritesheet",
                 new Vector2(0, 0),
                 isReversed ? -MathHelper.Pi: 0,
                 0f,
                 0f, 30);       
            int itab = factory.Create(
                 (int)RaginRovers.GameObjectTypes.POWERMETERTAB,
                 new Vector2(
                     factory.Objects[ibar].sprite.Location.X,
                     factory.Objects[ibar].sprite.Location.Y + factory.Objects[ibar].sprite.Origin.Y),
                 "spritesheet",
                 new Vector2(0, 0),
                 0,
                 0f,
                 0f, 30);
            //had to put after because cant access origin before sprite is created
            factory.Objects[itab].sprite.Location -= new Vector2(0, factory.Objects[itab].sprite.Origin.Y);


            //putting them all in a group
            //factory.Objects[icannon].sprite.groupNumber = groupNumber;
            //factory.Objects[iwheel].sprite.groupNumber = groupNumber;
            //factory.Objects[ibar].sprite.groupNumber = groupNumber;
            //factory.Objects[itab].sprite.groupNumber = groupNumber;

            //Sprite cannon = factory.Objects[icannon].sprite;
            //Sprite wheel = factory.Objects[iwheel].sprite;//boom

            int boom = factory.Create(
                (int)RaginRovers.GameObjectTypes.BOOM,
                factory.Objects[icannon].sprite.Location,
                "boom",
                Vector2.Zero,
                factory.Objects[icannon].sprite.Rotation,
                0,
                0, 5);

            factory.Objects[icannon].saveable = false;
            factory.Objects[iwheel].saveable = false;
            factory.Objects[itab].saveable = false;
            factory.Objects[ibar].saveable = false;
            factory.Objects[boom].saveable = false;


            //changing location so that origins equal
            factory.Objects[boom].sprite.Location += factory.Objects[icannon].sprite.Origin - factory.Objects[boom].sprite.Origin;

            factory.Objects[boom].sprite.Scale = 2.0f;
            if (isReversed)
                factory.Objects[boom].sprite.flipType = Sprite.FlipType.BOTH;
            factory.Objects[boom].sprite.Dead = true;


            cannonGroups.Add(new CannonGroups(icannon, iwheel, ibar, itab, boom, isReversed));

            factory.Objects[iwheel].sprite.Location = factory.Objects[icannon].sprite.Location + factory.Objects[icannon].sprite.Origin - new Vector2(109-20, 113); // factory.Objects[iwheel].sprite.Origin;
            //groupNumber++;
            return factory;
        }
        public GameObjectFactory ShootDoggy(GameObjectFactory factory, CannonGroups cannonGroup)
        {
            List<int> temp = new List<int>();
            //figure out which cannon to shoot from
            //replace once just pass which cannon
            //endreplace

            

                //dog
                int dog = factory.Create(
                    (int)RaginRovers.GameObjectTypes.DOG,
                    factory.Objects[cannonGroup.cannonKey].sprite.Location + new Vector2(30, 0),
                    "spritesheet",
                    Vector2.Zero,
                    cannonGroup.Rotation,
                    0,
                    0);

                factory.Objects[dog].sprite.OnCollision += new OnCollisionEventHandler(CollisionEvents.dog_OnCollision);

                if (factory.Objects[cannonGroup.cannonKey].sprite.Location.X > 6000)
                    factory.Objects[dog].sprite.PlayerNumber = 2; 
                if (factory.Objects[cannonGroup.cannonKey].sprite.Location.X < 6000)
                    factory.Objects[dog].sprite.PlayerNumber = 1;

                if (cannonGroup.isFlipped)
                {
                    factory.Objects[dog].sprite.flipType  = Sprite.FlipType.VERTICAL;
                }

                factory.Objects[dog].sprite.PhysicsBody.LinearVelocity = new Vector2(
                        cannonPower * (float)Math.Cos((double)cannonGroup.Rotation),
                        cannonPower * (float)Math.Sin((double)cannonGroup.Rotation));

                //chaning magnitude depending on power bar
                factory.Objects[dog].sprite.PhysicsBody.LinearVelocity *= cannonGroup.Power; // ((factory.Objects[cannonGroup.tabKey].sprite.Location.X - factory.Objects[cannonGroup.barKey].sprite.Location.X) / factory.Objects[cannonGroup.barKey].sprite.BoundingBoxRect.Width) + 1;

                factory.Objects[cannonGroup.boomKey].sprite.Dead = false;
                cannonGroup.boomTime = 0f;

                factory.Objects[dog].sprite.PhysicsBody.Mass = 30;
                factory.Objects[dog].sprite.PhysicsBody.Restitution = 0.4f;

                //factory.Objects[cannonGroup.boomKey].sprite.Rotation = factory.Objects[cannonGroup.cannonKey].sprite.Rotation;
                factory.Objects[cannonGroup.boomKey].sprite.Location = factory.Objects[cannonGroup.cannonKey].sprite.Location - factory.Objects[cannonGroup.boomKey].sprite.Origin + new Vector2(0, -150) + factory.Objects[dog].sprite.PhysicsBody.LinearVelocity / factory.Objects[dog].sprite.PhysicsBody.LinearVelocity.Length() * 200;
                

            return factory;
        }
Exemple #17
0
        public void Update(GameTime gameTime, Camera camera)
        {
            KeyboardState kb = Keyboard.GetState();
            MouseState msState = Mouse.GetState();

            Vector2 ms = Vector2.Transform(new Vector2(msState.X, msState.Y), Matrix.Invert(camera.GetViewMatrix(Vector2.One)));
            window.Title = "Local Mouse> X: " + msState.X + " Y: " + msState.Y + ", World Mouse> X: " + ms.X + " Y: " + ms.Y;

            DetectKeyPress(kb, Keys.OemTilde);
            DetectKeyPress(kb, Keys.D1);  // Record if this key is pressed
            DetectKeyPress(kb, Keys.D2);  // Record if this key is pressed
            DetectKeyPress(kb, Keys.D3);
            DetectKeyPress(kb, Keys.D4);
            DetectKeyPress(kb, Keys.D5);
            DetectKeyPress(kb, Keys.D6);
            DetectKeyPress(kb, Keys.D7);
            DetectKeyPress(kb, Keys.D8);
            DetectKeyPress(kb, Keys.D9);
            DetectKeyPress(kb, Keys.D0);
            DetectKeyPress(kb, Keys.P);
            DetectKeyPress(kb, Keys.R);
            DetectKeyPress(kb, Keys.B);
            DetectKeyPress(kb, Keys.Delete);
            DetectKeyPress(kb, Keys.M);
            DetectKeyPress(kb, Keys.L);
            DetectKeyPress(kb, Keys.Enter);
            DetectKeyPress(kb, Keys.Space);
            DetectKeyPress(kb, Keys.N);
            DetectKeyPress(kb, Keys.J);

            if (KeyDown)
            {
                if (kb.IsKeyUp(Key))
                {
                    switch (Key)
                    {
                        case Keys.Enter:

                            foreach (int i in factory.Objects.Keys)
                            {
                                if (factory.Objects[i].typeid == (int)GameObjectTypes.DOG)
                                    factory.Objects[i].sprite.PhysicsBody.ApplyLinearImpulse(new Vector2(60, 40));
                            }

                            break;
                        ////////////////////////////////////////////////////
                        case Keys.Space:
                            if (!EditMode)
                            {
                                cannonManager.ChangeCannonState(cannonGroups[0]);

                                if (cannonGroups[0].cannonState == CannonState.WAITING)
                                {
                                    client.SendMessage("action=shoot;cannonGroup=0;rotation=" + cannonGroups[0].Rotation + ";power=" + cannonGroups[0].Power);

                                }
                            }
                            break;

                        case Keys.N:
                            if (!EditMode)
                            {
                                cannonManager.ChangeCannonState(cannonGroups[1]);

                                if (cannonGroups[1].cannonState == CannonState.WAITING)
                                {
                                    client.SendMessage("action=shoot;cannonGroup=1;rotation=" + cannonGroups[1].Rotation + ";power=" + cannonGroups[1].Power);
                                }
                            }
                            break;

                        case Keys.OemTilde:
                            EditMode = !EditMode;
                            //camera.Zoom = 1f;

                            window.Title = "Ragin Rovers " + (EditMode ? " | EDITING MODE" : "");
                            break;

                        case Keys.D1:

                            if (EditMode)
                            {
                                int dog = factory.Create((int)GameObjectTypes.DOG, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                                factory.Objects[dog].sprite.PhysicsBody.Mass = 30;
                                factory.Objects[dog].sprite.PhysicsBody.Restitution = 0.4f;
                            }

                            break;

                        case Keys.D2:

                            if (EditMode)
                            {
                                int cat = factory.Create((int)GameObjectTypes.CAT, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                                factory.Objects[cat].sprite.PhysicsBody.Mass = 30;
                                factory.Objects[cat].sprite.PhysicsBody.Restitution = 0.8f;
                            }

                            break;

                        case Keys.D3:

                            if (EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD1, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }

                            break;

                        case Keys.D4:

                            if (EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD2, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }

                            break;

                        case Keys.D5:

                            if (EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD3, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }

                            break;

                        case Keys.D6:

                            if (EditMode)
                            {
                                int board = factory.Create((int)GameObjectTypes.WOOD4, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }

                            break;

                        case Keys.D7:

                            if (EditMode)
                            {
                                factory.Create((int)GameObjectTypes.PLATFORM_LEFT, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }

                            break;

                        case Keys.D8:

                            if (EditMode)
                            {
                                factory.Create((int)GameObjectTypes.PLATFORM_MIDDLE, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }

                            break;

                        case Keys.D9:

                            if (EditMode)
                            {
                                factory.Create((int)GameObjectTypes.PLATFORM_RIGHT, new Vector2((int)ms.X /*+ camera.Position.X*/ - 95, (int)ms.Y - 80), "spritesheet", new Vector2(0, 0), 0, 0f, 0f);
                            }

                            break;
                        case Keys.D0:

                            if (EditMode)
                            {
                                factory = cannonManager.CreateCannonStuff(factory, new Vector2(ms.X /*+ camera.Position.X*/ - 95, ms.Y - 80), camera, false, ref cannonGroups);

                            }

                            break;

                        case Keys.P:

                            if (EditMode)
                            {
                                factory = cannonManager.CreateCannonStuff(factory, new Vector2(ms.X, ms.Y), camera, true, ref cannonGroups);

                            }

                            break;
                        case Keys.J:

                            cannonManager.CreateCannonStuff(factory, new Vector2(0, 500), camera, true, ref cannonGroups); //need how to figure out location
                            cannonManager.CreateCannonStuff(factory, new Vector2(500, 500), camera, false, ref cannonGroups); //need how to figure out location
                            break;

                        case Keys.B:

                            int boom = factory.Create((int)GameObjectTypes.BOOM, new Vector2((int)ms.X + camera.Position.X - 95, (int)ms.Y - 80), "boom", new Vector2(0, 0), 0, 0f, 0f);

                            break;

                        case Keys.R:

                            if (EditMode && MouseDown && DragSprite != -1)
                            {
                                if (factory.Objects[DragSprite].sprite.Rotation == 0)
                                    factory.Objects[DragSprite].sprite.Rotation = MathHelper.PiOver2;
                                else
                                    factory.Objects[DragSprite].sprite.Rotation = 0;
                            }

                            break;

                        case Keys.Delete:

                            if (EditMode && MouseDown && DragSprite != -1)
                            {
                                factory.Remove(DragSprite);
                                DragSprite = -1;
                            }

                            break;

                        case Keys.L:

                            using (StreamReader infile = new StreamReader("map.txt"))
                            {
                                string objs = infile.ReadToEnd();
                                string[] lines = objs.Split('\n');

                                for (int i = 0; i < lines.Length; i++)
                                {
                                    if (lines[i].Length > 0)
                                    {
                                        string[] fields = lines[i].Split('\t');

                                        client.SendMessage("action=create;gotype=" + Convert.ToInt32(fields[1]) + ";textureassetname=" + fields[4] + ";location.x=" + (float)Convert.ToDouble(fields[2]) + ";location.y=" + (float)Convert.ToDouble(fields[3]) + ";rotation=" + (float)Convert.ToDouble(fields[5]) + ";upperBounds=" + 0f + ";lowerBounds=" + 0f);

                                        /*
                                        factory.Create(Convert.ToInt32(fields[1]),
                                                       new Vector2((float)Convert.ToDouble(fields[2]), (float)Convert.ToDouble(fields[3])),
                                                       fields[4],
                                                       Vector2.Zero,
                                                       (float)Convert.ToDouble(fields[5]),
                                                       0f,
                                                       0f);
                                        */
                                    }
                                }
                            }

                            break;

                        case Keys.M:

                            string objlist = factory.Serialize();

                            using (StreamWriter outfile = new StreamWriter(@"map.txt"))
                            {
                                outfile.Write(objlist);
                            }

                            break;
                    }

                    KeyDown = false;
                    Key = Keys.None;
                }
            }

            if (!EditMode)
            {
                for (int i = 0; i < cannonGroups.Count; i++)
                {
                    factory = cannonManager.ManipulateCannons(factory, cannonGroups[i]);
                }
            }

            cannonManager.Update(gameTime, factory, cannonGroups);

            if (EditMode)
            {
                if (msState.LeftButton == ButtonState.Pressed && !MouseDown)
                {
                    MouseDown = true;

                    foreach (int key in factory.Objects.Keys)
                    {
                        Sprite sprite = factory.Objects[key].sprite;
                        if (sprite.IsBoxColliding(new Rectangle((int)ms.X /*+ (int)camera.Position.X*/, (int)ms.Y, 1, 1)))
                        {
                            DragSprite = key;
                            DragOffset = new Vector2(ms.X, ms.Y) - sprite.Location;
                        }
                    }
                }

                if (MouseDown && DragSprite != -1)
                {
                    factory.Objects[DragSprite].sprite.Location = new Vector2(ms.X, ms.Y) - DragOffset;
                }

                if (msState.LeftButton == ButtonState.Released)
                {
                    MouseDown = false;
                    DragSprite = -1;
                }
            }
        }
Exemple #18
0
 private SpriteHelper ()
 {
     items = new List<TimedItem>();
     factory = GameObjectFactory.Instance;
 }
Exemple #19
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            GameWorld.Initialize(0, 5700, this.Window.ClientBounds.Width, this.Window.ClientBounds.Height, new Vector2(0, 9.8f));
            GameWorld.ViewPortXOffset = 0;

            SpriteCreators.Load("Content\\spritesheet.txt");

            // Create the texture manager
            textureManager = new TextureManager(Content);

            // Now load the sprite creator factory helper
            factory = GameObjectFactory.Instance;
            factory.Initialize(textureManager);

            cannonManager = new CannonManager();
            cannonGroups = new List<CannonGroups>();

            client = new ClientNetworking();
            client.Connect();
            client.ActionHandler["shoot"] = new EventHandler(this.HandleNetworkShoot);
            client.ActionHandler["create"] = new EventHandler(this.HandleNetworkCreate);

            // Add a few sprite creators
            factory.AddCreator((int)GameObjectTypes.CAT, SpriteCreators.CreateCat);
            factory.AddCreator((int)GameObjectTypes.DOG, SpriteCreators.CreateDog);
            factory.AddCreator((int)GameObjectTypes.BOOM, SpriteCreators.CreateBoom);
            factory.AddCreator((int)GameObjectTypes.WOOD1, SpriteCreators.CreateWood1);
            factory.AddCreator((int)GameObjectTypes.WOOD2, SpriteCreators.CreateWood2);
            factory.AddCreator((int)GameObjectTypes.WOOD3, SpriteCreators.CreateWood3);
            factory.AddCreator((int)GameObjectTypes.WOOD4, SpriteCreators.CreateWood4);
            factory.AddCreator((int)GameObjectTypes.PLATFORM_LEFT, SpriteCreators.CreatePlatformLeft);
            factory.AddCreator((int)GameObjectTypes.PLATFORM_MIDDLE, SpriteCreators.CreatePlatformMiddle);
            factory.AddCreator((int)GameObjectTypes.PLATFORM_RIGHT, SpriteCreators.CreatePlatformRight);
            factory.AddCreator((int)GameObjectTypes.CANNON, SpriteCreators.CreateCannon);
            factory.AddCreator((int)GameObjectTypes.CANNONWHEEL, SpriteCreators.CreateCannonWheel);
            factory.AddCreator((int)GameObjectTypes.POWERMETERBAR, SpriteCreators.CreatePowerMeterBar);
            factory.AddCreator((int)GameObjectTypes.POWERMETERTAB, SpriteCreators.CreatePowerMeterTab);

            mapEditor = new MapEditor(Window, client, cannonManager, cannonGroups);

            base.Initialize();
        }