public void Update(GameTime gametime, Grid grid) { KeyboardState kstate = Keyboard.GetState(); if (keydown == false) { if (kstate.IsKeyDown(Keys.Left)) { if (gridPosition.X > 1) { gridPosition.X -= 1; } keydown = true; } if (kstate.IsKeyDown(Keys.Right)) { if (gridPosition.X < grid.columns) { gridPosition.X += 1; } keydown = true; } if (kstate.IsKeyDown(Keys.Down)) { if (gridPosition.Y > 1) { gridPosition.Y -= 1; } keydown = true; } if (kstate.IsKeyDown(Keys.Up)) { if (gridPosition.Y < grid.rows) { gridPosition.Y += 1; } keydown = true; } } if (kstate.IsKeyUp(Keys.Up) && kstate.IsKeyUp(Keys.Down) && kstate.IsKeyUp(Keys.Left) && kstate.IsKeyUp(Keys.Right)) { keydown = false; } position = grid.CartesianCoords(gridPosition); }
public void Update(GameTime gametime, GraphicsDevice graphicsDevice, Grid grid, Cursor cursor, NumericalCounter research, NumericalCounter money, NumericalCounter madness, List<MiniProgressBar> proglist, Corpse corpse,NonInteractive door,NonInteractive digger, Resurrect resurrect, NonInteractive Switch, NumericalCounter humanity, NumericalCounter longevity,NumericalCounter lifeForce, Random random, ReachableArea reachable) { path.Update(reachable); if (outside == false) { position = grid.CartesianCoords(gridPosition); if (walking == true) { layer = 0.21f + (0.2f / (float)grid.rows) * walkingTarget.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(walkingTarget.X - (float)grid.columns / 2.0f); } else { layer = 0.21f + (0.2f / (float)grid.rows) * gridPosition.Y + (0.2f / ((float)grid.columns * (float)grid.rows + 1)) * Math.Abs(gridPosition.X - (float)grid.columns / 2.0f); } } offset = new Vector2((width * scale) / 2.0f, height * scale); // factor of 2 here and in the draw command are just for this test anim, so it's a decent size... // walking.... // to use a machine if (action != null && walking == false && doing == false) { // to corpse if (corpseWork == true) { if (gridPosition != tableLocation) { walking = true; drawPath = path.PathList(gridPosition, tableLocation, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } else { doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } } else if (gridPosition != floorObject.opPos) { walking = true; drawPath = path.PathList(gridPosition, floorObject.opPos, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } else { doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } } else if (gridPosition != defaultGridPosition && walking == false && doing == false) { walking = true; drawPath = path.PathList(gridPosition, defaultGridPosition, grid); pathStep = 1; walkingTarget = drawPath[pathStep]; } // if he's walking, make him walk! if (walking == true) { direction = (grid.CartesianCoords(walkingTarget) - grid.CartesianCoords(gridPosition)); targetDistance = direction.Length(); direction.Normalize(); walkingOffset += direction * gametime.ElapsedGameTime.Milliseconds * 0.2f; distanceGone = walkingOffset.Length(); if (distanceGone < targetDistance) { Vector2 move = walkingOffset; position += move; } else { pathStep += 1; if (pathStep < drawPath.Count) { gridPosition = drawPath[pathStep - 1]; walkingTarget = drawPath[pathStep]; position = grid.CartesianCoords(gridPosition); } else { walking = false; doing = true; currentFrame = 0; gridPosition = drawPath[pathStep - 1]; position = grid.CartesianCoords(gridPosition); } walkingOffset = Vector2.Zero; targetDistance = 0; distanceGone = 0; } } // update animation frame timer += gametime.ElapsedGameTime.Milliseconds; if (timer >= msecsTweenFrames) { timer = 0; if (walking == true) { if (Math.Abs(direction.X) >= Math.Abs(direction.Y)) { if (direction.X >= 0) { anim = 1; } else { anim = 0; } } if (Math.Abs(direction.Y) >= Math.Abs(direction.X)) { if (direction.Y >= 0) { anim = 2; } else { anim = 3; } } if (currentFrame++ == numberOfFrames - 1) { currentFrame = 0; } } // start up menu action if doing is done, animate doing if (doing == true) { // coming through door (either way) if (digging == true) { anim = 4; if (door.animNum == 0) { door.SetAnim(1); door.layer -= 0.3f; } if (currentFrame++ == 2) { digging = false; if (dug == true) { CarryCorpse(); doing = false; dug = false; outside = false; } else { outside = true; layer = 0.61f; position += new Vector2(0, -20); } currentFrame = 0; door.SetAnim(0); door.layer += 0.3f; } else if (dug == true) { layer = 0.595f; anim = 5; } } // animate digging outside else if (outside == true) { outTimer += gametime.ElapsedGameTime.Milliseconds; if (outTimer >= 150 && dug == false) { digger.anim = true; dug = true; outTimer = 0; } if (dug == true && digger.anim == false && outTimer >= 350) { digging = true; outTimer = 0; } } // animate putting corpse on table else if (corpseCarrying == true) { doing = false; corpseCarrying = false; corpse.flies.Restart(0); corpse.visible = true; } // animate animation! else if (animating == true) { anim = 4; if (currentFrame++ == numberOfFrames - 1) { doing = false; animating = false; Switch.SetAnim(1); resurrect.Alive(corpse, humanity, longevity,lifeForce, research,madness, random, this); } } // if not in the usual spot... else if (gridPosition != defaultGridPosition) { anim = 4; if (action != null) { // if not staying to run machine, run doing anim once, create mini progress bar if (action.remain == false) { if (currentFrame++ == numberOfFrames - 1) { doing = false; proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[proglist.Count - 1]; action = null; } } // if staying to run machine... else { // create a progess bar if starting if (animStart == true) { animStart = false; if (corpseWork == true) { proglist.Add(new MiniProgressBar(graphicsDevice, corpse.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[proglist.Count - 1]; corpseWork = false; } else { proglist.Add(new MiniProgressBar(graphicsDevice, floorObject.position + new Vector2(-5, -105), action, floorObject)); progBar = proglist[proglist.Count - 1]; } } // run animation until finished else { if (currentFrame++ == numberOfFrames - 1) { currentFrame = 0; if (action.done == true) { doing = false; action.done = false; action = null; animStart = true; } } } } } } // if not doing anything, stop... else { walking = false; doing = false; currentFrame = 0; } } // if not walking, do standing anim if (walking == false && doing == false) { anim = 2; currentFrame = 0; } // set frame and anim rect.X = currentFrame * width; rect.Y = height * anim; } }