Skip to content

Commit 419571b

Browse files
committed
Added projectile range
moved the projectile origin to the left arm of the the player
1 parent d6a48c1 commit 419571b

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/com/redomar/game/entities/Mob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public abstract class Mob extends Entity {
2929
* [0] Contains the <strong>xMin</strong><br>
3030
* [1] Contains the <strong>xMax</strong><br>
3131
* [2] Contains the <strong>yMin</strong><br>
32-
* [3] Contains the <strong>yMax
32+
* [3] Contains the <strong>yMax</strong>
3333
*/
3434
protected int[] collisionBoders = new int[4];
3535

src/com/redomar/game/entities/Player.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.redomar.game.Game;
44
import com.redomar.game.InputHandler;
55
import com.redomar.game.entities.efx.Swim;
6+
import com.redomar.game.entities.projectiles.Projectile;
67
import com.redomar.game.gfx.Colours;
78
import com.redomar.game.gfx.Screen;
89
import com.redomar.game.level.LevelHandler;
@@ -63,6 +64,14 @@ public void tick() {
6364
double dir = Math.atan2(dy, dx);
6465
shoot(x, y, dir);
6566
}
67+
68+
for (int i = 0; i < projectiles.size(); i++) {
69+
Projectile p = projectiles.get(i);
70+
if(p.isRemoved()){
71+
projectiles.remove(i);
72+
Game.getLevel().removeProjectileEntities(p);
73+
}
74+
}
6675

6776
if (xa != 0 || ya != 0) {
6877
move(xa, ya);

src/com/redomar/game/entities/projectiles/Projectile.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.redomar.game.entities.projectiles;
22

3+
import java.util.Random;
4+
35
import com.redomar.game.entities.Entity;
46
import com.redomar.game.level.LevelHandler;
57

@@ -8,7 +10,10 @@ public abstract class Projectile extends Entity{
810
protected final double xOrigin, yOrigin;
911
protected double angle;
1012
protected double nx, ny;
11-
protected double speed, rate, range, damage;
13+
protected double speed, rate, range, damage, distance;
14+
protected Random life = new Random();
15+
16+
private boolean removed = false;
1217

1318
public Projectile(LevelHandler level, int x, int y, double dir) {
1419
super(level);
@@ -21,4 +26,16 @@ public Projectile(LevelHandler level, int x, int y, double dir) {
2126

2227
protected abstract void move();
2328

29+
public void remove(){
30+
setRemoved(true);
31+
}
32+
33+
public boolean isRemoved() {
34+
return removed;
35+
}
36+
37+
public void setRemoved(boolean removed) {
38+
this.removed = removed;
39+
}
40+
2441
}

src/com/redomar/game/entities/projectiles/Small.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Small extends Projectile{
88

99
public Small(LevelHandler level, int x, int y, double dir) {
1010
super(level, x, y, dir);
11-
range = 200;
11+
range = life.nextInt(25) + 50;
1212
damage = 20;
1313
rate = 15;
1414
speed = 4;
@@ -24,10 +24,14 @@ public void tick() {
2424
protected void move(){
2525
x += nx;
2626
y += ny;
27+
28+
double distance = Math.sqrt(Math.abs((xOrigin - x)*(xOrigin - x)+(yOrigin - y)*(yOrigin - y)));
29+
this.distance = distance;
30+
if(this.distance > range) remove();
2731
}
2832

2933
public void render(Screen screen) {
30-
screen.render((int)x,(int)y, 8 * 32, Colours.get(-1, 222, 333, 555), 0x00, 1);
34+
screen.render((int)x + 6,(int)y, 8 * 32, Colours.get(-1, 222, 333, 555), 0x00, 1);
3135
}
3236

3337
}

0 commit comments

Comments
 (0)