From d31f49bf116b836bac6b9d1a2db83f72c216e31a Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sat, 29 Oct 2022 09:59:15 +0800 Subject: [PATCH] Small Update --- core/src/com/isharryh/arkpets/ArkPets.java | 31 +++++++++++++++++-- .../src/com/isharryh/arkpets/utils/Plane.java | 20 +++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/core/src/com/isharryh/arkpets/ArkPets.java b/core/src/com/isharryh/arkpets/ArkPets.java index 5e8fc89a..0cbfe275 100644 --- a/core/src/com/isharryh/arkpets/ArkPets.java +++ b/core/src/com/isharryh/arkpets/ArkPets.java @@ -72,8 +72,9 @@ public void create() { // Plane setup plane = new Plane(SCR_W, config.display_margin_bottom-SCR_H, SCR_H * 0.75f); plane.setFrict(SCR_W * 0.05f, SCR_W * 0.25f); + plane.setBounce(0); plane.setObjSize(WD_W, -WD_H); - plane.setSpeedLimit(SCR_W * 0.25f, SCR_H * 0.75f); + plane.setSpeedLimit(SCR_W * 0.5f, SCR_H * 1f); plane.changePosition(0, WD_postar.x, -WD_postar.y); Gdx.graphics.setForegroundFPS(APP_FPS); Gdx.input.setInputProcessor(this); @@ -242,16 +243,40 @@ private boolean setWindowPos(int x, int y, boolean override) { private HWND refreshWindowIdx() { ArrayList windowList = HWndCtrl.getWindowList(true); HWND minWindow = null; + HWndCtrl[] line = new HWndCtrl[SCR_H]; + int myPos = (int)(WD_poscur.x + WD_W / 2); int minNum = 2048; int myNum = getArkPetsWindowNum(APP_TITLE); for (HWndCtrl hWndCtrl : windowList) { + // Find windows as ground + if ((getArkPetsWindowNum(hWndCtrl.windowText) == -1) && hWndCtrl.posLeft <= myPos && myPos <= hWndCtrl.posRight) { + // This window IS in the vertical line that the app lies. + if (hWndCtrl.posBottom > 0 && hWndCtrl.posTop < SCR_H) { + for (int h = hWndCtrl.posTop<0?0:hWndCtrl.posTop; h < (hWndCtrl.posBottom>SCR_H?SCR_H:hWndCtrl.posBottom); h++) { + if (line[h] == null) + line[h] = (h == hWndCtrl.posTop) ? hWndCtrl : new HWndCtrl(); + } + } + } + // Find the last peer window. if (getArkPetsWindowNum(hWndCtrl.windowText) > myNum && getArkPetsWindowNum(hWndCtrl.windowText) < minNum) { minNum = getArkPetsWindowNum(hWndCtrl.windowText); minWindow = hWndCtrl.hWnd; } } - minWindow = (minWindow == null) ? new HWND(Pointer.createConstant(-1)) : minWindow; - return minWindow; + minWindow = (minWindow == null) ? new HWND(Pointer.createConstant(-1)) : minWindow; // Set as the top window if there is no peer. + if (plane != null) { + // Reset barriers + plane.barriers.clear(); + for (int h = 0; h < SCR_H; h++) { + HWndCtrl temp = line[h]; + if (temp != null && temp.hWnd != null) { + plane.setBarrier(-temp.posTop, 0, SCR_W, false); + //System.out.println("Barrier at "+(-temp.posTop)+" is "+temp.windowText+" pos "+temp.posLeft+","+temp.posRight); + } + } + } + return minWindow; // Return the last peer window. } private int getArkPetsWindowNum(String title) { diff --git a/core/src/com/isharryh/arkpets/utils/Plane.java b/core/src/com/isharryh/arkpets/utils/Plane.java index b7f8766b..6b6001de 100644 --- a/core/src/com/isharryh/arkpets/utils/Plane.java +++ b/core/src/com/isharryh/arkpets/utils/Plane.java @@ -7,7 +7,6 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; -import com.sun.jna.platform.win32.User32; public class Plane { @@ -17,6 +16,7 @@ public class Plane { public ArrayList barriers; private Vector2 world; private Vector2 obj; + private float bounce = 0; private float gravity = 0; private float airFrict = 0; private float staticFrict = 0; @@ -36,6 +36,7 @@ public Plane(int $worldWidth, int $worldHeight, float $gravity) { barriers = new ArrayList(); world = new Vector2($worldWidth, $worldHeight); obj = new Vector2(0, 0); + bounce = 0; gravity = $gravity; airFrict = 0; staticFrict = 0; @@ -51,6 +52,13 @@ public Plane(int $worldWidth, int $worldHeight) { this($worldWidth, $worldHeight, 0); } + /** Set the bounce coefficient. + * @param $bounce The ratio of Ek to be reserved after the bounce. + */ + public void setBounce(float $bounce) { + bounce = $bounce > 1 ? 1 : ($bounce < 0 ? 0 : $bounce); + } + /** Set the frictions. * @param $airFrict The acceleration of air friction (px/s^2). * @param $staticFrict The acceleration of static friction provided by the groud (px/s^2). @@ -104,6 +112,12 @@ public void updatePosition(float $deltaTime) { position.set(limitX(deltaX + position.x), limitY(deltaY + position.y)); } + /** Set a line barrier that can support the object. + * @param $posTop The y-position of the barrier. + * @param $posLeft The x-position of the barrier's left edge. + * @param $posRight The x-position of the barrier's right edge. + * @param $overCover Whether to set the highest priority to this barrier. + */ public void setBarrier(float $posTop, float $posLeft, float $width, boolean $overCover) { if ($overCover) barriers.add(0, new Vector3($posLeft, $posTop, $width)); @@ -169,6 +183,10 @@ else if (position.y == TOP && speed.y > 0) speed.x = Math.signum(speed.x) * speedLimit.x; if (speedLimit.y != 0 && Math.abs(speed.y) > speedLimit.y) speed.y = Math.signum(speed.y) * speedLimit.y; + // Bounce + if (bounce != 0 && (position.x == borderLeft() || position.x == borderRight())) { + speed.x = (float)(Math.sqrt(speed.x * speed.x * bounce) * Math.signum(-speed.x)); + } } /** Apply a friction to a velocity.