Skip to content

Commit

Permalink
Made reloading system
Browse files Browse the repository at this point in the history
Added reloading HUD
Made project HotSwap capable
Made coins drop more naturally
Removed shooting ability while reloading
  • Loading branch information
Matrx007 committed Dec 1, 2018
1 parent e96d753 commit a240b23
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/com/youngdev/shooter/Coin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public Coin(int x, int y, double angle) {
this.yD = y;
this.angle = angle;

this.speed = random.nextDouble()+3;
// this.speed = 0;
this.speed = random.nextDouble()*3+1d;
this.rotationSpeed = 8;
this.rotation = random.nextInt(359);

Expand Down
24 changes: 21 additions & 3 deletions src/com/youngdev/shooter/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.BinaryOperator;

import static com.youngdev.shooter.EnemyBolt.calcColorParameter;
import static java.awt.event.KeyEvent.*;

public class Main extends Game {
Expand Down Expand Up @@ -58,7 +59,7 @@ public Main() {

e.width = 320;
e.height = 240;
e.scale = 4f;
e.scale = 3f;

showDebugInfo = false;

Expand Down Expand Up @@ -617,9 +618,9 @@ public void render(Core core) {

r.absolute();

int xx = e.getInput().getMouseX();
int yy = e.getInput().getMouseY();
if(player.statsOverlayAlpha > 0) {
int xx = e.getInput().getMouseX();
int yy = e.getInput().getMouseY();
int radius = 40;
double angle = player.health/player.healthMax*359d;

Expand All @@ -640,6 +641,23 @@ public void render(Core core) {

((Graphics2D) r.getG()).setStroke(previous);
}

if(player.autoReloadTimer != 0) {
double w = player.autoReloadTimer/player.autoReloadTime*62d;
float alpha = (float)player.autoReloadBlinkingTimer/
(float)player.autoReloadBlinkingTime;
Color color = new Color(
calcColorParameter(128, 190, alpha),
calcColorParameter(128, 210, alpha),
calcColorParameter(128, 40, alpha)
);

r.fillRectangle(xx-32,yy+player.autoReloadY, 64, 8,
Color.gray);

r.fillRectangle(xx-32+1,yy+player.autoReloadY+1, (int)w, 6, color);
}

r.setFilter(0, backup);

if(showDebugInfo) {
Expand Down
68 changes: 58 additions & 10 deletions src/com/youngdev/shooter/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@ public class Player extends Healable {
private Random random;
private AABBCollisionManager cm;
boolean blinkingON;
private boolean found;
private boolean found, waitingForRelease;
public boolean buildingMode, inventoryOpen, leftHandShooting, rightHandShooting, clipOverlayOpen;
public int xx, yy, invSize = 24, midX, midY, selectedItem, time=60, timer, leftHandReload, rightHandReload,
reloadTime = 50, bulletTimingCap = 5, leftHandBulletTimingCapCounter, leftHandBulletAmountCounter,
rightHandBulletTimingCapCounter, rightHandBulletAmountCounter, bulletsPerShot = 5, ammo = 34, maxAmmo = 45, clip = 5, maxClip = 10, money;
public double lastCoinX, lastCoinY, coinOverlayAlpha, coinOverlayX, coinOverlayY, clipOverlayAlpha, clipOverlayRotation, clipOverlayRotationSpeed,
clipOverlayRotationTarget, health, healthMax, hunger, hungerMax, statsOverlayAlpha, statsOverlayRotation, statsOverlayRotationSpeed,
statsOverlayRotationTarget;
rightHandBulletTimingCapCounter, rightHandBulletAmountCounter, bulletsPerShot = 5, ammo = 34, maxAmmo = 45,
clip = 5, maxClip = 10, money;
public double lastCoinX, lastCoinY, coinOverlayAlpha, coinOverlayX, coinOverlayY, clipOverlayAlpha,
clipOverlayRotation, clipOverlayRotationSpeed, clipOverlayRotationTarget, health, healthMax,
hunger, hungerMax, statsOverlayAlpha, statsOverlayRotation, statsOverlayRotationSpeed,
statsOverlayRotationTarget, autoReloadBlinkingTime, autoReloadBlinkingTimer, autoReloadTime,
autoReloadTimer, autoReloadMaximumAmmo, autoReloadY, autoReloadTargetY;
private int blinkingTime = 30;
public int[] items;
private String[] itemNames;
private StructuralBlock[] itemSamples;
private static final Color baseColor = new Color(130, 32, 78); // 170, 32, 128
private static Color baseColor = new Color(130, 32, 78); // 170, 32, 128
private static int statsReloadTargetHeight = -56-12-16;
private static int reloadTargetHeight = -16;
private float speedX, targetSpeedX, speedY, targetSpeedY, maxSpeed, speedStep, blinkingTimer;


public Player(int x, int y) {
super(x, y, 4, 4, 200, 0, 9, false);
particles = new ArrayList<>();
Expand Down Expand Up @@ -104,6 +110,15 @@ public Player(int x, int y) {
this.statsOverlayRotation = 0;
this.statsOverlayRotationSpeed = 0;
this.statsOverlayRotationTarget = 0;
this.waitingForRelease = false;

autoReloadBlinkingTime = 15;
autoReloadBlinkingTimer = 0;
autoReloadTime = 120;
autoReloadTimer = 0;
autoReloadMaximumAmmo = 10;
autoReloadY = reloadTargetHeight;
autoReloadTargetY = reloadTargetHeight;

cm = new AABBCollisionManager(this, Main.collisionMap);
}
Expand Down Expand Up @@ -159,7 +174,7 @@ public void update(Input i) {
particles.forEach(UniParticle::update);
particles.removeIf(particle -> particle.dead);

if(i.isButtonDown(1) && ammo > 0) {
if(i.isButtonDown(1) && ammo > 0 && autoReloadTimer == 0) {
ammo--;
// System.out.println("Shot");
int addX = (int)(Math.cos(Math.toRadians(Fly.angle(x, y, i.getRelativeMouseX(), i.getRelativeMouseY())-180))*10d);
Expand Down Expand Up @@ -244,17 +259,50 @@ public void update(Input i) {
if(statsOverlayOpen) {
statsOverlayRotationTarget = 0;
statsOverlayAlpha += 24;
autoReloadTargetY = statsReloadTargetHeight;
} else {
autoReloadTargetY = reloadTargetHeight;
statsOverlayRotationTarget = -90;
statsOverlayAlpha -= 24;
}
statsOverlayRotation += (statsOverlayRotationTarget - statsOverlayRotation) * 0.1d;
statsOverlayAlpha = AdvancedMath.setRange(statsOverlayAlpha, 0, 160);

if(i.isKeyDown(KeyEvent.VK_R)) {
autoReloadY += (autoReloadTargetY - autoReloadY) * 0.1d;

boolean rPressed = i.isKey(KeyEvent.VK_R);

if(!rPressed) {
waitingForRelease = false;

if(statsOverlayOpen && ammo > autoReloadMaximumAmmo) {
autoReloadBlinkingTimer = 0;
autoReloadTimer = 0;
}
}

if((rPressed && !waitingForRelease) || statsOverlayOpen) {
// HERE: Reload
clip--;
ammo = maxAmmo;
autoReloadBlinkingTimer+=Main.toSlowMotion(1d);
if(autoReloadBlinkingTimer >= autoReloadBlinkingTime) {
autoReloadBlinkingTimer = 0;
}
if(rPressed || (ammo <= autoReloadMaximumAmmo)) {
autoReloadTimer+=Main.toSlowMotion(1d);

if(autoReloadTimer >= autoReloadTime) {
if(clip > 0) {
clip--;
ammo = maxAmmo;
autoReloadTimer = 0;
autoReloadBlinkingTimer = 0;
waitingForRelease = true;
}
}
}
} else {
autoReloadBlinkingTimer = 0;
autoReloadTimer = 0;
}

/*
Expand Down

0 comments on commit a240b23

Please sign in to comment.