Skip to content

Commit

Permalink
items now bounce out when spawned
Browse files Browse the repository at this point in the history
  • Loading branch information
RedactedProfile committed May 9, 2024
1 parent 0c890e0 commit ae0972f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
23 changes: 0 additions & 23 deletions core/src/com/ninjaghost/gamejam/ChronoFloraGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,8 @@ public void create () {

@Override
public void render () {

// this was used to test the FPS graph
// Random rnd = new Random();
// int rndMin = 1;
// int rndMax = 500;
// if(rnd.nextInt(rndMax) < 50) {
// try {
// Thread.sleep(rnd.nextInt(rndMax - rndMin) + rndMin);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
// }

// remove things out of circulation
cleanupThingsForDeletion();

rectanglesToRender.clear();

if(Gdx.input.isKeyJustPressed(Input.Keys.GRAVE)) {
Expand All @@ -272,8 +258,6 @@ public void render () {
ImGui.plotLines("Framerate", data, data.length, 0, "", 0, 60, 400, 100, 4);




// This chunk is all about setting a new target camera zoom based on player movement
float newTargetCameraZoom = getNewTargetCameraZoom();
cameraTargetZoomFactor[0] = newTargetCameraZoom;
Expand All @@ -284,11 +268,9 @@ public void render () {

// Control camera focus
camera.position.set(new Vector3(cameraFocus[0], cameraFocus[1], 0));

camera.update();



// Update non-player entities
for(Plant p : plants) {
p.update(Gdx.graphics.getDeltaTime());
Expand Down Expand Up @@ -394,9 +376,6 @@ public void render () {
// io.setKeyAlt(Gdx.input.isKeyPressed(Input.Keys.ALT_LEFT) || Gdx.input.isKeyPressed(Input.Keys.ALT_RIGHT));
// io.setKeySuper(Gdx.input.isKeyPressed(Input.Keys.SYM));




ImGui.text("Player");
ImGui.text("- Inventory");
for (PlantItem plant : playerInventory) {
Expand All @@ -413,8 +392,6 @@ public void render () {
ImGui.sliderFloat("gravity", GameSettingsState.itemGravityFactor, -100f, 100f);
ImGui.sliderFloat("jump", GameSettingsState.itemJumpFactor, -50f, 50f);
ImGui.sliderFloat("speed", GameSettingsState.itemSpeedFactor, 0.01f, 50f);
ImGui.checkbox("reverse gravity", GameSettingsState.reverseGravity);
ImGui.checkbox("reverse move input", GameSettingsState.reverseInput);

ImGui.end();

Expand Down
2 changes: 0 additions & 2 deletions core/src/com/ninjaghost/gamejam/GameSettingsState.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class GameSettingsState {
public static float[] itemGravityFactor = new float[] { -90f };
public static float[] itemJumpFactor = new float[] { -40f };
public static float[] itemSpeedFactor = new float[] { 0.5f };
public static boolean reverseGravity = true;
public static boolean reverseInput = false;

public static boolean showGameOver = false;

Expand Down
19 changes: 7 additions & 12 deletions core/src/com/ninjaghost/gamejam/entities/PlantItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.ninjaghost.gamejam.GameSettingsState;
import imgui.ImGui;

import java.util.concurrent.ThreadLocalRandom;

public class PlantItem {

Expand All @@ -28,15 +29,12 @@ public enum MODE { COLLECTABLE, INVENTORY }

// Collectable Item Mode Stuff
boolean isCollectable = false;
float gravityVelocityFactor = 980f;
float gravityVelocity = 0f;
float isCollectableTimer = 0f;
float animationTimer = 0f;
float getIsCollectableTimerMax = 0.8f;
float animationTimerMax = 0.8f;

float[] gui_gravityVelocityFactor = new float[]{ 980f };
float[] gui_gravityVelocity = new float[]{ 0f };
float popHorizontalDirection = 4f;

public PlantItem(int x, int y) {
m_sprite = new Sprite(new Texture("plants/001_item.png"));
Expand Down Expand Up @@ -86,29 +84,27 @@ public void update(float delta) {
if(!isCollectable && m_mode == MODE.COLLECTABLE && isCollectableTimer < getIsCollectableTimerMax) {
// item is a collectable item but we aren't quite collectable yet
isCollectableTimer += delta;
// animationTimer += delta;


}

if(!isCollectable && m_mode == MODE.COLLECTABLE && !isSpawnAnimationDone) {
boolean start = false;
if(animationTimer <= 0f) {
start = true;

// starting out we want a solid set for velocity
gravityVelocity = GameSettingsState.itemJumpFactor[0];
popHorizontalDirection = ThreadLocalRandom.current().nextFloat(-8f, 8f);
}

// do the next frame of the bounce animation here
animationTimer += delta;

// we're going to do a kind of bounce effect from the location registered
// but for now let's just put it in the "spot" it's going to wind up at

if(!start) {
gravityVelocity += -GameSettingsState.itemGravityFactor[0] * delta;
}
// m_position.x += 2f * delta;

m_position.x += popHorizontalDirection * delta;
m_position.y += gravityVelocity * delta;
m_sprite.setPosition(m_position.x, m_position.y);
}
Expand All @@ -119,7 +115,6 @@ public void update(float delta) {

if(!isCollectable && m_mode == MODE.COLLECTABLE && isCollectableTimer >= getIsCollectableTimerMax) {
isCollectable = true;

}


Expand Down

0 comments on commit ae0972f

Please sign in to comment.