summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3992892)
raw | patch | inline | side by side (parent: 3992892)
author | fredboy <fredboy@protonmail.com> | |
Sun, 14 Apr 2024 19:50:39 +0000 (02:50 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Sun, 14 Apr 2024 19:53:40 +0000 (02:53 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java
index 3f9b77322431e0275640edd3f12f6bf7d9b71626..09a7e7056383298ecddde2ccc2fdf890a9298dd1 100644 (file)
if (checkSwim()) {
mPlayer.swim = true;
} else if (mPlayer.canJump()) {
- mPlayer.getVelocity().add(0, -7);
+ mPlayer.getVelocity().add(0, -180);
} else if (!mPlayer.isFlyMode() && mPlayer.gameMode == 1) {
mPlayer.setFlyMode(true);
mPlayer.getVelocity().y = 0;
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java b/core/src/ru/deadsoftware/cavedroid/game/GamePhysics.java
index 6572cf558a9551692f67155b419f5e6d9cbaab51..cb5b64c844e1ca85886ea58c6269756d669f4f2c 100644 (file)
@GameScope
-class GamePhysics {
+public class GamePhysics {
- static final int PL_SPEED = 2;
+ public static final int PL_SPEED = 120;
- private final Vector2 gravity = new Vector2(0, .9f);
+ private final Vector2 gravity = new Vector2(0, .09f);
private final GameWorld mGameWorld;
private final MainConfig mMainConfig;
(int) (rect.y + rect.height / 8 * 7) / 16);
}
- private void dropPhy(Drop drop) {
+ private void dropPhy(Drop drop, float delta) {
int dropToPlayer = drop.closeToPlayer(mGameWorld, mMobsController.getPlayer());
if (dropToPlayer > 0) {
drop.moveToPlayer(mGameWorld, mMobsController.getPlayer(), dropToPlayer);
drop.getVelocity().y += gravity.y / 4;
}
}
- drop.move();
+ drop.move(delta);
if (checkColl(drop)) {
drop.getVelocity().set(0, -1);
do {
- drop.move();
+ drop.move(delta);
} while (checkColl(drop));
drop.getVelocity().setZero();
}
mob.getVelocity().y = 0;
} else {
- mob.setCanJump(false);
+ mob.y += 1;
+ mob.setCanJump(checkColl(mob));
+ mob.y -= 1;
}
if (mob.getY() > mGameWorld.getHeightPx()) {
}
}
- private void playerPhy(Player player) {
- player.y += player.getVelocity().y;
- mobYColl(player);
-
+ private void playerPhy(Player player, float delta) {
if (player.isDead()) {
return;
}
player.swim = true;
}
if (!player.swim) {
- if (!player.isFlyMode() && player.getVelocity().y < 4.5f) {
- player.getVelocity().add(gravity.x / 4, gravity.y / 4);
+ if (!player.isFlyMode() && player.getVelocity().y < 270f) {
+ player.getVelocity().x += gravity.y / 4;
}
- if (!player.isFlyMode() && player.getVelocity().y > 4.5f) {
- player.getVelocity().add(0, -1f);
+ if (!player.isFlyMode() && player.getVelocity().y > 270f) {
+ player.getVelocity().add(0, -60f);
}
} else {
- player.getVelocity().add(0, -.5f);
- if (player.getVelocity().y < -3) {
- player.getVelocity().y = -3;
+ player.getVelocity().add(0, -30f);
+ if (player.getVelocity().y < -180) {
+ player.getVelocity().y = -180;
}
}
} else {
- if (!player.isFlyMode() && player.getVelocity().y < 18) {
+ if (!player.isFlyMode() && player.getVelocity().y < 1080) {
player.getVelocity().add(gravity);
}
}
+ player.y += player.getVelocity().y * delta;
+ mobYColl(player);
+
player.x += player.getVelocity().x * (player.isFlyMode() ? 1.5f : 1) *
- (GameItems.isFluid(getBlock(player)) && !player.isFlyMode() ? .8f : 1);
+ (GameItems.isFluid(getBlock(player)) && !player.isFlyMode() ? .8f : 1) * delta;
mobXColl(player);
if (mMainConfig.isTouch() && !player.isFlyMode() && player.canJump() && player.getVelocity().x != 0 && checkJump(player)) {
- player.getVelocity().add(0, -8);
+ player.getVelocity().add(0, -480);
player.setCanJump(false);
}
}
- private void mobPhy(Mob mob) {
+ private void mobPhy(Mob mob, float delta) {
if (mob.getType() == Mob.Type.MOB && GameItems.isFluid(getBlock(mob))) {
- if (mob.getVelocity().y > 9) {
- mob.getVelocity().add(0, -.9f);
+ if (mob.getVelocity().y > 540) {
+ mob.getVelocity().add(0, -5.4f);
}
- mob.getVelocity().add(0, -.5f);
+ mob.getVelocity().add(0, -30f);
- if (mob.getVelocity().y < -3) {
- mob.getVelocity().y = -3;
+ if (mob.getVelocity().y < -180) {
+ mob.getVelocity().y = -180;
}
- } else if (!mob.isFlyMode() && mob.getVelocity().y < 18) {
+ } else if (!mob.isFlyMode() && mob.getVelocity().y < 1080) {
mob.getVelocity().add(gravity);
}
- mob.y += mob.getVelocity().y;
+ mob.y += mob.getVelocity().y * delta;
mobYColl(mob);
if (mob.isDead()) {
return;
}
- mob.x += mob.getVelocity().x;
+ mob.x += mob.getVelocity().x * delta;
mobXColl(mob);
if (mob.canJump() && mob.getVelocity().x != 0 && checkJump(mob)) {
- mob.getVelocity().add(0, -8);
+ mob.getVelocity().add(0, -480);
mob.setCanJump(false);
}
}
for (Iterator<Drop> it = mDropController.getIterator(); it.hasNext(); ) {
Drop drop = it.next();
- dropPhy(drop);
+ dropPhy(drop, delta);
if (Intersector.overlaps(drop, player)) {
drop.pickUpDrop(player);
}
for (Iterator<Mob> it = mMobsController.getIterator(); it.hasNext(); ) {
Mob mob = it.next();
- mob.ai(mGameWorld);
- mobPhy(mob);
+ mob.ai(mGameWorld, delta);
+ mobPhy(mob, delta);
if (mob.isDead()) {
it.remove();
}
}
- playerPhy(player);
+ playerPhy(player, delta);
if (player.isDead()) {
player.respawn(mGameWorld);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java b/core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
index 19f2681b0df65020285bcdb4572076bc089fb969..c35b3b4150e4f6ad7289a86f875622f9de269dce 100644 (file)
}
}
- private void drawMob(Mob mob) {
+ private void drawMob(Mob mob, float delta) {
float mobDrawX = mob.getX() - getCamX();
float mobDrawY = mob.getY() - getCamY();
return;
}
- mob.draw(spriter, mobDrawX, mobDrawY);
+ mob.draw(spriter, mobDrawX, mobDrawY, delta);
}
private void drawDrop(Drop drop) {
}
}
- private void drawGamePlay() {
+ private void drawGamePlay(float delta) {
Player player = mMobsController.getPlayer();
drawWorld(true);
- player.draw(spriter, player.getX() - getCamX() - player.getWidth() / 2, player.getY() - getCamY());
- mMobsController.forEach(this::drawMob);
+ player.draw(spriter, player.getX() - getCamX() - player.getWidth() / 2, player.getY() - getCamY(), delta);
+ mMobsController.forEach( (mob) -> { drawMob(mob, delta); });
mDropController.forEach(this::drawDrop);
drawWorld(false);
drawGUI();
spriter.begin();
- drawGamePlay();
+ drawGamePlay(delta);
switch (mMainConfig.getGameUiWindow()) {
case CREATIVE_INVENTORY:
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
index 359a74b59bd2e4beceeaa99d43ccede790574243..f4c62f95a0e97bb861f698f1e5a257e6f8320cbc 100644 (file)
}
@Override
- public void ai(GameWorld gameWorld) {
+ public void ai(GameWorld gameWorld, float delta) {
if (mVelocity.isZero()) {
gameWorld.setForeMap(getMapX(), getMiddleMapY(), 11);
kill();
}
@Override
- public void draw(SpriteBatch spriteBatch, float x, float y) {
+ public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
spriteBatch.draw(GameItems.getBlockTex(11), x, y);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
index a8d9ce27b0ccac5bdd6bf437582f5c1b5e6e29ca..d1242431f460c7f777462735e99d5558e8657605 100644 (file)
}
@Override
- public void ai(GameWorld gameWorld) {
+ public void ai(GameWorld gameWorld, float delta) {
if (mVelocity.isZero()) {
gameWorld.setForeMap(getMapX(), getMiddleMapY(), 10);
kill();
}
@Override
- public void draw(SpriteBatch spriteBatch, float x, float y) {
+ public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
spriteBatch.draw(GameItems.getBlockTex(10), x, y);
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index 3bc3b5b413dc620cb353ff7c351c7ea0a010d270..9f14a698cd526b6a5ce0e00d8fa7b91a20f54977 100644 (file)
*/
public abstract class Mob extends Rectangle implements Serializable {
+ protected static int ANIMATION_SPEED = 360;
+
public enum Type {
MOB,
SAND,
protected Vector2 mVelocity;
protected Type mType;
- protected int mAnimDelta = 6;
- protected int mAnim;
+ protected int mAnimDelta = ANIMATION_SPEED;
+ protected float mAnim;
private Direction mDirection;
private boolean mDead;
return mDead;
}
- public final int getAnim() {
+ public final float getAnim() {
return mAnim;
}
}
}
- public abstract void draw(SpriteBatch spriteBatch, float x, float y);
+ public abstract void draw(SpriteBatch spriteBatch, float x, float y, float delta);
- public abstract void ai(GameWorld gameWorld);
+ public abstract void ai(GameWorld gameWorld, float delta);
public abstract void changeDir();
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java
index b2760c24624a7d0c402f4727f6101fd4bf23f561..5742a7c2599c9bd0fe2377a34047d51689aad6a0 100644 (file)
}
@Override
- public void ai(GameWorld gameWorld) {
+ public void ai(GameWorld gameWorld, float delta) {
if (MathUtils.randomBoolean(.0025f)) {
if (mVelocity.x != 0f) {
mVelocity.x = 0;
}
if (mVelocity.x != 0f) {
- mAnim += mAnimDelta;
+ mAnim += mAnimDelta * delta;
} else {
mAnim = 0;
}
}
@Override
- public void draw(SpriteBatch spriteBatch, float x, float y) {
+ public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
pigSprite[0][1].setRotation(getAnim());
pigSprite[1][1].setRotation(-getAnim());
//back legs
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index f373dc3ad598785e1d8430229c10a87f3f2c24d9..5cdb5d85bb5baa6a28e01e14327675f2e1d59deb 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
+import ru.deadsoftware.cavedroid.game.GamePhysics;
import ru.deadsoftware.cavedroid.game.GameWorld;
import ru.deadsoftware.cavedroid.misc.Assets;
}
@Override
- public void ai(GameWorld gameWorld) {
+ public void ai(GameWorld gameWorld, float delta) {
}
@Override
}
@Override
- public void draw(SpriteBatch spriteBatch, float x, float y) {
- if (mVelocity.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) {
- Assets.playerSprite[0][2].rotate(mAnimDelta);
- Assets.playerSprite[1][2].rotate(-mAnimDelta);
- Assets.playerSprite[0][3].rotate(-mAnimDelta);
- Assets.playerSprite[1][3].rotate(mAnimDelta);
+ public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
+ final float correctedAnimationDelta = mAnimDelta * delta;
+
+ if (mVelocity.x != 0 || Math.abs(Assets.playerSprite[0][2].getRotation()) > Math.abs(correctedAnimationDelta)) {
+ Assets.playerSprite[0][2].rotate(correctedAnimationDelta);
+ Assets.playerSprite[1][2].rotate(-correctedAnimationDelta);
+ Assets.playerSprite[0][3].rotate(-correctedAnimationDelta);
+ Assets.playerSprite[1][3].rotate(correctedAnimationDelta);
} else {
Assets.playerSprite[0][2].setRotation(0);
Assets.playerSprite[1][2].setRotation(0);
diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Drop.java
index 07a2f6cf68b9ea8f6ecaeefbfbd0b604a4b48df3..e9f2e61f489ac4b3a276075c4ed1479f2483ce14 100644 (file)
// }
}
- public void move() {
- x += velocity.x;
- y += velocity.y;
+ public void move(float delta) {
+ x += velocity.x * delta;
+ y += velocity.y * delta;
checkWorldBounds();
y = MathUtils.round(y);
}
diff --git a/desktop/src/ru/deadsoftware/cavedroid/desktop/DesktopLauncher.java b/desktop/src/ru/deadsoftware/cavedroid/desktop/DesktopLauncher.java
index 62b554b3027671b4ba4aa46978a8d8ea15c4bf43..cc0bb932a0db15561b05e494c12f8ea1f8b6cd19 100644 (file)
public static void main (String[] arg) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setWindowIcon(Files.FileType.Internal, "icons/icon256.png", "icons/icon128.png");
- config.setForegroundFPS(144);
+// config.setForegroundFPS(144);
config.setTitle("CaveDroid");
config.setWindowedMode(960, 540);
+ config.useVsync(false);
boolean touch = false;
for (String anArg : arg) {