public override void move() { previousHitBox = new Rectangle(x, y, width, height); KeyboardState newKeyBoardState = Keyboard.GetState(); //Variables to keep track of animation sprite. int oldDirection = direction; moving = true; if (newKeyBoardState.IsKeyDown(Keys.Up)) { direction = 1; y -= velocity; } else if (newKeyBoardState.IsKeyDown(Keys.Down)) { direction = 3; y += velocity; } else if (newKeyBoardState.IsKeyDown(Keys.Left)) { direction = 0; x -= velocity; } else if (newKeyBoardState.IsKeyDown(Keys.Right)) { direction = 2; x += velocity; } else { moving = false; } if ((newKeyBoardState.IsKeyDown(Keys.LeftShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.LeftShift)) || (newKeyBoardState.IsKeyDown(Keys.RightShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.RightShift))) { if (!stateLocked) { engine.switchStates(); } } oldKeyBoardState = newKeyBoardState; //Get next image for sprite imageBoundingRectangle = getNextImageRectangle(direction, oldDirection, moving); hitBox = new Rectangle(x, y, width, height); }
public override void move() { timeTick++; if (readingChalkboard && !hitBox.Intersects(collideChalkboard.getHitBox())) { readingChalkboard = false; Game1.updateMiscObjects.Remove(playerChalkboard); } if (accessingBox && !hitBox.Intersects(collideBoxtop.getHitBox())) { accessingBox = false; Game1.updateMiscObjects.Remove(playerBox); } previousHitBox = new Rectangle(x, y, width, height); KeyboardState newKeyBoardState = Keyboard.GetState(); //Variables to keep track of animation sprite. int oldDirection = direction; moving = true; if (onBoat) { myBoat.setX(myBoat.getX() + myBoat.getVelocity()); direction = myBoat.getDirection(); velocity = myBoat.getVelocity(); return; } if (currentlyMove == false) { distanceTraveled = 0; if (newKeyBoardState.IsKeyDown(Keys.Up)) { direction = 1; setAnimation("moveUp"); currentlyMove = true; } else if (newKeyBoardState.IsKeyDown(Keys.Down)) { direction = 3; setAnimation("moveDown"); currentlyMove = true; } else if (newKeyBoardState.IsKeyDown(Keys.Left)) { direction = 0; setAnimation("moveLeft"); currentlyMove = true; } else if (newKeyBoardState.IsKeyDown(Keys.Right)) { direction = 2; setAnimation("moveRight"); currentlyMove = true; } else { moving = false; } } if ((moving == false) && (currentlyMove == false)) { switch (direction) { default: break; case 0: setAnimation("idleLeft"); break; case 1: setAnimation("idleUp"); break; case 2: setAnimation("idleRight"); break; case 3: setAnimation("idleDown"); break; } } if (initialShiftCD > 0) { initialShiftCD--; } else if ((newKeyBoardState.IsKeyDown(Keys.LeftShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.LeftShift)) || (newKeyBoardState.IsKeyDown(Keys.RightShift) && oldKeyBoardState != null && !oldKeyBoardState.IsKeyDown(Keys.RightShift))) { if (!isDead()) { engine.jitterLock(); if (!stateLocked && engine.getShiftCD() == 0 && !standingOnStateTile()) { engine.setShiftCD(); engine.switchStates(); } } } oldKeyBoardState = newKeyBoardState; //Get next image for sprite //imageBoundingRectangle = getNextImageRectangle(direction, oldDirection, moving); animate(); hitBox = new Rectangle(x, y, width, height); //used for "health". Hourglass decrements faster if its more than half if (proportion > 0.5) { proportion -= 0.001; } proportion -= 0.0001; if (hitInvulnTime > 0) { hitInvulnTime--; //flash the player while in hit invuln if (hitInvulnTime % 6 >= 3) { imageBoundingRectangle = new Rectangle(0, 0, 0, 0); } } if (isDead()) { imageBoundingRectangle = new Rectangle(0, 0, 0, 0); velocity = 0; } else { velocity = 4; } }