Skip to content

Commit 8d328eb

Browse files
committed
Concluding projectiles
2 parents e8030c9 + a97ff9d commit 8d328eb

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55
import java.util.Random;
66

7+
import com.redomar.game.entities.projectiles.Medium;
78
import com.redomar.game.entities.projectiles.Projectile;
89
import com.redomar.game.entities.projectiles.Small;
910
import com.redomar.game.level.LevelHandler;
@@ -233,13 +234,19 @@ protected void moveMob(double xa, double ya, Mob mob) {
233234
}
234235
}
235236

236-
protected void shoot(double x, double y, double dir){
237+
protected void shoot(double x, double y, double dir, double buttonId, boolean secondry){
237238
// dir = dir * (180 /Math.PI);
238239
// Printing print = new Printing();
239240
// print.print("Angle: "+ dir, PrintTypes.GAME);
240-
Projectile p = new Small(level, (int) x,(int) y, dir);
241-
projectiles.add(p);
242-
level.addProjectileEntities(p);
241+
if(buttonId == 1){
242+
Projectile p = new Small(level, (int) x,(int) y, dir);
243+
projectiles.add(p);
244+
level.addProjectileEntities(p);
245+
} else if(buttonId == 3 && secondry == true){
246+
Projectile p = new Medium(level, (int) x,(int) y, dir);
247+
projectiles.add(p);
248+
level.addProjectileEntities(p);
249+
}
243250
}
244251

245252
public String getName() {

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

Lines changed: 14 additions & 7 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.Medium;
67
import com.redomar.game.entities.projectiles.Projectile;
78
import com.redomar.game.entities.projectiles.Small;
89
import com.redomar.game.gfx.Colours;
@@ -63,13 +64,19 @@ public void tick() {
6364

6465
if(fireRate > 0) fireRate--;
6566

66-
if (Game.getMouse().getButton() == 1 && fireRate <= 0){
67-
if(!swim.isActive(swimType)){
68-
double dx = Game.getMouse().getX() - 480/2;
69-
double dy = Game.getMouse().getY() - 320/2;
70-
double dir = Math.atan2(dy, dx);
71-
shoot(x, y, dir);
72-
fireRate = Small.FIRE_RATE;
67+
if (Game.getMouse().getButton() == 1 || Game.getMouse().getButton() == 3){
68+
if(fireRate <= 0){
69+
if(Game.getMouse().getButton()== 1){
70+
fireRate = Small.FIRE_RATE;
71+
}else if(Game.getMouse().getButton() == 3){
72+
fireRate = Medium.FIRE_RATE;
73+
}
74+
if(!swim.isActive(swimType)){
75+
double dx = Game.getMouse().getX() - 480/2;
76+
double dy = Game.getMouse().getY() - 320/2;
77+
double dir = Math.atan2(dy, dx);
78+
shoot(x, y, dir, Game.getMouse().getButton(), false);
79+
}
7380
}
7481
}
7582

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.redomar.game.entities.projectiles;
2+
3+
import com.redomar.game.gfx.Colours;
4+
import com.redomar.game.gfx.Screen;
5+
import com.redomar.game.level.LevelHandler;
6+
7+
public class Medium extends Projectile{
8+
9+
public static final int FIRE_RATE = 20;
10+
11+
public Medium(LevelHandler level, int x, int y, double dir) {
12+
super(level, x, y, dir);
13+
range = 60 - life.nextInt(10);
14+
damage = 80;
15+
speed = 1;
16+
17+
nx = speed * Math.cos(angle);
18+
ny = speed * Math.sin(angle);
19+
}
20+
21+
public void tick() {
22+
if (tileCollision(x, y,(int) nx,(int) ny)) remove();
23+
move();
24+
}
25+
26+
protected void move() {
27+
x += nx;
28+
y += ny;
29+
30+
double distance = Math.sqrt(Math.abs((xOrigin - x)*(xOrigin - x)+(yOrigin - y)*(yOrigin - y)));
31+
this.distance = distance;
32+
if(this.distance > range) remove();
33+
}
34+
35+
public void render(Screen screen) {
36+
screen.render((int)x, (int)y, 7 * 32, Colours.get(-1, 311, 510, 544), 0x00, 1);
37+
}
38+
39+
}

src/com/redomar/game/script/Printing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void setMessage(String message) {
4040
}
4141

4242
private void readMessageType(PrintTypes type){
43-
if(type == PrintTypes.LEVEL){
43+
if(type == PrintTypes.ERROR){
4444
this.redMode = true;
4545
} else {
4646
this.redMode = false;

0 commit comments

Comments
 (0)