Beispiel #1
0
        internal void BossMove2()
        {
            if (!_ismoving2)
            {
                Sprite s = null;

                _origin2 = new Position2(_position2.X2, _position2.Y2);
                if (_orientation2 == "left")
                {
                    if (_context2.GetMapObject2.GetMap2.TryGetValue(new Position2((float)Math.Round(_position2.X2 - _bossMove2, MidpointRounding.ToNegativeInfinity), (float)Math.Round(_position2.Y2, MidpointRounding.ToNegativeInfinity)), out s)) // Block is solid?
                    {
                        if (!s.IsSolid2)
                        {
                            _position2.X2 -= _bossMove2;
                        }
                    }
                }
                else
                {
                    if (_context2.GetMapObject2.GetMap2.TryGetValue(new Position2((float)Math.Round(_position2.X2 + _bossMove2, MidpointRounding.ToPositiveInfinity), (float)Math.Round(_position2.Y2, MidpointRounding.ToNegativeInfinity)), out s)) // Block is solid?
                    {
                        if (!s.IsSolid2)
                        {
                            _position2.X2 += _bossMove2;
                        }
                    }
                }

                _ismoving2 = true;
            }
        }
Beispiel #2
0
        internal void Jump2()
        {
            if (!_isJumping2)
            {
                _origin2           = new Position2(_realPosition2.X2, _realPosition2.Y2);
                _realPosition2.Y2 += JUMPING_SPEED;
                _position2.Y2     += JUMPING_SPEED;
                _isJumping2        = true;

                _sprite2.JumpAnimation2();
            }
        }
Beispiel #3
0
 internal void Gravity2()
 {
     if (_ismoving2 && _origin2 != null && _position2.Y2 <= _origin2.Y2 + JUMPING_LIMIT) // Jump
     {
         _position2.Y2 += JUMPING_SPEED;
     }
     else // Fall
     {
         _origin2       = null;
         _position2.Y2 -= GRAVITY_SPEED;
     }
 }
Beispiel #4
0
        internal Monster(Game context, string name, Position position, Life life, ushort attack, float monsterMove, float range, string attackCombo, Sprite sprite = null, bool multiplayer = false)
        {
            _context  = context;
            _name     = name;
            _position = position;
            _life     = life;
            _isAlive  = true;
            _attack   = new Attack(context, this, attack, attackCombo);
            if (sprite == null)
            {
                if (_context == null)
                {
                    _sprite = new Sprite(MONSTER_ID, _name, $@"..\..\..\..\Assets\Monster\{name}", true, true, null, true, false, false);
                }
                else
                {
                    _sprite = new Sprite(MONSTER_ID, _name, $@"..\..\..\..\Assets\Monster\{name}", true, true, _context.GetMapObject, true, false, false);
                }
            }
            else
            {
                _sprite = sprite;
            }

            pw           = _sprite.GetSprite.TextureRect.Width;
            ph           = _sprite.GetSprite.TextureRect.Height;
            _monsterMove = monsterMove / 100;
            _range       = range + 0.2f;
            _attackCombo = attackCombo;

            if (multiplayer)
            {
                _context2  = context;
                _name2     = name;
                _range2    = range + 0.2f;
                _position2 = new Position2(_position.X, _position.Y);
                _life2     = life;
                _isAlive2  = true;
                _attack2   = new Attack(context, this, attack, attackCombo);
                if (_context2 == null)
                {
                    _sprite = new Sprite(MONSTER_ID, _name + "2", $@"..\..\..\..\Assets\Monster\{name}", true, true, null, true, false, false);
                }
                else
                {
                    _sprite2 = new Sprite(MONSTER_ID, _name + "2", $@"..\..\..\..\Assets\Monster\{name}", true, true, _context2.GetMapObject, true, false, false);
                }
                //ph2 = _sprite2.GetSprite2.TextureRect.Height;
                _monsterMove2 = monsterMove / 100;
            }
        }
Beispiel #5
0
 internal void Gravity2()
 {
     if (_isJumping2 && _origin2 != null && _realPosition2.Y2 <= _origin2.Y2 + JUMPING_LIMIT) // Jump
     {
         _realPosition2.Y2 += JUMPING_SPEED;
         _position2.Y2     += JUMPING_SPEED;
         _sprite2.JumpAnimation();
     }
     else // Fall
     {
         _origin2           = null;
         _realPosition2.Y2 -= GRAVITY_SPEED;
         _position2.Y2     -= GRAVITY_SPEED;
     }
 }
Beispiel #6
0
        internal Boss(Game context, String name, Position position, Position2 position2, Life life, ushort attack, float bossMove, float range, string attackCombo)
        {
            _context   = context;
            _context2  = context;
            _name      = name;
            _position  = position;
            _life      = life;
            _attack    = new Attack(_context, null, attack, attackCombo, this);
            _attack2   = new Attack(_context2, null, attack, attackCombo, this);
            _sprite    = new Sprite(BOSS_ID, _name, $@"..\..\..\..\Assets\Boss\{name}\All", true, false, _context.GetMapObject, false, false, true);
            _sprite2   = new Sprite(BOSS_ID, _name, $@"..\..\..\..\Assets\Boss\{name}\All", true, true, _context.GetMapObject, false, false, true);
            pw         = _sprite.GetSprite.TextureRect.Width;
            ph         = _sprite.GetSprite.TextureRect.Height;
            _bossMove  = bossMove;
            _bossMove2 = bossMove;
            _range     = range + 0.2f;

            _life2     = life;
            _position2 = position2;
        }
Beispiel #7
0
        public short GameTick2()
        {
            if (_game == null)
            {
                throw new Exception("Game not started!");
            }
            if (_game2 == null)
            {
                throw new Exception("Game 2 not started!");
            }

            //Events
            _gui.Events2();


            //Console.Write("Player : " + _game.GetPlayer.RealPosition.X + ";" + _game.GetPlayer.RealPosition.Y);
            //Console.WriteLine(" | Monster1 : " + _game.GetMonsters[0].Position.X + ";" + _game.GetMonsters[0].Position.Y + " " + _game.GetMonsters[0].life.GetCurrentPoint() + "HP.");
            //Gravity 4 player
            Sprite sToPositive  = null;
            Sprite sToNegative  = null;
            Sprite sToPositive2 = null;
            Sprite sToNegative2 = null;

            _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(_game.GetPlayer.RealPosition.X, MidpointRounding.ToPositiveInfinity), (float)Math.Round(_game.GetPlayer.RealPosition.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToPositive);
            _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(_game.GetPlayer.RealPosition.X, MidpointRounding.ToNegativeInfinity), (float)Math.Round(_game.GetPlayer.RealPosition.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToNegative);
            if (sToPositive != null && !sToPositive.IsSolid && sToNegative != null && !sToNegative.IsSolid)
            {
                //Block under player isn't solid
                if (sToPositive.IsDangerous || sToNegative.IsDangerous)
                {
                    //DIE
                    _game.GetPlayer.KilledBy = "Trap";
                    return(-1);
                }
                _game.GetPlayer.Gravity();
            }
            else
            {
                _game.GetPlayer.IsJumping = false;
                _game.GetPlayer.RoundY(); // Don't stuck player in ground
            }
            //Heal
            List <Position> heart = _game.GetMapObject.GetHeart;

            foreach (Position position in heart)
            {
                if (_game.GetPlayer.RealPosition.X == position.X && _game.GetMapObject.GetMap[position].Id != "A")
                {
                    _game.GetPlayer.GetLife.BonusPoint(1);
                    _game.GetMapObject.GetMap[position] = _game.GetMapObject.GetSpriteChange;
                    _gui.LoadMap();
                }
            }


            //strength
            List <Position> star = _game.GetMapObject.GetStar;

            foreach (Position position in star)
            {
                if (_game.GetPlayer.RealPosition.X == position.X && _game.GetMapObject.GetMap[position].Id != "A")
                {
                    _game.GetPlayer.GetAttack++;
                    _game.GetMapObject.GetMap[position] = _game.GetMapObject.GetSpriteChange;
                    _gui.LoadMap();
                }
            }



            if (!_game.GetPlayer.IsAlive)
            {
                //DIE
                _game.GetPlayer.KilledBy = "Monster";
                return(-1);
            }


            //Monsters move + Attack
            foreach (Monster m in _game.GetMonsters)
            {
                if (!m.isAlive)
                {
                    m.MonsterDead();
                }
                else
                {
                    if (m.Position.X > _game.GetPlayer.RealPosition.X) //left
                    {
                        m.Orientation = "left";
                    }
                    else if (m.Position.X < _game.GetPlayer.RealPosition.X) //right
                    {
                        m.Orientation = "right";
                    }

                    if (m.Position.X - 4 < _game.GetPlayer.RealPosition.X && m.Position.X - 1 > _game.GetPlayer.RealPosition.X || m.Position.X + 4 > _game.GetPlayer.RealPosition.X && m.Position.X + 1 < _game.GetPlayer.RealPosition.X)
                    {
                        m.MonsterMove();
                    }

                    {
                        m.MonsterAttack();
                    }
                }
            }

            //Gravity 4 monsters
            foreach (Monster m in _game.GetMonsters)
            {
                _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(m.Position.X, MidpointRounding.ToPositiveInfinity), (float)Math.Round(m.Position.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToPositive);
                _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(m.Position.X, MidpointRounding.ToNegativeInfinity), (float)Math.Round(m.Position.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToNegative);
                if (sToPositive != null && !sToPositive.IsSolid && sToNegative != null && !sToNegative.IsSolid)
                {
                    //Block under monster isn't solid
                    if (sToPositive.IsDangerous || sToNegative.IsDangerous)
                    {
                        //DIE
                        m.life.CurrentPoint = 0;
                        m.MonsterDead();
                    }
                    m.Gravity();
                }
                else
                {
                    m.IsMoving = false;
                    m.RoundY(); // Don't stuck monster in ground
                }
            }

            // boss
            if (!_game.GetBoss.IsAlive)
            {
                _game.GetBoss.BossDead();
            }
            else
            {
                if (_game.GetBoss.Position.X > _game.GetPlayer.RealPosition.X) //left
                {
                    _game.GetBoss.Orientation = "left";
                }
                else if (_game.GetBoss.Position.X < _game.GetPlayer.RealPosition.X) //right
                {
                    _game.GetBoss.Orientation = "right";
                }

                _game.GetBoss.GetBossSprite.BossOrientation(_game.GetBoss);

                if (_game.GetBoss.Position.X + 3 > _game.GetPlayer.RealPosition.X && _game.GetBoss.Position.X - 3 < _game.GetPlayer.RealPosition.X) //attack
                {
                    if (_game.GetBoss.Position.X - 1 > _game.GetPlayer.RealPosition.X || _game.GetBoss.Position.X + 1 < _game.GetPlayer.RealPosition.X)
                    {
                        _game.GetBoss.BossMove();
                    }
                    _game.GetBoss.BossAttack();
                }

                else if (_game.GetBoss.Position.X - 6 < _game.GetPlayer.RealPosition.X && _game.GetBoss.Position.X - 1 > _game.GetPlayer.RealPosition.X || _game.GetBoss.Position.X + 6 > _game.GetPlayer.RealPosition.X && _game.GetBoss.Position.X + 1 < _game.GetPlayer.RealPosition.X)
                {
                    _game.GetBoss.BossMove();
                    _game.GetBoss.GetBossSprite.BossMoveAnimation(_game.GetBoss);
                }
            }

            _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(_game.GetBoss.Position.X, MidpointRounding.ToPositiveInfinity), (float)Math.Round(_game.GetBoss.Position.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToPositive);
            _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(_game.GetBoss.Position.X, MidpointRounding.ToNegativeInfinity), (float)Math.Round(_game.GetBoss.Position.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToNegative);
            if (sToPositive != null && !sToPositive.IsSolid && sToNegative != null && !sToNegative.IsSolid)
            {
                //Block under monster isn't solid
                _game.GetBoss.Gravity();
            }
            else
            {
                _game.GetBoss.IsMoving = false;
                _game.GetBoss.RoundY(); // Don't stuck monster in ground
            }


            // Recalibrate float
            _game.GetPlayer.RoundX();
            // WIN !!!
            Position end = _game.GetMapObject.GetEndPosition;

            if (end.X <= _game.GetPlayer.RealPosition.X)
            {
                Console.WriteLine("YOUWINNNNNNNNNN");
                // SHOW WIN MENU !
                return(0);
            }
            //win player 2
            if (end.X <= _game2.GetPlayer2.RealPosition2.X2)
            {
                Console.WriteLine("YOUWINNNNNNNNNN");
                // SHOW WIN MENU !
                return(2);
            }

            //-------------------------------------------------------player 2
            _game2.GetMapObject2.GetMap2.TryGetValue(new Position2((float)Math.Round(_game2.GetPlayer2.RealPosition2.X2, MidpointRounding.ToPositiveInfinity), (float)Math.Round(_game2.GetPlayer2.RealPosition2.Y2 - 1, MidpointRounding.ToPositiveInfinity)), out sToPositive2);
            _game2.GetMapObject2.GetMap2.TryGetValue(new Position2((float)Math.Round(_game2.GetPlayer2.RealPosition2.X2, MidpointRounding.ToNegativeInfinity), (float)Math.Round(_game2.GetPlayer2.RealPosition2.Y2 - 1, MidpointRounding.ToPositiveInfinity)), out sToNegative2);


            if (sToPositive2 != null && !sToPositive2.IsSolid2 && sToNegative2 != null && !sToNegative2.IsSolid2)
            {
                //Block under player isn't solid
                if (sToPositive2.IsDangerous2 || sToNegative2.IsDangerous2)
                {
                    //DIE
                    _game2.GetPlayer2.KilledBy2 = "Trap";
                    return(-1);
                }
                _game2.GetPlayer2.Gravity2();
            }
            else
            {
                _game2.GetPlayer2.IsJumping2 = false;
                _game2.GetPlayer2.RoundY2(); // Don't stuck player in ground
            }
            //Heal
            List <Position2> heart2 = _game2.GetMapObject2.GetHeart2;

            foreach (Position2 position2 in heart2)
            {
                if (_game2.GetPlayer2.RealPosition2.X2 == position2.X2 && _game2.GetMapObject2.GetMap2[position2].Id2 != "A")
                {
                    _game2.GetPlayer2.GetLife2.BonusPoint2(1);
                    _game2.GetMapObject2.GetMap2[position2] = _game2.GetMapObject2.GetSpriteChange2;
                    _gui.LoadMap2();
                }
            }


            //strength
            List <Position2> star2 = _game2.GetMapObject2.GetStar2;

            foreach (Position2 position2 in star2)
            {
                if (_game2.GetPlayer2.RealPosition2.X2 == position2.X2 && _game2.GetMapObject2.GetMap2[position2].Id2 != "A")
                {
                    _game2.GetPlayer2.GetAttack2++;
                    _game2.GetMapObject2.GetMap2[position2] = _game2.GetMapObject2.GetSpriteChange2;
                    _gui.LoadMap2();
                }
            }

            if (!_game2.GetPlayer2.IsAlive2)
            {
                //DIE
                _game2.GetPlayer2.KilledBy2 = "Monster";
                return(-1);
            }

            //Monsters move + Attack
            foreach (Monster m2 in _game2.GetMonsters2)
            {
                if (m2.Position2.X2 > _game2.GetPlayer2.RealPosition2.X2 && m2.isAlive2) //left
                {
                    m2.Orientation2 = "left";
                }
                else if (m2.Position2.X2 < _game2.GetPlayer2.RealPosition2.X2 && m2.isAlive2) //right
                {
                    m2.Orientation2 = "right";
                }

                if (!m2.isAlive2)
                {
                    m2.MonsterDead2();
                }
                else if (m2.Position2.X2 - 4 < _game2.GetPlayer2.RealPosition2.X2 && m2.Position2.X2 - 1 > _game2.GetPlayer2.RealPosition2.X2 || m2.Position2.X2 + 4 > _game2.GetPlayer2.RealPosition2.X2 && m2.Position2.X2 + 1 < _game2.GetPlayer2.RealPosition2.X2)
                {
                    m2.MonsterMove2();
                }

                if (m2.Position2.X2 + 2 > _game2.GetPlayer2.RealPosition2.X2 && m2.Position2.X2 - 2 < _game2.GetPlayer2.RealPosition2.X2 && m2.isAlive2) //attack
                {
                    m2.MonsterAttack2();
                }
            }

            //Gravity 4 monsters
            foreach (Monster m2 in _game2.GetMonsters2)
            {
                _game2.GetMapObject2.GetMap2.TryGetValue(new Position2((float)Math.Round(m2.Position2.X2, MidpointRounding.ToPositiveInfinity), (float)Math.Round(m2.Position2.Y2 - 1, MidpointRounding.ToPositiveInfinity)), out sToPositive2);
                _game2.GetMapObject2.GetMap2.TryGetValue(new Position2((float)Math.Round(m2.Position2.X2, MidpointRounding.ToNegativeInfinity), (float)Math.Round(m2.Position2.Y2 - 1, MidpointRounding.ToPositiveInfinity)), out sToNegative2);
                if (sToPositive2 != null && !sToPositive2.IsSolid2 && sToNegative2 != null && !sToNegative2.IsSolid2)
                {
                    //Block under monster isn't solid
                    if (sToPositive2.IsDangerous2 || sToNegative2.IsDangerous2)
                    {
                        //DIE
                        m2.life2.CurrentPoint2 = 0;
                        m2.MonsterDead2();
                    }
                    m2.Gravity2();
                }
                else
                {
                    m2.IsMoving2 = false;
                    m2.RoundY2(); // Don't stuck monster in ground
                }
            }

            // boss
            if (!_game2.GetBoss2.IsAlive2)
            {
                _game2.GetBoss2.BossDead2();
            }
            else
            {
                if (_game2.GetBoss2.Position2.X2 > _game2.GetPlayer2.RealPosition2.X2) //left
                {
                    _game2.GetBoss2.Orientation2 = "left";
                }
                else if (_game2.GetBoss2.Position2.X2 < _game2.GetPlayer2.RealPosition2.X2) //right
                {
                    _game2.GetBoss2.Orientation2 = "right";
                }

                _game2.GetBoss2.GetBossSprite2.BossOrientation2(_game2.GetBoss2);

                if (_game2.GetBoss2.Position2.X2 + 3 > _game2.GetPlayer2.RealPosition2.X2 && _game2.GetBoss2.Position2.X2 - 3 < _game2.GetPlayer2.RealPosition2.X2) //attack
                {
                    if (_game2.GetBoss2.Position2.X2 - 1 > _game2.GetPlayer2.RealPosition2.X2 || _game2.GetBoss2.Position2.X2 + 1 < _game2.GetPlayer2.RealPosition2.X2)
                    {
                        _game2.GetBoss2.BossMove2();
                    }
                    _game2.GetBoss2.BossAttack2();
                }

                else if (_game2.GetBoss2.Position2.X2 - 6 < _game2.GetPlayer2.RealPosition2.X2 && _game2.GetBoss2.Position2.X2 - 1 > _game2.GetPlayer2.RealPosition2.X2 || _game2.GetBoss2.Position2.X2 + 6 > _game2.GetPlayer2.RealPosition2.X2 && _game2.GetBoss2.Position2.X2 + 1 < _game2.GetPlayer2.RealPosition2.X2)
                {
                    _game2.GetBoss2.BossMove2();
                    _game2.GetBoss2.GetBossSprite2.BossMoveAnimation2(_game2.GetBoss2);
                }
            }

            _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(_game.GetBoss.Position.X, MidpointRounding.ToPositiveInfinity), (float)Math.Round(_game.GetBoss.Position.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToPositive);
            _game.GetMapObject.GetMap.TryGetValue(new Position((float)Math.Round(_game.GetBoss.Position.X, MidpointRounding.ToNegativeInfinity), (float)Math.Round(_game.GetBoss.Position.Y - 1, MidpointRounding.ToPositiveInfinity)), out sToNegative);
            if (sToPositive != null && !sToPositive.IsSolid && sToNegative != null && !sToNegative.IsSolid)
            {
                //Block under monster isn't solid
                _game.GetBoss.Gravity();
            }
            else
            {
                _game.GetBoss.IsMoving = false;
                _game.GetBoss.RoundY(); // Don't stuck monster in ground
            }

            // Recalibrate float
            _game2.GetPlayer2.RoundX2();
            // WIN !!!
            Position2 end2 = _game2.GetMapObject2.GetEndPosition2;

            if (end2.X2 <= _game2.GetPlayer2.RealPosition2.X2)
            {
                Console.WriteLine("YOUWINNNNNNNNNN");
                // SHOW WIN MENU !
                return(0);
            }


            // Dead return -1;

            return(1);
        }
Beispiel #8
0
        internal Player(Game context, string name, Position position, Life life, ushort attack, string imgPath, bool multiplayer)
        {
            _context      = context;
            _name         = name;
            _position     = position;
            _realPosition = new Position(_position.X, _position.Y);
            _life         = life;
            _attack       = attack;
            _imgPath      = imgPath;
            _isJumping    = false;
            _isAttack     = false;
            if (context != null)
            {
                _sprite = new Sprite(PLAYER_ID, _name, imgPath, true, true, _context.GetMapObject, false, true);
            }
            else
            {
                _sprite = new Sprite(PLAYER_ID, _name, imgPath, true, true, null, false, true);
            }
            _orientation = "right";

            _incrementationHeal    = 0;
            _incrementationHeal2   = 0;
            _incrementationAttack  = 0;
            _incrementationAttack2 = 0;

            _attackSpeed = 1;
            _attackRange = 2.0f; // En block

            _attackTimer = new Stopwatch();
            _attackTimer.Start();
            pw = 128;
            ph = 128;

            _monsterKillName = "void";
            _degatsToShow    = new List <int>();

            if (multiplayer)
            {
                //Player 2
                pw2 = 128;
                ph2 = 128;
                _monsterKillName2 = "void";
                _context2         = context;
                _name2            = name;
                _position2        = new Position2(_position.X, _position.Y);
                _realPosition2    = new Position2(_position2.X2, _position2.Y2);
                _life2            = life;
                _attack2          = attack;
                _isJumping2       = false;
                _isAttack2        = false;
                if (_context2 == null)
                {
                    _sprite2 = new Sprite(PLAYER_ID2, _name2, imgPath, true, true, null, false, true);
                }
                else
                {
                    _sprite2 = new Sprite(PLAYER_ID2, _name2, imgPath, true, true, _context2.GetMapObject, false, true);
                }
                _orientation2 = "right";

                _attackSpeed2 = 1;
                _attackRange2 = 2.0f; // En block



                _attackTimer2 = new Stopwatch();
                _attackTimer2.Start();
            }
        }
Beispiel #9
0
        internal Game(Engine context, string mapPath, string playerPath, Position startPosition, Position2 startPosition2, ushort lifePoint, ushort atk, bool multiplayer)
        {
            _mapPath = mapPath;
            _context = context;
            _map     = new Map(this, mapPath, multiplayer);
            _context.GetGUI.ShowLoading(15);
            Console.WriteLine("map charged");
            _player = new Player(this, "player", startPosition, new Life(lifePoint), atk, playerPath, multiplayer);
            _context.GetGUI.ShowLoading(25);
            Console.WriteLine("player charged");
            _monsters = _map.GenerateMonsters();
            _context.GetGUI.ShowLoading(60);
            Console.WriteLine("monsters charged"); // Prend + de temps
            _boss = _map.GenerateBoss();
            _context.GetGUI.ShowLoading(85);
            Console.WriteLine("boss charged"); // Prends + de temps
            _timer = new Stopwatch();
            _timer.Start();

            if (multiplayer == true)
            {
                _map2      = new Map(this, mapPath, multiplayer);
                _boss2     = _map2.GenerateBoss2();
                _mapPath2  = mapPath;
                _context2  = context;
                _player2   = new Player(this, "player", startPosition, new Life(lifePoint), atk, playerPath, true);
                _monsters2 = _map.GenerateMonsters2();
                _timer2    = new Stopwatch();
                _timer2.Start();
            }
        }
Beispiel #10
0
 public Checkpoint(Position lastActivatedCheckpoint)
 {
     _lastActivatedCheckpoint  = lastActivatedCheckpoint;
     _lastActivatedCheckpoint2 = new Position2(0, 3);
 }
Beispiel #11
0
        /// <summary>
        /// Map file format :
        /// LIMIT
        /// min
        /// max
        /// LIMIT
        /// BLOCKS
        /// id name imgPath
        /// BLOCKS
        /// MONSTER
        /// id name [x;y] hp imgDirPath range attackcombo
        /// MONSTER
        /// MAP
        ///
        /// MAP
        /// </summary>
        void GenerateMap()
        {
            //Verify if it's a map file
            if (!_mapPath.EndsWith(".totmap"))
            {
                throw new ArgumentException("The map file is not correct (.totmap)");
            }
            // Open map file
            string text = File.ReadAllText(_mapPath);

            if (String.IsNullOrEmpty(text))
            {
                throw new FileLoadException("File is empty ?");
            }

            // Get background path
            _backgroundPath = StringBetweenString(text, "BACKGROUNDPATH", "BACKGROUNDPATHEND");
            _backgroundPath = _backgroundPath.Replace("\r", "");

            // Get limits
            string[] limits   = StringBetweenString(text, "LIMIT", "LIMITEND").Split("\n");
            string[] limitMin = limits[0].Split(" ");
            _limitMin = new Position(Convert.ToSingle(limitMin[0]), Convert.ToSingle(limitMin[1]));
            string[] limitMax = limits[1].Split(" ");
            _limitMax = new Position(Convert.ToSingle(limitMax[0]), Convert.ToSingle(limitMax[1]));

            // Get limits2
            if (_multiplayer)
            {
                string[] limits2   = StringBetweenString(text, "LIMIT", "LIMITEND").Split("\n");
                string[] limitMin2 = limits[0].Split(" ");
                _limitMin2 = new Position2(Convert.ToSingle(limitMin[0]), Convert.ToSingle(limitMin[1]));
                string[] limitMax2 = limits[1].Split(" ");
                _limitMax2 = new Position2(Convert.ToSingle(limitMax[0]), Convert.ToSingle(limitMax[1]));
            }


            // Get all blocks in level (id, name, path, isSolid)
            string[] blocks = StringBetweenString(text, "BLOCKS", "BLOCKSEND").Split("\n");
            for (int i = 0; i < blocks.Length; i++)
            {
                string   s           = (string)blocks[i];
                string[] str         = s.Split(" ");
                Sprite   SpriteToAdd = new Sprite(str[0], str[1], str[2], Convert.ToBoolean(str[3]), true, this, false, false, false);
                _sprites.Add(SpriteToAdd);
                if (_context2 != null)
                {
                    _sprites2.Add(SpriteToAdd);
                }
                if (str[1] == "TRAP")
                {
                    //Console.WriteLine(str[4]);
                    //if (str[4] == "DANGEROUS")
                    //{
                    _sprites[i].IsDangerous = true;
                    if (_context2 != null)
                    {
                        _sprites2[i].IsDangerous2 = true;
                    }
                    Console.WriteLine(str[1] + " IS DANGEROUS");
                    //}
                }
                if (str[1] == "AIR")
                {
                    _spriteChange = new Sprite(str[0], str[1], str[2], Convert.ToBoolean(str[3]), true, this, false, false, false);
                    if (_context2 != null)
                    {
                        _spriteChange2 = _spriteChange;
                    }
                }
            }

            // Get map
            string[] mapParsed = StringBetweenString(text, "MAP", "MAPEND").Split("\n");
            for (int y = 0; y < mapParsed.Length; y++)
            {
                for (int x = 0; x < mapParsed[y].Length; x++)
                {
                    if (mapParsed[y][x] == 'H')
                    {
                        _heart.Add(new Position((float)x, (float)_limitMax.Y - y));
                        if (_multiplayer)
                        {
                            _heart2.Add(new Position2((float)x, (float)_limitMax2.Y2 - y));
                        }
                    }
                    if (mapParsed[y][x] == 'S')
                    {
                        _star.Add(new Position((float)x, (float)_limitMax.Y - y));
                        if (_multiplayer)
                        {
                            _star2.Add(new Position2((float)x, (float)_limitMax2.Y2 - y));
                        }
                    }
                    if (mapParsed[y][x] == '2')
                    {
                        _trap.Add(new Position((float)x, (float)_limitMax.Y - y));
                        if (_multiplayer)
                        {
                            _trap2.Add(new Position2((float)x, (float)_limitMax2.Y2 - y));
                        }
                    }
                }
            }

            //Boucle Y
            int indexTemp = 0;

            for (int y = Convert.ToInt32(_limitMax.Y); y >= Convert.ToInt32(_limitMin.Y); y--)
            {
                for (int x = Convert.ToInt32(_limitMin.X); x <= Convert.ToInt32(_limitMax.X); x++)
                {
                    _map.Add(new Position(x, y), RetrieveSpriteWithId(mapParsed[indexTemp].Substring(x, 1)));
                    if (_context2 != null)
                    {
                        _map2.Add(new Position2(x, y), RetrieveSpriteWithId(mapParsed[indexTemp].Substring(x, 1)));
                    }
                }
                indexTemp++;
            }
        }