Esempio n. 1
0
        public bool Cleared(Character character, InputManager input)
        {
            //Check surrounding cells.
            int col = (int)Math.Floor(character.position.X / (CELL_SIZE * 2f));
            int row = (int)Math.Floor(character.position.Y / (CELL_SIZE * 2f));

            if (col > -1 && col < grid.GetLength(0) &&
                row > -1 && row < grid.GetLength(1))
            {
                Cell cell = (Cell)grid[col, row];
                tempRect.X = col * (CELL_SIZE * 2);
                tempRect.Y = row * (CELL_SIZE * 2);
                tempRect.Width = CELL_SIZE * 2;
                tempRect.Height = CELL_SIZE * 2;
                switch (cell)
                {
                    case Cell.End: //Door
                        if (character.CollRect.Intersects(tempRect))
                        {
                            if (input.KeyClicked(Keys.Space))
                            {
                                return true;
                            }
                        }
                        break;
                }
            }
            return false;
        }
Esempio n. 2
0
 public void Draw(SpriteBatch sb, Character character, Level level)
 {
     if (!character.alive)
     {
         DrawMessage(sb, new Vector2(800 / 2, 600 / 2), "DEAD");
         DrawMessage(sb, new Vector2(800 / 2, 600 * 0.8f), "PRESS SPACE TO RESTART");
     }
 }
Esempio n. 3
0
        public void DrawCamRelated(SpriteBatch sb, Character character, Level level)
        {
            if (!character.alive)
            {
            }
            else
            {
                int[,] grid = level.grid;
                //Get current cell
                int col = (int)Math.Floor(character.position.X / (Level.CELL_SIZE * 2));
                int row = (int)Math.Floor(character.position.Y / (Level.CELL_SIZE * 2));

                for (int i = col - 2; i < col + 1; i++)
                {
                    for (int j = row - 2; j < row + 1; j++)
                    {
                        if (i > -1 && i < grid.GetLength(0) &&
                            j > -1 && j < grid.GetLength(1))
                        {
                            Cell cell = (Cell)grid[i, j];
                            Vector2 pos;
                            switch (cell)
                            {
                                case Cell.None:
                                    break;
                                case Cell.Start:
                                    pos = new Vector2(i * (Level.CELL_SIZE * 2) + Level.CELL_SIZE, j * (Level.CELL_SIZE * 2));
                                    DrawMessage(sb, pos, "START");
                                    break;
                                case Cell.End:
                                    pos = new Vector2(i * (Level.CELL_SIZE * 2) + Level.CELL_SIZE, j * (Level.CELL_SIZE * 2));
                                    DrawMessage(sb, pos, "PRESS SPACE");
                                    break;
                                case Cell.Spikes:
                                    break;
                                case Cell.Dirt:
                                    break;
                                case Cell.DirtFloor:
                                    break;
                                case Cell.DirtSky:
                                    break;
                                case Cell.Stone:
                                    break;
                                case Cell.StoneFloor:
                                    break;
                                case Cell.StoneSky:
                                    break;
                                default:
                                    break;
                            }

                        }
                    }
                }
            }
        }
Esempio n. 4
0
 public void DrawSignMessages(SpriteBatch sb, Character character, Level level)
 {
     if (character.alive)
     {
         foreach (Sign s in level.signs)
         {
             if (Vector2.Distance(character.position, new Vector2(s.col * (Level.CELL_SIZE * 2f), s.row * (Level.CELL_SIZE * 2f))) < 100f)
             {
                 DrawMessage(sb, new Vector2(800 / 2, 600 * 0.7f), s.text);
             }
         }
     }
 }
Esempio n. 5
0
        public void Update(float time, Character character)
        {
            current += time;
            if (current > interval)
            {
                current = 0f;
                //Spawn leaves
                for (int i = 0; i < Utility.Rand(2, 12); i++)
                {
                    Particle p = particles.Pop();
                    p.position.X = character.position.X + Utility.Rand(-600, 600);
                    p.position.Y = character.position.Y + Utility.Rand(-400, 400);
                    p.current = 0;
                    p.duration = Utility.Rand(2000, 5000);
                    p.source = rain;
                    p.origin.X = sources[p.source].Width / 2f;
                    p.origin.Y = sources[p.source].Height / 2f;
                    p.velocity.X = Utility.Rand(-0.1f, -0.01f);
                    p.velocity.Y = Utility.Rand(0.01f, 0.1f);
                    p.color = Color.White;
                    p.scale = Utility.Rand(0.8f, 1f);
                    p.rotation = Utility.Rand(2f);
                    p.rotval = Utility.Rand(-0.01f, 0.01f);
                }
            }

            for (int i = 0; i < particles.Count; i++)
            {
                Particle p = particles[i];
                p.current += time;
                if (p.gravity)
                {
                    p.velocity.Y += 0.001f * time;
                }
                p.position.X += p.velocity.X * time;
                p.position.Y += p.velocity.Y * time;
                p.rotation += p.rotval * time;
                if (p.current > p.duration)
                {
                    p.gravity = false;
                    particles.Push(i--);
                }
            }
        }
Esempio n. 6
0
        public void DoXCollision(Character character)
        {
            //Check surrounding cells.
            int col = (int)Math.Floor(character.position.X / (CELL_SIZE * 2f));
            int row = (int)Math.Floor(character.position.Y / (CELL_SIZE * 2f));

            for (int i = col-2; i < col+3; i++)
            {
                for (int j = row-2; j < row+3; j++)
                {
                    if (i > -1 && i < grid.GetLength(0) &&
                        j > -1 && j < grid.GetLength(1))
                    {
                        Cell cell = (Cell)grid[i, j];
                        tempRect.X = i * (CELL_SIZE * 2);
                        tempRect.Y = j * (CELL_SIZE * 2);
                        tempRect.Width = CELL_SIZE * 2;
                        tempRect.Height = CELL_SIZE * 2;
                        switch (cell)
                        {
                            case Cell.None:
                                //No collision
                                break;
                            case Cell.Start: //Door
                                break;
                            case Cell.End: //Door
                                break;
                            //case Cell.Spikes://Spikes Allow walking up to spikes, but not stepping on them

                            default: //Collidable cell found
                                if (character.CollRect.Intersects(tempRect))
                                {
                                    //Collision found
                                    if (character.velocity.X < 0f)
                                    {
                                        //Move to right side
                                        character.velocity.X = 0;
                                        character.position.X = tempRect.Right;
                                        //collRects.Add(tempRect);
                                    }
                                    else if (character.velocity.X > 0f)
                                    {
                                        //Move to left side
                                        character.velocity.X = 0;
                                        character.position.X = tempRect.Left - character.CollRect.Width;
                                        //collRects.Add(tempRect);
                                    }
                                }
                                break;
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public void Update(float time, ParticleManager pMan, Character character)
        {
            //Fan stuff
            Vector2 pos = Vector2.Zero;
            foreach (Fan s in fans)
            {
                pos = new Vector2(s.col * (CELL_SIZE * 2) + (CELL_SIZE), s.row * (CELL_SIZE * 2) + (CELL_SIZE));
                s.current += time;
                if (s.current > s.interval)
                {
                    s.current = 0f;
                    pMan.SprayAir(pos, s.Rotation, s.power);
                }

                //Check for collision
                //Broad phase
                float distance = Vector2.Distance(character.position, pos);
                if(distance < 500f)
                {
                    //Check if in area of airflow
                    bool applyForce = false;
                    switch (s.direction)
                    {
                        case Direction.Up:
                            if (character.CollRect.Center.X > pos.X - CELL_SIZE && character.CollRect.Center.X < pos.X + CELL_SIZE &&
                                character.CollRect.Center.Y <= pos.Y)
                            {
                                applyForce = true;
                            }
                            break;
                        case Direction.Down:
                            if (character.CollRect.Center.X > pos.X - CELL_SIZE && character.CollRect.Center.X < pos.X + CELL_SIZE &&
                                character.CollRect.Center.Y <= pos.Y)
                            {
                                applyForce = true;
                            }
                            break;
                        case Direction.Left:
                            if (character.CollRect.Center.Y > pos.Y - CELL_SIZE && character.CollRect.Center.Y < pos.Y + CELL_SIZE &&
                                character.CollRect.Center.X <= pos.X)
                            {
                                applyForce = true;
                            }
                            break;
                        case Direction.Right:
                            if (character.CollRect.Center.Y > pos.Y - CELL_SIZE && character.CollRect.Center.Y < pos.Y + CELL_SIZE &&
                                character.CollRect.Center.X >= pos.X)
                            {
                                applyForce = true;
                            }
                            break;
                        default:
                            break;
                    }
                    if (applyForce)
                    {
                        character.ApplyForce(Utility.AngleFrom(s.Rotation), distance, s.power);
                    }
                }

            }
        }
Esempio n. 8
0
        public bool HasFloor(Character character)
        {
            Rectangle charCollRect = character.CollRect;
            charCollRect.Y += character.CollRect.Height + 5;
            //Check surrounding cells.
            int col = (int)Math.Floor(character.position.X / (CELL_SIZE * 2f));
            int row = (int)Math.Floor((character.position.Y + character.CollRect.Height + 5) / (CELL_SIZE * 2f));
            bool ret = false;
            for (int i = col - 3; i < col + 3; i++)
            {
                if (i > -1 && i < grid.GetLength(0) &&
                    row > -1 && row < grid.GetLength(1))
                {
                    //Check collision first
                    tempRect.X = i * (CELL_SIZE * 2);
                    tempRect.Y = row * (CELL_SIZE * 2);
                    tempRect.Width = CELL_SIZE * 2;
                    tempRect.Height = CELL_SIZE * 2;

                    if (tempRect.Intersects(charCollRect))
                    {
                        //collRects.Add(tempRect);
                        Cell cell = (Cell)grid[i, row];
                        switch (cell)
                        {
                            case Cell.None:
                                ret = false;
                                break;//No floor
                            case Cell.Start:
                                ret = false;
                                break;//No floor
                            case Cell.End: ret = false;
                                break;//No floor
                            case Cell.Spikes:
                                ret = false;
                                break;
                            default:
                                return true;//Probably has floor
                        }
                    }
                }
            }

            //No map found, so no floor.
            return ret;
        }
Esempio n. 9
0
        public void Draw(SpriteBatch sb, Character character, Texture2D pixel)
        {
            int col = (int)Math.Floor(character.CollRect.Center.X / (CELL_SIZE * 2f));
            int row = (int)Math.Floor(character.CollRect.Center.Y / (CELL_SIZE * 2f));

            for (int i = col - 16; i < col + 16; i++)
            {
                for (int j = row - 16; j < row + 16; j++)
                {
                    if (i > -1 && i < grid.GetLength(0) &&
                        j > -1 && j < grid.GetLength(1))
                    {
                        sb.Draw(texture, new Vector2(i * (CELL_SIZE * 2), j * (CELL_SIZE * 2)), sources[(Cell)grid[i, j]], Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 1f);
                    }
                }
            }

            foreach (Sign s in signs)
            {
                sb.Draw(signTex, new Vector2(s.col * (CELL_SIZE * 2), s.row * (CELL_SIZE * 2)), Color.White);
            }
            foreach (Fan s in fans)
            {
                sb.Draw(fanTex,
                    new Vector2(s.col * (CELL_SIZE * 2) + (CELL_SIZE), s.row * (CELL_SIZE * 2) + (CELL_SIZE)),
                    null,
                    Color.White,
                    s.Rotation,
                    new Vector2(CELL_SIZE, CELL_SIZE),
                    1f,
                    SpriteEffects.None, 1f);
            }

            /*

            foreach (Rectangle r in collRects)
            {
                sb.Draw(pixel, r, Color.Yellow * 0.8f);
            }
            collRects.Clear();
            */
        }
Esempio n. 10
0
        public void DoYCollision(Character character)
        {
            //Check surrounding cells.
            int col = (int)Math.Floor(character.position.X / (CELL_SIZE * 2f));
            int row = (int)Math.Floor(character.position.Y / (CELL_SIZE * 2f));

            for (int i = col - 2; i < col + 3; i++)
            {
                for (int j = row - 2; j < row + 3; j++)
                {
                    if (i > -1 && i < grid.GetLength(0) &&
                        j > -1 && j < grid.GetLength(1))
                    {
                        Cell cell = (Cell)grid[i, j];
                        tempRect.X = i * (CELL_SIZE * 2);
                        tempRect.Y = j * (CELL_SIZE * 2);
                        tempRect.Width = CELL_SIZE * 2;
                        tempRect.Height = CELL_SIZE * 2;
                        switch (cell)
                        {
                            case Cell.None:
                                //No collision
                                break;
                            case Cell.Start: //Door
                                break;
                            case Cell.End: //Door
                                break;
                            case Cell.Spikes://Spikes
                                if (character.CollRect.Intersects(tempRect))
                                {
                                    character.alive = false;
                                }
                                break;

                            default: //Collidable cell found
                                if (character.CollRect.Intersects(tempRect))
                                {
                                    if (character.inAir)
                                    {
                                        //Collision found
                                        if (character.velocity.Y > 0f)
                                        {
                                            //Move to top side
                                            character.position.Y = tempRect.Top - character.CollRect.Height;
                                            character.Land();
                                            //collRects.Add(tempRect);
                                        }
                                        else if (character.velocity.Y < 0f)
                                        {
                                            //Move to bottom side, bump head into top.
                                            character.velocity.Y = 0;
                                            character.position.Y = tempRect.Bottom;
                                            character.SetAnim("jump");
                                            character.inAir = true;
                                            //collRects.Add(tempRect);
                                        }
                                    }
                                }
                                break;
                        }
                    }
                }
            }
        }
Esempio n. 11
0
 public void Start()
 {
     level = new Level();
     pMan = new ParticleManager();
     character = new Character();
     currentLevel--;
     NextLevel();
 }