Example #1
0
        private GameRound GenerateGameRound()
        {
            GameRound gameRound = new GameRound();

            /*
             * gameRound.Add(new PlayerCharacter(KeyboardControls.Player1) { Position = new Vector2(1, 10) });
             * //gameRound.Add(new Shellcreeper() { Position = new Vector2(20, 10), Direction = Direction.Left });
             * //gameRound.Add(new Shellcreeper() { Position = new Vector2(20, 10), Direction = Direction.Right });
             *
             * for(int column = 0; column < 32; column++)
             * {
             *  gameRound.Add(new Block(0.5f + column, 0.5f));
             *  gameRound.Add(new Block(0.5f + column, 1.5f));
             * }
             *
             * gameRound.Add(new Block(0.5f, 7.5f));
             * gameRound.Add(new Block(1.5f, 7.5f));
             * gameRound.Add(new Block(2.5f, 7.5f));
             */

            LevelLoader loader = new LevelLoader(File.ReadAllText("level.txt"));

            loader.LoadLevel(gameRound);

            //gameRound.Add(new Block(11.5f, 7.5f));
            //gameRound.Add(new Block(12.5f, 7.5f));
            //gameRound.Add(new Block(13.5f, 7.5f));
            //gameRound.Add(new Block(14.5f, 7.5f));
            //gameRound.Add(new Block(15.5f, 7.5f));

            return(gameRound);
        }
Example #2
0
 public override void UpdateCore(GameRound gameRound, float elapsedSeconds)
 {
     timeRemaining -= elapsedSeconds;
     if (timeRemaining <= 0)
     {
         IsAlive = false;
     }
 }
Example #3
0
 protected override void Initialize()
 {
     base.Initialize();
     gameRound       = GenerateGameRound();
     renderer        = new BasicRenderer(Content);
     backgroundMusic = Content.Load <Song>("Ragtime");
     MediaPlayer.Play(backgroundMusic);
 }
Example #4
0
        public override void UpdateCore(GameRound round, float elapsedSeconds)
        {
            base.UpdateCore(round, elapsedSeconds);

            if (!IsStunned || !round.ObjectsIn(new Box(Position, GroundArea)).OfType <Block>().Any())
            {
                Position += new Vector2((Direction == Direction.Left ? -1 : +1) * speed * elapsedSeconds, 0);
            }
        }
Example #5
0
 public override void UpdateCore(GameRound round, float elapsedSeconds)
 {
     // Gravity
     Velocity -= new Vector2(0, 62f) * elapsedSeconds;
     Position += Velocity * elapsedSeconds;
     if (Position.X < 0)
     {
         Position += new Vector2(round.WorldSize.X, 0);
     }
     if (Position.X > round.WorldSize.X)
     {
         Position -= new Vector2(round.WorldSize.X, 0);
     }
 }
Example #6
0
        public void Render(GameRound gameRound, SpriteBatch SpriteBatch)
        {
            spriteBatch = SpriteBatch;

            foreach (GameObject gameObject in gameRound.Objects)
            {
                if (gameObject is Brick brick)
                {
                    DrawBrick(brick);
                }
                else if (gameObject is Block b)
                {
                    DrawBlock(b);
                }
                if (gameObject is BlockBump bump)
                {
                    DrawBlockBump(bump);
                }
                if (gameObject is PlayerCharacter c)
                {
                    DrawPlayerCharacter(c);
                }
                if (gameObject is Shellcreeper s)
                {
                    DrawShellCreeper(s);
                }
                if (gameObject is Coin coin)
                {
                    DrawCoin(coin);
                }
                //else if (gameObject is Monster m) DrawGenericMonster(m);
                if (gameObject is ExitPipe p)
                {
                    DrawExitPipe(p);
                }
                if (gameObject is Sidestepper stepper)
                {
                    DrawSideStepper(stepper);
                }
                spriteBatch.DrawString(font, "Score: " + gameRound.score, new Vector2(0, 0), Color.White);
                if (gameObject is POWBlock pw)
                {
                    DrawPOW(pw);
                }
            }
        }
Example #7
0
        public void LoadLevel(GameRound gameRound)
        {
            if (!levelSource.Contains("LEVEL"))
            {
                throw new ContentLoadException("Level does not contain LEVEL section.");
            }

            int xCounter = -1;
            int yCounter = -1;

            for (int index = levelSource.IndexOf("LEVEL") + 5; index < levelSource.Length; index++)
            {
                char curChar = levelSource[index];

                if (curChar == '\n')
                {
                    yCounter++;
                    xCounter = -1;
                    continue;
                }

                if (char.IsWhiteSpace(curChar))
                {
                    continue;
                }

                if (char.IsNumber(curChar))
                {
                    xCounter++;
                    int currentId = int.Parse(curChar.ToString());
                    if (TileExpressions.TryGetValue(currentId, out var expression))
                    {
                        float x = TILE_SIZE * (xCounter + X_OFFSET);
                        float y = TILE_SIZE * (yCounter + Y_OFFSET);

                        //x = 32 - x;
                        y = 25 - y;

                        gameRound.Add(CreateObject(expression, x, y));
                    }
                }
            }
        }
Example #8
0
        public override void UpdateCore(GameRound round, float elapsedSeconds)
        {
            base.UpdateCore(round, elapsedSeconds);

            controls.Update(elapsedSeconds);
            Position += new Vector2(controls.HorizontalSpeed * 20f, 0) * elapsedSeconds;
            if (controls.HorizontalSpeed > 0)
            {
                Direction = true;
            }
            if (controls.HorizontalSpeed < 0)
            {
                Direction = false;
            }
            if (controls.IsAttemptingToJump)
            {
                if (round.ObjectsIn(new Box(Position, JumpArea)).Any())
                {
                    Velocity = new Vector2(Velocity.X, 30);
                }
            }
        }
Example #9
0
 public override void UpdateCore(GameRound round, float elapsedSeconds)
 {
 }
Example #10
0
        //public POWBlock(Vector2 position) : base(POWDimensions, POWDimensions) { }

        public override void UpdateCore(GameRound gameRound, float elapsedSeconds)
        {
            //throw new NotImplementedException();
        }
Example #11
0
 public override void UpdateCore(GameRound round, float elapsedSeconds)
 {
     base.UpdateCore(round, elapsedSeconds);
     totalTime += elapsedSeconds;
     Position  += new Vector2((Direction == Direction.Left ? -1 : +1) * CoinSpeed * elapsedSeconds, 0);
 }
Example #12
0
 public abstract void UpdateCore(GameRound gameRound, float elapsedSeconds);
Example #13
0
 public void Update(GameRound gameRound, float elapsedSeconds)
 {
     PreviousPhysicsBox = PhysicsBox;
     UpdateCore(gameRound, elapsedSeconds);
 }