Пример #1
0
        public static bool inRange(int range, Player player, int x, int y)
        {
            World world = new World();
            int width = world.player.sizeBreedte;
            int height = world.player.sizeHoogte;
            bool inrange = false;
            int PythagorasX;
            int Pythagorasy;
            int px = width / 2 + player.playerX;
            int py = height / 2 + player.playerY;

            int ex = x; //moet nog worden verandert als de xlocatie van enemy bekend is
            int ey = y; //moet nog worden verandert als de ylocatie van enemy bekend is

            //xcoordinaar bepalen
            if (px >= ex)
            {
                PythagorasX = px - ex;
            }
            else
            {
                PythagorasX = ex - px;
            }
            //ycoordinaat bepalen

            if (py >= ey)
            {
                Pythagorasy = py - ey;
            }
            else
            {
                Pythagorasy = ey - py;
            }

            //xkwadraat
            int PowerToX = PythagorasX * PythagorasX;
            //ykwadraat
            int PowerToY = Pythagorasy * Pythagorasy;
            //xkwadraat + ykwadraat
            int compareNumber = PowerToX + PowerToY;
            //ckwadraat
            int compareToNumer = range * range;
            //ultimate check
            if (compareNumber < compareToNumer)
            {
                inrange = true;
            }

            return inrange;
        }
Пример #2
0
        public void checkCollision(World world, Game game)
        {
            this.game = game;
            this.world = world;
            powerup = new Rectangle(this.x, this.y, (int)sizeBreedte, (int)sizeHoogte);

            if (playerIntersectWithPowerup())
            {
                if (!getUsed())
                {
                    UsePowerup();
                }
            }
        }
Пример #3
0
        public Designer(Form startform, string level, string levelID)
        {
            InitializeComponent();

            // Keep reference to the start form
            this.startForm = startform;

            // Set level to be edited
            this.levelString = level;

            // Initialize Timer variables
            this.MouseDownLeftTimer = new Timer();
            this.MouseDownRightTimer = new Timer();
            this.MouseDownLeftTimer.Interval = 1;
            this.MouseDownRightTimer.Interval = 1;

            // Set level ID (needed for saving)
            this.levelID = levelID;

            // Checks if there's a level to be edited or there has to be a new level to be created
            if (levelString == "")
            {
                this.world = new World();
            }
            else
            {

                this.world = JsonConvert.DeserializeObject<World>(levelString);
                if (this.world.player != null){
                    playerCount = 1;
                }
                if (this.world.finish != null)
                {
                    finishCount = 1;
                }
                foreach (Npc npc in this.world.npcs)
                {
                    if (npc.type == Npc.Type.SuicideBomber)
                    {
                        this.bomberCount = 1;
                    }
                }
            }

            // Set double buffer to prevent flickering
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }
Пример #4
0
 // Load the world
 private void load()
 {
     // Assign the world variable
     this.world = JsonConvert.DeserializeObject<World>(levelString);
     this.world.player.sizeBreedte = this.Width / 40 - 5;
     this.world.player.sizeHoogte = this.Height / 20 - 5;
 }
Пример #5
0
        // Prepare the game
        private void Game_Load(object sender, EventArgs e)
        {
            this.world = new World();

            // Set initial location
            this.Location = this.startScreen.Location;

            // Set the initial size
            this.setFullScreenSize(this, null);

            // Add gamepad
            this.addGamePad();

            // Subscribe to the events
            this.attachEvents();

            // Load the world
            this.load();

            // Set the main timer
            this.loop = new Timer();
            this.loop.Interval = 1000 / targetFps;
            this.loop.Tick += updateWorld;

            // Set the animation timer
            this.animate = new Timer();
            this.animate.Interval = 100;
            this.animate.Tick += updateAnimations;

            // Set the stopwatch
            this.delta = new Stopwatch();

            // Start the game timer/stopwatch
            startTimers(true);
        }
Пример #6
0
        public void moveNPC(World world)
        {
            this.world = world;
            npc = new Rectangle(positions.current_position.x, positions.current_position.y, (int)sizeBreedte, (int)sizeHoogte);
            oldx = positions.current_position.x;//OLD X POSITION NPC
            oldy = positions.current_position.y;//OLD Y POSITION NPC

            if (type == Type.Enemy)
            {
                if (newRange < normalRange)
                {
                    newRange = normalRange;
                }
                playerIsInRange = inRange(newRange);
                if (playerIsInRange)
                {
                    this.substractScore();
                    if (!npcIntersectsWithObjects())
                    {
                        if (newRange < maximumRange)
                        {
                            newRange += rangeSpeed;
                        }

                        if (View.Game.Player.isPlayerMoving)
                        {
                            var playerCurrentX = (int)(this.world.player.positions.current_position.x);
                            var playerCurrentY = (int)(this.world.player.positions.current_position.y);
                            var playerLastX = (int)(this.world.player.positions.last_position.x);
                            var playerLastY = (int)(this.world.player.positions.last_position.y);
                            if (playerCurrentX > playerLastX && positions.current_position.x < playerCurrentX)
                            {
                                positions.current_position.x += speed.x;
                            }
                            else if (playerCurrentX > playerLastX && positions.current_position.x > playerCurrentX)
                            {
                                positions.current_position.x -= speed.x;
                            }
                            else if (playerCurrentX < playerLastX && positions.current_position.x > playerCurrentX)
                            {
                                positions.current_position.x -= speed.x;
                            }
                            else if (playerCurrentX < playerLastX && positions.current_position.x < playerCurrentX)
                            {
                                positions.current_position.x += speed.x;
                            }
                            else if (playerCurrentY > playerLastY && positions.current_position.y < playerCurrentY)
                            {
                                positions.current_position.y += speed.y;
                            }
                            else if (playerCurrentY > playerLastY && positions.current_position.y > playerCurrentY)
                            {
                                positions.current_position.y -= speed.y;
                            }
                            else if (playerCurrentY < playerLastY && positions.current_position.y > playerCurrentY)
                            {
                                positions.current_position.y -= speed.y;
                            }
                            else if (playerCurrentY < playerLastY && positions.current_position.y < playerCurrentY)
                            {
                                positions.current_position.y += speed.y;
                            }
                        }
                        else
                        {
                            var playerCurrentX = (int)(this.world.player.positions.current_position.x);
                            var playerCurrentY = (int)(this.world.player.positions.current_position.y);
                            if (playerCurrentX > positions.current_position.x)
                            {
                                positions.current_position.x += speed.x;
                            }
                            if (playerCurrentX < positions.current_position.x)
                            {
                                positions.current_position.x -= speed.x;
                            }
                            if (playerCurrentY > positions.current_position.y)
                            {
                                positions.current_position.y += speed.y;
                            }
                            if (playerCurrentY < positions.current_position.y)
                            {
                                positions.current_position.y -= speed.y;
                            }
                        }
                    }
                }
                else
                {
                    newRange -= rangeSpeed / 5;
                    if (EnemyChooseNewRoute())
                    {
                        this.positions.current_position.x = oldx;
                        this.positions.current_position.y = oldy;
                        var lastRandomPosition = randomPosition;

                        while (lastRandomPosition == randomPosition)
                        {
                            randomPosition = rnd.Next(4);
                        }
                    }
                }
            }

            if (type == Type.V_Bouncer)
            {
                if (v_bouncer_up)
                {
                    positions.current_position.y -= speed.y;
            }
                else if (v_bouncer_down)
                {
                    positions.current_position.y += speed.y;
                }

                npc.X = positions.current_position.x;
                npc.Y = positions.current_position.y;

                //check of er intersect is met objecten als de positie wordt veranderd
                if (npcIntersectsWithObjects())
            {
                    if (v_bouncer_up)
                    {
                        v_bouncer_up = false;
                        v_bouncer_down = true;
                    }
                    else if (v_bouncer_down)
                    {
                        v_bouncer_up = true;
                        v_bouncer_down = false;
                    }

                    //intersect verwacht dus zet oude coordinaten
                    this.positions.current_position.x = oldx;
                    this.positions.current_position.y = oldy;
                }
                //Check if player intersects with bouncer, yes draw a border around te player(visual)
                if (playerIntersectWithBouncers())
                {
                    this.substractScore();
                    drawHitAroundPlayer = true;
                }
                else
                {
                    drawHitAroundPlayer = false;
                }
            }

            if (type == Type.H_Bouncer)
            {
                if (h_bouncer_left)
                {
                    positions.current_position.x -= speed.x;
                }
                else if (h_bouncer_right)
                {
                    positions.current_position.x += speed.x;
                }

                npc.X = positions.current_position.x;
                npc.Y = positions.current_position.y;

                //check of er intersect is met objecten als de positie wordt veranderd
                if (npcIntersectsWithObjects())
                {
                    if (h_bouncer_left)
            {
                        h_bouncer_left = false;
                        h_bouncer_right = true;
            }
                    else if (h_bouncer_right)
            {
                        h_bouncer_left = true;
                        h_bouncer_right = false;
                    }

                    //intersect verwacht dus zet oude coordinaten
                    this.positions.current_position.x = oldx;
                    this.positions.current_position.y = oldy;
            }

                //Check if player intersects with bouncer, yes draw a border around te player(visual)
                if (playerIntersectWithBouncers())
                {
                    this.substractScore();
                    drawHitAroundPlayer = true;
                }
                else
                {
                        drawHitAroundPlayer = false;
                }
            }
            if (type == Type.SuicideBomber)
            {
                if (Player.lastPositionsList.Count > 0)
                {
                    Rectangle PlayerRectangle = new Rectangle(this.world.player.positions.current_position.x, this.world.player.positions.current_position.y, this.world.player.sizeBreedte, this.world.player.sizeHoogte);
                    Rectangle SSBRectangle = new Rectangle(this.positions.current_position.x,this.positions.current_position.y,this.sizeBreedte,this.sizeHoogte);
                    if (SSBRectangle.IntersectsWith(PlayerRectangle))
                    {
                        View.Game.Player.SSBPlayerCollision = true;
                    }
                    this.positions.current_position.x = Player.lastPositionsList[currentSSBpos].x;
                    this.positions.current_position.y = Player.lastPositionsList[currentSSBpos].y;
                    if (currentSSBpos < Player.lastPositionsList.Count -1)
                    {
                        currentSSBpos++;
                    }

                }
            }
        }
Пример #7
0
 //methode om te kijken of er een player in range is
 public void checkForPlayer(World world, View.Game.Player game)
 {
     //kijk of de informatie aan gezet is en of er een speler in range is
     if (Properties.Settings.Default.enemyInformation && inRange(300))
     {
         //kijk of de label leeg is
         if (this.infoLabel == null)
         {
             this.game = game;
             //als de label leeg is doe dit
             this.infoLabel = new Label();
             this.infoLabel.AutoSize = true;
             this.infoLabel.Visible = true;
             //voeg de label toe aan het form
             game.Controls.Add(infoLabel);
         }
         //update de informatie en de locatie van het label zolang deze in range blijft
         this.infoLabel.Location = new System.Drawing.Point((int)this.positions.current_position.x - 50, (int)(this.positions.current_position.y - 20));
         this.infoLabel.Text = "X: " + this.positions.current_position.x + ", Y: " + this.positions.current_position.y + ", Speed:  " + this.speed.x;
     }
     else
     {
         //is hij niet in range of is het uit gezet verwijder dan het label van het form en maak het label leeg voor de volgende keer
         game.Controls.Remove(infoLabel);
         this.infoLabel = null;
     }
 }
Пример #8
0
        // Load the world
        private void load()
        {
            string data = (string)Properties.Levels.Default[levelString];

            // Assign the world variable
            this.world = JsonConvert.DeserializeObject<World>(data);

            // Check if level contains an SSBer, if so start spawn timer.
            foreach (Npc npcs in this.world.npcs)
            {
                if (npcs.type == Npc.Type.SuicideBomber)
                {
                    this.isSSBSpawned = false;
                    this.explosionState = 0;
                    Model.Player.lastPositionsList.Clear();
                    geluidjes.AADone = false;
                    geluidjes.EXDone = false;
                    SSBPlayerCollision = false;
                    isSSBVisible = true;
                    this.isSoundPlaying = false;
                    this.isExploding = false;
                    this.SSBExplosion.Stop();
                    this.SSBSpawnTimer.Interval = npcs.SSBspawnTimer;
                    this.SSBSpawnTimer.Start();
                }
            }

            // Normalize
            this.normalize();
        }
Пример #9
0
        // Prepare the game
        private void Game_Load(object sender, EventArgs e)
        {
            // Set initial location
            this.Location = this.startScreen.Location;

            // Set the initial size
            this.setFullScreenSize(this, null);

            // Check if the onscreen controls have to be displayed
            if (Properties.Settings.Default.onScreenControls)
            {
                // Add gamepad
                this.addGamePad();
            }

            // Subscribe to the events
            this.attachEvents();

            // Load the world
            this.load();

            // Set highscore name
            this.world.getScore().world = lvlNames[this.levelString];

            // Set the main timer
            this.loop = new Timer();
            this.loop.Interval = 1000 / targetFps;
            this.loop.Tick += updateWorld;

            // Set the animation timer
            this.animate = new Timer();
            this.animate.Interval = 100;
            this.animate.Tick += updateAnimations;

            // Set speedboost timer
            this.speedBoostTimer.Interval = 1000;
            this.speedBoostTimer.Tick += updateSpeedBoostLength;

            // Set SSB timer
            this.SSBSpawnTimer.Tick += SSBTimerStop;
            this.SSBExplosion.Interval = 100;
            this.SSBExplosion.Tick += playExplosion;

            // Set EMP timer
            this.EMPTimer.Tick += EMPReset;

            // Set the stopwatch
            this.delta = new Stopwatch();

            // Start the game timer/stopwatch
            startTimers(true);
        }