Example #1
0
        public void Update(Map map, int screenwidth, int screenheight)
        {
            #region Character color
            if (color_ == new Color(255, 0, 0))
            {
                next_color_ = new Color(255, 255, 0);
            }
            else if (color_ == new Color(255, 255, 0))
            {
                next_color_ = new Color(0, 255, 0);
            }
            else if (color_ == new Color(0, 255, 0))
            {
                next_color_ = new Color(0, 255, 255);
            }
            else if (color_ == new Color(0, 255, 255))
            {
                next_color_ = new Color(0, 0, 255);
            }
            else if (color_ == new Color(0, 0, 255))
            {
                next_color_ = new Color(255, 0, 255);
            }
            else if (color_ == new Color(255, 0, 255))
            {
                next_color_ = new Color(255, 0, 0);
            }
            color_.R += (byte)Math.Sign(next_color_.R - color_.R);
            color_.G += (byte)Math.Sign(next_color_.G - color_.G);
            color_.B += (byte)Math.Sign(next_color_.B - color_.B);
            color_.A  = (byte)(shade_ * 255f);
            #endregion
            if (!freeze_)
            {
                #region Displacement
                if ((!force_jump_ && (Input.IsPressed(Keys.Up) || Input.IsPressed(Keys.Space))) && !freeze_move_)
                {
                    switch (content_[1])
                    {
                    case 3:
                        gravity_ = Vector2.Zero;
                        Jump(gravity_sign_ * jump_water_);
                        break;

                    default:
                        /*if (grounded_ && Math.Abs(speed_.Y) + Math.Abs(jump_.Y) >= Math.Abs(gravity_.Y))
                         *  jump_.Y = -5.5f - gravity_.Y / 2;*/
                        if (Jump(gravity_sign_ * jump_air_))
                        {
                            Particles.createParticles(this, 25);
                        }
                        break;
                    }
                }
                else
                {
                    force_jump_ = false;
                }
                if ((Input.IsPressed(Keys.Right) && !Input.IsPressed(Keys.Left)) && !freeze_move_)
                {
                    if ((Input.IsPressedOnce(Keys.LeftShift) || Input.IsPressedOnce(Keys.RightShift)) && DateTime.Now - last_dash_ >= dash_delay_)
                    {
                        last_dash_ = DateTime.Now;
                        GameHandler.CreateDashCharacter();
                        for (int i = 0; i < 100 && StepMove(map, new Vector2(1, 0)); i++)
                        {
                            ;
                        }
                    }
                    else
                    {
                        switch (content_[1])
                        {
                        case 3:
                            if (speed_.X < speed_water_)
                            {
                                speed_.X += inertia_;
                            }
                            else if (speed_.X > speed_water_)
                            {
                                speed_.X -= inertia_;
                            }
                            break;

                        default:
                            if (speed_.X < speed_air_ / (Input.IsPressed(Keys.RightControl) || Input.IsPressed(Keys.LeftControl) ? 1.5f : 1))
                            {
                                speed_.X += inertia_;
                            }
                            else if (speed_.X > speed_air_ / (Input.IsPressed(Keys.RightControl) || Input.IsPressed(Keys.LeftControl) ? 1.5f : 1))
                            {
                                speed_.X -= inertia_;
                            }
                            break;
                        }
                    }
                }
                else if ((Input.IsPressed(Keys.Left) && !Input.IsPressed(Keys.Right)) && !freeze_move_)
                {
                    if ((Input.IsPressedOnce(Keys.LeftShift) || Input.IsPressedOnce(Keys.RightShift)) && DateTime.Now - last_dash_ >= dash_delay_)
                    {
                        last_dash_ = DateTime.Now;
                        GameHandler.CreateDashCharacter();
                        for (int i = 0; i < 100 && StepMove(map, new Vector2(-1, 0)); i++)
                        {
                            ;
                        }
                    }
                    else
                    {
                        switch (content_[1])
                        {
                        case 3:
                            if (speed_.X > -speed_water_)
                            {
                                speed_.X -= inertia_;
                            }
                            else if (speed_.X < -speed_water_)
                            {
                                speed_.X += inertia_;
                            }
                            break;

                        default:
                            if (speed_.X > -speed_air_ / (Input.IsPressed(Keys.RightControl) || Input.IsPressed(Keys.LeftControl) ? 1.5f : 1))
                            {
                                speed_.X -= inertia_;
                            }
                            else if (speed_.X < -speed_air_ / (Input.IsPressed(Keys.RightControl) || Input.IsPressed(Keys.LeftControl) ? 1.5f : 1))
                            {
                                speed_.X += inertia_;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    if (speed_.X < 0)
                    {
                        if (speed_.X > -inertia_)
                        {
                            speed_.X = 0;
                        }
                        else
                        {
                            speed_.X += inertia_;
                        }
                    }
                    else if (speed_.X > 0)
                    {
                        if (speed_.X < inertia_)
                        {
                            speed_.X = 0;
                        }
                        else
                        {
                            speed_.X -= inertia_;
                        }
                    }
                }
                #endregion
                speedbis_ = speed_ + gravity_ + jump_;
                if (speedbis_.Length() > max_speed_)
                {
                    speedbis_.Normalize();
                    speedbis_ *= max_speed_;
                }
                if (content_[1] == 3)
                {
                    gravity_ += gravity_sign_ * gravity_water_;
                }
                else
                {
                    gravity_ += gravity_sign_ * gravity_air_;
                }
                bool move1 = false;
                bool move2 = false;
                try
                {
                    move1 = Move(map, new Vector2(speedbis_.X, 0));
                    move2 = Move(map, new Vector2(0, speedbis_.Y));
                }
                catch
                {
                    Die(500, map);
                }
                speed_length_ = (speed_ + gravity_ + jump_).Length();
                grounded_     = !move2;
                if (previous_move_ && gravity_ == Vector2.Zero) // Fall
                {
                    Particles.createParticles(this, 25);
                }
                previous_move_ = move2;
                if (move1 && !move2 && gravity_ == Vector2.Zero)
                {
                    if (speed_.X > 0)
                    {
                        Particles.createParticles(this, 0, 1);
                    }
                    else if (speed_.X < 0)
                    {
                        Particles.createParticles(this, 0, -1);
                    }
                }
                int   x = ((int)position_.X + size_ / 2) / Map.Size_;
                int   y = ((int)position_.Y + size_ / 2) / Map.Size_;
                int[] previous_content = content_;
                if (content_ != map.Map_[x, y].Content_)
                {
                    SpecialCells(map, screenwidth, screenheight, x, y, previous_content);
                }
                if (move1 || move2)
                {
                    content_ = map.Map_[(int)(position_.X + size_ / 2) / Map.Size_, (int)(position_.Y + size_ / 2) / Map.Size_].Content_;
                }
                else
                {
                    content_ = map.Map_[(int)(position_.X + size_ / 2) / Map.Size_, (int)(position_.Y + size_ / 2) / Map.Size_].Content_;
                }
            }
            shift_x_ = map.Shift_x_ + map.F_shift_x_;
            shift_y_ = map.Shift_y_ + map.F_shift_y_;
        }
Example #2
0
        private void SpecialCells(Map map, int screenwidth, int screenheight, int x, int y, int[] previous_content)
        {
            content_ = map.Map_[x, y].Content_;
            if (previous_content[1] != 3 && content_[1] == 3) // Water
            {
                gravity_ = Vector2.Zero;
                jump_    = Vector2.Zero;
                map.changeViewDistance(4, this, screenwidth, screenheight);
                if (Input.IsPressed(Keys.Up))
                {
                    Jump(gravity_sign_ * new Vector2(0, -3.5f), true);
                    Particles.createParticles(this, 25, new Color(32, 32, 255));
                }
                //else
                //{
                Sounds.PlaySplash();
                //}
            }
            if (content_[0] == 4) // Jump pad
            {
                Sounds.PlayJumpPad();
                map.Map_[x, y].Activate();
                gravity_ = Vector2.Zero;
                jump_    = Vector2.Zero;
                Jump(gravity_sign_ * new Vector2(0, -7.2f), true);
            }
            if (content_[0] == 5) // Gravity pad
            {
                Sounds.PlayGravityPad();
                map.Map_[x, y].Activate();
                gravity_sign_ *= -1;
                jump_          = Vector2.Zero;
                switch (content_[1])
                {
                case 3:
                    gravity_ = gravity_sign_ * gravity_water_;
                    break;

                default:
                    gravity_ = gravity_sign_ * gravity_air_;
                    break;
                }
            }
            if (content_[0] == 6)
            {
                GameHandler.SetMap(map.Next_map_, true);
            }
            if (content_[0] == 10)
            {
                Thread thread = new Thread(() =>
                {
                    text_ = " Blocks\n" +
                            "switched";
                    draw_text_ = true;
                    Thread.Sleep(1500);
                    draw_text_ = false;
                });
                thread.Start();
                Map.Block_type_enabled_++;
                Map.Block_type_enabled_ %= 2;
            }
            if (previous_content[1] != 7 && content_[1] == 7)
            {
                gravity_sign_ = map.Initial_gravity_;
                Die(500, map);
                Drawer.Fade(500);
            }
            if (content_[0] == 8 && (map.Checkpoint_ != new Vector2(x, y) || map.Checkpoint_gravity_ != gravity_sign_))
            {
                Thread thread = new Thread(() =>
                {
                    Console.WriteLine("Checkpoint set");
                    text_      = "Checkpoint set";
                    draw_text_ = true;
                    Thread.Sleep(1500);
                    draw_text_ = false;
                });
                thread.Start();
                map.SetCheckpoint(new Vector2(x, y), gravity_sign_);
            }
            if (content_[0] == 9)
            {
                score_++;
                int[] new_content = { -1, map.Map_[x, y].Content_[1], map.Map_[x, y].Content_[2] };
                map.Map_[x, y] = new Cell(new_content);
            }
            if (content_[0] == 13)
            {
                SetPosition(map, map.GetNearestPortal1(new Vector2(x, y)), true);
                gravity_ = Vector2.Zero;
                jump_    = Vector2.Zero;
                Jump(new Vector2(0, -speedbis_.Y), true);
            }
            if (content_[0] == 14)
            {
                SetPosition(map, map.GetNearestPortal2(new Vector2(x, y)), true);
                gravity_ = Vector2.Zero;
                jump_    = Vector2.Zero;
                Jump(new Vector2(0, speedbis_.Y), true);
            }
            if (content_[0] == 15)
            {
                map.Map_[x, y].Activate();
                gravity_sign_ *= -1;
                jump_          = Vector2.Zero;
                switch (content_[1])
                {
                case 3:
                    gravity_ = gravity_sign_ * gravity_water_;
                    break;

                default:
                    gravity_ = gravity_sign_ * gravity_air_;
                    break;
                }
                gravity_ = Vector2.Zero;
                jump_    = Vector2.Zero;
                Jump(gravity_sign_ * new Vector2(0, -7f), true);
            }
            if (previous_content[1] != content_[1] && content_[1] != 3)
            {
                /* Normal distance : 6 */
                map.changeViewDistance(6, this, screenwidth, screenheight);
            }
            if (content_[2] == -2)
            {
                int index = map.Map_[x, y].Message_index_;
                if (!ignored_messages_.Contains(index))
                {
                    if (current_message_ != index)
                    {
                        current_message_ = index;
                        if (index != -1)
                        {
                            Message.Display(map.Messages_[index], false);
                        }
                    }
                }
            }
            else if (previous_content[2] == -2)
            {
                ignored_messages_.Add(current_message_);
                Message.Close();
            }
        }
Example #3
0
 public void Update(int i, int j)
 {
     if (content_[1] == 3 || content_[1] == 7)
     {
         if (var_[1, 1] < 128)
         {
             sign_ = rand_.Next(1, 5);
         }
         else if (var_[1, 1] > 255)
         {
             sign_ = -rand_.Next(1, 5);
         }
         var_[1, 1] += sign_;
     }
     if (content_[0] == 2)
     {
         Particles.createParticles(new Vector2(i * Map.Size_ + Map.Size_ / 2, j * Map.Size_ + Map.Size_ / 2 - 3), rand_.Next() % 2 == 0 ? Color.Orange : Color.Red);
     }
     if (content_[0] == 13 || content_[0] == 14)
     {
         Vector2 position = GameHandler.Character_.Position_ + new Vector2(GameHandler.Character_.Size_);
         Vector2 diff     = new Vector2((i + 0.5f) * Map.Size_, (j + 0.5f) * Map.Size_) - position;
         float   temp     = diff.X;
         diff.X = diff.Y;
         diff.Y = temp;
         diff.Normalize();
         float angle = 0f;
         if (diff.X > 0 && diff.Y < 0)
         {
             angle = (float)Math.Acos(Vector2.Dot(diff, new Vector2(1, 0)));
         }
         else if (diff.X > 0 && diff.Y > 0)
         {
             angle = (float)Math.PI + (float)Math.Acos(Vector2.Dot(diff, new Vector2(-1, 0)));
         }
         else if (diff.X < 0 && diff.Y > 0)
         {
             angle = (float)Math.PI + (float)Math.Acos(Vector2.Dot(diff, new Vector2(-1, 0)));
         }
         else
         {
             angle = (float)Math.Acos(Vector2.Dot(diff, new Vector2(1, 0)));
         }
         var_[0, 0] = angle;
         if (Math.Abs(var_[0, 1] - var_[0, 0]) < 0.2f)
         {
             var_[0, 1] = var_[0, 0];
         }
         else
         {
             var_[0, 1] += Math.Sign(var_[0, 0] - var_[0, 1]) * 0.1f;
         }
     }
     if (content_[0] == 6)
     {
         for (int k = 1; k <= 4; k++)
         {
             if (var_[0, k] < 128)
             {
                 var_[0, k + 4] = rand_.Next(1, 5);
             }
             else if (var_[0, k] > 255)
             {
                 var_[0, k + 4] = -rand_.Next(1, 5);
             }
             var_[0, k] += var_[0, k + 4];
         }
         var_[0, 0] += 0.05f;
     }
     if (content_[0] == 16) // Laser
     {
         if (var_[0, 3] != 0f)
         {
             if (var_[0, 3] == 360f)
             {
                 var_[0, 1] += rotate_speed_;
                 var_[0, 1] += 360f;
                 var_[0, 1] %= 360f;
             }
             else
             {
                 if (var_[0, 2] >= var_[0, 3])
                 {
                     var_[0, 4] = -rotate_speed_;
                 }
                 else if (var_[0, 2] <= 0)
                 {
                     var_[0, 4] = rotate_speed_;
                 }
                 var_[0, 1] += var_[0, 4];
                 var_[0, 2] += var_[0, 4];
             }
         }
         Vector2 direction = new Vector2((float)Math.Cos(-var_[0, 1] / 180f * Math.PI), (float)Math.Sin(-var_[0, 1] / 180f * Math.PI));
         direction.Normalize();
         Particles.createParticles(new Vector2(i + 0.5f, j + 0.5f) * Map.Size_ + direction * var_[0, 5], Color.Red);
     }
 }