public Game() : base(640, 480, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8)) { Title = ""; slevel = "menu"; WindowBorder = WindowBorder.Fixed; if (SoundManager.volume == -1) { SoundManager.volume = 0.1f; } DialogBox.cd = intro[0].color; DialogBox.LoadString(intro[0].msg); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); //Set how the alpha blending function works GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); ObjectHandler.Load(); Input.Initialize(this); view = new View(Vector2.Zero, 1f, 0.0); } //Window initializer
public void Update(ref Level level) { if (Game.Level == 6) { return; } if (ObjectHandler.fireballsonscreen < 0) { ObjectHandler.fireballsonscreen = 0; } if (position.Y > 655 + 240) //View centery + half of room = below level { if (!dying) { Death(); return; } else { //Reached outside of room while dead = reset position dying = false; isInvincible = true; facingRight = true; invincibletime = Environment.TickCount; position = new Vector2(level.playerStartPos.X + 0.5f, level.playerStartPos.Y + 0.5f) * 48; //48 is gridsize velocity = Vector2.Zero; if (View.Lives == 0) { Game.intro = new Message[] { new Message("Sponge? Where are you?!", Color.DarkGreen), new Message("You died Press Z to restart", Color.Gray), }; Game.introind = 0; View.Lives = 3; View.Coins = 0; Game.slevel = "deathstory"; DialogBox.cd = Game.intro[0].color; DialogBox.LoadString(Game.intro[0].msg); Game.Reset(); } else { Game.Reload(); } } } if (!dying) { counter++; if (counter == 2) { counter = 0; } if (Input.KeyDown(OpenTK.Input.Key.Up) || Input.KeyDown(OpenTK.Input.Key.Down) || Input.up || Input.down) { xcounter++; } if (xcounter == 12) { xcounter = 0; } HandleInput(); if (invincibletime + 1500 < Environment.TickCount) { isInvincible = false; } if (grounded) { if (velocity.X < -10f) { velocity.X = -10f; } if (velocity.X > 10f) { velocity.X = 10f; } } else { if (velocity.X < -8f) { velocity.X = -8f; } if (velocity.X > 8f) { velocity.X = 8f; } } ResolveCollisions(ref level); foreach (Enemy ex in Game.enemies.ToArray()) { if (Math.Abs(ex.position.X - position.X) < 640) { if (ex.enemyType == 2) { if (Math.Abs(ex.position.X - position.X) < 340) { ex.update = true; } } else { ex.update = true; } } ex.Update(ref level, this); } } if (!climbing) { this.velocity += gravity; } this.position += velocity; }
//Update - triggers before render - do math here protected override void OnUpdateFrame(FrameEventArgs e) { base.OnUpdateFrame(e); if (slevel == "menu") { Input.EarlyUpdate(); view.SetPosition(player.position, TweenType.Instant, 15); view.Update(); foreach (GameObject o in ObjectHandler.objects.ToArray()) { o.Update(player); } Input.Update(); Input.LateUpdate(); } else { Input.EarlyUpdate(); if (!slevel.Contains("story")) //Levels that contain "story" will not render the level or update anything, just display //the story { player.Update(ref level); } if (slevel.Contains("story")) { if (DialogBox.UpdateString()) { if (Input.KeyPress(Key.Z) || (Input.A && !Input.lastA)) { if (introind < intro.Length - 1) { introind++; DialogBox.cd = intro[introind].color; DialogBox.LoadString(intro[introind].msg); } else { slevel = "game"; player.invincibletime = Environment.TickCount; DialogBox.cd = Color.White; intro = new Message[] { }; } } } else { if (Input.KeyPress(Key.Z) || (Input.A && !Input.lastA)) { DialogBox.meter = DialogBox.message.Length; } } if (Input.KeyPress(Key.X) || (Input.B && !Input.lastB)) { intro = new Message[] { }; slevel = "game"; player.invincibletime = Environment.TickCount; DialogBox.cd = Color.White; } } Input.Update(); view.SetPosition(player.position, TweenType.QuarticOut, 15); view.Update(); foreach (GameObject o in ObjectHandler.objects.ToArray()) { o.Update(player); } if (0 > ObjectHandler.fireballsonscreen) { ObjectHandler.fireballsonscreen = 0; } else if (ObjectHandler.fireballsonscreen > 2) { ObjectHandler.fireballsonscreen = 2; } Input.LateUpdate(); } }
public void Update(Player player = null) { try { if (player.dying) { return; } } catch { } if (type != ObjectType.Cursor) { index++; } if (index >= 12) { index = 0; } if (type == ObjectType.Coin) { if (Environment.TickCount >= spawnTime + 500) { objects.Remove(this); } position.Y -= 2; } else if (type == ObjectType.Fireball) { if (Environment.TickCount >= spawnTime + 2000) { objects.Remove(this); fireballsonscreen -= 1; } this.velocity += new Vector2(0, 1); ResolveCollisions(ref Game.level); position += velocity; } else if (type == ObjectType.Fireflower) { if (spawnTime + 500 > Environment.TickCount) { position.Y -= 2; } else { float cx, cy; cx = position.X + size.X / 2; cy = position.Y + size.Y / 2; if (Math.Sqrt(Math.Pow(player.position.X - cx, 2) + (Math.Pow(player.position.Y - cy, 2))) < size.X) { SoundManager.sounds[3].Play(); objects.Remove(this); Player.fireflower = true; player.isInvincible = true; player.invincibletime = Environment.TickCount - 200; } } } else if (type == ObjectType.StandingCoin) { float cx, cy; cx = position.X + size.X / 2; cy = position.Y + size.Y / 2; if (Math.Sqrt(Math.Pow(player.position.X - cx, 2) + (Math.Pow(player.position.Y - cy, 2))) < 54) { SoundManager.sounds[2].Play(); objects.Remove(this); View.Coins++; } } else if (type == ObjectType.Door) { float cx, cy; cx = position.X + size.X / 2; cy = position.Y + size.Y / 2; if (Math.Sqrt(Math.Pow(player.position.X - cx, 2) + (Math.Pow(player.position.Y - cy, 2))) < size.X) { if (Input.KeyDown(OpenTK.Input.Key.Up) || Input.up) { ObjectHandler.fireballsonscreen = 0; if (Game.Level == 1) { Game.intro = new Message[] { new Message("Who the f**k is calling me? I'm busy.", Color.DarkRed), new Message("*click*", Color.Gray), new Message("Hello?", Color.DarkRed), new Message("Oh its'a you boss.How are you-a doing?", Color.Red), new Message("Yes the new world will be done soon!", Color.Red), new Message("No no, don't you-aworry about it boss.It will be the happiest worldever.", Color.Red), new Message("*click*", Color.Gray), new Message("If this degenerateof a brother doesn't make it intime,I will make sure he regrets this.", Color.DarkRed), new Message("I wonder whose bright idea it wasto introduce a newbrother. Let aloneANY brother.", Color.DarkRed), //check this }; Game.slevel = "afterstory1"; Game.Level = 2; Game.introind = 0; Game.LoadLevel("Desert.xml"); DialogBox.cd = Game.intro[0].color; DialogBox.LoadString(Game.intro[0].msg); } else if (Game.Level == 2) { Game.intro = new Message[] { //fix dialog new Message("Sponge has not been good lately.", Color.DarkGreen), new Message("I think replacing his princess with a fake skeleton atthe end of his first adventure...", Color.DarkGreen), new Message("was a pretty bad idea for a prank, and-", Color.DarkGreen), new Message("I don't want to hear it.", Color.DarkRed), new Message("You always take things too seriously.", Color.DarkRed), new Message("No wonder you're always the one noone picks in my games.", Color.DarkRed), new Message("You better pray that your emo brother has already passed theghost house.", Color.DarkRed), new Message("For your own good", Color.DarkRed), }; Game.slevel = "afterstory2"; Game.Level = 3; Game.introind = 0; Game.LoadLevel("GhostHouse.xml"); DialogBox.cd = Game.intro[0].color; DialogBox.LoadString(Game.intro[0].msg); } else if (Game.Level == 3) { Game.Level = 4; Game.LoadLevel("GhostEventRoom.xml"); } else if (Game.Level == 4) { Game.intro = new Message[] { //fix dialog new Message("He is not here yet...", Color.DarkRed), new Message("I guess it was my fault for trustinga retard like him.", Color.DarkRed), new Message("Should've known from the fact he believes we actually run around and save princesses.", Color.DarkRed), new Message("Ignorant just likehis other brother.", Color.DarkRed), new Message("At least I can useHIM to make money.", Color.DarkRed), new Message("The other one was just a useless space consumer.", Color.DarkRed), }; Game.slevel = "afterstory3"; Game.Level = 5; Game.introind = 0; Game.LoadLevel("Castle.xml"); DialogBox.cd = Game.intro[0].color; DialogBox.LoadString(Game.intro[0].msg); } else if (Game.Level == 5) { Game.intro = new Message[] { new Message("I am done.. Now please... Give them ba-", Color.DarkOrange), new Message("You are late.", Color.DarkRed), new Message("I threw your candyin the lava along with your brother.", Color.DarkRed), new Message("What is it Sponge?Are you going to jump in too?", Color.DarkRed), new Message("Go ahead. I've already made enough money of ofyou to live for years to come.", Color.DarkRed), new Message("Noone even knows you exist. I take all the credit andmoney for your work.", Color.FromArgb(255, 80, 0, 0)), new Message("You are worthless just like your br-", Color.DarkRed), new Message("Huh. He actually did it", Color.DarkRed), new Message("Whatever. This world isn't for the weak.", Color.DarkRed), new Message("I'll just use the other brother Pretzel just like I used Sponge.", Color.DarkRed), }; Game.slevel = "afterstory4"; Game.introind = 0; Game.Level = 6; Game.LoadLevel("Epilogue.xml"); DialogBox.cd = Game.intro[0].color; DialogBox.LoadString(Game.intro[0].msg); } } } } else if (type == ObjectType.Cursor) { if ((Input.KeyDown(OpenTK.Input.Key.Up) || Input.up) && index == 1) { index = 0; position.Y -= 48; } //No "else if" because now if you hold both buttons the cursor wont move. if ((Input.KeyDown(OpenTK.Input.Key.Down) || Input.down) && index == 0) { index = 1; position.Y += 48; } if (Input.KeyPress(OpenTK.Input.Key.Z) || Input.A) { if (index == 0) { Game.music.Stop(); Game.slevel = "introstory"; Game.Reload(); } else { new Settings().ShowDialog(); } } } }