Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Java tower defense game  (Read 10223 times)
0 Members and 1 Guest are viewing this topic.
Offline thez3r0312

Senior Newbie


Projects: 1



« Reply #30 - Posted 2012-01-23 07: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.
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


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

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

Offline thez3r0312

Senior Newbie


Projects: 1



« Reply #32 - Posted 2012-01-23 09: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #33 - Posted 2012-01-23 11: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

Senior Newbie


Projects: 1



« Reply #34 - Posted 2012-01-24 11: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
« Reply #35 - Posted 2012-01-24 13:22:22 »

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

Offline elamre

JGO Coder


Medals: 17
Projects: 1


hitar!


« Reply #36 - Posted 2012-02-05 23: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!