From ac60cfcddcf13632217a442e9c6bba8e2882bca0 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Thu, 26 May 2016 22:12:44 -0400 Subject: [PATCH] main class fixes added image files fixed class constructors --- .gitignore | 3 +- src/tanks/Tanks.java | 95 +++++++++++++++++++++++++++++++++---------- src/tanks/bullet.png | Bin 0 -> 1433 bytes src/tanks/player.png | Bin 0 -> 3288 bytes 4 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 src/tanks/bullet.png create mode 100644 src/tanks/player.png diff --git a/.gitignore b/.gitignore index 14bc68c..46cba4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/nbproject/private/ \ No newline at end of file +/nbproject/private/ +/build/ \ No newline at end of file diff --git a/src/tanks/Tanks.java b/src/tanks/Tanks.java index 773e54f..c77fbe8 100644 --- a/src/tanks/Tanks.java +++ b/src/tanks/Tanks.java @@ -7,6 +7,7 @@ package tanks; +import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -36,11 +37,14 @@ public class Tanks //constructor public Tanks() { - + frame=new JFrame("Tanks project"); frame.setSize(500,500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + newGame(); + key=new KeyListener() { @Override @@ -65,7 +69,7 @@ public class Tanks protected void paintComponent(Graphics g) { //Paint Wave - //wave.draw(g); + wave.draw(g); for(Bullet b: bullets) { b.draw(g); @@ -89,14 +93,29 @@ public class Tanks public void actionPerformed(ActionEvent e) { p.move(); - for(Bullet b: bullets) + for(int i = 0; i < bullets.size(); i ++) { - b.move(); + try + { + bullets.get(i).move(); + } + catch(Exception ex) + { + + } + } - for(Enemy en: enemy) + for(int i = 0; i < enemy.size(); i++) { - en.move(); + try + { + enemy.get(i).move(); + } + catch(Exception ex) + { + + } } panel.repaint(); } @@ -106,6 +125,18 @@ public class Tanks move.start(); } + void newGame() + { + bullets = new ArrayList(); + enemy = new ArrayList(); + p = new Player(); + wave = new Wave(); + } + + public static void main(String[] arguments) + { + Tanks game = new Tanks(); + } /* @@ -121,8 +152,20 @@ public class Tanks */ private class Player extends Living { - Turret t; - boolean up,down,left,right; + private Turret t; + private boolean up,down,left,right; + + public Player() + { + speed = 5; + x = frame.getWidth()/2; + y = frame.getHeight()/2; + health = 100; + this.imageLocation = "player.png"; + super.loadImage(); + width = 50; + height = 50; + } void move() { @@ -130,17 +173,17 @@ public class Tanks { super.move(-1); } - else if(down==true) + if(down==true) { super.move(1); } - else if(left==true) + if(left==true) { - super.direction +=5; + super.direction -=5; } - else if(right==true) + if(right==true) { - super.direction-=5; + super.direction+=5; } } void updateDir(KeyEvent e, boolean pressed) @@ -149,22 +192,18 @@ public class Tanks if(id== KeyEvent.VK_UP) { up=pressed; - move(); } else if(id==KeyEvent.VK_DOWN) { down=pressed; - move(); } else if(id==KeyEvent.VK_LEFT) { left=pressed; - move(); } else if(id==KeyEvent.VK_RIGHT) { right=pressed; - move(); } else if(id==KeyEvent.VK_SPACE) { @@ -199,6 +238,9 @@ public class Tanks height = 30; health = 10; isAlive=true; + speed = 3; + imageLocation = "player.png"; + super.loadImage(); } //uses super to move player if collision then removes zombie and player //takes damage @@ -235,6 +277,8 @@ public class Tanks y = e.y; direction = e.direction; speed = 10; + imageLocation = "bullet.png"; + super.loadImage(); } //Moving the bullet @@ -243,11 +287,11 @@ public class Tanks super.move(-1); //Checks if the bullet goes off screen, if so... it get removed - if(x < 0 || x > frame.getHeight()) + if(x < 0 || x > frame.getWidth()) { bullets.remove(this); } - if (y < 0 || y > frame.getWidth()) + if (y < 0 || y > frame.getHeight()) { bullets.remove(this); } @@ -257,11 +301,15 @@ public class Tanks { if(enemyBullet == false) { - boolean collided = this.checkCollision(bullets.get(i)); + boolean collided = this.checkCollision(enemy.get(i)); if(collided) { enemy.get(i).takeDamage(); - bullets.remove(i); + bullets.remove(this); + if(!enemy.get(i).isAlive) + { + enemy.remove(enemy.get(i)); + } } } } @@ -333,6 +381,11 @@ public class Tanks spawn.start(); } + public void draw(Graphics g) + { + g.setColor(Color.yellow); + g.fillRect(0, 0, 500, 500); + } //spawn method checks if spawn timer ==0 and if so then spawns an diff --git a/src/tanks/bullet.png b/src/tanks/bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..6c5214dc8c63d6f350c2736e6d2a5f9814feb403 GIT binary patch literal 1433 zcmV;K1!nq*P)P000>X1^@s6#OZ}&000GGNkla)ut@Qo|l#4QEIxb?HHpEA%nso zD;>*IQ?hko43>^SArH-4Sg7$s5;KxCdvKGOIAJz6QcQ&HNKT~4vUIPcvxnH)yrhFA z2mY7;|2f|||2h9TN8`z&E2Vz8ckkXe6N$u2u~^JiO5yuHo12@I%VjnuTX%+Agh z78VwUZQFi*e0=;Dnx;`Mm(g_{$8ngQoh@ij0DQl%ukUyL{rv-$WwE-t%H6wnxp(g# zrBaDXrGoGKbs)g__&B$2-9p!OEX$%&si0{Z4Gj$>lgW(wPwlSjemFWh`kQDpsxK@o zu(Y&9Hk&072+-c%PA->YZEX!r)9`(tTCGMn9Hv|@qiGtwy}d*t5vtWHnxU15larHmg#eaiVcRw>EiGg+8RGFc zt*xz8t5pCR8ylIQpMM02L?TCrhlk%urBd9!eVbS;MmC!zlgY5SxXASMH0gA@?y-oV zltR~a0)YU%y}e|!SyHJ~JyzRBJb3T`rR(}j0|NuUPN&n{ym^y+K2LXdHvk6?9AIi{ zs{Z!>Et;lLtyW1UldP<)aQX6OLZQ&Vvq#riU0sFl?(QoiBO}t;*(t$bPz=Km%d+I? z(W4?Fa^%Pn0UldQDRCS}T-TMZt}bz1_lfs_dkhQ=NFtGta5yYVDFI|?Xh^o@>eZ|N z6XH0|*D0?+`TU(=8EK;ddux*=5moBlqybOR+I}-4zM9<}N6pKZ|;V=NDQip=ks`;$C)!{wtp}a6B9U&Lo%7<*s){J457KXS#({O{{DWscI}#o zh~#oPIeq%Hw6?Z>?OXppF~M=1dcXnc?Cg~0mKFiz$FIIBZ;y<~o@a&Fwk^7@KX!Qb z?Ah(~k^;!Do(1wGz=7f6M}V0bk&izX0TGbzJ}tyB4AC@AG)=1?oI8JBWO-S{FzNsS z`Tf)W6VtN9FbqTlfVU4FV)*5kVPgZf3LOCNy+_C4!;dA7Qi^yyPBa=tDTQTOn5Kzo znpl>FVHhZ1b(i z8P?a=aU7>^uu_UtDup^;D*e_S9K0~`(MMnyV4C3jk6Fz6I@jjscWj9WhG7to$4RHt z^z`)XDD}2&bMfLuj4vR0{>v|$n$Df;j~WI{PeZBnNJ}IFpM3^zy+!%?=Q;er2i(tQ zfkzcqDTQGe04y&rvw#17+S}U+hr>i75u(v3$z-yq32-0GKfvcdfggR#alrGST!ugZ z3I#At{`~2u{PNv*>kUgOMMFaafk1$cjt(9^d`MqkAHiU--cL-^j3T9{F{rCCXg$w+2VuFogu?{f|gHR}hQi`6Q9`4+^gXejernw^~ znM@{Qe7FS(LiIav?jQO5Kfkc;MC6rMTJOL3B7Z%3l0Sa(3A$n6ghJT1jcwaFjzcsW z#kOts?b}B_pJ!!d1<&&+7K@b2WvbOGrBbO__k^va*5Yygv}aG~(A3mxot>R;e50$Y zf7h;EjoVX*@B37%RRVzkZEbB_zkaDGZES381OnM?cE$6&&qX9y nC=`a3QuUE&V`GC-sg(T}I8E5ZN09O_00000NkvXXu0mjfV_(4? literal 0 HcmV?d00001 diff --git a/src/tanks/player.png b/src/tanks/player.png new file mode 100644 index 0000000000000000000000000000000000000000..20f970252c056ecd1d7ceb7620731f10bb0f40f9 GIT binary patch literal 3288 zcmV;}3@7u6P)>?wRS? zof)nIC-Pe~!Re~5djERw{p-~$^_fqHh$M8a{2-xLphQhh&h2~R$=4s?msmD!?ALpC zZ{Mzz8Wa(%QlNk+N>G6i*aD=l^gFBSwM6RwCN9QSs}2#*ie7C|u~j76Xl>qEC9f?a z5LnaWBo2Z=TRU}i1I~H6SH#bcP0sc!rQ~vPc0=J)DO#&F58k|+m4zMz;kB_LUb=W3 z6cla1Z{NI|?x2VOFJC&rE2D!bpr=scf$blrXhRb3_`#VMxi~X{2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