Example #1
0
        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;
        }
Example #2
0
        //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();
            }
        }
Example #3
0
        //Render - draw stuff here
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            if (slevel == "menu")
            {
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                GL.ClearColor(Color.FromArgb(255, 10, 10, 10));
                Spritebatch.Begin(this);
                view.ApplyTransforms();
                foreach (GameObject o in ObjectHandler.objects)
                {
                    o.Draw(Color.FromArgb(255, 90, 90, 90));
                }

                for (int x = 0; x < level.Width; x++)
                {
                    for (int y = 0; y < level.Height; y++)
                    {
                        int        tileSize  = 70;
                        RectangleF sourceRec = new RectangleF(0, 0, 0, 0);

                        sourceRec = new RectangleF(level[x, y].tileX, level[x, y].tileY, tileSize, tileSize);

                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                        Spritebatch.DrawSprite(tileSet, new RectangleF(x * GRIDSIZE, y * GRIDSIZE, GRIDSIZE + 1, GRIDSIZE + 1), Color.FromArgb(255, 90, 90, 90), sourceRec);
                    }
                }
            }
            else
            {
                List <Enemy> afterdraw = new List <Enemy>(); //Enemies drawn after tiles - above them. (atm all except piranhas)
                Color        tilec     = Color.LightGray;
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                if (slevel.Contains("story"))
                {
                    GL.ClearColor(Color.FromArgb(255, 0, 0, 0));
                }
                else if (Level == 1)
                {
                    GL.ClearColor(Color.FromArgb(255, 10, 10, 10));
                    tilec = Color.LightGray;
                }
                else if (Level == 2)
                {
                    GL.ClearColor(Color.FromArgb(255, 0, 20, 20));
                    tilec = Color.LightGray;
                }
                else if (Level == 3 || Level == 4 || Level == 5)
                {
                    GL.ClearColor(Color.FromArgb(255, 0, 0, 16));
                    tilec = Color.Gray;
                }
                else if (Level == 6)
                {
                    GL.ClearColor(Color.FromArgb(255, 16, 16, 16));
                    tilec = Color.Gray;
                }


                Spritebatch.Begin(this);
                view.ApplyTransforms();

                if (!slevel.Contains("story"))
                {
                    foreach (GameObject o in ObjectHandler.objects)
                    {
                        o.Draw(tilec);
                    }
                }

                List <Tuple <Block, Vector2> > afterdraws = new List <Tuple <Block, Vector2> >();
                if (!slevel.Contains("story"))
                {
                    for (int x = 0; x < level.Width; x++)
                    {
                        for (int y = 0; y < level.Height; y++)
                        {
                            if (level[x, y].type == BlockType.Empty)
                            {
                                Tuple <Block, Vector2> t = new Tuple <Block, Vector2>(level[x, y], new Vector2(x, y));
                                afterdraws.Add(t);
                                continue;
                            }
                            int        tileSize  = 70;
                            RectangleF sourceRec = new RectangleF(0, 0, 0, 0);

                            sourceRec = new RectangleF(level[x, y].tileX, level[x, y].tileY, tileSize, tileSize);

                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                            Spritebatch.DrawSprite(tileSet, new RectangleF(x * GRIDSIZE, y * GRIDSIZE, GRIDSIZE + 1, GRIDSIZE + 1), tilec, sourceRec);
                        }
                    }
                }
                if (!slevel.Contains("story"))
                {
                    foreach (Enemy ex in enemies)
                    {
                        if (ex.enemyType == 5)
                        {
                            ex.Draw();
                        }
                        else
                        {
                            afterdraw.Add(ex);
                        }
                    }
                }
                if (!slevel.Contains("story"))
                {
                    player.Draw(tilec);
                }
                foreach (Tuple <Block, Vector2> t in afterdraws.ToArray())
                {
                    int        tileSize  = 70;
                    RectangleF sourceRec = new RectangleF(0, 0, 0, 0);

                    sourceRec = new RectangleF(t.Item1.tileX, t.Item1.tileY, tileSize, tileSize);

                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                    Spritebatch.DrawSprite(tileSet, new RectangleF(t.Item2.X * GRIDSIZE, t.Item2.Y * GRIDSIZE, GRIDSIZE + 1, GRIDSIZE + 1), tilec, sourceRec);
                }
                foreach (Enemy ex in afterdraw)
                {
                    ex.Draw();
                }

                if (!slevel.Contains("story"))
                {
                    view.DrawHUD();
                }
                if (slevel.Contains("story"))
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                    DialogBox.DrawString(view.Position.X - 288, view.Position.Y);
                }
            }
            this.SwapBuffers();
        }
Example #4
0
        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();
                    }
                }
            }
        }