public override void Simulate(float dt)
{
//pulleyPipe1.Position = new Vector2(16.8f,pulleyPipe1.Position.Y);
//pulleyPipe2.Position = new Vector2(18.2f, pulleyPipe2.Position.Y);
//Console.WriteLine("{0}", getGameCoords(new Vector2(Mouse.GetState().X, Mouse.GetState().Y)));
//ronnies 2 line attempt at fixing drawing
//float guyPos = -dude.Position.X * CASSWorld.SCALE + (GameEngine.GAME_WINDOW_WIDTH / 2);
// screenOffset = new Vector2(guyPos, 0);
//hackish code to make the platform move
/*
if (movPlat)
{
movPlatform1.Position = movPlatform1.Position + new Vector2(.05f, 0);
if (movPlatform1.Position.X > 20)
movPlat = false;
}
else
{
movPlatform1.Position = movPlatform1.Position - new Vector2(.05f, 0);
if (movPlatform1.Position.X <10 )
movPlat = true;
}
//if (mov==false)
//{ movPlat2 = true; }
*/
//Hackie Moving Platform Code
/*
if (movPlat1 == true)
{
movPlatform2.Position = movPlatform2.Position + new Vector2(.035f, 0);
// dude.Position = dude.Position + new Vector2(0.05f, 0);
if (movPlatform2.Position.X > 36){
movPlat1 = false;
}
}
else
{
movPlatform2.Position = movPlatform2.Position - new Vector2(.035f, 0);
// dude.Position = dude.Position - new Vector2(0.05f, 0);
if (movPlatform2.Position.X < 34f)
{
movPlat1 = true;
}
}
*/
//new Vector2(14.5f, 13.3f);
/*
if (pistonMove == true)
{
pistonHead.Position = pistonHead.Position - new Vector2(.01f, 0);
if (pistonHead.Position.X < 12f)
pistonMove = false;
}
else
{
pistonHead.Position = pistonHead.Position + new Vector2(.2f, 0);
if (pistonHead.Position.X > 13f)
pistonMove= true;
}
*/
dude.Grounded = false; // unrelated to the following
dude.OnSlope = false; // unrelated to the following
// code for erasing a painted object
MouseState mouse = Mouse.GetState();
bool mouseinbounds = mouse.X > 0 && mouse.X < GameEngine.SCREEN_WIDTH && mouse.Y < GameEngine.SCREEN_HEIGHT && mouse.Y > 0;
Vector2 scaledMousePosition = new Vector2(mouse.X / CASSWorld.SCALE, mouse.Y / CASSWorld.SCALE);
Vector2 mouseGamePosition = getScreenOrigin() + scaledMousePosition;
//Console.WriteLine("{0} {1} {2} {3}", dude.Position.X, dude.Position.Y, mouseGamePosition.X, mouseGamePosition.Y);
AudioManager audio = GameEngine.AudioManager;
//ERASING
if (mouse.RightButton == ButtonState.Pressed && laser.canErase())
{
//ronnie added for laser
laser.startErasing();
// if the right button is pressed, remove any painted objects under the cursor from the world
// Query a small box around the mouse
AABB aabb = new AABB();
aabb.LowerBound = Common.Utils.Convert(mouseGamePosition - new Vector2(0.1f));
aabb.UpperBound = Common.Utils.Convert(mouseGamePosition + new Vector2(0.1f));
Shape[] shapes = new Shape[1];
int nHit = World.Query(aabb, shapes, 1);
if (nHit > 0)
{
Body body = shapes[0].GetBody();
PhysicsObject po = (PhysicsObject)body.GetUserData();
if (po is PaintedObject)
{
this.RemoveObject(po);
//Implementing deconstruct sfx
audio.Play(CrisisAtSwissStation.AudioManager.SFXSelection.Deconstruct);
PaintedObject painto = (PaintedObject)po;
numDrawLeft += painto.getAmountOfInstasteel();
}
}
// laser.finishErasing();
}
else
{
laser.finishErasing();
}
if (mouse.LeftButton == ButtonState.Released && laser.canDraw())
drawingInterrupted = false;
if (mouse.LeftButton == ButtonState.Pressed && laser.canDraw() && !drawingInterrupted && mouseinbounds && numDrawLeft > PAINTING_GRANULARITY && lengthCurDrawing < drawLimit)
{
//random ronnie addition for laser
laser.startDrawing();
/* Still working on this nasty loop
audio.Play(AudioManager.SFXSelection.Charge); */
// if we're holding down the mouse button
//Vector2 mousepos = new Vector2(mouse.X, mouse.Y);
if (dotPositions.Count == 0 || ( getScreenCoords(mouseGamePosition) - getScreenCoords(dotPositions[dotPositions.Count - 1])).Length() > PAINTING_GRANULARITY)
{ // according to the granularity constraint for paintings,
float drawDist = 0;
Vector2 drawPos = mouseGamePosition;
// make sure there is enough insta-steel to make it to the next point. if not, adjust the point
if (dotPositions.Count > 0)
{
drawDist = Vector2.Distance(drawPos * CASSWorld.SCALE, prevMousePos);
if (drawDist > numDrawLeft)
{
Vector2 relativePos = prevMousePos - (drawPos * CASSWorld.SCALE);
relativePos = relativePos * (numDrawLeft / drawDist);
drawPos = (prevMousePos - relativePos) / CASSWorld.SCALE;
drawDist = numDrawLeft;
}
}
dotPositions.Add(drawPos);
if (dotPositions.Count == 1)
{
lengthCurDrawing = 0;
}
else
{
numDrawLeft -= drawDist;
lengthCurDrawing += drawDist;
}
prevMousePos = drawPos * CASSWorld.SCALE;
finishDraw = true;
}
//other random ronnie addition for laser
//laser.finishDrawing();
}
else if (((mouse.LeftButton == ButtonState.Released || !laser.canDraw() || (mouseWasInbounds && prevms.LeftButton == ButtonState.Pressed)) && (numDrawLeft > PAINTING_GRANULARITY || finishDraw)) && (prevms.LeftButton == ButtonState.Pressed || drawingInterrupted) && (mouseinbounds || mouseWasInbounds))
{
if (!laser.canDraw())
drawingInterrupted = true;
Box2DX.Dynamics.Body overlapped = null;
PhysicsObject po = null;
foreach (Vector2 pos in dotPositions)
{
// Query a small box around the mouse
AABB aabb = new AABB();
//Vector2 gamepos = new Vector2(pos.X / CASSWorld.SCALE, pos.Y / CASSWorld.SCALE) + screenOffset;
//Vector2 gamepos = new Vector2(pos.X, pos.Y);
aabb.LowerBound = Common.Utils.Convert(pos - new Vector2(0.1f));
aabb.UpperBound = Common.Utils.Convert(pos + new Vector2(0.1f));
Box2DX.Collision.Shape[] shapes = new Box2DX.Collision.Shape[1];
int nHit = World.Query(aabb, shapes, 1);
if (nHit > 0)
{
Body body = shapes[0].GetBody();
po = (PhysicsObject)body.GetUserData();
if (po is PaintedObject)
{
overlapped = body;
}
break;
}
}
if (dotPositions.Count > 1)
{
audio.Play(AudioManager.SFXSelection.Construct);
}
laser.finishDrawing();
List<Vector2> dp2 = new List<Vector2>();
// hack to make the drawing fit the offset
//foreach (Vector2 pos in dotPositions)
//{
// //Console.WriteLine(dude.Position.X * CASSWorld.SCALE);
// dp2.Add(pos + new Vector2(dude.Position.X * CASSWorld.SCALE, 0));
//}
// create the painting as an object in the world
if (dotPositions.Count > 1)
//this.AddObject(new PaintedObject(World, paintTexture, paintedSegmentTexture, dp2));
this.AddObject(new PaintedObject(World, "paint", "paintedsegment", dotPositions));
// clear the way for another painting
dotPositions = new List<Vector2>(); //
lengthCurDrawing = 0;
finishDraw = false;
}
// end painting code (except for prevms = ms below)
prevms = mouse;
mouseWasInbounds = mouseinbounds;
laser.Update(scaledMousePosition.X, scaledMousePosition.Y, getCameraCoords(), gameLevelWidth);
// update cursor insta-steel level
float fractionInstasteel = numDrawLeft / totalInstaSteelInWorld;
int cursorPic = (int)(fractionInstasteel * 8);
cursorSrcRect = new Rectangle(cursorPic * cursorWidth, 0, cursorWidth, cursorWidth);
base.Simulate(dt);
screenOffset = new Vector2(0, 0); // TODO Diana: Change this!
allHolesFilled = true;
foreach (HoleObject hole in holeList)
{
allHolesFilled = allHolesFilled && (hole.Filled >= HoleObject.MAX_FILL);
}
}