public void update() { if (Time.timeScale < 0.1f) { return; } if (gotHit) { updateHit(); } else if (!collectedItem && !headingHome && !inCar) { updateNormal(); } else if (!headingHome && !inCar) { velocity.Y += gravity * Time.deltaTime; velocity = Vector2.Clamp(velocity, -maxSpeedVec, maxSpeedVec); mover.move(velocity * Time.deltaTime, moveBox, collisionState); } else if (!inCar) { updateCalm(); } }
public void update() { if (gabbingLadder) { // deny any movement in the x axis velocity.X = 0.0f; } else { // apply gravity velocity.Y += ((grabbingWall && velocity.Y > 0) ? wallGravity : gravity) * Time.deltaTime; } // apply movement _mover.move(velocity * Time.deltaTime, _boxCollider, collisionState); // handle map bounds var map = Core.getGlobalManager <SystemManager>().TiledMap; var x = MathHelper.Clamp(_mover.transform.position.X, 0, map.widthInPixels); _mover.transform.position = new Vector2(x, _mover.transform.position.Y); // update velocity if (collisionState.right || collisionState.left) { velocity.X = 0; } if (collisionState.above || collisionState.below) { velocity.Y = 0; } }
void Walk_Tick() { if (CollisionState.right) { velocity.X = -130f; } else if (CollisionState.left) { velocity.X = 130f; } if (velocity.X > 0) { sprite.flipX = false; } else { sprite.flipX = true; } mover.move(velocity * Time.deltaTime, box, CollisionState); if (!sprite.isPlaying) { sprite.play(Animations.Boss.Walk); } if (entity.getComponent <BoxCollider>().overlaps(entity.scene.findEntity("player").getComponent <BoxCollider>())) { entity.scene.findEntity("player").getComponent <PlayerController>().kill(entity.scene.findEntity("player").getComponent <PlayerController>().irA); } if (Math.Abs(this.entity.transform.position.Y - entity.scene.findEntity("player").transform.position.Y) < 30) { if (Math.Abs(this.entity.transform.position.X - entity.scene.findEntity("player").transform.position.X) <= 100) { if (!hit) { if (Nez.Random.chance(0.6f)) { currentState = Animations.Boss.Attack2; } else { currentState = Animations.Boss.Attack1; } } hit = Nez.Random.chance(0.5f); } } }
/// <summary> /// /// </summary> public void update() { if (!enabled) { Debug.log("Enemy cont is Disabled!"); return; } #region _velocity.X Stuff //If the enemy's attack collider overlaps the players collider, then move towards player if (enemyAttCollider.overlaps(entity.scene.findEntity("Player").getCollider <BoxCollider>())) { if (this.transform.position.X < entity.scene.findEntity("Player").transform.position.X) { if (_velocity.X < 200) { _velocity.X += speed; } else if (_velocity.X >= 200) { _velocity.X = 200; } } else if (this.transform.position.X > entity.scene.findEntity("Player").transform.position.X) { if (_velocity.X > -200) { _velocity.X -= speed; } else if (_velocity.X < -200) { _velocity.X = -200; } } } else { _velocity.X = 0; } #endregion #region _velocity.Y Stuff _velocity.Y += gravity * Time.deltaTime; //Apply gravity if (_collisionState.below && !bouncing) { _velocity.Y = 0; } if (bouncing) { bouncing = false; //Have to set bouncing back to false so Y velocity does not build up when back on ground } #endregion //Finally, move the enemy enemyMover.move(_velocity * Time.deltaTime, enemyCollider, _collisionState); }
public void update() { MouseState mouse = Mouse.GetState(); _distance.X = mouse.X - entity.position.X - 16; _distance.Y = mouse.Y - entity.position.Y - 8; entity.transform.rotation = (float)Math.Atan2(_distance.Y, _distance.X - 480); // bind movement to keys if (Input.isKeyDown(Keys.Left)) { _velocity.X = -moveSpeed; } else if (Input.isKeyDown(Keys.Right)) { _velocity.X = moveSpeed; } else { _velocity.X = 0; } if (_collisionState.below && Input.isKeyPressed(Keys.Space)) { _velocity.Y = -Mathf.sqrt(2 * jumpHeight * gravity); } //if (Input.isKeyDown(Keys.Q)) // entity.rotation += 0.1f; //if (Input.isKeyDown(Keys.E)) // entity.rotation -= 0.1f; // apply gravity _velocity.Y += gravity * Time.deltaTime; // move _mover.move(_velocity * Time.deltaTime, _boxCollider, _collisionState); // update velocity if (_collisionState.right || _collisionState.left) { _velocity.X = 0; } if (_collisionState.above || _collisionState.below) { _velocity.Y = 0; } }
void IUpdatable.update() { var moveDir = new Vector2(0, 0); var animation = Animations.Idle; if (moveDir.X < 0) { if (collisionState.below) { animation = Animations.Run; } animations.flipX = true; } else if (moveDir.X > 0) { if (collisionState.below) { animation = Animations.Run; } animations.flipX = false; } else { if (collisionState.below) { velocity.X = 0; animation = Animations.Idle; } } if (!collisionState.below && velocity.Y > 0) { animation = Animations.Fall; } //apply gravity velocity.Y += gravity * Time.deltaTime; //move mover.move(velocity * Time.deltaTime, boxCollider, collisionState); if (collisionState.below) { velocity.Y = 0; } //"forcing" the animation to play if (!animations.isAnimationPlaying(animation)) { animations.play(animation); } }
public void update() { if (Input.isKeyDown(Keys.Left)) { _velocity.X = -moveSpeed; } else if (Input.isKeyDown(Keys.Right)) { _velocity.X = moveSpeed; } else { _velocity.X = 0; } if (_collisionState.below && Input.isKeyPressed(Keys.Space)) { _velocity.Y = -Mathf.sqrt(2 * jumpHeight * gravity); } //slopes //apply gravity _velocity.Y += gravity * Time.deltaTime; //move _mover.move(_velocity * Time.deltaTime, _boxCollider, _collisionState); //update velocity if (_collisionState.right || _collisionState.left) { _velocity.X = 0; } if (_collisionState.above || _collisionState.below) { _velocity.Y = 0; } }
public void move() { //groundInputBuffer if (collisionState.wasGroundedLastFrame && !collisionState.below) { offGroundInputBufferTimer = offGroundInputBufferFrames; } //handle left/right if (collisionState.below) { velocity.X = input.onlyXInput.X * moveSpeed; } else { velocity.X = input.onlyXInput.X * airMoveSpeed; } //drop through one way if (collisionState.isGroundedOnOneWayPlatform && input.onlyYInput.Y > 0 && input.Button2Input.isPressed) { entity.setPosition(new Vector2(entity.position.X, entity.position.Y + 1)); collisionState.clearLastGroundTile(); landingInputBufferTimer = 0; } //jump else if (input.Button2Input.isPressed) { if (canJumpThisFrame) { Jump(); } else { landingInputBufferTimer = landingInputBufferFrames; } } // jump if you recently hit jump before you landed else if (landingInputBufferTimer > 0) { landingInputBufferTimer--; if (collisionState.below) { Jump(); } } // handle variable jump height if (!collisionState.below && input.Button2Input.isReleased) { velocity.Y *= 0.5f; } //apply gravity velocity.Y += gravity * Time.deltaTime; velocity = Vector2.Clamp(velocity, -maxSpeedVec, maxSpeedVec); var oldPos = entity.position; mover.move(velocity * Time.deltaTime, collider, collisionState); var leftSide = entity.position.X - collider.width / 2; var rightSide = entity.position.X + collider.width / 2; // dont let gravity just build while you're grounded if (collisionState.above || collisionState.below) { velocity.Y = 0; } // tick jump input buffer timer if (offGroundInputBufferTimer > 0) { offGroundInputBufferTimer--; } if (justJumpedBufferTimer > 0) { justJumpedBufferTimer--; } }
public void update() { #region Control if (!onLadders) { if (velocity.X != 0) { height = 32 * 3.6f * (Mathf.sqrt(Math.Abs(velocity.X) + 1) - Mathf.sqrt(Math.Abs(gravity) - 800)); } else { height = 32 * 3.6f * Mathf.sqrt(Math.Abs(velocity.X) + 1) - Mathf.sqrt(Math.Abs(gravity) - 800); } onIce = false; foreach (RectangleF hie in boxCollider) { onIce |= hie.contains(this.entity.position + new Vector2(0f, 16f)); onIce |= hie.contains(this.entity.position - new Vector2(0f, 16f)); onIce |= hie.contains(this.entity.position + new Vector2(16f, 0)); onIce |= hie.contains(this.entity.position - new Vector2(16f, 0f)); onIce |= hie.contains(this.entity.position - new Vector2(16f, 16f)); onIce |= hie.contains(this.entity.position + new Vector2(16f, 16f)); onIce |= hie.contains(this.entity.position); } //if (!isGravityInverted) //{ // if (barr == null) // { // entity.addComponent(new TiledMapMover(til.getLayer<TiledTileLayer>("barreras"))); // } //} //else //{ // entity.removeComponent((new TiledMapMover(til.getLayer<TiledTileLayer>("barreras")))); //} if (Input.isKeyPressed(Keys.V)) { inverted = -inverted; velocity.Y -= 1f; isGravityInverted = !isGravityInverted; } else if (Input.isKeyPressed(Keys.E) && canEnterOnDoor) { this.entity.position = objectLayer.objectWithName(irA).position; canEnterOnDoor = false; } if (Input.isKeyPressed(Keys.J) && !isBottleSpawned && mana >= 7.5f) { isBottleSpawned = createBottle(sprite.flipX); mana -= 7.5f; if (mana < 0) { mana = 0; } } if (isGravityInverted) { if (sprite.transform.localRotationDegrees < 180) { sprite.transform.localRotationDegrees += 10; } } else { if (sprite.transform.localRotationDegrees != 0) { sprite.transform.localRotationDegrees -= 10; } } if (Input.isKeyDown(Keys.A)) { velocity.X = -movespeed; left = true; right = false; if (!sprite.flipX) { sprite.flipX = true; } if (sprite.flipX && isGravityInverted) { sprite.flipX = false; } if (!sprite.isPlaying) { sprite.play(Animations.Main.Walk); } } else if (Input.isKeyDown(Keys.D)) { velocity.X = movespeed; left = !true; right = !false; if (sprite.flipX) { sprite.flipX = false; } if (!sprite.flipX && isGravityInverted) { sprite.flipX = true; } if (!sprite.isPlaying) { sprite.play(Animations.Main.Walk); } } else if (left && onIce) { velocity.X += friccion; if (velocity.X >= 0) { velocity.X = 0; left = false; right = false; } } else if (right && onIce) { velocity.X -= friccion; if (velocity.X <= 0) { velocity.X = 0; left = false; right = false; } } else { velocity.X = 0; sprite.stop(); } if (CollisionState.below && Input.isKeyPressed(Keys.W)) { velocity.Y = -Mathf.sqrt(Math.Abs(2 * height * gravity)); Console.WriteLine("He sido presionado OwO " + velocity.Y); onAir = true; isGravityInverted = false; inverted = 1; if (!sprite.isPlaying) { sprite.play(Animations.Main.Jump); } } else if (!CollisionState.below && Input.isKeyPressed(Keys.W) && isGravityInverted && !onAir) { velocity.Y = Mathf.sqrt(Math.Abs(2 * height * gravity)); onAir = true; if (!sprite.isPlaying) { sprite.play(Animations.Main.Jump); } } velocity.Y += gravity * Time.deltaTime * inverted; mover.move(velocity * Time.deltaTime, box, CollisionState); if (CollisionState.right || CollisionState.left) { velocity.X = 0; } if (CollisionState.above || CollisionState.below) { velocity.Y = 0; onAir = false; } if (mana < 100) { mana += 5 * Time.deltaTime; } if (mana > 100) { mana = 100; } } else { } #endregion #region colisiones var spawn = objectLayer.objectWithName(irA); foreach (RectangleF rectangle in pinchos) { pos[0] = rectangle.contains(this.entity.position + new Vector2(0f, 16f)); pos[1] = rectangle.contains(this.entity.position - new Vector2(0f, 16f)); pos[2] = rectangle.contains(this.entity.position + new Vector2(16f, 0)); pos[3] = rectangle.contains(this.entity.position - new Vector2(16f, 0f)); pos[4] = rectangle.contains(this.entity.position - new Vector2(16f, 16f)); pos[5] = rectangle.contains(this.entity.position + new Vector2(16f, 16f)); bool pose = false; foreach (bool p in pos) { pose |= p; } if (pose) { kill(irA); break; } } foreach (RectangleF rectangleF in palancas) { canUseSwitch = rectangleF.contains(this.entity.position); } foreach (RectangleF rectangleP in puertas) { if (rectangleP.contains(new Vector2(this.entity.position.X, this.entity.position.Y))) { canEnterOnDoor = true; irA = ubicaciones[puertas.IndexOf(rectangleP)]; } } if (deadCounter == 10) { Core.scene = new GameOverScreen(); } #endregion }
/// <summary> /// /// </summary> public void update() { if (!enabled) { Debug.log("Player cont is Disabled!"); return; } if (Input.isKeyDown(Keys.D)) //Moving right { if (_velocity.X < 0) { _velocity.X += (moveSpeed + momentumLoss); //Combine momentum loss and movespeed if previously going left } else { _velocity.X += moveSpeed; //Just add movespeed if starting from standstill } if (_velocity.X > maxVelocity) { _velocity.X = maxVelocity; } if (!entity.getComponent <Sprite <Player.Animations> >().isAnimationPlaying(Player.Animations.WalkingRight)) { entity.getComponent <Sprite <Player.Animations> >().play(Player.Animations.WalkingRight); } } else if (Input.isKeyDown(Keys.A)) //Moving left { if (_velocity.X > 0) { _velocity.X -= (moveSpeed + momentumLoss); //Combine momentum loss and movespeed if previously going right } else { _velocity.X -= moveSpeed; //Just subtract movespeed if starting from standstill } if (_velocity.X < (-maxVelocity)) { _velocity.X = -maxVelocity; } if (entity.getComponent <Sprite <Player.Animations> >().isAnimationPlaying(Player.Animations.WalkingRight)) { entity.getComponent <Sprite <Player.Animations> >().stop(); } } else { //When the player is not moving left or right, go into standing position entity.getComponent <Sprite <Player.Animations> >().play(Player.Animations.standing); //Now account for the players momentum when they release the controls if (Input.isKeyUp(Keys.D)) { if (_velocity.X >= 0) { _velocity.X -= momentumLoss; if (_velocity.X < 0) { _velocity.X = 0; } } } if (Input.isKeyUp(Keys.A)) { if (_velocity.X <= 0) { _velocity.X += momentumLoss; if (_velocity.X > 0) { _velocity.X = 0; } } } } //When D key is released and A was up, stop the WalkingRight animation and disable it, then enable the static standing sprite if (Input.isKeyReleased(Keys.D) && Input.isKeyUp(Keys.A)) { if (entity.getComponent <Sprite <Player.Animations> >().isAnimationPlaying(Player.Animations.WalkingRight)) { entity.getComponent <Sprite <Player.Animations> >().stop(); } } //Check for jumping if (_collisionState.below && Input.isKeyPressed(Keys.Space)) { _velocity.Y = (float)(-Math.Sqrt(2 * jumpHeight * gravity)); } //If the player is not on a ladder, apply gravity if (!entity.getComponent <ObjectInteractor>().onLadder) { _velocity.Y += gravity * Time.deltaTime; } else { _velocity.Y = 0; } //Finally, move the player _mover.move(_velocity * Time.deltaTime, _collider, _collisionState); //Do not allow player to build up velocity when colliding if (_collisionState.right || _collisionState.left) { _velocity.X = 0; } if (_collisionState.above || _collisionState.below) { _velocity.Y = 0; } if (p.weapon != null) { p.weapon.transform.position = new Vector2(p.transform.position.X + p.weapon.getXOffset(), p.transform.position.Y + p.weapon.getYOffset()); if (Input.leftMouseButtonPressed) { Sword sw = p.weapon as Sword; sw.attack(); } } }
void IUpdatable.update() { var moveDir = new Vector2(xAxisInput.value, 0); var animation = Animations.Idle; if (moveDir.X < 0) { if (collisionState.below) { animation = Animations.Run; } animations.flipX = true; if (sprintInput.isPressed) { velocity.X = -(moveSpeed + sprint); } else { velocity.X = -moveSpeed; } } else if (moveDir.X > 0) { if (collisionState.below) { animation = Animations.Run; } animations.flipX = false; if (sprintInput.isPressed) { velocity.X = moveSpeed + sprint; } else { velocity.X = moveSpeed; } } else { velocity.X = 0; if (collisionState.below) { animation = Animations.Idle; } } //if colliding with our head fall imidiatly if (collisionState.above) { velocity.Y = 0; } if (collisionState.below && jumpInput.isPressed) { animation = Animations.Jump; velocity.Y = -Mathf.sqrt(3f * jumpHeight * gravity); } if (!collisionState.below && velocity.Y > 0) { animation = Animations.Fall; } //apply gravity velocity.Y += gravity * Time.deltaTime; if (shootInput.isPressed) { //Check direction we are facing var dir = Vector2.Zero; if (animations.flipX) { dir.X = -1; } else { dir.X = 1; } var gameScene = entity.scene as GameScene; gameScene.createProjectiles(entity.position, projectileVelocity * dir); } //move mover.move(velocity * Time.deltaTime, boxCollider, collisionState); if (collisionState.below) { velocity.Y = 0; } if (!animations.isAnimationPlaying(animation)) { animations.play(animation); } }