コード例 #1
0
 public override void OnKeyDown(bool[] keyState)
 {
     if (keyState[(int)Keyboard.Key.Escape])
     {
         RunningEngine.SetQuit(true);
     }
 }
コード例 #2
0
        public override void Draw(RenderTarget target, RenderStates states)
        {
            /*Text text = new Text("Eksedra Engine Test Demo", RunningEngine.Fonts["JosefinSans"], 20);
             * text.Position = new Vector2f(RunningEngine.ViewPort.Left + 32, RunningEngine.ViewPort.Top + 32);
             * text.FillColor = Color.Black;
             *
             * target.Draw(text);*/

            if (RunningEngine.CurrentRoom == "title")
            {
                Text text = new Text("NEW SUPER CHUNKS", RunningEngine.Fonts["Pixeled"], 36);
                text.Position  = new Vector2f(64 + 1280 / 4, 720 - 64 * 7);
                text.FillColor = Color.White;

                Vector2i mousePos = Mouse.GetPosition() - RunningEngine.GetWindow().Position;
                float    centerX  = RunningEngine.ViewPort.Left + RunningEngine.ViewPort.Width / 2;
                float    centerY  = RunningEngine.ViewPort.Top + RunningEngine.ViewPort.Height / 2;
                if (mousePos.X > centerX - 172 && mousePos.X < centerX + 172 &&
                    mousePos.Y > centerY - 160 + 32 && mousePos.Y < centerY - 80 + 32)
                {
                    target.Draw(PlayButtonOn);
                }
                else
                {
                    target.Draw(PlayButtonOff);
                }

                target.Draw(text);
            }
        }
コード例 #3
0
        public override void OnKeyDown(bool[] keyState)
        {
            if (keyState[(int)Keyboard.Key.Escape])
            {
                RunningEngine.SetQuit(true);
            }

            /*if(keyState[(int) Keyboard.Key.Space])
             *  RunningEngine.CurrentRoom = "test";*/
        }
コード例 #4
0
        public override void Update(float deltaTime)
        {
            GameObject player = null;

            if (RunningEngine.CheckCollision(X, Y - 1, this, typeof(Player), (self, otra) => true, ref player))
            {
                if ((player as Player).Pounded && BlockPosition != BlockType.PassThrough)
                {
                    BlockPosition      = BlockType.PassThrough;
                    SpriteIndex        = new EksedraSprite(RunningEngine.Images["box"], new IntRect[] { new IntRect(128, 0, 64, 64) });
                    SpriteIndex.Smooth = false;

                    (player as Player).Pounded = false;

                    player.VSpeed = -300;
                }
            }
        }
コード例 #5
0
        public override void OnKeyHeld(bool[] keyState)
        {
            if (RunningEngine.CurrentRoom == "title")
            {
                SpriteIndex = PlayerRun;
                return;
            }

            GameObject other = null;

            if (RunningEngine.CheckCollision(X, Y, this, typeof(LadderBlock), (self, otra) => true, ref other))
            {
                if (!IsSwimming && !IsClimbing && (keyState[(int)Keyboard.Key.Up] || keyState[(int)Keyboard.Key.Down]))
                {
                    IsClimbing = true;
                }
            }

            if (keyState[(int)Keyboard.Key.Left] && CanPunch)
            {
                HSpeed = -MoveSpeed;
            }
            else if (keyState[(int)Keyboard.Key.Right] && CanPunch)
            {
                HSpeed = MoveSpeed;
            }

            if ((IsClimbing || IsSwimming) && keyState[(int)Keyboard.Key.Up])
            {
                VSpeed = -MoveSpeed;
            }
            else if ((IsClimbing || IsSwimming) && keyState[(int)Keyboard.Key.Down])
            {
                VSpeed = MoveSpeed;
            }
        }
コード例 #6
0
        public override void Update(float deltaTime)
        {
            //Console.WriteLine(RunningEngine.GetWindowWidth() + ", " + RunningEngine.GetWindowHeight());
            if (X + MaskX + MaskWidth > RunningEngine.GetRoomSize().X)
            {
                X      = RunningEngine.GetRoomSize().X - MaskX - MaskWidth;
                HSpeed = 0;
            }
            else if (X + MaskX < 0)
            {
                X      = -MaskX;
                HSpeed = 0;
            }
            else if (Y + MaskY + MaskHeight > RunningEngine.GetRoomSize().Y)
            {
                Y      = RunningEngine.GetRoomSize().Y - MaskY - MaskHeight;
                VSpeed = 0;
            }
            else if (Y + MaskY < 0)
            {
                Y      = -MaskY;
                VSpeed = 0;
            }

            if (VSpeed < MaxVSpeed && !IsGrounded)
            {
                VSpeed += Gravity * deltaTime;
            }

            // Horizontal collision
            GameObject other = null;

            if (HSpeed > 0 && RunningEngine.CheckCollision(X + HSpeed * deltaTime, Y - 0.1f, this, typeof(Rock), (self, otra) => true, ref other))
            {
                X      = other.X + other.MaskX - (MaskX + MaskWidth);
                HSpeed = 0;
            }

            if (HSpeed < 0 && RunningEngine.CheckCollision(X + HSpeed * deltaTime, Y - 0.1f, this, typeof(Rock), (self, otra) => true, ref other))
            {
                X      = other.X + other.MaskX + other.MaskWidth - MaskX;
                HSpeed = 0;
            }

            // Vertical Collision
            if (VSpeed > 0 && RunningEngine.CheckCollision(X, Y + VSpeed * deltaTime, this, typeof(Rock),
                                                           (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY, ref other))
            {
                Y          = other.Y + other.MaskY - (MaskY + MaskHeight);
                VSpeed     = 0;
                IsGrounded = true;
            }
            else if (VSpeed > 0 && RunningEngine.CheckCollision(X, Y + VSpeed * deltaTime, this, typeof(JumpThrough),
                                                                (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY, ref other))
            {
                Y          = other.Y + other.MaskY - (MaskY + MaskHeight);
                VSpeed     = 0;
                IsGrounded = true;
            }
            else if (!RunningEngine.CheckCollision(X, Y + 1, this, typeof(Rock),
                                                   (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY, ref other) &&
                     !RunningEngine.CheckCollision(X, Y + 1, this, typeof(JumpThrough),
                                                   (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY, ref other))
            {
                IsGrounded = false;
            }

            if (VSpeed < 0 && RunningEngine.CheckCollision(X, Y + VSpeed * deltaTime, this, typeof(Rock),
                                                           (self, otra) => self.Y + self.MaskY >= otra.Y + otra.MaskY + otra.MaskHeight, ref other))
            {
                Y      = other.Y + other.MaskY + other.MaskHeight - MaskY;
                VSpeed = 0;
            }

            // Animate
            if (IsGrounded)
            {
                SpriteIndex = Math.Abs(HSpeed) > 0 ? PlayerRun : PlayerStand;
            }
            else
            {
                SpriteIndex = PlayerFall;
            }

            if (HSpeed > 0)
            {
                ImageScaleX = Math.Abs(ImageScaleX);
            }
            else if (HSpeed < 0)
            {
                ImageScaleX = -Math.Abs(ImageScaleX);
            }

            // Move the view
            if (X - RunningEngine.ViewPort.Width / 2 < 0)
            {
                RunningEngine.ViewPort.Left = 0;
            }
            else if (X + RunningEngine.ViewPort.Width / 2 > RunningEngine.GetRoomSize().X)
            {
                RunningEngine.ViewPort.Left = RunningEngine.GetRoomSize().X - RunningEngine.ViewPort.Width;
            }
            else
            {
                RunningEngine.ViewPort.Left = X - RunningEngine.ViewPort.Width / 2;
            }

            if (Y - RunningEngine.ViewPort.Height / 2 < 0)
            {
                RunningEngine.ViewPort.Top = 0;
            }
            else if (Y + RunningEngine.ViewPort.Height / 2 > RunningEngine.GetRoomSize().Y)
            {
                RunningEngine.ViewPort.Top = RunningEngine.GetRoomSize().Y - RunningEngine.ViewPort.Height;
            }
            else
            {
                RunningEngine.ViewPort.Top = Y - RunningEngine.ViewPort.Height / 2;
            }
        }
コード例 #7
0
        public override void Update(float deltaTime)
        {
            if (RunningEngine.CurrentRoom == "title" && RunningEngine.Audio["chunks-title-2"].Status != SoundStatus.Playing)
            {
                RunningEngine.Audio["chunks-title-2"].Loop   = true;
                RunningEngine.Audio["chunks-title-2"].Volume = 40;
                RunningEngine.Audio["chunks-title-2"].Play();
            }
            else if (RunningEngine.CurrentRoom != "title")
            {
                RunningEngine.Audio["chunks-title-2"].Loop = false;
                RunningEngine.Audio["chunks-title-2"].Stop();
            }

            if (new List <string>()
            {
                "grass-world", "air-world", "water-world"
            }.Contains(RunningEngine.CurrentRoom) &&
                RunningEngine.Audio["chunks-worldmap"].Status != SoundStatus.Playing)
            {
                RunningEngine.Audio["chunks-worldmap"].Loop   = true;
                RunningEngine.Audio["chunks-worldmap"].Volume = 75;
                RunningEngine.Audio["chunks-worldmap"].Play();
            }
            else if (!new List <string>()
            {
                "grass-world", "air-world", "water-world"
            }.Contains(RunningEngine.CurrentRoom))
            {
                RunningEngine.Audio["chunks-worldmap"].Loop = false;
                RunningEngine.Audio["chunks-worldmap"].Stop();
            }

            switch (RunningEngine.CurrentRoom)
            {
            case "title":
                RunningEngine.Background = new Color(102, 161, 255);
                break;

            case "grass-world":
                RunningEngine.Background = new Color(102, 161, 255);
                break;

            case "air-world":
                RunningEngine.Background = new Color(235, 226, 143);
                break;

            case "water-world":
                RunningEngine.Background = new Color(120, 120, 120);
                break;

            default:
                RunningEngine.Background = Color.Yellow;
                break;
            }

            if (Mouse.IsButtonPressed(Mouse.Button.Left))
            {
                //Console.WriteLine("CLICK!");
                Vector2i mousePos = Mouse.GetPosition() - RunningEngine.GetWindow().Position;
                //if(mousePos.X > 1280 / 4 + 64 && mousePos.X < 1280 / 4 + 576
                //        && mousePos.Y > (3 * 720 / 4) - 256 && mousePos.Y < (3 * 720 / 4) - 128) {
                float centerX = RunningEngine.ViewPort.Left + RunningEngine.ViewPort.Width / 2;
                float centerY = RunningEngine.ViewPort.Top + RunningEngine.ViewPort.Height / 2;
                if (mousePos.X > centerX - 172 && mousePos.X < centerX + 172 &&
                    mousePos.Y > centerY - 160 + 32 && mousePos.Y < centerY - 80 + 32)
                {
                    RunningEngine.FindGameObjectsWithTag("Player")[0].X = 32 + 64 * 9.5f;
                    RunningEngine.FindGameObjectsWithTag("Player")[0].Y = 27 * 64;
                    RunningEngine.CurrentRoom = "grass-world";
                }
            }
        }
コード例 #8
0
        // Do collisions here to update right before speed affects movement
        public override void LateUpdate(float deltaTime)
        {
            GameObject other = null;

            //Console.WriteLine(RunningEngine.GetWindowWidth() + ", " + RunningEngine.GetWindowHeight());
            if (X + MaskX + MaskWidth > RunningEngine.GetRoomSize().X)
            {
                X      = RunningEngine.GetRoomSize().X - MaskX - MaskWidth;
                HSpeed = 0;
            }
            else if (X + MaskX < 0)
            {
                X      = -MaskX;
                HSpeed = 0;
            }
            else if (Y + MaskY + MaskHeight > RunningEngine.GetRoomSize().Y)
            {
                Y      = RunningEngine.GetRoomSize().Y - MaskY - MaskHeight;
                VSpeed = 0;
            }
            else if (Y + MaskY < 0)
            {
                Y      = -MaskY;
                VSpeed = 0;
            }

            if (!RunningEngine.CheckCollision(X, Y, this, typeof(LadderBlock), (self, otra) => true, ref other))
            {
                if (IsClimbing)
                {
                    VSpeed -= JumpSpeed / 2;
                }

                IsClimbing = false;
            }

            if (RunningEngine.CheckCollision(X, Y, this, typeof(Water), (self, otra) => true, ref other))
            {
                if (!IsSwimming)
                {
                    Splash.ImageIndex = 0;
                    Timers[1]         = 0.25f;
                }

                IsSwimming = true;
            }
            else if (IsSwimming && !IsClimbing)
            {
                if (VSpeed < 0)
                {
                    VSpeed -= JumpSpeed / 2;
                }
                IsSwimming        = false;
                Splash.ImageIndex = 0;
                Timers[1]         = 0.25f;
            }

            if (IsSwimming)
            {
                CanPunch     = true;
                DoubleJumped = false;
                Pounded      = false;
            }

            if (VSpeed < MaxVSpeed && !IsGrounded && !Punched && !IsClimbing && !IsSwimming && !Pounded)
            {
                VSpeed += Gravity * deltaTime;
            }
            else if (Pounded)
            {
                VSpeed = PunchSpeed;
            }

            if (Punched)
            {
                HSpeed = Math.Sign(ImageScaleX) * PunchSpeed;
            }
            else if (!CanPunch)
            {
                HSpeed = Math.Sign(ImageScaleX) * MoveSpeed;
            }

            if (IsClimbing || IsSwimming)
            {
                //Console.WriteLine("Swimming!");
                if (HSpeed > 0 && RunningEngine.CheckCollision(X + 1, Y, this, typeof(Solid), (self, otra) => (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    X     -= HSpeed * deltaTime;
                    HSpeed = 0;
                }

                if (HSpeed < 0 && RunningEngine.CheckCollision(X - 1, Y, this, typeof(Solid), (self, otra) => (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    X     -= HSpeed * deltaTime;
                    HSpeed = 0;
                }

                if (VSpeed > 0 && RunningEngine.CheckCollision(X, Y + 1, this, typeof(Solid), (self, otra) => (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    Y     -= VSpeed * deltaTime;
                    VSpeed = 0;
                }
                else if (VSpeed > 0 && RunningEngine.CheckCollision(X, Y + 1, this, typeof(JumpThrough), (self, otra) => true, ref other))
                {
                    Y     -= VSpeed * deltaTime;
                    VSpeed = 0;
                }

                if (VSpeed < 0 && RunningEngine.CheckCollision(X, Y - 1, this, typeof(Solid), (self, otra) => (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    Y     -= VSpeed * deltaTime;
                    VSpeed = 0;
                }
            }
            else
            {
                // Work differently for proper landing
                // Horizontal collision
                if (HSpeed > 0 && RunningEngine.CheckCollision(X + 2, Y - 0.1f, this, typeof(Solid),
                                                               (self, otra) => self.Y < otra.Y + otra.MaskY + otra.MaskHeight &&
                                                               (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    X      = other.X + other.MaskX - (MaskX + MaskWidth);
                    HSpeed = 0;
                }

                if (HSpeed < 0 && RunningEngine.CheckCollision(X - 2, Y - 0.1f, this, typeof(Solid),
                                                               (self, otra) => self.Y < otra.Y + otra.MaskY + otra.MaskHeight &&
                                                               (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    //Console.WriteLine("Left Side: " + (Y + MaskY + MaskHeight) + " > Right Side: " + (other.Y + other.MaskY - 1));
                    X      = other.X + other.MaskX + other.MaskWidth - MaskX;
                    HSpeed = 0;
                }

                if (VSpeed > 0 && RunningEngine.CheckCollision(X - Math.Sign(ImageScaleX) * 1, Y + VSpeed * deltaTime, this, typeof(Solid),
                                                               (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY &&
                                                               (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    Y          = other.Y + other.MaskY - (MaskY + MaskHeight);
                    VSpeed     = 0;
                    IsGrounded = true;
                }
                else if (VSpeed > 0 && RunningEngine.CheckCollision(X - Math.Sign(ImageScaleX) * 1, Y + VSpeed * deltaTime, this, typeof(JumpThrough),
                                                                    (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY, ref other))
                {
                    Y          = other.Y + other.MaskY - (MaskY + MaskHeight);
                    VSpeed     = 0;
                    IsGrounded = true;
                }
                else if (!RunningEngine.CheckCollision(X - Math.Sign(ImageScaleX) * 1, Y + 1, this, typeof(Solid),
                                                       (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY &&
                                                       (otra as Solid).BlockPosition != BlockType.PassThrough, ref other) &&
                         !RunningEngine.CheckCollision(X - Math.Sign(ImageScaleX) * 1, Y + 1, this, typeof(JumpThrough),
                                                       (self, otra) => self.Y + self.MaskY + self.MaskHeight <= otra.Y + otra.MaskY, ref other))
                {
                    IsGrounded = false;
                }

                if (VSpeed < 0 && RunningEngine.CheckCollision(X - Math.Sign(ImageScaleX) * 1, Y + VSpeed * deltaTime, this, typeof(Solid),
                                                               (self, otra) => self.Y + self.MaskY >= otra.Y + otra.MaskY + otra.MaskHeight &&
                                                               (otra as Solid).BlockPosition != BlockType.PassThrough, ref other))
                {
                    Y      = other.Y + other.MaskY + other.MaskHeight - MaskY;
                    VSpeed = 0;
                }
            }
        }
コード例 #9
0
        public override void Update(float deltaTime)
        {
            // Animate
            if (IsSwimming)
            {
                SpriteIndex = PlayerSwim;

                if (Math.Abs(VSpeed) > 0 || Math.Abs(HSpeed) > 0)
                {
                    ImageSpeed = 10;
                }
                else
                {
                    ImageSpeed = 5;
                }
            }
            else if (IsClimbing)
            {
                SpriteIndex = PlayerClimb;

                if (Math.Abs(VSpeed) > 0)
                {
                    ImageSpeed = 10;
                }
                else
                {
                    ImageSpeed = 0;
                }
            }
            else
            {
                ImageSpeed = 10;

                if (Punched)
                {
                    SpriteIndex = PlayerPunch;
                }
                else if (Pounded)
                {
                    SpriteIndex = PlayerPound;

                    if (IsGrounded)
                    {
                        Pounded = false;
                    }
                }
                else if (IsGrounded)
                {
                    SpriteIndex = Math.Abs(HSpeed) > 0 ? PlayerRun : PlayerStand;

                    DoubleJumped = false;
                    if (!Punched)
                    {
                        CanPunch = true;
                    }
                }
                else
                {
                    SpriteIndex = !CanPunch ? (!Punched ? PlayerPunchDone : PlayerPunch) : (VSpeed > 0 ? PlayerFall : (DoubleJumped ? PlayerSuperJump : PlayerJump));
                }
            }

            if (HSpeed > 0 && CanPunch)
            {
                ImageScaleX = Math.Abs(ImageScaleX);
            }
            else if (HSpeed < 0 && CanPunch)
            {
                ImageScaleX = -Math.Abs(ImageScaleX);
            }

            if (RunningEngine.CurrentRoom == "title")
            {
                SpriteIndex = PlayerRun;
            }

            // Move the view
            if (X - RunningEngine.ViewPort.Width / 2 < 0)
            {
                RunningEngine.ViewPort.Left = 0;
            }
            else if (X + RunningEngine.ViewPort.Width / 2 > RunningEngine.GetRoomSize().X)
            {
                RunningEngine.ViewPort.Left = RunningEngine.GetRoomSize().X - RunningEngine.ViewPort.Width;
            }
            else
            {
                RunningEngine.ViewPort.Left = X - RunningEngine.ViewPort.Width / 2;
            }

            if (Y - RunningEngine.ViewPort.Height / 2 < 0)
            {
                RunningEngine.ViewPort.Top = 0;
            }
            else if (Y + RunningEngine.ViewPort.Height / 2 > RunningEngine.GetRoomSize().Y)
            {
                RunningEngine.ViewPort.Top = RunningEngine.GetRoomSize().Y - RunningEngine.ViewPort.Height;
            }
            else
            {
                RunningEngine.ViewPort.Top = Y - RunningEngine.ViewPort.Height / 2;
            }

            if (Pounded)
            {
                VSpeed = PoundSpeed;
            }

            // Room transitions
            switch (RunningEngine.CurrentRoom)
            {
            case "grass-world":
                if (X >= 32 + 29 * 64 && Y > 32 + 29 * 64)
                {
                    RunningEngine.CurrentRoom = "air-world";
                    VSpeed = 0;
                    X      = 32 + 3.5f * 64;
                    Y      = 64;
                }
                break;

            case "air-world":
                if (X < 32 && (Y < 32 + 13 * 64 && Y > 32 + 9 * 64))
                {
                    RunningEngine.CurrentRoom = "grass-world";
                    VSpeed = 0;
                    X      = 32 + 29 * 64;
                    Y      = 32 + 21 * 64;
                }
                else if (X > 32 + 15 * 64 && X < 32 + 18 * 64 && Y > 32 + 19 * 64)
                {
                    RunningEngine.CurrentRoom = "water-world";
                    X = 15 * 64;
                    Y = 32 + 64;
                }
                break;

            case "water-world":
                if (X > 32 + 12 * 64 && X < 32 + 17 * 64 && Y < 32)
                {
                    RunningEngine.CurrentRoom = "air-world";
                    X = 17 * 64;
                    Y = 32 + 18 * 64;
                }
                break;

            default:
                break;
            }
        }