예제 #1
0
        public override void Init()
        {
            base.Init();
            BackColor = Color.Black;
            var by = new char[5];

            //for (int i = 0; i < 15; i++)
            //{
            //    var len = MathAssist.RandInt(15, 80);
            //    var size = new SizeF(len, len);
            //    var location = new Vector2F(MathAssist.RandInt(0, GameWindow.DisplaySize.Width), MathAssist.RandInt(0, GameWindow.DisplaySize.Height));
            //    var angle = MathAssist.RandInt(0, 359);
            //    var velocity = MathAssist.RandInt(1, 3);
            //    var asteroid = new Asteroid(Color.Gray, size, location, angle, velocity);
            //    asteroid.Init();
            //    gameObjects.Add("Asteroid" + i, asteroid);
            //}

            for (int i = 0; i < 200; i++)
            {
                var radius = MathAssist.RandInt(1, 3);
                var color  = Color.FromArgb(MathAssist.RandInt(50, 200), MathAssist.RandInt(50, 200), MathAssist.RandInt(50, 200));
                var rect   = new Rectangle(MathAssist.RandInt(0, Screen.PrimaryScreen.Bounds.Width), MathAssist.RandInt(0, Screen.PrimaryScreen.Bounds.Height), radius, radius);
                var star   = new Star(color, rect, MathAssist.RandInt(1, 2), MathAssist.RandInt(1, 2));
                gameObjects.TryAdd("star" + i, star);
            }

            //   new Thread(new ThreadStart( ConnectNewPlayingClient)).Start();
            // ConnectNewPlayingClient();
            foreach (var obj in gameObjects)
            {
                obj.Value.Init();
            }
        }
예제 #2
0
 public void Init()
 {
     Size      = new Size(5, 5);
     Velocity  = 6f;
     this.ID   = "Projectile" + MathAssist.Rand(1, 0).ToString();
     Color     = Color.Yellow;
     IsVisible = true;
 }
예제 #3
0
 public StarFighter(Color color, SizeF size, Vector2F location, float angle)
 {
     this.Location = location;
     this.Angle    = angle;
     this.Color    = color;
     this.IsDead   = false;
     this.Size     = size;
     this.ID       = "fighter" + MathAssist.Rand(1, 0).ToString();
 }
예제 #4
0
 public Thrust(Vector2F location, Color color, double angle, float velocity, int delay)
 {
     this.Velocity = velocity;
     this.Location = location;
     this.Color    = color;
     this.Angle    = angle;
     this.Size     = new Size(3, 3);
     delayFade     = new Framework2D.Delay(delay);
     this.ID       = "Thrust" + MathAssist.Rand(1, 0).ToString();
 }
예제 #5
0
 public Shockwave(Color color, Vector2F location, float velocity, int delayPerFrame, float radiusMax, float velocity2D, double angle)
 {
     Color      = color;
     waveTiming = new Delay(delayPerFrame);
     RaduisMax  = radiusMax;
     Location   = location;
     Velocity   = velocity;
     ID         = MathAssist.Rand(1, 0).ToString();
     v2d        = velocity2D;
     Angle      = angle;
     Init();
 }
예제 #6
0
        public void Init()
        {
            Alpha         = 1f;
            ToBeDestroyed = false;
            IsVisible     = true;
            var count = MathAssist.RandInt(10, 20);

            pts = new Point[count];
            for (int i = 0; i < count; i++)
            {
                var delx = Location.X + Size.Width * Math.Cos(i * 360 / count * Math.PI / 180f);
                var dely = Location.Y + Size.Height * Math.Sin(i * 360 / count * Math.PI / 180f);
                pts[i] = new Point((int)delx - MathAssist.RandInt(1, 30), (int)dely + MathAssist.RandInt(1, 20));
            }
        }
예제 #7
0
        public override void Init()
        {
            base.Init();
            BackColor = Color.Black;
            GameWindow.AudioPlayer.Item1.PlayTrack("background");

            for (int i = 0; i < 15; i++)
            {
                var len      = MathAssist.RandInt(15, 80);
                var size     = new SizeF(len, len);
                var location = new Vector2F(MathAssist.RandInt(0, GameWindow.DisplaySize.Width), MathAssist.RandInt(0, GameWindow.DisplaySize.Height));
                var angle    = MathAssist.RandInt(0, 359);
                var velocity = MathAssist.RandInt(1, 3);
                var asteroid = new Asteroid(Color.Gray, size, location, angle, velocity);
                asteroid.Init();
                gameObjects.Add("asteroid" + i, asteroid);
            }

            for (int i = 0; i < 200; i++)
            {
                var radius = MathAssist.RandInt(1, 3);
                var color  = Color.FromArgb(MathAssist.RandInt(50, 200), MathAssist.RandInt(50, 200), MathAssist.RandInt(50, 200));
                var rect   = new Rectangle(MathAssist.RandInt(0, Screen.PrimaryScreen.Bounds.Width), MathAssist.RandInt(0, Screen.PrimaryScreen.Bounds.Height), radius, radius);
                gameObjects.Add("star" + i, new Star(color, rect, MathAssist.RandInt(1, 2), MathAssist.RandInt(1, 2)));
            }

            var f1 = new StarFighter(Color.Red, new SizeF(10f, 10f), new Vector2F(200, 200), 0);

            mainPlayerID = f1.ID;
            scores.Add(mainPlayerID, 0);
            var f2 = new StarFighter(Color.Blue, new SizeF(10f, 10f), new Vector2F(250, 250), 180);

            secondPlayer = f2.ID;
            scores.Add(secondPlayer, 0);
            gameObjects.Add(f1.ID, f1);
            gameObjects.Add(f2.ID, f2);
            //  GameWindow.View.FollowedObject = (IViewFollowed)f1;
            //  RenderManager.RenderList.Add("f1", new Graphic.Render(RenderType.Default, true, f.Location, null, f.Angle,new Vector2F(0,0), f.Size, null, new RectangleF(0,0,0,0), "", null, Color.Red, 1,DrawRoutine.DrawTriangle));
            gameObjects.Add("view", GameWindow.View);

            foreach (var obj in gameObjects)
            {
                obj.Value.Init();
            }
        }
예제 #8
0
        public static Complex Asin(Complex c)
        {
            //var ix = new Complex(-c.Imz, c.Real);
            //var xsq = c * c;
            //var oneminusxsq = new Complex(1, 0) - xsq;
            //var r = Math.Pow(oneminusxsq.GetMag(), 0.5);
            //var ang = oneminusxsq.GetArgz() / 2;
            //var sqrt = r*Complex.cis(ang);
            //return (ix + sqrt);
            var r     = c.Real;
            var i     = c.Imz;
            var a     = Math.Pow((r * r + 2 * r + i * i + 1), 0.5);
            var b     = Math.Pow((r * r - 2 * r + i * i + 1), 0.5);
            var real  = Math.Asin(a / 2 - b / 2);
            var inner = (Math.Pow(2 * (a * b + r * r + i * i - 1), 0.5) + a + b) / 2;
            var imz   = -Math.Log(inner) * MathAssist.sign(i);

            return(new Complex(real, imz));
        }
예제 #9
0
        public override void Init()
        {
            base.Init();
            BackColor = Color.Black;
            var by = new char[5];

            //for (int i = 0; i < 15; i++)
            //{
            //    var len = MathAssist.RandInt(15, 80);
            //    var size = new SizeF(len, len);
            //    var location = new Vector2F(MathAssist.RandInt(0, GameWindow.DisplaySize.Width), MathAssist.RandInt(0, GameWindow.DisplaySize.Height));
            //    var angle = MathAssist.RandInt(0, 359);
            //    var velocity = MathAssist.RandInt(1, 3);
            //    var asteroid = new Asteroid(Color.Gray, size, location, angle, velocity);
            //    asteroid.Init();
            //    gameObjects.Add("Asteroid" + i, asteroid);
            //}

            for (int i = 0; i < 200; i++)
            {
                var radius = MathAssist.RandInt(1, 3);
                var color  = Color.FromArgb(MathAssist.RandInt(50, 200), MathAssist.RandInt(50, 200), MathAssist.RandInt(50, 200));
                var rect   = new Rectangle(MathAssist.RandInt(0, Screen.PrimaryScreen.Bounds.Width), MathAssist.RandInt(0, Screen.PrimaryScreen.Bounds.Height), radius, radius);
                var star   = new Star(color, rect, MathAssist.RandInt(1, 2), MathAssist.RandInt(1, 2));
                gameObjects.Add("star" + i, star);
            }

            //handles client actively playing and not playing
            Thread ConnectReadyClient = new Thread(new ThreadStart(
                                                       () =>
            {
                while (true)
                {
                    foreach (var client in ServerSide.ConnectClients.ConnectedClients)
                    {
                        if (client.Connected)
                        {
                            try
                            {
                                NetworkStream ns = client.GetStream();
                                byte[] b         = new byte[sizeof(short)];
                                ns.Read(b, 0, b.Length);
                                var message = (GameAction)BitConverter.ToInt16(b, 0);


                                if (message == GameAction.Ready)
                                {
                                    var key = client.Client.RemoteEndPoint.ToString();
                                    client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

                                    Console.WriteLine("client " + key + " playing");
                                    PlayingClients.Add(key, new ClientMember(client, client.GetStream()));    //, sw, sr));
                                    Console.WriteLine("initing " + key + " background transfer");
                                    InitClient(key);
                                }
                                //   ns.Close();
                            }
                            catch { }
                        }
                    }

                    for (int i = 0; i < ServerSide.ConnectClients.ConnectedClients.Count; i++)
                    {
                        if (!ServerSide.ConnectClients.ConnectedClients[i].Connected)
                        {
                            // disconnect clients
                            var key = ServerSide.ConnectClients.ConnectedClients[i].Client.RemoteEndPoint.ToString();
                            ////   PlayingClients.Remove(key);
                            ServerSide.ConnectClients.ConnectedClients.Remove(ServerSide.ConnectClients.ConnectedClients[i]);
                            i--;
                            Console.WriteLine("client " + key + " disconnected");
                            delClient = true;
                        }
                    }
                    Thread.Sleep(5000);
                }
            }
                                                       ));

            ConnectReadyClient.Start();
        }
예제 #10
0
 private void resolveVelocity()
 {
     this.velocityVector.X = MathAssist.Between <float>(this.velocityVector.X + this.Velocity * (float)Math.Cos(this.Angle.ToType <double>() * Math.PI / 180d), -this.maxVelocity, this.maxVelocity);
     this.velocityVector.Y = MathAssist.Between <float>(this.velocityVector.Y + this.Velocity * (float)Math.Sin(this.Angle.ToType <double>() * Math.PI / 180d), -this.maxVelocity, this.maxVelocity);
     this.Velocity         = 0;
 }
예제 #11
0
        public override void Update(GameTime gameTime)
        {
            //  GameWindow.myText = new PointF(GameInput.GetMouseLocation().X - GameWindow.View.Location.X, GameInput.GetMouseLocation().Y - GameWindow.View.Location.Y).ToString();
            GameWindow.GameMessages[1] = ("objCount:" + gameObjects.Count.ToString());
            DestroyManager.DestroyFromList(ref gameObjects);
            DestroyManager.DestroyOutOfBounds(ref gameObjects, new Utilities.BoundF(0, 0, Screen.PrimaryScreen.Bounds.Size.Width, Screen.PrimaryScreen.Bounds.Size.Height));

            BoundF bound = new BoundF(
                0,                            // GameWindow.View.Size.Width ,
                0,                            // GameWindow.View.Size.Height / 4,
                GameWindow.DisplaySize.Width, // - GameWindow.View.Size.Width / 4,
                GameWindow.DisplaySize.Height // - GameWindow.View.Size.Height / 4
                );

            if (gameObjects.ContainsKey(mainPlayerID))
            {
                var fighter = mainPlayerID.GetByKey <string, IGameBehavior>(gameObjects) as StarFighter;

                if (GameInput.isKeyDown(Keys.Down))
                {
                    // if (GetAsyncKeyState(Keys.Down))
                    fighter.Deaccelerate();
                }
                if (GameInput.isKeyDown(Keys.Up))
                {
                    // if (GetAsyncKeyState(Keys.Up))
                    fighter.Accelerate();
                }
                if (GameInput.isKeyDown(Keys.Right))
                {
                    // if (GetAsyncKeyState(Keys.Right))
                    fighter.TurnRight();
                }
                if (GameInput.isKeyDown(Keys.Left))
                {
                    //  if (GetAsyncKeyState(Keys.Left))
                    fighter.TurnLeft();
                }

                if (gameActive)
                {
                    if (GameInput.isKeyDown(Keys.Space))
                    {
                        // if (GetAsyncKeyState(Keys.Space))
                        fighter.Shoot();
                    }
                }

                fighter.Location = ((IGame2DProperties)fighter)
                                   .KeepInBounds(bound
                                                 ).Location;
            }


            if (gameObjects.ContainsKey(secondPlayer))
            {
                var fighter2 = secondPlayer.GetByKey <string, IGameBehavior>(gameObjects) as StarFighter;

                if (GameInput.isKeyDown(Keys.W))
                {
                    fighter2.Accelerate();
                }
                if (GameInput.isKeyDown(Keys.S))
                {
                    fighter2.Deaccelerate();
                }
                if (GameInput.isKeyDown(Keys.D))
                {
                    fighter2.TurnRight();
                }
                if (GameInput.isKeyDown(Keys.A))
                {
                    fighter2.TurnLeft();
                }
                if (gameActive)
                {
                    if (GameInput.isKeyDown(Keys.Q))
                    {
                        fighter2.Shoot();
                    }
                }

                fighter2.Location = ((IGame2DProperties)fighter2).KeepInBounds(bound).Location;
            }


            foreach (var player in gameObjects.Values.OfType <StarFighter>())
            {
                foreach (var bullet in gameObjects.Values.OfType <Projectile>())
                {
                    var delx = player.Size.Width;
                    var dely = player.Size.Height;
                    if (bullet.InBounds(new BoundF(player.Location.X - delx, player.Location.Y - dely, player.Location.X + delx, player.Location.Y + dely)))
                    {
                        if (!bullet.ID.Contains(player.ID))
                        {
                            var id = bullet.ID.Split(',').Last();
                            bullet.ToBeDestroyed = true;
                            if (player.IsDead.IsNotTrue())
                            {
                                player.IsDead = true;
                                scores[id]++;
                            }
                        }
                    }
                }
            }

            angle += 1;
            if (angle > 360)
            {
                angle = 0;
            }
            var dx = 500 + 200 * Math.Cos(angle * Math.PI / 180f);

            GameWindow.View.Size = new SizeF((float)dx, (float)dx);

            var keys = gameObjects.Keys.ToArray <string>();

            for (int i = 0; i < keys.Count <string>(); i++)
            {
                var ass = gameObjects[keys[i]];
                if (ass.GetType() == typeof(Asteroid))
                {
                    ((IGame2DProperties)ass).Location = ((IGame2DProperties)ass).KeepInBounds(bound).Location;
                }
            }


            foreach (var obj in gameObjects)
            {
                obj.Value.Update(gameTime);
            }

            if (((StarFighter)gameObjects[mainPlayerID]).IsDead || ((StarFighter)gameObjects[secondPlayer]).IsDead)
            {
                gameActive = false;
                gameWaitTiming.WaitThenDoOnce(() =>
                {
                    foreach (var fighter in gameObjects.Values.OfType <StarFighter>())
                    {
                        var v            = new Vector2F(MathAssist.RandInt(0, (GameWindow.DisplaySize.Width - 50)), MathAssist.RandInt(0, GameWindow.DisplaySize.Height));
                        fighter.Location = v;
                        fighter.IsDead   = false;

                        fighter.StopMoving();
                    }
                    gameActive = true;
                    gameWaitTiming.Reset();
                });
            }


            if (GameInput.isKeyDown(Keys.Escape))
            {
                RunAgain = false;
                GameWindow.AudioPlayer.Item1.StopTrack("background");
                GameWindow.CurrentScene = NextScene;
                GameWindow.View.Init();
                gameObjects.Clear();
            }
        }