public void Init() { speed = 5;//1000 / speed; player = new Player(game, this, new Rectangle(512, 0, 32, 32)); game.Components.Add(player); Block floor = new Block(game, this, new Rectangle(0, 736, 1024, 32), Color.SpringGreen, 0, 0);//740 blocks.Add(floor); game.Components.Add(floor); CheckNextBlockSpawn(); this.highScore = new HighScoresWindow(game); game.Components.Add(this.highScore); this.scoreText = new Text(game, "Score: " + this.points, new Vector2(0,0), Color.Blue); game.Components.Add(this.scoreText); music = this.game.Content.Load<SoundEffect>("home_at_last"); musicInstance = music.CreateInstance(); musicInstance.IsLooped = true; musicInstance.Play(); points = 0; }
public void Init() { this.player = new Player(game, this, new Rectangle(512, -32, 32, 32)); game.Components.Add(player); Block floor = new Block(game, this, new Rectangle(-32, 32, 1024 + 64, 32), Color.RoyalBlue, this.speed); blocks.Add(floor); game.Components.Add(floor); this.scoreText = new Text(game, "Score: " + this.points, new Vector2(0,0), Color.Blue); game.Components.Add(this.scoreText); this.highScore = new HighScoresWindow(game); game.Components.Add(this.highScore); music = this.game.Content.Load<SoundEffect>("bamboo"); musicInstance = music.CreateInstance(); musicInstance.IsLooped = true; musicInstance.Play(); }
public void Init() { this.player = new Player(game, this, new Rectangle(1024 - 40, 768 - 64, 32, 32)); game.Components.Add(player); Block floor = new Block(game, this, new Rectangle(1024 - 48, 768 - 32, 48, 1024), Color.Cyan, this.speed, 0); blocks.Add(floor); game.Components.Add(floor); this.scoreText = new Text(game, "Score: " + this.points, new Vector2(0,0), Color.Blue); game.Components.Add(this.scoreText); this.highScore = new HighScoresWindow(game); game.Components.Add(this.highScore); music = this.game.Content.Load<SoundEffect>("home_at_last"); musicInstance = music.CreateInstance(); musicInstance.IsLooped = true; musicInstance.Play(); }
public void Tick() { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { if (!this.highScore.Active) { this.game.level = new LevelM(this.game); this.End(); return; } } this.scoreText.Content = "Score: " + this.points; this.ticks++; if (this.tilNext <= 0) { Block newBlock = new Block(game, this, new Rectangle(1024, 760 - rng.Next((int)((50.0/this.spawnInterval) * 100)) , 48 - rng.Next(this.narrowness), 768), Color.Cyan, this.speed, 0); blocks.Add(newBlock); game.Components.Add(newBlock); this.tilNext = rng.Next(100) + 50 - ((-this.speed) / 8); this.spawnInterval = this.tilNext; } if (this.ticks % 300 == 0) { if (this.speed > -256) { this.speed -= 64; } if (this.narrowness < 44) this.narrowness += 4; else this.narrowness = 44; } this.tilNext--; if (player.rect.Y > 1024 || (player.rect.X + player.rect.Width) < 0) { if (!this.gameOver) { this.gameOver = true; this.highScore.SetStateInput(this.points, 1); } } }
private void SpawnNextBlock() { Block lastBlock = blocks[blocks.Count - 1]; int nextWidth = random.Next(widthMax - widthVariance, widthMax); Rectangle tRect = new Rectangle (XRange(lastBlock.rect.X + lastBlock.rect.Width), YRange(lastBlock.rect.Y), nextWidth, 32);//YRange(lastBlock.rect.Y) Block block = new Block (game, this, tRect, Color.SpringGreen, 0); blocks.Add(block); game.Components.Add(block); }
public void Tick() { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { if (!this.highScore.Active) { this.game.level = new LevelM(game); this.End(); return; } } this.scoreText.Content = "Score: " + this.points; this.ticks++; if (this.tilNext == 0) { Block b1 = new Block(game, this, new Rectangle(-32, -30, rng.Next(1024), 24), Color.RoyalBlue, this.speed); Block b2 = new Block(game, this, new Rectangle(b1.rect.X + b1.rect.Width + 64, -30, 1024, 24), Color.RoyalBlue, this.speed); b1.SetPartner(b2); this.blocks.Add(b1); this.blocks.Add(b2); this.game.Components.Add(b1); this.game.Components.Add(b2); this.tilNext = this.spawnInterval; } if (this.ticks % (200 * 5) == 0) { if (this.spawnInterval > 88) { this.spawnInterval = (int)(this.spawnInterval * 0.90); Console.WriteLine("Spawn interval is: " + this.spawnInterval); } } this.tilNext--; if (player.rect.X > 1024) { player.rect.X = 0 - player.rect.Width; } else if (player.rect.X + player.rect.Width < 0) { player.rect.X = 1024; } if (player.rect.Y > 1024) { if (!this.gameOver) { this.gameOver = true; this.highScore.SetStateInput(this.points, 0); } } }
public void SetPartner(Block partnerBlock) { partner = partnerBlock; partnerBlock.partner = this; }