Skip to content

Commit 7ed7b98

Browse files
committed
Improved cooldown timer for tornados
1 parent d42994a commit 7ed7b98

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

game/src/main/java/dev/game/spacechaos/game/entities/component/combat/WeaponInventoryComponent.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class WeaponInventoryComponent extends BaseComponent {
2121
private BaseWeapon leftWeapon;
2222
private ArrayList<BaseWeapon> rightWeapons;
2323
private int rightWeaponIndex = 0;
24+
private boolean canShotRightFirstSlot = false;
2425

2526
// The right weapon can later be replaced by a list, so you can switch your
2627
// equipped weapon (e.g. via scrolling)
@@ -65,19 +66,26 @@ public void addAmmoToRightWeapon(int add) {
6566
}
6667

6768
public boolean canShootNowWithLeftWeapon() {
68-
return leftWeapon.canShootNow();
69+
return leftWeapon.canShootLeftNow();
6970
}
7071

7172
public boolean canShootNowWithRightWeapon() {
72-
return rightWeapons.get(rightWeaponIndex).canShootNow();
73+
return rightWeapons.get(rightWeaponIndex).canShootRightNow();
7374
}
7475

7576
public void setLastShotWithLeftWeapon() {
7677
leftWeapon.setLastShot();
7778
}
7879

7980
public void setLastShotWithRightWeapon() {
80-
rightWeapons.get(rightWeaponIndex).setLastShot();
81+
82+
if (canShotRightFirstSlot) {
83+
rightWeapons.get(rightWeaponIndex).setLastShotRightFirstSlot();
84+
this.canShotRightFirstSlot = false;
85+
} else {
86+
rightWeapons.get(rightWeaponIndex).setLastShotRightSecondSlot();
87+
this.canShotRightFirstSlot = true;
88+
}
8189
}
8290

8391
}

game/src/main/java/dev/game/spacechaos/game/entities/factory/PlayerFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static Entity createPlayer(EntityManager ecs, float x, float y, Texture t
102102

103103
// add component for shooting
104104
BaseWeapon leftWeapon = new BaseWeapon(200, 1);
105-
BaseWeapon rightWeapon = new BaseWeapon(100, 10, 20);
105+
BaseWeapon rightWeapon = new BaseWeapon(500, 500, 10, 20);
106106
player.addComponent(new WeaponInventoryComponent(leftWeapon, rightWeapon));
107107

108108
// add component for shield

game/src/main/java/dev/game/spacechaos/game/weapons/BaseWeapon.java

+34-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@
1010
public class BaseWeapon {
1111

1212
private long lastShot = 0;
13+
private long lastShotRightFirstSlot = 0;
14+
private long lastShotRightSecondSlot = 0;
15+
1316
private int currentAmmo;
1417
private int maxAmmo;
15-
private int cooldown;
1618

17-
public BaseWeapon(int cooldown, int ammo, int maxAmmo) {
18-
this.cooldown = cooldown;
19+
//cooldown of right and left weapon
20+
private int cooldownLeft;
21+
private int cooldownRight;
22+
23+
public BaseWeapon(int cooldownLeft, int cooldownRight, int ammo, int maxAmmo) {
24+
this.cooldownLeft = cooldownLeft;
1925
this.currentAmmo = ammo;
2026
this.maxAmmo = maxAmmo;
27+
this.cooldownRight = cooldownRight;
28+
}
29+
30+
public BaseWeapon(int cooldown, int ammo, int maxAmmo) {
31+
this(cooldown, 0, ammo, maxAmmo);
2132
}
2233

2334
public BaseWeapon(int cooldown, int ammo) {
@@ -50,13 +61,31 @@ public void setLastShot() {
5061
lastShot = System.currentTimeMillis();
5162
}
5263

53-
public boolean canShootNow() {
54-
if (System.currentTimeMillis() - lastShot > cooldown && currentAmmo > 0) {
64+
public void setLastShotRightFirstSlot() {
65+
lastShotRightFirstSlot = System.currentTimeMillis();
66+
}
67+
68+
public void setLastShotRightSecondSlot() {
69+
lastShotRightSecondSlot = System.currentTimeMillis();
70+
}
71+
72+
public boolean canShootLeftNow() {
73+
74+
if (System.currentTimeMillis() - lastShot > cooldownLeft && currentAmmo > 0) {
5575
// lastShot = System.currentTimeMillis();
5676
return true;
5777
} else {
5878
return false;
5979
}
6080
}
6181

82+
public boolean canShootRightNow() {
83+
if (System.currentTimeMillis() - lastShotRightFirstSlot > cooldownRight && currentAmmo > 0) {
84+
return true;
85+
} else if (System.currentTimeMillis() - lastShotRightSecondSlot > cooldownRight && currentAmmo > 0) {
86+
return true;
87+
}
88+
return false;
89+
}
90+
6291
}

0 commit comments

Comments
 (0)