public void Update(double gameTime)
        {
            switch (_direction)
            {
            case Direction.Up:

                _sprite.Move(0, _speed * -1);

                break;

            case Direction.Down:

                _sprite.Move(0, _speed);

                break;

            case Direction.Left:

                _sprite.Move(_speed * -1, 0);

                break;

            case Direction.Right:

                _sprite.Move(_speed, 0);

                break;
            }

            if (_collision.CheckCollision(new Rectangle((int)_sprite.Position.X, (int)_sprite.Position.Y, _sprite.Width, _sprite.Height), false))
            {
                Dead = true;
            }
        }
Example #2
0
        /// <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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            #region Controls
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                cam.Move(new Vector2(-1, 0) * speed, GraphicsDevice.Viewport);
                SPghost.Move(new Vector2(-1, 0) * speeds);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                cam.Move(new Vector2(1, 0) * speed, GraphicsDevice.Viewport);
                SPghost.Move(new Vector2(1, 0) * speed);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                cam.Move(new Vector2(0, -1) * speed, GraphicsDevice.Viewport);
                SPghost.Move(new Vector2(0, -1) * speed);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                cam.Move(new Vector2(0, 1) * speed, GraphicsDevice.Viewport);
                SPghost.Move(new Vector2(0, 1) * speed);
            }
            #endregion

            base.Update(gameTime);
        }
Example #3
0
        private void MoveBack(Sprite sprite)
        {
            var ownerSprite = Owner.GetComponent <Sprite>();

            if (ownerSprite == null)
            {
                _currentState = BoomerangState.Stop;
                Active        = false;
            }

            if (ManagerFunction.Distance(sprite.Position, ownerSprite.Position) < 2)
            {
                _currentState = BoomerangState.Stop;
                Active        = false;
                return;
            }

            if (ownerSprite.Position.X < sprite.Position.X)
            {
                sprite.Move(-1 * _speed, 0);
            }
            if (ownerSprite.Position.X > sprite.Position.X)
            {
                sprite.Move(_speed, 0);
            }
            if (ownerSprite.Position.Y < sprite.Position.Y)
            {
                sprite.Move(0, -1 * _speed);
            }
            if (ownerSprite.Position.Y > sprite.Position.Y)
            {
                sprite.Move(0, _speed);
            }
        }
Example #4
0
        public void JumpSide(Sprite character, double start, double end, int dir, Coordinates land)
        {
            Coordinates startpos = (Coordinates)character.Value(start)[CommandType.Move];
            Coordinates endpos   = (Coordinates)(startpos - new Coordinates(10 * dir, 0));

            character.Move(EaseType.EasingOut, start, start + 30, startpos, endpos);
            character.Move(EaseType.EasingIn, end - 30, end, endpos, land);
        }
Example #5
0
        public void Support(double start, int target, Color color)
        {
            var offset = 20;
            var amount = 12;

            for (var i = 0; i < amount; i++)
            {
                Sprite back  = Layers.CreateSprite($"kiai spell back{target / 6}", "sb/atk/rb", Origin.BottomCentre);
                Sprite front = Layers.CreateSprite($"kiai spell front{target / 6}", "sb/atk/rf", Origin.BottomCentre);

                var stime = start + offset * i;
                var etime = start + beat / 2 + offset * i;

                var width  = 900 / 6;
                var height = 220 / 3;
                var row    = target / 6;
                var col    = target % 6;

                Coordinates c = new Coordinates(col * width + 900 / 12 + (320 - 450), row * height + 220 / 6 + 240);

                back.Move(stime, (Coordinates)(c + new generator.Coordinates(0, -10 * i)));
                front.Move(stime, (Coordinates)(c + new generator.Coordinates(0, -10 * i)));

                back.Color(stime, color);
                front.Color(stime, color);

                back.Fade(stime, stime + 10, 0, .5);
                front.Fade(stime, stime + 10, 0, .5);

                back.Fade(etime - 10, etime, .5, 0);
                front.Fade(etime - 10, etime, .5, 0);
            }
        }
Example #6
0
        private async void Fireball_MessageReceived(Sprite me, Sprite.MessageReceivedArgs what)
        {
            if (what.message == "fire" && !me.Visible)
            {
                me.SetPosition(Dark.Position);
                me.SetRotationStyle(Sprite.RotationStyle.AllAround);
                me.PointTowards(Player.Position);
                me.Show();

                int i = 60;
                while (i-- > 0 && Running)
                {
                    await Delay(0.1);

                    me.Move(20);
                    if (me.IsTouching(Player))
                    {
                        await Delay(0.25);

                        break;
                    }
                    if (me.IsTouchingEdge())
                    {
                        break;
                    }
                }

                me.Hide();
            }
        }
Example #7
0
        public Sprite CreateCharacter(int charnum, int col, int row, double start)
        {
            Sprite s      = Layers.CreateSprite($"kiai chars{row}", $"sb/char/{charnum}", Origin.BottomCentre);
            var    width  = 900 / 6;
            var    height = 220 / 3;

            s.Move(start, col * width + 900 / 12 + (320 - 450), row * height + 220 / 6 + 240);
            return(s);
        }
Example #8
0
        private bool GetCloser(int target)
        {
            if (Rooted)
            {
                return(false);
            }

            var step = -1;

            if (Level.Adjacent(pos, target))
            {
                if (FindChar(target) == null)
                {
                    if (Level.pit[target] && !Flying && !Chasm.JumpConfirmed)
                    {
                        Chasm.HeroJump(this);
                        Interrupt();
                        return(false);
                    }

                    if (Level.passable[target] || Level.avoid[target])
                    {
                        step = target;
                    }
                }
            }
            else
            {
                const int len      = Level.Length;
                var       p        = Level.passable;
                var       v        = Dungeon.Level.visited;
                var       m        = Dungeon.Level.mapped;
                var       passable = new bool[len];
                for (var i = 0; i < len; i++)
                {
                    passable[i] = p[i] && (v[i] || m[i]);
                }

                step = Dungeon.FindPath(this, pos, target, passable, Level.fieldOfView);
            }

            if (step == -1)
            {
                return(false);
            }

            var oldPos = pos;

            Move(step);
            Sprite.Move(oldPos, pos);

            Spend(1 / Speed());

            return(true);
        }
Example #9
0
        private async Task Move(Sprite me)
        {
            int times = 10;

            while (times-- > 0 && Running)
            {
                await Delay(0.2);

                me.Move(10);
            }
        }
Example #10
0
        public void Update(double gameTime)
        {
            switch (_direction)
            {
            case Direction.Up:
                _sprite.Move(0, -_speed);
                break;

            case Direction.Down:
                _sprite.Move(0, _speed);
                break;

            case Direction.Left:
                _sprite.Move(-_speed, 0);
                break;

            case Direction.Right:
                _sprite.Move(_speed, 0);
                break;
            }
        }
Example #11
0
        public override void Update(float dt)
        {
            m_sprite.Move(200.0f * dt, 200.0f * dt);

            if (m_sprite.X > Engine.Canvas.Width + m_sprite.Width)
            {
                m_sprite.SetPosition(0f, m_sprite.Y);
            }

            if (m_sprite.Y > Engine.Canvas.Height + m_sprite.Height)
            {
                m_sprite.SetPosition(m_sprite.X, 0f);
            }
        }
        // --

        public void HandleQuadMovement()
        {
            if (WindowLayer.GetKeyDown(ctx, 'W') && Math.Abs(quad.body.GetVelocity().y) <= 0.01f)
            {
                quad.body.ApplyImpulse(IMPULSE_POWER);
            }
            if (WindowLayer.GetKey(ctx, 'A'))
            {
                quad.Move(-vec2.UnitX * deltaTime);
            }
            if (WindowLayer.GetKey(ctx, 'D'))
            {
                quad.Move(vec2.UnitX * deltaTime);
            }
            if (WindowLayer.GetKey(ctx, 'Q'))
            {
                quad.Rotate(deltaTime * (float)Math.PI);
            }
            if (WindowLayer.GetKey(ctx, 'E'))
            {
                quad.Rotate(-deltaTime * (float)Math.PI);
            }
        }
Example #13
0
        public void Shoot(double start, Coordinates origin, int target, string image, bool spin, params Color[] colors)
        {
            int amount = 3;
            var offset = 100;

            for (var i = 0; i < amount; i++)
            {
                Color cl;
                if (colors.Length == 1)
                {
                    cl = colors[0];
                }
                else
                {
                    cl = colors[i];
                }
                Sprite bullet = Layers.CreateSprite($"kiai spell front{target / 6}", image);

                var stime = start + offset * i;
                var etime = start + 500 + offset * i;

                var width  = 900 / 6;
                var height = 220 / 3;
                var row    = target / 6;
                var col    = target % 6;

                Coordinates c     = (Coordinates)(new Coordinates(col * width + 900 / 12 + (320 - 450), row * height + 220 / 6 + 240) + new Coordinates(random.Next(-40, 40), random.Next(-40, 40) - 80));
                Coordinates o     = (Coordinates)(origin + new Coordinates(random.Next(-40, 40), random.Next(-40, 40) - 80));
                var         angle = Math.Tan((c.Y - o.Y) / (c.X - o.X));

                bullet.Move(stime, etime, o, c);
                if (!spin)
                {
                    bullet.Rotate(stime, new Angle(angle, true));
                }
                else
                {
                    bullet.Rotate(stime, etime, new Angle(angle, true), (Angle)(new Angle(angle, true) + new Angle(720)));
                }
                if (target % 6 < 3)
                {
                    bullet.Flip(stime, etime, "H");
                }

                bullet.Color(stime, cl);
            }
        }
Example #14
0
        public void DrawTileBackground(double starttime, double endtime)
        {
            //The background colors of tiles
            Sprite tback1 = Util.Line(450, 220, Origin.TopRight);
            Sprite tback2 = Util.Line(450, 220, Origin.TopLeft);
            Sprite tside1 = Util.Line(450, 20, Origin.TopRight);
            Sprite tside2 = Util.Line(450, 20, Origin.TopLeft);

            tback1.Move(starttime, 320, 240);
            tback2.Move(starttime, 320, 240);
            tside1.Move(starttime, 320, 460);
            tside2.Move(starttime, 320, 460);

            Color red   = new ColorRGB(210, 210, 210);
            Color sred  = (Color)(red - 30);
            Color blue  = new ColorRGB(45, 45, 45);
            Color sblue = (Color)(blue - 30);

            Color black = new ColorRGB(0, 0, 0);

            double fadestart = endtime - beat * 4;
            double fadeend   = endtime;

            tback1.Color(starttime, red);
            tback1.Color(fadestart, fadeend, red, black);

            tside1.Color(starttime, sred);
            tside1.Color(fadestart, fadeend, sred, black);

            tback2.Color(starttime, blue);
            tback2.Color(fadestart, fadeend, blue, black);

            tside2.Color(starttime, sblue);
            tside2.Color(fadestart, fadeend, sblue, black);

            tback1.Fade(starttime, starttime + beat * 1.5, 0, 1);
            tback2.Fade(starttime, starttime + beat * 1.5, 0, 1);
            tside1.Fade(starttime, starttime + beat * 1.5, 0, 1);
            tside2.Fade(starttime, starttime + beat * 1.5, 0, 1);

            tback1.Fade(fadestart, fadeend, 1, 0);
            tback2.Fade(fadestart, fadeend, 1, 0);
            tside1.Fade(fadestart, fadeend, 1, 0);
            tside2.Fade(fadestart, fadeend, 1, 0);

            Layers.AddSprite("kiai tiles", tback1, tback2, tside1, tside2);
        }
Example #15
0
        private void Jump()
        {
            _timeToJump = JumpDelay;

            for (var i = 0; i < 4; i++)
            {
                int trapPos;

                do
                {
                    trapPos = pdsharp.utils.Random.Int(Level.Length);
                }while (!Level.fieldOfView[trapPos] || !Level.passable[trapPos]);

                if (Dungeon.Level.map[trapPos] != Terrain.INACTIVE_TRAP)
                {
                    continue;
                }

                Level.Set(trapPos, Terrain.POISON_TRAP);
                GameScene.UpdateMap(trapPos);
                ScrollOfMagicMapping.Discover(trapPos);
            }

            int newPos;

            do
            {
                newPos = pdsharp.utils.Random.Int(Level.Length);
            }while (!Level.fieldOfView[newPos] || !Level.passable[newPos] || Level.Adjacent(newPos, Enemy.pos) || FindChar(newPos) != null);

            Sprite.Move(pos, newPos);
            Move(newPos);

            if (Dungeon.Visible[newPos])
            {
                CellEmitter.Get(newPos).Burst(Speck.Factory(Speck.WOOL), 6);
                Sample.Instance.Play(Assets.SND_PUFF);
            }

            Spend(1 / Speed());
        }
Example #16
0
        private void MoveForward(Sprite sprite)
        {
            var x = 0f;
            var y = 0f;

            switch (_currentDirection)
            {
            case Direction.Up:
                y = -1 * _speed;
                break;

            case Direction.Down:
                y = _speed;
                break;

            case Direction.Left:
                x = -1 * _speed;
                break;

            case Direction.Right:
                x = _speed;
                break;

            default:
                return;
            }

            if (_currentState == BoomerangState.Forward)
            {
                var collision = GetComponent <Collision>();
                if (collision != null && collision.CheckCollisionWithTiles(new Rectangle((int)(sprite.Position.X + x), (int)(sprite.Position.Y + y), sprite.Width, sprite.Height)))
                {
                    _currentState = BoomerangState.Back;
                    _counter      = 0;
                }
                else
                {
                    sprite.Move(x, y);
                }
            }
        }
Example #17
0
        void UpdateGame(GameTime gameTime)
        {
            if (toGame)
            {
                playerSprite.UpperLeft = new Vector2(0, 0);

                pointerSprite.UpperLeft = new Vector2(0, 200);

                toGame = false;
            }
            if (playerSprite.IsCollided(pointerSprite) == true)
            {
                playerSprite.SetVelocity(0, 0);
            }
            else
            {
                playerSprite.Accelerate(0.0f, 0.05f);

                playerSprite.Move();
            }
        }
Example #18
0
        // This method is provided fully complete as part of the activity starter.
        private void updatePlaying(GameTime gameTime, KeyboardState currentKeyboard, GamePadState currentGamePad1, GamePadState currentGamePad2)
        {
            // Escape key (or gamepad Start button)pauses the game when playing
            if (wasKeyPressed(Keys.Escape, currentKeyboard) || wasButtonStartPressed(currentGamePad1, currentGamePad2))
            {
                currentScreen = GameScreen.PAUSED;
                return; // don't do anything else if we're now paused!
            }

            // check player 1 keys
            if (currentKeyboard.IsKeyDown(Keys.W) || (currentGamePad1.ThumbSticks.Left.Y > 0))
            {
                // 'W' (or gamepad thumbstick up) means accelerate up
                StarShip1.Accelerate(0, -ACCELERATION_FACTOR);
            }

            if (currentKeyboard.IsKeyDown(Keys.A) || (currentGamePad1.ThumbSticks.Left.X < 0))
            {
                // 'A' (or gamepad thumbstick left) means move a bit to the left
                StarShip1.UpperLeft.X -= X_STEER_FACTOR;
                if (StarShip1.UpperLeft.X < 0)
                {
                    StarShip1.UpperLeft.X = 0;
                }
            }

            if (currentKeyboard.IsKeyDown(Keys.D) || (currentGamePad1.ThumbSticks.Left.X > 0))
            {
                // 'D' (or gamepad thumbstick right) means move a bit to the right
                StarShip1.UpperLeft.X += X_STEER_FACTOR;
                if (StarShip1.UpperLeft.X + StarShip1.GetWidth() > VIEWPORT_WIDTH)
                {
                    StarShip1.UpperLeft.X = VIEWPORT_WIDTH - StarShip1.GetWidth();
                }
            }

            if (currentKeyboard.IsKeyDown(Keys.X) || (currentGamePad1.ThumbSticks.Left.Y < 0))
            {
                // 'X' (or gamepad thumbstick down) means slow down
                if (StarShip1.GetVelocity().Y < 0)
                {
                    StarShip1.Accelerate(0, ACCELERATION_FACTOR);
                }
            }

            // now check player2 input unless it's an AI-controlled player
            if (!isGameAIEnabled)
            {
                // check player 2 controls
                if (currentKeyboard.IsKeyDown(Keys.Up) || (currentGamePad2.ThumbSticks.Left.Y > 0))
                {
                    // up arrow means accelerate up
                    StarShip2.Accelerate(0, -ACCELERATION_FACTOR);
                }

                if (currentKeyboard.IsKeyDown(Keys.Down) || (currentGamePad2.ThumbSticks.Left.Y < 0))
                {
                    // down arrow means slow down
                    if (StarShip2.GetVelocity().Y < 0)
                    {
                        StarShip2.Accelerate(0, ACCELERATION_FACTOR);
                    }
                }

                if (currentKeyboard.IsKeyDown(Keys.Left) || (currentGamePad2.ThumbSticks.Left.X < 0))
                {
                    // left arrow means move a bit to the left
                    StarShip2.UpperLeft.X -= X_STEER_FACTOR;
                    if (StarShip2.UpperLeft.X < 0)
                    {
                        StarShip2.UpperLeft.X = 0;
                    }
                }

                if (currentKeyboard.IsKeyDown(Keys.Right) || (currentGamePad2.ThumbSticks.Left.X > 0))
                {
                    // right arrow means move a bit to the right
                    StarShip2.UpperLeft.X += X_STEER_FACTOR;
                    if (StarShip2.UpperLeft.X + StarShip2.GetWidth() > VIEWPORT_WIDTH)
                    {
                        StarShip2.UpperLeft.X = VIEWPORT_WIDTH - StarShip2.GetWidth();
                    }
                }
            }
            else
            {
                // call the AI routine to control the second space ship
                DoSimpleAI();
            }

            // move both ships in the Y direction
            // (X velocity we leave at zero so we can move strictly according to left/right keys above)
            StarShip1.Move();
            StarShip2.Move();

            // move the cameras along with the space ship, keeping ship 4/5 of the way down the screen
            if (player1Camera != null)
            {
                player1Camera.UpperLeft.Y = StarShip1.UpperLeft.Y - VIEWPORT_HEIGHT * 4 / 5;
            }
            if (player2Camera != null)
            {
                player2Camera.UpperLeft.Y = StarShip2.UpperLeft.Y - VIEWPORT_HEIGHT * 4 / 5;
            }

            // make sure camera remains within valid world coordinates near the finish line!
            if (player1Camera != null)
            {
                player1Camera.LockCamera();
            }
            if (player2Camera != null)
            {
                player2Camera.LockCamera();
            }

            // move all the asteroids, allowing them to wrap around the screen.
            // not realistic, but to the player it might as well be a new asteroid!
            foreach (Sprite asteroid in Asteroids)
            {
                asteroid.MoveAndWrap(WORLD_WIDTH, WORLD_HEIGHT);
            }

            // see if any asteroids have hit a ship
            checkCollisions();

            // check to see if anyone has won
            if (StarShip1.UpperLeft.Y <= (finishLine.UpperLeft.Y + finishLine.GetHeight()))
            {
                currentScreen   = GameScreen.GAMEOVER;
                gameOverMessage = "Player 1 has won!";
            }
            if (StarShip2.UpperLeft.Y <= finishLine.GetHeight())
            {
                currentScreen   = GameScreen.GAMEOVER;
                gameOverMessage = "Player 2 has won!";
            }
        }
Example #19
0
        private void Virus_MessageReceived(Sprite me, Sprite.MessageReceivedArgs what)
        {
            if (what.message == "start")
            {
                me.SetCostumes("04/V.png", "04/I.png", "04/R.png", "04/U.png", "04/S.png");
                me.SetPosition(RightEdge, 0);
                me.PointTowards(Neo_Cat.Position);
                me.SetRotationStyle(Sprite.RotationStyle.DoNotRotate);
                me.Show();

                Task.Run(async() =>
                {
                    while (Running)
                    {
                        await Delay(0.3);
                        me.NextCostume();
                    }
                    while (true)
                    {
                        if (IsGamePadButtonPressed(GamepadButtons.Menu))
                        {
                            GoBack();
                        }
                        await Delay(0.1);
                    }
                });
                Task.Run(async() =>
                {
                    var deadly = true;
                    while (Running)
                    {
                        if (me.IsTouching(Neo_Cat))
                        {
                            me.PointInDirection(Random(-45, 45));
                            Score.Value++;

                            if (Score.Value >= 30)
                            {
                                Sprite.Broadcast("win");
                                Running = false;
                            }

                            me.Move(100);
                        }
                        else if ((me.IsTouching(Server1) || me.IsTouching(Server2)) && deadly)
                        {
                            deadly = false;
                            Sprite.Broadcast("oh");
                            Chances.Value--;
                            if (Chances.Value <= 0)
                            {
                                Running = false;
                                Sprite.Broadcast("lose");
                            }

                            var ignore = Task.Run(async() =>
                            {
                                await Delay(1.0);
                                deadly = true;
                            });
                        }
                        me.Move(30);
                        await Delay(0.075);
                        me.IfOnEdgeBounce();
                    }
                    me.Hide();
                });
            }
        }
Example #20
0
        public void JumpReturn(Sprite character, double start, Coordinates origin)
        {
            Coordinates startpos = (Coordinates)character.Value(start)[CommandType.Move];

            character.Move(EaseType.EasingOut, start, start + 30, startpos, origin);
        }
Example #21
0
        protected override void Update(GameTime gameTime)
        {
            Galaxy.Core.Input.Update();

            // Allows the game to exit
            if (Input.IsKeyPressed(Keys.Escape) ||
                Input.IsButtonPressed(Buttons.Start))
            {
                this.Exit();
            }

            /* Just test code to move, zoom and rotation the demo sprite */
            if (demoSpr != null)
            {
                demoSpr.Rotate(1);
                demoSpr.SetZoom((uint)zoom, (uint)zoom);
                zoom += zoomStep;
                if (zoom > 500)
                {
                    zoomStep = -5;
                    zoom     = 500;
                }
                if (zoom < 0)
                {
                    zoomStep = 5;
                    zoom     = 0;
                }

                if (Input.IsKeyDown(Keys.Left) ||
                    Input.IsButtonDown(Buttons.DPadLeft))
                {
                    demoSpr.Move(-2.0f, 0.0f);
                }
                if (Input.IsKeyDown(Keys.Right) ||
                    Input.IsButtonDown(Buttons.DPadRight))
                {
                    demoSpr.Move(2.0f, 0.0f);
                }
                if (Input.IsKeyDown(Keys.Up) ||
                    Input.IsButtonDown(Buttons.DPadUp))
                {
                    demoSpr.Move(0.0f, -2.0f);
                }
                if (Input.IsKeyDown(Keys.Down) ||
                    Input.IsButtonDown(Buttons.DPadDown))
                {
                    demoSpr.Move(.0f, 2.0f);
                }

                if (Input.IsKeyPressed(Keys.Space) ||
                    Input.IsButtonPressed(Buttons.A))
                {
                    Graphics.RemoveImage(1, demoSpr);
                    demoSpr = null;
                }
            }

            UpdateCamera(ref projectionMatrix, ref viewMatrix);

            m_Terrain.Update(projectionMatrix, viewMatrix);
            m_PlayerPlane.Update(gameTime, projectionMatrix, viewMatrix);

            base.Update(gameTime);
        }
Example #22
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //give player pad control
            pad.Control();

            //ball move/check
            if (ball.Move() == 1)
            {
                soundBank.PlayCue("kick_shell");
            }

            //checks if the wall behind the paddle was hit, and increases computer's score
            if (ball.wallCheck() == 1)
            {
                defaultLoads();
                scorec++;
            }

            //checks for music pause
            KeyboardState kbs = Keyboard.GetState();

            if (kbs.IsKeyDown(Keys.P) && pkbs.IsKeyDown(Keys.P) == false)
            {
                if (p == 1)
                {
                    MediaPlayer.Resume();
                    p = 0;
                }
                else
                {
                    MediaPlayer.Pause();
                    p = 1;
                }
            }
            pkbs = kbs;

            //bounding sphere checks for paddle and ball
            if (ball.boundingSphere.Intersects(pad.boundingBox))
            {
                ball.velocity = new Vector2(ballSpeed++, angle++);
                soundBank.PlayCue("bonk");
                scorep++;
                pad.increasePad();
            }

            //game over check
            if (scorep == 25 || scorec == 25)
            {
                scorep = scorec = 0;
                soundBank.PlayCue("victory");
                defaultLoads();
            }

            //animate speed
            timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
            if (timeSinceLastFrame > msPerFrame)
            {
                timeSinceLastFrame -= msPerFrame;
                ++cFrame.X;
                if (cFrame.X >= sSize.X)
                {
                    cFrame.X = 0;
                    ++cFrame.Y;
                    if (cFrame.Y >= sSize.Y)
                    {
                        cFrame.Y = 0;
                    }
                }
            }

            base.Update(gameTime);
        }
Example #23
0
        private void MoveForward(Sprite sprite)
        {
            var x = 0f;
            var y = 0f;

            switch (_currentDirection)
            {
                case Direction.Up:
                    y = -1*_speed;
                    break;

                case Direction.Down:
                    y = _speed;
                    break;

                case Direction.Left:
                    x = -1*_speed;
                    break;

                case Direction.Right:
                    x = _speed;
                    break;
                default:
                    return;

            }

            if (_currentState == BoomerangState.Forward)
            {
                var collision = GetComponent<Collision>();
                if(collision != null && collision.CheckCollisionWithTiles(new Rectangle((int) (sprite.Position.X + x), (int) (sprite.Position.Y + y),sprite.Width,sprite.Height)))
                {
                    _currentState = BoomerangState.Back;
                    _counter = 0;
                }
                else
                {
                    sprite.Move(x,y);
                }
            }
        }
Example #24
0
        private void MoveBack(Sprite sprite)
        {
            var ownerSprite = Owner.GetComponent<Sprite>();
            if(ownerSprite == null)
            {
                _currentState = BoomerangState.Stop;
                Active = false;
            }

            if(ManagerFunction.Distance(sprite.Position,ownerSprite.Position) < 2)
            {
                _currentState = BoomerangState.Stop;
                Active = false;
                return;
            }

            if(ownerSprite.Position.X < sprite.Position.X)
                sprite.Move(-1*_speed,0);
            if (ownerSprite.Position.X > sprite.Position.X)
                sprite.Move(_speed, 0);
            if (ownerSprite.Position.Y < sprite.Position.Y)
                sprite.Move(0, -1*_speed);
            if (ownerSprite.Position.Y > sprite.Position.Y)
                sprite.Move(0, _speed);
        }
Example #25
0
        public List <Sprite> Render(double StartTime, double EndTime, double RevolutionDuration, double Scale, double Tilt, double SpriteScale, String SpritePath, bool ImageRotation = false, bool AutoFade = true, bool AutoScale = true, bool Revolution = true)
        {
            List <Sprite> Sprites = new List <Sprite>();

            foreach (Vector3 Vertex in Vertices)
            {
                Sprite Sprite = Layer.CreateSprite(SpritePath, Origin);
                double Angle  = Math.Atan2(Vertex.Z, Vertex.X);
                double Delay  = Angle / (Math.PI * 2) * RevolutionDuration;
                double Radius = Scale * Vector2.Distance(new Vector2(Vertex.X, Vertex.Z), new Vector2());

                if (SpriteScale != 0 && AutoScale)
                {
                    Sprite.Scale(StartTime, SpriteScale);
                }

                Sprite.Fade(StartTime - Delay - RevolutionDuration, 0);

                if (AutoFade)
                {
                    Sprite.Fade(StartTime, 1);
                    Sprite.Fade(EndTime, 0);
                }

                Sprite.BeginLoop(StartTime - Delay - RevolutionDuration, (EndTime - StartTime) / RevolutionDuration + 3);

                if (Revolution)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        double StartAngle      = Math.PI * i / 2;
                        double EndAngle        = Math.PI * (i + 1) / 2;
                        double SpriteStartTime = RevolutionDuration * i / 4;
                        double SpriteEndTime   = RevolutionDuration * (i + 1) / 4;

                        Sprite.MoveX(i % 2 + 1, SpriteStartTime, SpriteEndTime,
                                     PositionX + Radius * Math.Sin(StartAngle),
                                     PositionX + Radius * Math.Sin(EndAngle));
                        Sprite.MoveY((i + 1) % 2 + 1, SpriteStartTime, SpriteEndTime,
                                     PositionY - Vertex.Y * Scale + Tilt * Radius * Math.Cos(StartAngle),
                                     PositionY - Vertex.Y * Scale + Tilt * Radius * Math.Cos(EndAngle));
                    }
                }
                else
                {
                    double X = PositionX + Radius * Math.Sin(Angle);
                    double Y = PositionY + Tilt * Radius * Math.Cos(Angle) - Vertex.Y * Scale;

                    Sprite.Move(StartTime, X, Y);
                }

                if (ImageRotation)
                {
                    Sprite.Rotate(0, RevolutionDuration, 0, -Math.PI * 2);
                }

                Sprite.EndLoop();

                Sprites.Add(Sprite);
            }

            return(Sprites);
        }