Results 1 to 1 of 1
Thread: Tower Defense Rocket
- 04-12-2012, 03:16 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 4
- Rep Power
- 0
Tower Defense Rocket
Hey everyone, I've been using lwjgl in order to make a zombie tower defense game on here. The lwjgl is not the problem, but instead the mechanics of the towers shooting. I have the shooting with the function:
public void shoot(int damage, int time, float speed, int width, int height, Texture bullet, Zombies... zom)
The problem here are the moving numbers with the zombies. The zombies movie horizontally, with x++ right, and x-- for left, and then when the going around the corners, they go x+= .35 and x-=.35, and y++. The move numbers are two predict the zombies while moving to account for the fact its not shooting at an immobile target. These functions are:Java Code:{ int delta = getDelta(); Zombies t = choose(zom); waittime += delta / 16; for(int i = 0; i < zom.length; i++) { if(zom[i] == null) { continue; } if(zom[i].equals(t)) { if(zom[i].inRange(this)) { aim(zom[i]); } if(zom[i] != null && canShoot && Point2D.distance(t.x, t.y + t.randomy, bulletx, bullety) > 1) { float disty = t.y - finaly + t.randomy - 10 + t.movingNumY(speed); float distx = (float) (t.x - finalx - 10) + t.movingNumX(speed); System.out.println(t.x + " " + t.y); bulletx += distx/speed; bullety += disty/speed; drawBullet(width, height, bullet); } if(waittime % time == 0 && zom[i].inRange(this) && canShoot == false) { canShoot = true; } if((Point2D.distance(t.x, t.y + t.randomy, bulletx, bullety) <= 1) || (bulletx<0 || bullety<0 || bulletx > 800 || bullety > 600)) { bulletx = finalx + 10; bullety = finaly + 10; zom[i].health -= damage; canShoot = false; } System.out.println(Point2D.distance(t.x, t.y + t.randomy, bulletx, bullety)); if(zom[i].dead()) { SpawnManager.moneyamount += 20; chosezombie = false; zom[i]=null; } } } }
public float movingNumX(float speed)
and:Java Code:{ if(x > 624) { if((y <= 160 && y >= 106)) { numx = -0.7f; } else if(y < 106) { numx = 0.7f; } } else if(x < 144 && y >= 160) { if((y < 212 && y >= 160) || (y < 392 && y <= 338) || (y < 454 && y >= 392)) { numx = -0.35f; } else if((y < 278 && y >= 212) || (y < 338 && y <= 278) || (y < 516 && y >= 454)) { numx = 0.35f; } } else if(x <= 624 || (y > 106 && x > 144)) { if(y == 44 || y == 278 || y == 516) { numx = 1f; } else if(y == 160 || y == 392) { numx = -1f; } } System.out.println(numx); return (speed/2) * numx; }
For some reason it will miss them, usually by about 5 or 6 pixels, but sometimes even by 10 or 12. I don't need it to be exact, but I know there has to be a way to make it under 2. I understand if you can't help, it's very confusing, and I suck at explaining.Java Code:public float movingNumY(float speed) { if(x >= 624) { numy = 1f; } else if(x <= 144 && y > 106) { numy = 1f; } else { numy = 0; } System.out.println(numy); return (speed) * numy; }
Thanks though,
PFolder
Similar Threads
-
Recursive and Tower of Hanoi!
By xdrazkalnytex in forum New To JavaReplies: 4Last Post: 04-02-2012, 05:51 PM -
Java's Class Final Project - Tower Defense
By lastpirate89 in forum New To JavaReplies: 6Last Post: 05-11-2011, 03:04 PM -
Tower Defense problems
By emo bob in forum New To JavaReplies: 1Last Post: 04-29-2011, 03:13 PM -
In defense of the Garbage Collector
By Katanagas in forum Advanced JavaReplies: 2Last Post: 10-25-2010, 06:40 PM -
Amazing Rocket Launch Simulation
By adam1 in forum Forum LobbyReplies: 0Last Post: 10-01-2010, 03:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks