1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| package com.slyth.spaceGame.Models;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2;
public class Ship extends MovableEntity {
public boolean left = false, right = false, up = false, down = false, isKeyDown = false; float rotateSpeed = 30, health = 100, SPEEDORIG; Rectangle pickupBounds; boolean isUpgradedSpeed = false; public int usT = 0, usP = 400;
public Ship(Vector2 position, float width, float height, float rotation, float SPEED) { super(SPEED, rotation, width, height, position); this.SPEEDORIG = SPEED; pickupBounds = new Rectangle(position.x - ((width * 3) / 2), position.y - ((height * 3) / 2), width * 3, height * 3); }
public void update() { if (isUpgradedSpeed) { if (usT >= usP) { isUpgradedSpeed = false; SPEED = SPEEDORIG; usP = 400; usT = 0; } else { SPEED = SPEEDORIG + 2; usT++; } } pickupBounds = new Rectangle(position.x - ((width * 10) / 2.5f), position.y - ((height * 10) / 2.5f), width * 10, height * 10); if (left) { if (rotation <= 360) { rotation += .1f * rotateSpeed - 0.03; } else { rotation = 0; rotation += .1f * rotateSpeed - 0.03; }
} else if (right) { if (rotation >= 0) { rotation += -.1f * rotateSpeed - 0.03; } else { rotation = 360; rotation += -.1f * rotateSpeed - 0.03; } } if (up) { float yP = MathUtils.sinDeg(rotation + 90) * SPEED; float xP = MathUtils.cosDeg(rotation + 90) * SPEED;
velocity.y = yP; velocity.x = xP; } else if (!up && !down) { velocity.x *= .95; velocity.y *= .95; } else if (down) { float yP = MathUtils.sinDeg(rotation + 90) * SPEED; float xP = MathUtils.cosDeg(rotation + 90) * SPEED;
velocity.y = -yP; velocity.x = -xP; } if(!isKeyDown){
} position.add(velocity.tmp().mul(Gdx.graphics.getDeltaTime() * SPEED));
bounds.x = position.x; bounds.y = position.y; }
public float getHealth() { return health; }
public Rectangle getPickupBounds() { return pickupBounds; }
public void setHealth(float am) { health = am; }
public void loseHealth(float am) { health -= am; }
public void heal(float am) { health += am; }
public void upgradeSpeed() { if (!isUpgradedSpeed) { isUpgradedSpeed = true; } else { usP += 400; } }
public boolean isSpeedUpgraded() { return isUpgradedSpeed; } } |