Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  Print  
  Java tower defense game  (Read 3372 times)
0 Members and 2 Guests are viewing this topic.
Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #30 on: 2012-01-23 01:09:20 »

That doesn't help its something wrong with my calculations. Its not rotating toward the enemies its more just a random spinning and then the second tower placed down spins randomly around the first so on an so on. I can post the whole class if you want to take a look otherwise ill keep trying.
Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #31 on: 2012-01-23 01:28:57 »

Sure, but your problem sounds like you're still not resetting the transform Smiley

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #32 on: 2012-01-23 03:29:15 »

alright so here is the whole class let me know if you see anything, thanks for checking it out!

1  
hidden
Games published by our own members! Go get 'em!
Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #33 on: 2012-01-23 05:22:18 »

The only relevant code was paintComponent(Graphics g) Stare

You reset the transform before you draw the image when, as I pointed out before, you're supposed to reset after drawing each image:
1  
2  
3  
4  
5  
6  
7  
8  
9  
Graphics2D g2d = (Graphics2D) g;
for(int i = 0; i < tower.length; i++){
    double rot = Math.atan2(mobs[i].y - tower[i].y, mobs[i].x - tower[i].y);
    g2d.rotate(rot, tower[i].x + tower[i].width / 2, tower[i].y + tower[i].height / 2);
    if(towerID[i] != air) {
        g2d.drawImage(aa.f.bp.tower[towerID[i]], tower[i].x, tower[i].y, tower[i].width, tower[i].height, null);
        g2d.getTransform().setToIdentity();
    }
}


This is because the transform is applied to the AffineTransform. AffineTransform stores a 3x3 matrix that, through magic (and math), transforms drawing commands. The call to rotate(...) sets a rotation transform and so all future drawing commands are rotated accordingly. Resetting the AffineTransform to the identity matrix is like setting a multiplier to 1. All inputs will equal the output.

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #34 on: 2012-01-24 05:17:50 »

So I kinda gave up on the rotation for now, I'll come back to it, its not working no matter what I do. But i posted a new screen shot of stuff I did today. Check it out there will be a new video up later. Thanks!
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #35 on: 2012-01-24 07:22:22 »

that's not counted as logic part, angle calculation can be added later. Just do another stuff Smiley

Offline elamre

Jr. Member
**

Posts: 79
Medals: 14


hitar!


« Reply #36 on: 2012-02-05 17:49:37 »

You can better NOT follow tutorials in my opinion. You should try to make it from scratch. Much better that way. This way you will learn how you can start a project, what is needed, and how it should work (draw it out on paper, helps!). And just google as much as you can, this is the way im making my towerdefence. I've just started with java 1-2 weeks as well, but at least i know exactly what im doing, and thus can fine tune it much more, and make it much more to my liking.

Also dont just give up when people help you so much. These are the moments where you build personality. You find a problem, solve it. Dont dodge it!
how ive done it:
first i calculate the angle, using the coordinates where my arrow has to go to (This should be your enemy's coordinates) which i give in my constructor:
1  
       this.angle = Math.atan2(toY-Y_Position, toX-X_Position);  

Then in my draw function:
1  
2  
3  
4  
5  
6  
7  
   public void draw(Graphics g){
      Graphics2D g2d = (Graphics2D)g;
      g2d.rotate(angle-Math.toDegrees(90), getX_Position(), getY_Position());
      g2d.drawImage(image,getX_Position(),getY_Position(),null);
      g2d.rotate(-angle+Math.toDegrees(90), getX_Position(), getY_Position());
     
   }

i do the -90 because of the way my image is turned (its looking up) and then i invoke the function g2d.rotate one more time so everything else in my game draws using the right rotation.

My projects:
Tower Defence!]http://www.java-gaming.org/topics/iconified/25690/view.html]Tower Defence! [lll.......] 30%!
Lightsnakerider! [llllll....] 60%!
Pages: 1 [2]
  Print  
 
 
Jump to:  


Add your game by posting it in the showcase section.

The first screenshot will be displayed as a thumbnail.

obsidian_golem 2012-05-23 10:14:50

Danny02 2012-05-21 17:10:34

Danny02 2012-05-21 17:07:10

Danny02 2012-05-21 16:56:12

davedes 2012-05-21 13:59:23

obsidian_golem 2012-05-20 20:28:41

darkjava55 2012-05-12 16:14:40

Ultroman 2012-05-12 09:36:05

Ultroman 2012-05-11 22:49:53

Ultroman 2012-05-11 22:20:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.079 seconds with 20 queries.