List of usage examples for com.badlogic.gdx.math Vector2 rotate90
public Vector2 rotate90(int dir)
From source file:com.octa.topdown.entities.Player.java
License:Open Source License
@Override public boolean update(float dTime) { knock.x = 0;//from www. j av a 2s . c o m knock.y = 0; this.delta.x = 0; this.delta.y = 0; // Handle user input if (InputTracker.isPressed(InputTracker.DOWN)) { this.delta.y = -this.speed * dTime; } if (InputTracker.isPressed(InputTracker.UP)) { this.delta.y = this.speed * dTime; } if (InputTracker.isPressed(InputTracker.RIGHT)) { this.delta.x = this.speed * dTime; } if (InputTracker.isPressed(InputTracker.LEFT)) { this.delta.x = -this.speed * dTime; } if (InputTracker.isJustReleased(InputTracker.UP) || InputTracker.isJustReleased(InputTracker.DOWN)) { this.delta.y = 0; } if (InputTracker.isJustReleased(InputTracker.LEFT) || InputTracker.isJustReleased(InputTracker.RIGHT)) { this.delta.x = 0; } if (InputTracker.isJustReleased(InputTracker.SPACE)) { arm = arm == gun ? stick : gun; } // Animate sprite if moving if (this.delta.x != 0 || this.delta.y != 0) { updateAnim(); } // Cast a vector from the player's position in the screen(always the center) // to the mouse pointer. Then, get that vector's angle and set it to the sprite's // rotation, so the sprite "faces" the mouse. float midX = Gdx.graphics.getWidth() / 2; float midY = Gdx.graphics.getHeight() / 2; float mouseX = InputTracker.getMousePos().x; float mouseY = Gdx.graphics.getHeight() - InputTracker.getMousePos().y; Vector2 dir = new Vector2(mouseX - midX, mouseY - midY); dir.rotate90(-1); this.setRotation(dir.angle()); // Update player's position this.setX(this.getX() + this.delta.x); this.setY(this.getY() + this.delta.y); if (Gdx.input.isTouched()) { float px = this.getX() + (this.getWidth() / 2); float py = this.getY() + (this.getHeight() / 2); px -= SinCosTable.getSin((int) this.getRotation() + 20) * 23; py += SinCosTable.getCos((int) this.getRotation() + 20) * 23; if (!arm.isMeele()) { if (ammo > 0) { ammo--; arm.shoot(px, py, getRotation()); } } else { arm.shoot(px, py, getRotation()); } } updateAABB(); stick.setAABB(AABB); return true; }
From source file:com.octa.topdown.entities.Zombie.java
License:Open Source License
@Override public boolean update(float dTime) { this.delta.x = this.delta.y = 0; knock.x = 0;// w w w.j a v a 2 s .co m knock.y = 0; if (this.hp <= 0) return false; if (objective != null && chaseObj) { Vector2 dir = new Vector2(objective.x - this.getX(), objective.y - this.getY()); dir.rotate90(-1); this.setRotation(dir.angle()); sin = SinCosTable.getSin((int) this.getRotation()); cos = SinCosTable.getCos((int) this.getRotation()); delta.x = -sin * speed * dTime; delta.y = cos * speed * dTime; this.setX(this.getX() + this.delta.x); this.setY(this.getY() + this.delta.y); } if (this.delta.x != 0 || this.delta.y != 0) updateAnim(); updateAABB(); return true; }