From a4257a3abfbe23eb72113fdb418267d37f4d1cff Mon Sep 17 00:00:00 2001 From: Hgupta1912 Date: Wed, 15 Oct 2025 19:57:00 -0400 Subject: [PATCH] a lot --- SpaceEvaders/bin/game/Polygon.class | Bin 2680 -> 2894 bytes SpaceEvaders/bin/game/SpaceEvaders.class | Bin 1793 -> 3133 bytes SpaceEvaders/src/game/Asteroid.java | 19 ++++ .../src/game/BackgroundGenerator.java | 5 - SpaceEvaders/src/game/BlackHole.java | 50 +++++++++ SpaceEvaders/src/game/BorderGenerator.java | 5 + SpaceEvaders/src/game/Polygon.java | 9 ++ SpaceEvaders/src/game/Projectile.java | 3 +- SpaceEvaders/src/game/SpaceEvaders.java | 50 ++++++++- SpaceEvaders/src/game/Spaceship.java | 100 +++++++++++++----- 10 files changed, 201 insertions(+), 40 deletions(-) delete mode 100644 SpaceEvaders/src/game/BackgroundGenerator.java create mode 100644 SpaceEvaders/src/game/BorderGenerator.java diff --git a/SpaceEvaders/bin/game/Polygon.class b/SpaceEvaders/bin/game/Polygon.class index 99b12eb04be428d1a5206b49019bc9db893ae14b..de48a1bebab43baf8a00cf76d0d93be59b00655d 100644 GIT binary patch delta 752 zcmX|9OK%cU7(I8UFl3|#6eyWLIqPxhes(wApsw8r3;g~ zFeW<2Xk0aFT-F9sUkN|Jg$uX-1Al-q(NxbsOD4JV-E-!ibH4A+Z^t*6`gP}X3qSzH zEj1=hS?gJ?oS&kl|L|3DH02G-j6 z_kD{;WejsYfF7;^m=J`I@6(vXF(QKgp-67NPl4xC&TWT2YL70v6 zUH1kS^e4(e=hb%GDqbPP2qwC{KvMstc#otI?zodNF&tp?v0G>Vde(t!Pc4q&cw5=k z;kwE;EbjJYjCkCljl`=Tv9w8n&VXE$1D1F!P4i_AD9x}Ly=CchYDD-Ouo)wc%+|t; z^V9NUF%vPa!{5YV2Xda0A<4~Pcf$*L-?bRUKGp?_t-_8Xytu(>7Lh;+YbfIx-!I8+ yqJk!>`jFZ;p}|6HD_*y)CG5urlI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meVL#DvE?a(ZCcw6fk@lEV{L}-vvn&9(DcG21*#9-;>YV>{@t61%71UV_ao3%zFL4 zd{MRhKsss`7b7%tKPbsP=>(-7cRB27(6oGkp`P|ftT};X%VZA)MtjmMd1k9=)qF;0 za06uxGXxH6QYdq-?Ro}gag*UYwpn|oX8XFktm8KBYPdsXz49FAHE<7e96oyx<|4Nq z^w1PS3oIB|M2ax`Ry}B{K`k4oC`+m-twu9YF!v2q@dfiev26RHtg#xcP~oRb|4Rc8 zLaO^sE09VF4-I^VYZ}%#tN%~xUfZ&%{xm4Y)S9&`XYx8$v8iUeB`|WvY}Mo*<68~i z92Xl-zQT8H?R~f;$x(aW1Dpy^0x? zsi9z-0>gzfp>E@;foDprdfhYkkC`QRytdD%p_6GI&x}&h8){zB6~Nb(mq22d>QUl( ze2Nq&sC4VA#to=d+rXZZw&ux5a|zRHC}Exv%sNaWuDWfnCKoOBB4&Fpr)f1esn^$sk0 z65H&@3DFB|E=WzoI7v=$b%`XWvB^7Y8&^WYqg_%FVbX(*T~f}#fg4eu;8T4Pg!qNe z7*to)*nq3AI+{TX&!dP6&!}Sijv%%U;Z<2xa6+s { + int[] XCoords = {50, 750, 750, 50}; + int[] YCoords = {50, 50, 550, 550}; + + brush.setColor(Color.BLUE); + brush.drawPolygon(XCoords, YCoords, 4); + }; + Point[] shape = {new Point(50,50), new Point(750,50), new Point(750, 550), new Point(50,550)}; + borderHitbox = new Polygon(shape, new Point(400,300), 0); + + } + + public Polygon getBorderHitbox() { + return borderHitbox; } public void paint(Graphics brush) { @@ -31,19 +47,41 @@ public void paint(Graphics brush) { // sample code for printing message for debugging // counter is incremented and this message printed // each time the canvas is repainted - + borderGen.generateBorder(brush); brush.setColor(Color.white); - + test.paint(brush); + Asteroid ast = new Asteroid();//please turn this process into a method in polygon!!!!!! + int[] x = new int[ast.getPoints().length]; + int[] y = new int[ast.getPoints().length]; + for(int i = 0; i < x.length; i++) { + x[i] = (int) ast.getPoints()[i].x; + y[i] = (int) ast.getPoints()[i].y + counter; + } + + brush.drawPolygon(x, y, x.length); + + BlackHole bh = new BlackHole();//please turn this process into a method in polygon!!!!!! + bh.paint(brush); + + + //for(int i = 0; ) {} + //int[] yMissileCords = + //int[] xMissileCords = + //brush.setColor(Color.ORANGE); + //brush.fillPolygon(xMissileCords, yMissileCords, 8); + + /* * the comment below is just me messing with the code before we meet * officially on friday * feel free to delete it or something it doesn't do anything important */ - brush.drawString("Time: " + Integer.toString(counter / 60) + ":" + Integer.toString(counter % 60 * 5 / 3), 10, 10); + //brush.drawString("Time: " + Integer.toString(counter / 60) + ":" + Integer.toString(counter % 60 * 5 / 3), 10, 10); + counter++; } @@ -55,4 +93,6 @@ public static void main (String[] args) { SpaceEvaders a = new SpaceEvaders(); a.repaint(); } + + } \ No newline at end of file diff --git a/SpaceEvaders/src/game/Spaceship.java b/SpaceEvaders/src/game/Spaceship.java index 6af9fd6..21a29d2 100644 --- a/SpaceEvaders/src/game/Spaceship.java +++ b/SpaceEvaders/src/game/Spaceship.java @@ -3,13 +3,14 @@ import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.util.Iterator; -public class Spaceship extends Polygon implements KeyListener{ +public class Spaceship extends Polygon implements KeyListener, Iterable{ private static final int SIZE = 30; // Will be deprecated once Hans is done private static final double ACCELRATE = 0.1; private static final int ROTATERATE = 3; - private static final int MAXMISSILES = 400; + private static final int MAXPROJECTILES = 400; private double xVel; private double yVel; @@ -19,7 +20,7 @@ public class Spaceship extends Polygon implements KeyListener{ private boolean isTurningLeft; private boolean isTurningRight; private boolean missileFired; - private Missile[] missiles; + private Projectile[] firedProjectiles; public Spaceship(Point position, double rotation) { super(instantiateShape(), position, rotation); @@ -27,7 +28,7 @@ public Spaceship(Point position, double rotation) { yVel = 0.0; xAccel = 0.0; yAccel = 0.0; - missiles = new Missile[MAXMISSILES]; + firedProjectiles = new Projectile[MAXPROJECTILES]; } /* @@ -36,13 +37,8 @@ public Spaceship(Point position, double rotation) { * here. */ private static Point[] instantiateShape() { - Point[] square = new Point[4]; - square[0] = new Point(0, 0); - square[1] = new Point(SIZE, 0); - square[2] = new Point(SIZE, SIZE); - square[3] = new Point(0, SIZE); - - return square; + Point[] shape = {new Point(0,0), new Point(2,0), new Point(1,1), new Point(3,1), new Point(4,2), new Point(3,3), new Point(1,3), new Point(2,4), new Point(0,4), new Point(0,0)}; + return shape; } @@ -103,13 +99,13 @@ private void handleMovement() { private void fireMissile() { int openMissile = canFireMissile(); if (openMissile != -1) { - missiles[openMissile] = new Spaceship.Missile(this, this.rotation); + firedProjectiles[openMissile] = new Spaceship.Missile(this, this.rotation); } } private int canFireMissile() { - for (int i = 0; i < MAXMISSILES; i++) { - if (missiles[i] == null) { + for (int i = 0; i < MAXPROJECTILES; i++) { + if (firedProjectiles[i] == null) { return i; } } @@ -117,9 +113,9 @@ private int canFireMissile() { } private void drawMissiles(Graphics brush) { - for (int i = 0; i < MAXMISSILES; i++) { - if (missiles[i] != null) { - missiles[i].paint(brush); + for (int i = 0; i < MAXPROJECTILES; i++) { + if (firedProjectiles[i] != null) { + ((Missile)firedProjectiles[i]).paint(brush); } } } @@ -199,14 +195,8 @@ public Missile(Spaceship spaceship, double rotation) { * missile polygon construction code should go here. */ private static Point[] instantiateShape() { - Point[] square = new Point[4]; - - square[0] = new Point(0, 0); - square[1] = new Point(0, WIDTH); - square[2] = new Point(LENGTH, WIDTH); - square[3] = new Point(LENGTH, 0); - - return square; + Point[] shape = {new Point(0,0), new Point(4,0), new Point(3,1), new Point(3,4), new Point(2,5), new Point(1,4), new Point(1,1), new Point(0,0)}; + return shape; } @@ -268,7 +258,61 @@ private void handleMovement() { } -// private class Mine extends Polygon implements Projectile { -// -// } + //comments for this iterator must explicitly state that it mutates as it traverses... + @Override + public Iterator iterator() { + Iterator it = new Iterator() { + int pos = 0; //so basically u call the next method manually and never use a for in enhaced for loop and it iterates to the next null after rmemoving any out of bounds missiles and then u just use the pos instance var to set that null value to a new missile; essentially the next method only serves to iterate the pos instance to the next null elemnt rather than returning the next null elemnt... + public boolean hasNext() { + eraseOutOfBoundsProjectiles(); + if(pos < MAXPROJECTILES && hasNullsAfter(pos)) { + return true; + } + return false; + } + public Projectile next() { + eraseOutOfBoundsProjectiles(); + pos++; + while(firedProjectiles[pos] != null) { + pos++; + } + return firedProjectiles[pos]; + } + + private boolean hasNullsAfter(int pos) { + for(int i = pos; i < firedProjectiles.length; i++) { + if(firedProjectiles[i] == null) { + return true; + } + } + return false; + } + + public void eraseOutOfBoundsProjectiles() { + for(int i = 0; i < firedProjectiles.length; i++) { + if(!firedProjectiles[i].checkCollision(getBorderHitbox())) { //how can I access this method from the space evaders class? + firedProjectiles[i] = null; + } + } + } + }; + return it; + } + + + private class Mine extends Polygon implements Projectile { + public Mine() { + super(instantiateShape(), Spaceship.position, Spaceship.roatation); + this.scalePolygon(7); + } + + private static Point[] instantiateShape() { + Point[] shape = {new Point(1,0), new Point(3,0), new Point(4,1), new Point(4,3), new Point(3,4), new Point(1,4), new Point(0,3), new Point(0,1), new Point(1,0)}; + return shape; + } + + + } + + }