Skip to content

Commit 7689673

Browse files
committed
Added a second projectile
Added a medium projectile to shoot when you right click. Changed when messages print in red; Error.
1 parent 8323f7b commit 7689673

File tree

4 files changed

+75
-12
lines changed

4 files changed

+75
-12
lines changed

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

Lines changed: 15 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,23 @@ protected void moveMob(double xa, double ya, Mob mob) {
233234
}
234235
}
235236

236-
protected void shoot(double x, double y, double dir){
237+
protected double shoot(double x, double y, double dir, double buttonId){
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+
return 1;
246+
} else if(buttonId == 2){
247+
Projectile p = new Medium(level, (int) x,(int) y, dir);
248+
projectiles.add(p);
249+
level.addProjectileEntities(p);
250+
return 2;
251+
} else {
252+
return 0;
253+
}
243254
}
244255

245256
public String getName() {

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

Lines changed: 20 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,25 @@ 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+
int buttonId;
70+
if(Game.getMouse().getButton()== 1){
71+
buttonId = 1;
72+
}else {
73+
buttonId = 2;
74+
}
75+
if(!swim.isActive(swimType)){
76+
double dx = Game.getMouse().getX() - 480/2;
77+
double dy = Game.getMouse().getY() - 320/2;
78+
double dir = Math.atan2(dy, dx);
79+
double shootData = shoot(x, y, dir, buttonId);
80+
if(shootData == 1){
81+
fireRate = Small.FIRE_RATE;
82+
}else if(shootData == 2){
83+
fireRate = Medium.FIRE_RATE;
84+
}
85+
}
7386
}
7487
}
7588

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)