CrisisAtSwissStation.DudeObject.DudeObject C# (CSharp) Method

DudeObject() public method

public DudeObject ( World world, ScrollingWorld theWorld, string texturename, string objectTexturename, string armTexturename, LaserObject Laser, string groundSensorName ) : System
world Box2DX.Dynamics.World
theWorld ScrollingWorld
texturename string
objectTexturename string
armTexturename string
Laser LaserObject
groundSensorName string
return System
        public DudeObject(World world, ScrollingWorld theWorld, string texturename, string objectTexturename, string armTexturename, LaserObject Laser, string groundSensorName)
            : base(world, objectTexturename, DUDE_DENSITY, 0.0f, 0.0f, 1, false)
        {
            this.armTextureName = armTexturename;
            this.animTextureName = texturename;

            Texture2D objectTexture = GameEngine.TextureList[objectTexturename];
            Texture2D texture = GameEngine.TextureList[texturename];
            Texture2D armTexture = GameEngine.TextureList[armTexturename];
            deadTexture = GameEngine.TextureList["Art\\failure_cosmo"];

            Height = objectTexture.Height;
            Width = objectTexture.Width;

            boundingBox = new Rectangle((int)(Position.X * CASSWorld.SCALE), (int)(Position.Y * CASSWorld.SCALE), (int)Height, (int)Width);

            amDead = false;

            // Initialize
            isGrounded = false;
            isSloped = false;

            TextureFilename = objectTexturename;
            // BodyDef options
            BodyDef.FixedRotation = true;

            // Make a dude controller
            controllers.Add(new DudeController());

            armAngle = 0;

            myWorld = theWorld;

            //animation stuff
            myGameTime = 0;
            animTexture = texture;
            this.armTexture = armTexture;
            walkTimer = 0;
            walkInterval = 5;
            xFrame = 0;
            yFrame = 0;
            spriteWidth = 100;
            spriteHeight = 100;
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);
            animOrigin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2);
            armOrigin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2) - new Vector2(10,18);

            // Ground Sensor
            // -------------
            //   We only allow the dude to jump when he's
            // on the ground.  After all, how can you jump
            // when you're flying in the air?  (Unless you
            // can double jump)
            //   To determine whether or not the dude is on
            // the ground, we create a thin sensor under his
            // feet, which reports collisions with the world
            // but has no collision response.
            //   Game logic in PlatformWorld tells the dude
            // whether or not he is grounded.

            //animation stuff
            /*
            // Compute dimensions of the ground sensor
            float halfWidth = (float)texture.Width / (2 * CASSWorld.SCALE);
            float halfHeight = (float)texture.Height / (2 * CASSWorld.SCALE);
            Vector2 sensorCenter = new Vector2(0, halfHeight);
             */
            float halfWidth = (float)objectTexture.Width / (2 * CASSWorld.SCALE);
            float halfHeight = (float)objectTexture.Height / (2 * CASSWorld.SCALE);
            //Vector2 sensorCenter = new Vector2(0, halfHeight);
            Vector2 sensorCenter = new Vector2(0, halfHeight - (5f / CASSWorld.SCALE));

            // Create collision shape of the ground sensor
            PolygonDef groundSensor = new PolygonDef();
            groundSensor.Density = 0.0f;
            groundSensor.IsSensor = true;
            groundSensor.UserData = groundSensorName;
            //groundSensor.SetAsBox(halfWidth*0.6f, halfHeight*0.5f, Utils.Convert(sensorCenter), 0);
            groundSensor.SetAsBox(2f/CASSWorld.SCALE, halfWidth/2f, Utils.Convert(sensorCenter), 0);
            shapes.Add(groundSensor);

            /* CIRCULAR GROUND SENSOR - just comment above out and uncomment this
            CircleDef groundSensor = new CircleDef();
            groundSensor.Radius = halfWidth * 0.95f;
            //groundSensor.Radius = (15f/2f) / CASSWorld.SCALE;
            groundSensor.LocalPosition = Utils.Convert(sensorCenter);
            groundSensor.UserData = groundSensorName;
            groundSensor.IsSensor = true;
            shapes.Add(groundSensor);
            */

            PolygonDef slopeSensor = new PolygonDef();
            slopeSensor.Density = 0.0f;
            slopeSensor.IsSensor = true;
            slopeSensor.UserData = groundSensorName + "SLOPE";
            slopeSensor.SetAsBox(halfWidth * 1.1f, 0.1f, Utils.Convert(sensorCenter + new Vector2(0, 0)), 0);
            shapes.Add(slopeSensor);

            lockDude = false;

            //animation stuff
            //base.(world, texture, 1.0f, 0.0f, 0.0f);
        }