Пример #1
0
        public override void onUpdate(double time)
        {
            // collision Management
            collisionManagement();
            //cooldown update
            Rukos.shotCooldownCounter -= time;

            //MouseState Mus = OpenTK.Input.Mouse.GetState ();

            //crossHairs.center = new Vector2() {X = Mus.X * Globals.Width - 50, Y = Mus.Y * Globals.Height - 50};

            Vector2 mus = game.getMouse();

            crossHairs.center = new Vector2()
            {
                X = mus.X * Globals.Width, Y = mus.Y * Globals.Height
            };
            if (crossHairs.center.X < 0)
            {
                crossHairs.center.X = 0;
            }
            if (crossHairs.center.X > 100)
            {
                crossHairs.center.X = 100;
            }
            if (crossHairs.center.Y < 0)
            {
                crossHairs.center.Y = 0;
            }
            if (crossHairs.center.Y > 100)
            {
                crossHairs.center.Y = 100;
            }

            crossHairs.update(time, player.center, crossHairs.center);
            //
            KeyboardState Kboard = OpenTK.Input.Keyboard.GetState();

            if (Kboard [Key.B])
            {
                Console.WriteLine("Mus X = " + mus.X.ToString());
                Console.WriteLine("Mus Y = " + mus.Y.ToString());
                Console.WriteLine("Ratio = " + Globals.Ratio.ToString());
                Console.WriteLine("Height= " + Globals.Height.ToString());
                Console.WriteLine("Width = " + Globals.Width.ToString());
                Console.WriteLine("MusX' = " + (mus.X * Globals.Ratio).ToString());
                Console.WriteLine("MusY' = " + (mus.Y * Globals.Ratio).ToString());
            }
            if (Kboard [Key.C])
            {
                Console.WriteLine("C ArcLength = " + (180 * crossHairs.arcLength / Math.PI).ToString());
                Console.WriteLine("C ArcDirection = " + (180 * crossHairs.angleDirection / Math.PI).ToString());
                Console.WriteLine("C leftEnd = " + crossHairs.leftEnd.ToString());
                Console.WriteLine("C rightEnd = " + crossHairs.leftEnd.ToString());
            }

            if (Kboard[Key.Escape])
            {
                Globals.ExitFlag = true;
            }

            if (player.getSides().X > 0 && (Kboard[Key.A] || Kboard[Key.Left]))
            {
                player.velocity.X = -60f;
            }
            else if (player.getSides().Z < 100 && (Kboard[Key.D] || Kboard[Key.Right]))
            {
                player.velocity.X = 60f;
            }
            else
            {
                player.velocity.X = 0;
            }

            if (player.getSides().W <= ground.getSides().Y&& (Kboard [Key.W] || Kboard [Key.Up]))
            {
                player.velocity.Y = 120f;
            }
            else if (player.getSides().W > ground.getSides().Y)
            {
                player.velocity.Y *= 0.95f;
                player.velocity.Y -= 12.0f;
            }
            else
            {
                player.velocity.Y = 0f;
            }

            if (Kboard[Key.Space] && Rukos.shotCooldownCounter <= 0)
            {
                Rukos.shotCooldownCounter = Rukos.shotCooldown;
                if (Rukos.waveCounter < 3)
                {
                    square bullet = new square(position_0: new Vector2 {
                        X = player.center.X, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.25f, Y = 1.5f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    bullets.Add(bullet);
                }
                else if (Rukos.waveCounter < 6)
                {
                    square bullet01 = new square(position_0: new Vector2 {
                        X = player.center.X - 1f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.5f, Y = 1f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    square bullet02 = new square(position_0: new Vector2 {
                        X = player.center.X + 1f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.5f, Y = 1f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    bullets.Add(bullet01);
                    bullets.Add(bullet02);
                }
                else
                {
                    square bullet01 = new square(position_0: new Vector2 {
                        X = player.center.X - 1.5f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.75f, Y = 0.85f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    square bullet02 = new square(position_0: new Vector2 {
                        X = player.center.X, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.75f, Y = 0.85f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    square bullet03 = new square(position_0: new Vector2 {
                        X = player.center.X + 1.5f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.75f, Y = 0.85f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    bullets.Add(bullet01);
                    bullets.Add(bullet02);
                    bullets.Add(bullet03);
                }
            }

            player.update(time);
            foreach (square b in bullets)
            {
                b.update(time);
            }
            foreach (square b in enemies)
            {
                b.update(time);
            }

            // collision Management
            collisionManagement();
            enemyGenerator(time);

            // check enemy death
            for (int k = enemies.Count - 1; k >= 0; k--)
            {
                if (enemies[k].hp <= 0)
                {
                    enemies.RemoveAt(k);
                }
            }

            // check bullet death
            for (int k = bullets.Count - 1; k >= 0; k--)
            {
                if (bullets[k].hp <= 0)
                {
                    bullets.RemoveAt(k);
                }
            }

            if (player.hp <= 0)
            {
                Globals.ExitFlag = true;
            }
        }
Пример #2
0
        public override void onUpdate(double time)
        {
            // collision Management
            collisionManagement();
            //cooldown update
            Rukos.shotCooldownCounter -= time;

            //
            KeyboardState Kboard = OpenTK.Input.Keyboard.GetState();

            if (Kboard[Key.Escape])
            {
                Globals.ExitFlag = true;
            }

            if (player.getSides().X > 0 && (Kboard[Key.A] || Kboard[Key.Left]))
            {
                player.velocity.X = -60f;
            }
            else if (player.getSides().Z < 100 && (Kboard[Key.D] || Kboard[Key.Right]))
            {
                player.velocity.X = 60f;
            }
            else
            {
                player.velocity.X = 0;
            }

            if (player.getSides().W > 0 && (Kboard[Key.S] || Kboard[Key.Down]))
            {
                player.velocity.Y = -60f;
            }
            else if (player.getSides().Y < 100 && (Kboard[Key.W] || Kboard[Key.Up]))
            {
                player.velocity.Y = 60f;
            }
            else
            {
                player.velocity.Y = 0;
            }

            if (Kboard[Key.Space] && Rukos.shotCooldownCounter <= 0)
            {
                Rukos.shotCooldownCounter = Rukos.shotCooldown;
                if (Rukos.waveCounter < 3)
                {
                    square bullet = new square(position_0: new Vector2 {
                        X = player.center.X, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.25f, Y = 1.5f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    bullets.Add(bullet);
                }
                else if (Rukos.waveCounter < 6)
                {
                    square bullet01 = new square(position_0: new Vector2 {
                        X = player.center.X - 1f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.5f, Y = 1f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    square bullet02 = new square(position_0: new Vector2 {
                        X = player.center.X + 1f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.5f, Y = 1f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    bullets.Add(bullet01);
                    bullets.Add(bullet02);
                }
                else
                {
                    square bullet01 = new square(position_0: new Vector2 {
                        X = player.center.X - 1.5f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.75f, Y = 0.85f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    square bullet02 = new square(position_0: new Vector2 {
                        X = player.center.X, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.75f, Y = 0.85f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    square bullet03 = new square(position_0: new Vector2 {
                        X = player.center.X + 1.5f, Y = player.getSides().Y
                    }, size_0: new Vector2 {
                        X = 0.75f, Y = 0.85f
                    }, color_0: Color.OrangeRed, velocity_0: new Vector2 {
                        X = 0, Y = 50f
                    });
                    bullets.Add(bullet01);
                    bullets.Add(bullet02);
                    bullets.Add(bullet03);
                }
            }

            player.update(time);
            foreach (square b in bullets)
            {
                b.update(time);
            }
            foreach (square b in enemies)
            {
                b.update(time);
            }

            // collision Management
            collisionManagement();
            enemyGenerator(time);

            // check enemy death
            for (int k = enemies.Count - 1; k >= 0; k--)
            {
                if (enemies[k].hp <= 0)
                {
                    enemies.RemoveAt(k);
                }
            }

            // check bullet death
            for (int k = bullets.Count - 1; k >= 0; k--)
            {
                if (bullets[k].hp <= 0)
                {
                    bullets.RemoveAt(k);
                }
            }

            if (player.hp <= 0)
            {
                Globals.ExitFlag = true;
            }
        }