Exemple #1
0
        /// <summary>
        /// Geeft aan welke variabelen Finishlijn met zich mee geeft.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="image"></param>
        public Finishlijn(Rectangle location, Texture2D image)
        {
            this.location = location;
            this.image    = image;
            this.bounds   = location;
            id            = "Finish";
            CollisionSystem.triggers.Add(this);

            if (CollisionSystem.CollisionDetection(this) != null)
            {
            }
        }
Exemple #2
0
        /// <summary>
        /// Geeft aan wat de Konijn per frame doet.
        /// </summary>
        /// <param name="elapsed"></param>
        public void Update(float elapsed)
        {
            // Update water
            waterComponent.WaterChange();
            // Is voor consisten Frame rate
            location += velocity * elapsed;

            // TODO: Add your update logic here

            // Update de animatie indien het konijn beweegt
            if (speed > 0 || speed < 0)
            {
                currentFrame++;
                if (currentFrame == totalFrames)
                {
                    currentFrame = 0;
                }
            }
            else
            {
                currentFrame = 0;
            }

            // Neemt de collisionsystem en bekijkt of de powerup en dergelijke tegen komt, waar het konijn tegenaan knalt.
            if (!MainGame.backgroundbound.Contains(bounds))
            {
                location = startLocation;
                angle    = startAngle;
            }

            string trigger = CollisionSystem.TriggerDetection(this);

            if (trigger != "")
            {
                if (trigger == "Powerup")
                {
                    speed        = 600;
                    powercounter = 0;
                }

                if (trigger == "trap" || !MainGame.backgroundbound.Contains(bounds))
                {
                    angle += 3;
                }

                if (trigger == "Finish" && checks == 3)
                {
                    laps++;
                    checks        = 0;
                    startLocation = location;
                    startAngle    = angle;

                    if (laps == 6)
                    {
                        Endscreen.winner   = playerid;
                        SceneManager.state = SceneManager.Scenes.end;
                    }
                }

                if (trigger == "Pitstop")
                {
                    if (waterComponent.water < 100)
                    {
                        waterComponent.water++;
                    }
                }

                if (trigger == ("Checkpoint" + (checks + 1)))
                {
                    checks++;
                    startLocation = location;
                    startAngle    = angle;
                }
                if (trigger == "heet")
                {
                    if (waterComponent.water < 100)
                    {
                        waterComponent.water++;
                    }
                }
            }
            // Neemt de collisionsystem en bekijkt of de twee konijnen tegen elkaar aan zit.
            string collision = CollisionSystem.CollisionDetection(this);

            if (collision != "")
            {
                if (collision == "Konijn")
                {
                    speed = -60;
                }

                if (collision == "Pitstop")
                {
                    if (waterComponent.water < 100)
                    {
                        waterComponent.water += 0.11f;
                    }
                    waterComponent.check = false;
                    pitstopsBool         = true;
                }
            }

            if (collision == "heet")
            {
                if (waterComponent.water < 100)
                {
                    waterComponent.water -= 0.2f;
                }
            }

            if (collision != "Pitstop")
            {
                if (pitstopsBool == true)
                {
                    pitstops++;
                    pitstopsBool = false;
                }
            }

            velocity = new Vector2(0, 0);

            Keys[]        allKeys  = Keyboard.GetState().GetPressedKeys();
            KeyboardState keyState = new KeyboardState();

            Keys[] commands = new Keys[4];
            foreach (Keys k in allKeys)
            {
                Console.WriteLine(k);
                if (k == controls.up)
                {
                    commands[0] = k;
                }
                if (k == controls.left)
                {
                    commands[1] = k;
                }
                if (k == controls.right)
                {
                    commands[2] = k;
                }
                if (k == controls.down)
                {
                    commands[3] = k;
                }
            }
            keyState = new KeyboardState(commands);

            if (keyState != null)
            {
                //Als knop A en down wordt ingedrukt
                if (keyState.IsKeyDown(controls.left))
                {
                    angle -= speed / 3000;
                }
                //Als knop D en right wordt ingedrukt
                if (keyState.IsKeyDown(controls.right))
                {
                    angle += speed / 3000;
                }
                //Als knop S en down wordt ingedrukt
                if (keyState.IsKeyDown(controls.down))
                {
                    if (speed > -80)
                    {
                        speed -= 2 * boost;
                    }
                    else if (speed == -80)
                    {
                        speed -= boost;
                    }
                }
                //Als knop W en up wordt ingedrukt
                if (keyState.IsKeyDown(controls.up))
                {
                    if (speed < (waterComponent.water * 2.5f) + 150)
                    {
                        speed += boost;
                    }

                    if (speed > (waterComponent.water * 2.5f) + 150)
                    {
                        if (powercounter < 100)
                        {
                            powercounter++;
                        }
                        else
                        {
                            speed -= boost;
                        }
                    }
                }

                else
                {
                    if (speed > 0)
                    {
                        speed -= boost;
                    }

                    if (speed < 0)
                    {
                        speed += boost;
                    }
                }
            }
            velocity.Y += (float)Math.Sin(angle) * speed;
            velocity.X += (float)Math.Cos(angle) * speed;
            // geeft de speed en laps door aan de GUI per konijn.
            if (playerid == 1)
            {
                GUIM.speed1    = speed;
                GUIM.laps1     = laps;
                GUIM.checks1   = checks;
                GUIM.pitstops1 = pitstops;
            }

            if (playerid == 2)
            {
                GUIM.speed2    = speed;
                GUIM.laps2     = laps;
                GUIM.checks2   = checks;
                GUIM.pitstops2 = pitstops;
            }
        }