示例#1
0
        public Bug(MovingObject target)
            : base(target)
        {
            bmp = new AnimatedBitmap(10, 10, 14, false);
            bmp.AddState("assets/objects/zombie_2-2", "stay", true);
            bmp.AddState("assets/objects/zombie_2", "run", true);
            bmp.SetState("stay");
            AddChild(bmp);

            hp = 50;
        }
示例#2
0
        public Zombie(MovingObject target)
            : base(target)
        {
            bmp = new AnimatedBitmap(16, 23, 14, false);
            bmp.AddState("assets/objects/zombie_1-2", "stay", true);
            bmp.AddState("assets/objects/zombie_1", "run", true);
            bmp.SetState("stay");
            AddChild(bmp);

            hp = 100;
        }
示例#3
0
        private void CheckCollisions_Vertical(MovingObject obj)
        {
            float tempX, tempY;
            Tile tempTile;
            int hitsCount = 0;

            obj.Grounded = false;

            if (obj.velocity.Y > 0)
            {
                tempY = obj.Y + obj.Height;
                for (tempX = obj.X + Level.TILE_SIZE / 4; tempX < obj.X + obj.Width; tempX += Level.TILE_SIZE / 4)
                {
                    var tx = (int)(tempX / Level.TILE_SIZE);
                    var ty = (int)(tempY / Level.TILE_SIZE);

                    tx = Math.Max(tx, 0);
                    tx = Math.Min(tx, level.levelWidth - 1);

                    ty = Math.Max(ty, 0);
                    ty = Math.Min(ty, level.levelHeight - 1);

                    tempTile = level.tileMap[tx, ty];
                    if (tempTile.type > 0 && tempTile.type < 5 && tempTile != obj.ground)
                    {
                        hitsCount++;
                        obj.velocity.Y = 0;
                        obj.Y = (int)(tempY / Level.TILE_SIZE) * Level.TILE_SIZE - obj.Height;
                        obj.Grounded = true;
                        obj.ground = tempTile;
                    }
                }
            }
            else
            {
                tempY = obj.Y;
                for (tempX = obj.X + Level.TILE_SIZE / 4; tempX < obj.X + obj.Width; tempX += Level.TILE_SIZE / 4)
                {
                    var tx = (int)(tempX / Level.TILE_SIZE);
                    var ty = (int)(tempY / Level.TILE_SIZE);

                    tx = Math.Max(tx, 0);
                    tx = Math.Min(tx, level.levelWidth - 1);

                    ty = Math.Max(ty, 0);
                    ty = Math.Min(ty, level.levelHeight - 1);

                    tempTile = level.tileMap[tx, ty];
                    if (tempTile.type > 0 && tempTile.type < 5 && tempTile != obj.wall)
                    {
                        hitsCount++;
                        obj.velocity.Y = 0;
                        obj.Y = (int)((tempY + 1) / Level.TILE_SIZE) * Level.TILE_SIZE;
                        obj.ground = tempTile;
                    }
                }
            }
            if (hitsCount == 0)
            {
                obj.ground = null;
                obj.Grounded = false;
            }
        }
示例#4
0
        public void SolveCollisions_Vertical(MovingObject obj)
        {
            obj.Grounded = false;
            float x_offset = obj.Width / 16;
            float x_step = obj.Width / 8;
            float y_up = obj.Y, y_down = obj.Y + obj.Height;
            var tileMap = level.tileMap;

            int hitsCount = 0;

            for (float x = obj.X + x_offset; x < obj.X + obj.Width; x += x_step)
            {
                int tileX = (int)(x / Level.TILE_SIZE), tileY_up = (int)(y_up / Level.TILE_SIZE),
                tileY_down = (int)(y_down / Level.TILE_SIZE);

                bool is_going_down = obj.velocity.Y >= 0;
                var tempTile = tileMap[tileX, is_going_down ? tileY_down : tileY_up];

                if (tempTile.type > 0 && obj.wall != tempTile)
                {
                    obj.Y = (is_going_down ? tileY_down : (tileY_up + 1)) * Level.TILE_SIZE - Convert.ToInt32(is_going_down) * obj.Height;
                    obj.velocity.Y = 0;
                    obj.ground = tempTile;
                    obj.Grounded = is_going_down;
                    hitsCount++;
                    return;
                }
            }
            if (hitsCount == 0)
                obj.ground = null;
        }
示例#5
0
        public void SolveCollisions_Horizontal(MovingObject obj)
        {
            obj.Walled = false;

            float y_offset = obj.Height / 16;
            float y_step = obj.Height / 8;
            float x_left = obj.X, x_right = obj.X + obj.Width;
            var tileMap = level.tileMap;

            int hitsCount = 0;

            for (float y = obj.Y + y_offset; y < obj.Y + obj.Width; y += y_step)
            {
                int tileY = (int)(y / Level.TILE_SIZE), tileX_left = (int)(x_left / Level.TILE_SIZE),
                tileX_right = (int)(x_right / Level.TILE_SIZE);

                bool is_going_right = obj.velocity.X >= 0;
                var tempTile = tileMap[(is_going_right) ? tileX_right : tileX_left, tileY];

                if (tempTile.type > 0 && tempTile != obj.ground)
                {
                    obj.X = (is_going_right ? tileX_right : (tileX_left + 1)) * Level.TILE_SIZE - Convert.ToInt32(is_going_right) * obj.Width;
                    obj.velocity.X = 0;
                    obj.v0x = 0;
                    obj.wall = tempTile;
                    obj.Walled = true;
                    hitsCount++;
                }
            }
            if (hitsCount == 0)
                obj.wall = null;
        }
示例#6
0
 public Enemy(MovingObject target)
 {
     this.target = target;
     Random rand = new Random();
     sx = rand.Next(20, MAX_VELOCITY);
 }