/** * Creates a new box object */ public MovingObject(World world, string texturename, float density, float friction, float restitution, float myScale, bool isPulley, SwitchObject mySwitch, Vector2 myForce, float bound1, float bound2) : base(world) { BodyDef.FixedRotation = true; texture = GameEngine.TextureList[texturename]; TextureFilename = texturename; Height = texture.Height * myScale; Width = texture.Width * myScale; boundingBox = new Rectangle((int)Position.X, (int)Position.Y, (int)Width, (int)Height); this.bound1 = bound1; this.bound2 = bound2; this.myForce = myForce; this.mySwitch = mySwitch; BodyDef.IsBullet = true; // Initialize this.texture = texture; scale = myScale; if (isPulley) BodyDef.FixedRotation = true; // Determine dimensions float halfWidth = ((float)texture.Width / (2 * CASSWorld.SCALE)) * scale; float halfHeight = ((float)texture.Height / (2 * CASSWorld.SCALE)) * scale; // Create the collision shape PolygonDef shape = new PolygonDef(); shape.SetAsBox(halfWidth, halfHeight); shape.Density = density; shape.Friction = friction; shape.Restitution = restitution; shapes.Add(shape); isMoving = false; }
public ScrollingWorld(string backgroundname = "background") : base(WIDTH, HEIGHT, new Vector2(0, GRAVITY)) { backgroundName = "Art\\Backgrounds\\" + backgroundname; musicName = backgroundname; background = GameEngine.TextureList[backgroundName]; movPlat1 = true; //movPlat2 = true; //mov = true; gameLevelWidth = background.Width; gameLevelHeight = background.Height; cursorSrcRect = new Rectangle(cursorWidth, cursorWidth, cursorWidth, cursorWidth); numDrawLeft = 0; // reset the amount of instasteel when loading the level totalInstaSteelInWorld = 0; // Create win door // HACK HACK - this will break door animation until a fix is created //winDoor = new SensorObject(World, winDoorAnimTexture, winTexture,93,99,20,5); winDoor = new WinDoorObject(World, "door_strip", "WinDoor", 93, 99, 20, 5); winDoor.Position = winDoorPos; AddObject(winDoor); // Create ground pieces //AddObject(new PolygonObject(World, wall1, groundTexture, 0, 0.0f, 0.1f)); //AddObject(new PolygonObject(World, wall2, groundTexture, 0, 0.0f, 0.1f)); // Create platforms //foreach(Vector2[] platform in platforms) // AddObject(new PolygonObject(World, platform, groundTexture, 0, 0.1f, 0.0f)); //new platforms //float s = CASSWorld.SCALE; // AddObject(new HackObject(World, (int)(1024/s), (int)(38/s), 0, (int)(730/s),.1f)); // Create laser laser = new LaserObject(World, dude, "paintedsegment", 10); // Create dude //dude = new DudeObject(World, dudeTexture, dudeObjectTexture, armTexture, dudeSensorName); //dude = new DudeObject(World, this, dudeTexture, dudeObjectTexture, armTexture, laser, dudeSensorName); dude = new DudeObject(World, this, "newDudeFilmstrip", "Dude", "arm", laser, dudeSensorName); dude.Position = dudePosition; AddObject(dude); // Create the dude's arm /* arm = new BoxObject(World, armTexture, 0, .1f, 0); arm.Position = dudePosition; AddObject(arm); */ //Left pillar (walls) pillar = new BoxObject(World, "Barrier", 0, .1f, 0,1,false); pillar.Position = pillarPosition; AddObject(pillar); /* pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -3.7f); AddObject(pillar); pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -7.4f); AddObject(pillar); pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -11.1f); AddObject(pillar); pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -14.8f); AddObject(pillar); */ //right pillar now pillar2 = new BoxObject(World, "Barrier", 0, .1f, 0,1,false); pillar2.Position = pillarPosition + new Vector2(81.9f, 0); AddObject(pillar2); /* pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -3.7f); AddObject(pillar); pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -7.4f); AddObject(pillar); pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -11.1f); AddObject(pillar); pillar = new BoxObject(World, barrierTexture, 0, .1f, 0,1,false); pillar.Position = pillarPosition + new Vector2(0, -14.8f); AddObject(pillar);*/ /* bigBox = new BoxObject(World, bigBoxTexture, 0, .1f, 0); bigBox.Position = bigBoxPosition + new Vector2(61.5f, .05f); AddObject(bigBox); littleBox = new BoxObject(World, littleBoxTexture, 0, .1f, 0); littleBox.Position = littleBoxPosition + new Vector2(61.5f, 0f); AddObject(littleBox); leftPipe = new BoxObject(World, leftPipeTexture, 0, .1f, 0); leftPipe.Position = leftPipePosition + new Vector2(61.5f, 0f); AddObject(leftPipe); rightPipe = new BoxObject(World, rightPipeTexture, 0, .1f, 0); rightPipe.Position = rightPipePosition + new Vector2(61.5f, 0f); AddObject(rightPipe); */ platform = new BoxObject(World, "platformTexture", 0, .1f, 0, 1, false); platform.Position = platformPosition + new Vector2(61.5f, 0f); // AddObject(platform); straightPipe1 = new BoxObject(World, "straight_pipe", 0, .5f, 0,1,false); straightPipe1.Position = straightPipe1Position; straightPipe1.Angle = 1.57f; //straightPipe1.Angle = 3.14f; // AddObject(straightPipe1); straightPipe2 = new BoxObject(World, "ground_like_platform", 0, .5f, 0,.6f,false); straightPipe2.Position = straightPipe2Position; // AddObject(straightPipe2); straightPipe3 = new BoxObject(World, "straight_pipe", 0, .5f, 0, .6f,false); straightPipe3.Position = straightPipe3Position; // AddObject(straightPipe3); straightPipe4 = new BoxObject(World, "straight_pipe_tile", 0, .5f, 0, .8f,false); straightPipe4.Position = straightPipe4Position; straightPipe4.Angle = 1.57f; // AddObject(straightPipe4); straightPipe5 = new BoxObject(World, "straight_pipe", 0, .5f, 0, 1f,false); straightPipe5.Position = straightPipe5Position; straightPipe5.Angle = 1.57f; // AddObject(straightPipe5); straightPipe6 = new BoxObject(World, "straight_pipe", 0, .5f, 0, .45f,false); straightPipe6.Position = straightPipe6Position; // AddObject(straightPipe6); straightPipe7 = new BoxObject(World, "straight_pipe", 0, .5f, 0, .58f,false); straightPipe7.Position = straightPipe7Position; // AddObject(straightPipe7); straightPipe8 = new BoxObject(World, "straight_pipe_tile", 0, .5f, 0, .4f,false); straightPipe8.Position = straightPipe8Position; straightPipe8.Angle = 1.57f; //AddObject(straightPipe8); straightPipe9 = new BoxObject(World, "straight_pipe_tile", 0, .5f, 0, 1f,false); straightPipe9.Position = straightPipe9Position; // AddObject(straightPipe9); straightPipe10 = new BoxObject(World, "straight_pipe_tile", 0, .5f, 0, 1.3f, false); straightPipe10.Position = straightPipe10Position; straightPipe10.Angle = 1.57f; // AddObject(straightPipe10); straightPipe11 = new BoxObject(World, "straight_pipe_tile", 0, .5f, 0, 1.3f, false); straightPipe11.Position = straightPipe11Position; straightPipe11.Angle = 1.57f; // AddObject(straightPipe11); pulleyPipe1 = new BoxObject(World, "pulley_platform", 1f, .5f, 0, .7f,true); pulleyPipe1.Position = pulleyPipe1Position; // pulleyPipe1.Body. // AddObject(pulleyPipe1); pulleyPipe2 = new BoxObject(World, "pulley_platform_long", 1f, .5f, 0, .35f,true); pulleyPipe2.Position = pulleyPipe2Position; // AddObject(pulleyPipe2); // PulleyJointDef jointDef1 = new PulleyJointDef(); // Box2DX.Common.Vec2 anchor1 = pulleyPipe1.Body.GetWorldCenter(); // Box2DX.Common.Vec2 anchor2 = pulleyPipe2.Body.GetWorldCenter(); // Box2DX.Common.Vec2 groundAnchor1 = pulleyPipe1.Body.GetWorldCenter() + Utils.Convert(new Vector2(0, -2f)); // Box2DX.Common.Vec2 groundAnchor2 = pulleyPipe2.Body.GetWorldCenter() + Utils.Convert(new Vector2(0, -5f)); //Box2DX.Common.Vec2 groundAnchor2 = Utils.Convert(new Vector2(18.2f, 10.0f)); // jointDef1.Initialize(pulleyPipe1.Body,pulleyPipe2.Body, groundAnchor1, groundAnchor2, anchor1, anchor2, 1f); /* PulleyJointDef jointDef1 = new PulleyJointDef(); Box2DX.Common.Vec2 anchor1 = pulleyPipe2.Body.GetWorldCenter(); Box2DX.Common.Vec2 anchor2 = pulleyPipe1.Body.GetWorldCenter(); Box2DX.Common.Vec2 groundAnchor1 = pulleyPipe2.Body.GetWorldCenter() + Utils.Convert(new Vector2(0, -5f)); Box2DX.Common.Vec2 groundAnchor2 = pulleyPipe1.Body.GetWorldCenter(); //Box2DX.Common.Vec2 groundAnchor2 = Utils.Convert(new Vector2(18.2f, 10.0f)); jointDef1.Initialize(pulleyPipe2.Body, pulleyPipe1.Body, groundAnchor1, groundAnchor2, anchor1, anchor2, .5f); */ // jointDef1.Length1 = 2f; // jointDef1.Length2 = 5f; // jointDef1.MaxLength1 = 5f; // jointDef1.MaxLength2 = 5f; //Console.WriteLine("{0} {1}", pulleyPipe1.Body.GetMass(), pulleyPipe2.Body.GetMass()); //Console.WriteLine("{0} {1}", jointDef1.Length1, jointDef1.Length2); //Console.WriteLine("{0} {1}", pulleyPipe2.Body.GetWorldCenter().X, pulleyPipe2.Body.GetWorldCenter().Y); //Console.WriteLine("{0}", getGameCoords(new Vector2(Mouse.GetState().X, Mouse.GetState().Y))); // World.CreateJoint(jointDef1); /* pistonHead = new BoxObject(World, "Art\\Objects\\PistonObjects\\piston_moving", 0, .5f, 0, .5f, false); pistonHead.Position = pistonHeadPosition; AddObject(pistonHead); */ piston = new PistonObject(World, .5f, .5f, 12f, 13f, 9.7f, 12.6f, .01f, .2f, pistonPosition); piston.Position = pistonPosition; // AddObject(piston); //private static Vector2 pistonPosition = new Vector2(12f, 13.2f); bottom1 = new BoxObject(World, "bottomTexture2273", 0, .5f, 0,1,false); bottom1.Position = bottom1Position; //AddObject(bottom1); bottom2 = new BoxObject(World, "bottomTexture1636", 0, .5f, 0,1,false); bottom2.Position = bottom2Position; // AddObject(bottom2); //omgar its a ceiling!! top = new BoxObject(World, "Barrier1", 0, .5f, 0,1,false); top.Position = topPosition; AddObject(top); /* top = new BoxObject(World, bottomTexture, 0, .5f, 0,1,false); top.Position = topPosition + new Vector2(20.3f, 0f); AddObject(top); top = new BoxObject(World, bottomTexture, 0, .5f, 0,1,false); top.Position = topPosition + new Vector2(40.6f, 0f); AddObject(top); top = new BoxObject(World, bottomTexture, 0, .5f, 0,1,false); top.Position = topPosition + new Vector2(60.9f, 0f); AddObject(top);*/ table = new CircleObject(World, "table", 1f, .5f, 0,.3f); table.Position = tablePosition; // AddObject(table); fan1 = new AnimationObject(World, "fan_strip", "fan", 200, 200, 20, 7); fan1.Position = fan1Position; // AddObject(fan1); //hole1 = new HoleObject(World, "big_hole_strip", "hole_tile_sealed"); hole1 = new HoleObject(World, "Art\\Objects\\HoleObjects\\hole_strip", "Art\\Objects\\HoleObjects\\hole"); hole1.Position = hole1Position; // AddObject(hole1); //movPlatform1 = new MovingObject(World, "moving platform", 0, .5f, 0,1,false); //movPlatform2 = new BoxObject(World, movingPlatformTexture, 0, .5f, 0); //movPlatform1.Position = movPlatform1Position; //AddObject(movPlatform1); //movPlatform1.Position = movPlatform1Position; //AddObject(movPlatform1); //DEBUG /* littleBox = new BoxObject(World, littleBoxTexture, 10f, .1f, 0, 1, false); littleBox.Position = new Vector2(16.7f, 1.46f);// dudePosition + new Vector2(0, -5f); AddObject(littleBox); PulleyJointDef jointDef2 = new PulleyJointDef(); Box2DX.Common.Vec2 anchora = movPlatform1.Body.GetWorldCenter(); Box2DX.Common.Vec2 anchorb = littleBox.Body.GetWorldCenter(); Box2DX.Common.Vec2 groundAnchora = movPlatform1.Body.GetWorldCenter() + Utils.Convert(new Vector2(0, -5f)); Box2DX.Common.Vec2 groundAnchorb = littleBox.Body.GetWorldCenter() + Utils.Convert(new Vector2(0, -5f)); jointDef2.Initialize(movPlatform1.Body, littleBox.Body, groundAnchorb, groundAnchorb, anchora, anchorb, 1f); jointDef2.Length1 = 4f; jointDef2.Length2 = 4f; //jointDef1.MaxLength1 = 2.65f; //jointDef2.MaxLength2 = 4f; World.CreateJoint(jointDef2); */ // END DEBUG //public AnimationObject( World world, Texture2D mytexture, Texture2D objectTexture, int sprWidth, int sprHeight, int animInt, int myNumFrames) /* Vector2 seesawposition = new Vector2(5f,8f); SeeSawObject seesaw = new SeeSawObject(World, "straight_pipe",.4f,seesawposition ); seesaw.Position = seesawposition; AddObject(seesaw); RevoluteJointDef jointDef2 = new RevoluteJointDef(); jointDef2.Initialize( World.GetGroundBody(),seesaw.Body, Common.Utils.Convert(seesaw.Position)); Console.WriteLine(Common.Utils.Convert(seesaw.Position)); //jointDef.EnableMotor = true; //jointDef.MotorSpeed = 1f; World.CreateJoint(jointDef2); */ brokenMovingPlatform1 = new SwitchObject(World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2); brokenMovingPlatform1.Position = brokenMovingPlatform1Position; // AddObject(brokenMovingPlatform1); movPlatform1 = new MovingObject(World, "Art\\Objects\\MovingPlatformObjects\\moving_platform", 1000f, .5f, 0, 1, false, brokenMovingPlatform1, new Vector2(0, -11500), 4.5f, 14.2f); movPlatform2 = new HorizontalMovingObject(World, "Art\\Objects\\HorizontalMovingPlatformObjects\\moving_platform", 0f, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 32f, 38f); //movPlatform2 = new BoxObject(World, movingPlatformTexture, 0, .5f, 0); //movPlatform1.Position = movPlatform1Position; //AddObject(movPlatform1); //movPlatform1.Body.SetBullet(true); movPlatform1.Position = movPlatform1Position; movPlatform2.Position = movPlatform2Position; // AddObject(movPlatform1); // AddObject(movPlatform2); lamp1 = new AnimationObject(World, "light_strip", "light", 312, 120, 20, 8); lamp1.Position = lamp1Position; // AddObject(lamp1); /* platform = new BoxObject(World, "platformTexture", 0, .1f, 0); platform.Position = platformPosition; AddObject(platform); bottom = new BoxObject(World, "bottomTexture", 0, .5f, 0); bottom.Position = bottomPosition; AddObject(bottom); */ // Create laser laser = new LaserObject(World, dude, "Art\\spray2_strip", 10); //creating insta steel already in the level //group1 float startx = .3f, endx = 1.5f, starty = 4f, spacing = .5f; List<Vector2> blobs = new List<Vector2>(); blobs.Add(new Vector2(startx, starty)); blobs.Add(new Vector2(endx,starty)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); //AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); blobs.Clear(); blobs.Add(new Vector2(startx, starty + .2f)); blobs.Add(new Vector2(endx, starty + .2f)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); //AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); blobs.Clear(); blobs.Add(new Vector2(startx, starty + .4f)); blobs.Add(new Vector2(endx, starty + .4f)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); //AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); blobs.Clear(); blobs.Add(new Vector2(startx, starty + .6f)); blobs.Add(new Vector2(endx, starty + .6f)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); //AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); blobs.Clear(); /* a TON of insta-steel blobs.Add(new Vector2(startx, starty + .6f)); blobs.Add(new Vector2(endx, starty + .6f)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); kaintedObject po = new PaintedObject(World, "paint", "paintedsegment", blobs); po.Length = 200000; // DEBUG AddObject(po); blobs.Clear(); */ /* float startx = .3f, endx = 1.5f, starty = 4f, spacing = .5f; List<Vector2> blobs = new List<Vector2>(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); blobs.Clear(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty+.2f)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); blobs.Clear(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty+.4f)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); blobs.Clear(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty+.6f)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); */ //group2 startx = 3.5f; endx = 5.2f; starty = 13f; blobs.Add(new Vector2(startx, starty)); blobs.Add(new Vector2(endx, starty)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); // AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); blobs.Clear(); blobs.Add(new Vector2(startx, starty + .2f)); blobs.Add(new Vector2(endx, starty + .2f)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); // AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); blobs.Clear(); blobs.Add(new Vector2(startx, starty + .4f)); blobs.Add(new Vector2(endx, starty + .4f)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); // AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); blobs.Clear(); blobs.Add(new Vector2(startx, starty + .6f)); blobs.Add(new Vector2(endx, starty + .6f)); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); // AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); /* startx = 3.5f; endx = 5.2f; starty = 13f; blobs.Clear(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); blobs.Clear(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty + .2f)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); blobs.Clear(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty + .4f)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); blobs.Clear(); for (float x = startx; x <= endx; x += spacing) { blobs.Add(new Vector2(x, starty + .6f)); } AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); */ /* // create a DEBUG painted object List<Vector2> blobs = new List<Vector2>(500); int i = 0; for (int y = 250; y >= 50; y-= 20) { for (int x = 3422; x <= 3522; x += 20)//(int x = 350; x <= 450; x+=20) { //Vector2 temp = new Vector2(); //temp.X = x; // temp.Y = y; //blobs[i] = temp; //blobs.Insert(i,new Vector2(x, y)); Vector2 addition = getGameCoords(new Vector2(x, y)); Console.WriteLine("{0}", addition); blobs.Add(addition); i++; } i++; } //Console.WriteLine("{0}", blobs.Count); //AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, blobs)); AddObject(new PaintedObject(World, "paint", "paintedsegment", blobs)); */ // Create rope bridge //AddObject(new RopeBridge(World, ropeBridgeTexture, 8.1f, 5.5f, 11.5f, 1, 0, 0)); // Create spinning platform /** BoxObject spinPlatform = new BoxObject(World, barrierTexture, 25,0,0); spinPlatform.Position = spinPlatformPos; AddObject(spinPlatform); // Create a joint to affix the platform to the world. //////////////////////////////////////////// RevoluteJointDef joint = new RevoluteJointDef(); joint.Initialize(spinPlatform.Body, World.GetGroundBody(), Common.Utils.Convert(spinPlatform.Position)); World.CreateJoint(joint); */ //////////////////////////////////////////// World.SetContactListener(new PlatformContactListener(this)); World.SetBoundaryListener(new PlatformBoundaryListener(this)); paintTexture = GameEngine.TextureList["paint"]; halfdotsize = new Vector2(paintTexture.Width / 2, paintTexture.Height / 2); //PLAYS THE SONG!!! (It resets at the beginning of the level) AudioManager audio = GameEngine.AudioManager; //audio.Play(AudioManager.MusicSelection.Destruction); }