Heya guys!!!
Well, i have a little gameplay video to show, and hm, i was wondering, how can i make my archer and animals move properly in the slopes??
Heres the movement code i have, its from dermetfan but i changed so much due to my own needs hehe
So anyway, i need help, at least with theory so i can start drawning ideas and logics in my book
So heres the video :
And heres the movement code of the archer :
public void update(float delta) {
if (data.getCurrent_Health() <= 0) {
alive = false;
}
if (alive) {
// apply gravity
velocity.y -= gravity * delta;
// clamp velocity
if (velocity.y > speed) {
velocity.y = speed;
} else if (velocity.y < -speed) {
velocity.y = -speed;
}
// save old position
float oldX = getX(), oldY = getY(), tileWidth = collisionLayer.getTileWidth(), tileHeight = collisionLayer.getTileHeight();
boolean collisionX = false, collisionY = false;
// move on x
setX(getX() + velocity.x * delta);
if (velocity.x < 0) { // going left
// top left
TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (getX() / tileWidth), (int) ((getY() + getHeight()) / tileHeight));
if (cell != null) {
collisionX = cell.getTile().getProperties().containsKey("blocked");
}
// middle left
if (!collisionX) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) (getX() / tileWidth), (int) ((getY() + getHeight() / 2) / tileHeight));
if (cell1 != null) {
collisionX = cell1.getTile().getProperties().containsKey("blocked");
}
}
// bottom left
if (!collisionX) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) (getX() / tileWidth), (int) (getY() / tileHeight));
if (cell1 != null) {
collisionX = cell1.getTile().getProperties().containsKey("blocked");
}
}
} else if (velocity.x > 0) { // going right
// top right
TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) ((getY() + getHeight()) / tileHeight));
if (cell != null) {
collisionX = cell.getTile().getProperties().containsKey("blocked");
}
// middle right
if (!collisionX) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) ((getY() + getHeight() / 2) / tileHeight));
if (cell1 != null) {
collisionX = cell1.getTile().getProperties().containsKey("blocked");
}
}
// bottom right
if (!collisionX) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) (getY() / tileHeight));
if (cell1 != null) {
collisionX = cell1.getTile().getProperties().containsKey("blocked");
}
}
}
// react to x collision
if (collisionX) {
setX(oldX);
velocity.x = 0;
}
// move on y
setY(getY() + velocity.y * delta);
if (velocity.y < 0) { // going down
// bottom left
TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (getX() / tileWidth), (int) (getY() / tileHeight));
if (cell != null) {
collisionY = cell.getTile().getProperties().containsKey("blocked");
}
// bottom middle
if (!collisionY) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth() / 2) / tileWidth), (int) (getY() / tileHeight));
if (cell1 != null) {
collisionY = cell1.getTile().getProperties().containsKey("blocked");
}
}
// bottom right
if (!collisionY) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) (getY() / tileHeight));
if (cell1 != null) {
collisionY = cell1.getTile().getProperties().containsKey("blocked");
}
}
canJump = collisionY;
} else if (velocity.y > 0) { // going up
// top left
TiledMapTileLayer.Cell cell = collisionLayer.getCell((int) (getX() / tileWidth), (int) ((getY() + getHeight()) / tileHeight));
if (cell != null) {
collisionY = cell.getTile().getProperties().containsKey("blocked");
}
// top middle
if (!collisionY) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth() / 2) / tileWidth), (int) ((getY() + getHeight()) / tileHeight));
if (cell1 != null) {
collisionY = cell1.getTile().getProperties().containsKey("blocked");
}
}
// top right
if (!collisionY) {
TiledMapTileLayer.Cell cell1 = collisionLayer.getCell((int) ((getX() + getWidth()) / tileWidth), (int) ((getY() + getHeight()) / tileHeight));
if (cell1 != null) {
collisionY = cell1.getTile().getProperties().containsKey("blocked");
}
}
}
// react to y collision
if (collisionY) {
setY(oldY);
velocity.y = 0;
}
}
.....
}
}