GUYS IM NOT DEAD. My computer just crashed and I managed to install ubuntu on it to start programming again. I went 2 months without programming D:! Anyways, remember those old top down racing games where you just guided that car along the track and get as much “drift” as possible? How would I implement that in my libgdx game? Just in case you need it, here’s the spaceship class:
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;
}
}
Thanks
-cMp