Example #1
0
File: Main.cs Project: fiahil/Zappy
 public Main()
 {
     this.time = TimeSpan.Zero;
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     this.map = new Map(this);
     this.Components.Add(this.map);
     #if WINDOWS
     server = new Network();
     #endif
     this.plist = new List<Player>();
     this.elist = new List<Egg>();
     this.tlist = new List<string>();
     this.lbc = new Queue<string>();
     this.screen = new Rectangle(0, 0, 1280, 720);
     this.inventory_details = null;
     this.inventory_timer = TimeSpan.Zero;
     this.dot = new Vector2(640, 360);
     this.followed = null;
     this.followedId = 0;
     this.oldState = Keyboard.GetState();
     this.oldStick = GamePad.GetState(PlayerIndex.One);
     this.end = false;
 }
Example #2
0
File: Main.cs Project: fiahil/Zappy
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            #if WINDOWS
            if (server.IsConnected())
            {
                server.Update();
                if (this.Teams.Count > 0 && this.teams == null)
                    this.InitTeamString();
            }
            #endif

            base.Update(gameTime);

            #if WINDOWS
            mm.Update();

            if (Keyboard.GetState().IsKeyDown(Keys.Escape) || !server.IsConnected() || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start))
                this.Exit();
            #endif
            #if XBOX
            if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y))
                this.Exit();
            #endif

            Vector2 test = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left * 5;

            this.dot.X += test.X;
            this.dot.Y -= test.Y;

            #if WINDOWS
            this.plist.RemoveAll(delegate(Player p) { return p.State == Player.States.FINISHED; });
            this.elist.RemoveAll(delegate(Egg e) { return e.State == Egg.States.BROKE; });

            if ((oldState.IsKeyUp(Keys.C) && Keyboard.GetState().IsKeyDown(Keys.C)) || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y) && oldStick.IsButtonUp(Buttons.Y)))
            {
                mm.Mute();
                sounds.Mute();
            }
            #endif
            #if XBOX
            try
            {
                for (Player P = null; (P = this.plist.First(p => p.State == Player.States.FINISHED)) != null; )
                {
                    this.plist.Remove(P);
                }
            }
            catch { }
            #endif

            if (this.end == false)
            {
                if ((oldState.IsKeyUp(Keys.PageDown) && Keyboard.GetState().IsKeyDown(Keys.PageDown)) ||
                    (oldStick.IsButtonUp(Buttons.RightTrigger) && GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.RightTrigger)))
                {
                    try
                    {
                        Rectangle r = new Rectangle();
                        this.followed = this.plist[(++this.followedId) % this.plist.Count];
                        this.inventory_details = this.followed;
                        r.X = -(-this.followed.Pos.Y * (this.Map.getSquare().Width / 2) + (this.followed.getPos().X + 1) * (this.Map.getSquare().Width / 2) + ((int)this.Map.getSize().Y - 1) * (this.Map.getSquare().Width / 2) - 550);
                        r.Y = -(this.followed.Pos.Y * (this.Map.getSquare().Height / 2) + (this.followed.getPos().X) * (this.Map.getSquare().Height / 2) - ((int)this.Map.getSize().Y - 1) * (this.Map.getSquare().Height / 2) - 340);
                        this.Map.Square = r;
                    }
                    catch
                    {
                        this.followed = null;
                        this.inventory_details = null;
                        this.followedId = 0;
                    }
                }
                if ((oldState.IsKeyUp(Keys.PageUp) && Keyboard.GetState().IsKeyDown(Keys.PageUp)) ||
                    (oldStick.IsButtonUp(Buttons.LeftTrigger) &&  GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftTrigger)))
                {
                    try
                    {
                        Rectangle r = new Rectangle();
                        this.followedId = (this.followedId - 1) >= 0 ? (this.followedId - 1) : this.plist.Count - 1;
                        this.followed = this.plist[this.followedId];
                        this.inventory_details = this.followed;
                        r.X = -(-this.followed.Pos.Y * (this.Map.getSquare().Width / 2) + (this.followed.getPos().X + 1) * (this.Map.getSquare().Width / 2) + ((int)this.Map.getSize().Y - 1) * (this.Map.getSquare().Width / 2) - 550);
                        r.Y = -(this.followed.Pos.Y * (this.Map.getSquare().Height / 2) + (this.followed.getPos().X) * (this.Map.getSquare().Height / 2) - ((int)this.Map.getSize().Y - 1) * (this.Map.getSquare().Height / 2) - 340);
                        this.Map.Square = r;
                    }
                    catch
                    {
                        this.followed = null;
                        this.inventory_details = null;
                        this.followedId = 0;
                    }
                }
                if (Mouse.GetState().RightButton == ButtonState.Pressed || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B))
                {
                    if (Mouse.GetState().RightButton == ButtonState.Pressed)
                        this.dot = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                    foreach (Player elt in this.plist)
                    {
                        Point p;
                        Point off;

            #if WINDOWS
                        if (this.server.IsConnected())
                            server.SendDatas("pin " + elt.Id + "\n");
            #endif
                        off.X = (elt.getPos().X + 1) * (this.map.getSquare().Width / 2);
                        off.Y = (elt.getPos().X) * (this.map.getSquare().Height / 2);

                        p.X = ((int)this.map.getSize().Y - elt.getPos().Y - 1) * (this.map.getSquare().Width / 2) + off.X + this.map.getSquare().X;
                        p.Y = -((int)this.map.getSize().Y - elt.getPos().Y - 1) * (this.map.getSquare().Height / 2) + off.Y + this.map.getSquare().Y;

                        Rectangle bound = new Rectangle((int)(p.X + (int)(42 * (this.map.getSquare().Width / 155.0))), (int)(p.Y - (int)(19 * (this.map.getSquare().Height / 58.0))), (int)(elt.getBounds().Width * (this.map.getSquare().Width / 155.0)), (int)(elt.getBounds().Height * (this.map.getSquare().Height / 58.0)));

                        if (bound.Contains(new Point((int)this.dot.X, (int)this.dot.Y)))
                        {
                            this.inventory_details = elt;
                            this.inventory_timer = gameTime.TotalGameTime + TimeSpan.FromSeconds(10);
                            if (Keyboard.GetState().IsKeyDown(Keys.LeftControl) || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftShoulder))
                            {
                                this.followed = elt;
                                Rectangle r = new Rectangle();
                                r.X = -(-elt.Pos.Y * (this.map.getSquare().Width / 2) + (elt.getPos().X + 1) * (this.map.getSquare().Width / 2) + ((int)map.getSize().Y - 1) * (this.map.getSquare().Width / 2) - 620);
                                r.Y = -(elt.Pos.Y * (this.map.getSquare().Height / 2) + (elt.getPos().X) * (this.map.getSquare().Height / 2) - ((int)map.getSize().Y - 1) * (this.map.getSquare().Height / 2) - 360);
                                this.map.Square = r;
                            }
                            else
                            {
                                this.followed = null;
                            }
                        }
                    }
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                    this.followed = null;

                if (this.inventory_timer <= gameTime.TotalGameTime && this.inventory_details != null && this.followed == null)
                {
                    this.inventory_details = null;
                }
            }
            #if WINDOWS
            else
                this.mm.PlayEnd();
            #endif
            this.oldState = Keyboard.GetState();
            this.oldStick = GamePad.GetState(PlayerIndex.One);
        }
Example #3
0
File: Main.cs Project: fiahil/Zappy
 public void unplug()
 {
     this.inventory_details = null;
 }