Skip to content

Commit

Permalink
Small Update
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Oct 29, 2022
1 parent f4232a6 commit d31f49b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
31 changes: 28 additions & 3 deletions core/src/com/isharryh/arkpets/ArkPets.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -242,16 +243,40 @@ private boolean setWindowPos(int x, int y, boolean override) {
private HWND refreshWindowIdx() {
ArrayList<HWndCtrl> 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) {
Expand Down
20 changes: 19 additions & 1 deletion core/src/com/isharryh/arkpets/utils/Plane.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,6 +16,7 @@ public class Plane {
public ArrayList<Vector3> barriers;
private Vector2 world;
private Vector2 obj;
private float bounce = 0;
private float gravity = 0;
private float airFrict = 0;
private float staticFrict = 0;
Expand All @@ -36,6 +36,7 @@ public Plane(int $worldWidth, int $worldHeight, float $gravity) {
barriers = new ArrayList<Vector3>();
world = new Vector2($worldWidth, $worldHeight);
obj = new Vector2(0, 0);
bounce = 0;
gravity = $gravity;
airFrict = 0;
staticFrict = 0;
Expand All @@ -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).
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d31f49b

Please sign in to comment.