continuous shooting and bullet deletion template
This commit is contained in:
parent
45247c6674
commit
4c610c8ca7
28
.gitignore
vendored
28
.gitignore
vendored
|
@ -1,30 +1,2 @@
|
|||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
.idea/*
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -3,6 +3,8 @@ package Classes;
|
|||
import processing.core.PApplet;
|
||||
import processing.core.PVector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Bullet {
|
||||
private final PVector position, velocity, offset;
|
||||
private final float diameter, heading;
|
||||
|
@ -17,6 +19,10 @@ public class Bullet {
|
|||
heading = direction;
|
||||
}
|
||||
|
||||
public void delete(ArrayList<Bullet> others) {
|
||||
// If outside of screen, delete from given list
|
||||
}
|
||||
|
||||
public void update() {
|
||||
position.add(velocity);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,11 @@ public class Gun {
|
|||
public PVector position;
|
||||
public float rotation;
|
||||
|
||||
public Gun(PApplet sketch, String filePath, int gunWidth, int gunHeight, float gunX, float gunY, float laserOffset, float gunRotation, boolean mirrorGun, float bulletDiameter, float shootingSpeed) {
|
||||
// Gun constructor
|
||||
public Gun(PApplet sketch, String filePath,
|
||||
int gunWidth, int gunHeight, float gunX, float gunY,
|
||||
float laserOffset, float gunRotation, boolean mirrorGun,
|
||||
float bulletDiameter, float shootingSpeed) {
|
||||
processing = sketch;
|
||||
bullets = new ArrayList<>();
|
||||
diameter = bulletDiameter;
|
||||
|
@ -38,8 +42,10 @@ public class Gun {
|
|||
|
||||
// Update Gun and children
|
||||
public void update() {
|
||||
for (Bullet b : bullets)
|
||||
for (Bullet b : bullets) {
|
||||
b.update();
|
||||
b.delete(bullets);
|
||||
}
|
||||
}
|
||||
|
||||
public void show(float lineLength, int lineColor, int bulletColor) {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class Main extends PApplet {
|
|||
textSize(height/24f);
|
||||
|
||||
testTarget = new Target(this, width - 200, height/2f, 100, 100);
|
||||
testGun = new Rifle(this, 3, 150, height/2f);
|
||||
testGun = new Pistol(this, 1, 150, height/2f);
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,6 +51,9 @@ public class Main extends PApplet {
|
|||
stroke(0);
|
||||
testTarget.show();
|
||||
|
||||
if (mousePressed)
|
||||
testGun.shoot();
|
||||
|
||||
testGun.setHeading(new PVector(mouseX, mouseY));
|
||||
testGun.show(MAX_LINE_LENGTH, color(255, 0, 0), color(0));
|
||||
testGun.update();
|
||||
|
@ -58,9 +61,4 @@ public class Main extends PApplet {
|
|||
noStroke();
|
||||
text("FPS: %d".formatted(round(frameRate)), width, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed() {
|
||||
testGun.shoot();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user