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 3 Guests are viewing this topic.
Offline thez3r0312

JGO n00b
*

Posts: 18



« on: 2012-01-14 19:22:41 »

So I'm very new to java I've been programming for only about 2 weeks. The past couple days I have been working on this tower defense game. Its in its very early stages many things don't work in it however for two days of work I'm pretty happy! Let me know what you think all feed back is welcome! I'll continue to post as I change things!

<youtube> http://www.youtube.com/watch?v=l4XrAnWxev4 VIDEO 1
               http://www.youtube.com/watch?v=Ymww6vpgndA VIDEO 2 UPDATE

New screen shot


New game over screen I've been working on:


New first wave zombie sprite:


New tower:




Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #1 on: 2012-01-16 21:22:16 »

Any thoughts?
Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #2 on: 2012-01-16 22:54:27 »

You've only been programming in general....for 2 weeks... Shocked

It's looking good so far, keep up the good work Smiley

Games published by our own members! Go get 'em!
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #3 on: 2012-01-16 23:33:33 »

Can't watch youtube here hehehe Grin

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #4 on: 2012-01-16 23:54:40 »

You've only been programming in general....for 2 weeks... Shocked

It's looking good so far, keep up the good work Smiley

Thank you! I still have a lot to figure out though! Uploaded the new game over screen!
Offline asphaltgalaxy

JGO n00b
*

Posts: 29
Medals: 1



« Reply #5 on: 2012-01-18 12:47:08 »

Nice artwork as I can see. Waitin for any version to try it Smiley
Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #6 on: 2012-01-18 20:23:43 »

Nice artwork as I can see. Waitin for any version to try it Smiley

Thanks! its taken me forever to do all the art! Hopefully I can have a demo up soon!
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #7 on: 2012-01-18 23:08:38 »

Now you put the images. The tower is cool, looks like helmet Grin

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #8 on: 2012-01-19 16:52:15 »

Now you put the images. The tower is cool, looks like helmet Grin

I was going for a kind of an Iron man looking tower haha, ill post more tonight either pictures or videos.
Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #9 on: 2012-01-20 19:34:35 »

Does anyone know if i can use a 3d modeler with java? Like blender or something like that.
Games published by our own members! Go get 'em!
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #10 on: 2012-01-20 23:16:53 »

You can, with help of library such as LWJGL.

Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #11 on: 2012-01-21 00:49:03 »

LWJGL is a simple binding to OpenGL. OpenGL has no clue what a model is. All it knows how to do is render geometry and textures.

@thez3r0312
To load a model into OpenGL, you have to use a library that allows you to do that. I believe libGDX has classes that load OBJ and MD5 models.

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #12 on: 2012-01-21 19:58:50 »

So i want to make my towers and enemies like this:


Anyone have any ideas how i would make my characters/towers 3d like this and animated? Also anyone have an example code of a targeting system for the towers that makes towers pivot and follow the characters.
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #13 on: 2012-01-21 23:53:17 »

animation is simply change sprite in constant time. Target an enemy and calculate the rotation for tower so it looks like following, and shoot in desired rate.

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #14 on: 2012-01-22 00:25:06 »

animation is simply change sprite in constant time. Target an enemy and calculate the rotation for tower so it looks like following, and shoot in desired rate.

wont i need multiple images for that though? otherwise the whole tower image is going to shift instead of just the barrel of the tower.
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #15 on: 2012-01-22 00:29:18 »

For creating smooth animation, it's pretty common to have multiple sprites/images, except yours are procedural generated. If you want whole tower to rotate, it'll be neat to have 3D approach.

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #16 on: 2012-01-22 00:39:01 »

Considering i have very little java experience this sounds quite complicated. Basically if i understand correctly i have to have the tower target the enemy then depending on its location choose an image that accurately depicts where is should be facing?

and to make this smooth ill need at least 20 images that each are slightly rotated in order to get a smooth rotating image?
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #17 on: 2012-01-22 00:49:13 »

Yeah you can do that, but not efficient I think. You can have less image by rotating with code (generated on fly) but it's expensive with java2d so you better bring it to opengl. My suggest is to leave animation first and create logic first. In the end you'll have a game where the towers are static but shoot enemy with right directed bullets. Then you can enchant animation.

Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #18 on: 2012-01-22 00:52:49 »

You don't need many images to produce a smooth animation. For example, a smooth looking walking animation is only 3-4 images. Animation is very easily simulated with little amount of frames Smiley

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #19 on: 2012-01-22 00:59:03 »

im gonna do the shooting system tonight, and ill put up a video of it, if anyone can suggest how i do the image animation after you see it let me know. I have some ideas but i really dont know if they are going to work!
Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #20 on: 2012-01-22 04:16:50 »

New Video: http://www.youtube.com/watch?v=Ymww6vpgndA

Put up the new video showing the towers firing, I'm gonna try and get the towers to rotate with the line in order to get 3D feel.
Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #21 on: 2012-01-22 04:26:19 »

It's looking good, great progress!

One comment: "public class ad ... " Really?! Shocked
If you want to obfuscate your code, use a tool like Proguard. Don't do it manually! Pointing Tongue

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #22 on: 2012-01-22 04:30:39 »

One comment: "public class ad ... " Really?! Shocked

haha just laziness. But thanks for checking it out! I'm trying to get the image to follow the line right now.
Offline ReBirth

JGO Wizard
****

Posts: 1275
Medals: 19



« Reply #23 on: 2012-01-22 07:07:27 »

Or that's really Ad class, for showing ad before you purchase the game Tongue

Offline thez3r0312

JGO n00b
*

Posts: 18



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

i really cant figure out how to make the tower rotate toward enemies, anyone have any ideas?
Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #25 on: 2012-01-22 23:45:45 »

All you need is the rotation angle of the tower when it faces the enemy:
1  
2  
3  
4  
5  
double rot = Math.atan2(enemy.y-tower.y,enemy.x-tower.x);

// then when rendering:

g.rotate(rot,tower.x+tower.width/2,tower.y+tower.height/2);

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #26 on: 2012-01-23 00:09:39 »

Ok so here is my code and its getting an error,

1  
2  
3  
4  
5  
6  
7  
8  
9  
//Tower
     double rot;
      for(int i = 0; i < tower.length; i++){
         rot = Math.atan2(mobs[i].y - tower[i].y, mobs[i].x - tower[i].y);
         if(towerID[i] != air) {
            g.drawImage(aa.f.bp.tower[towerID[i]], tower[i].x, tower[i].y, tower[i].width, tower[i].height, null);
            g.rotate(rot, tower[i].x + tower.length / 2, tower[i].y + tower.height / 2);
      }
      }
Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #27 on: 2012-01-23 00:17:39 »

you should be rotating before drawing the image then you need to reset the transform:
1  
2  
3  
g.rotate...
g.drawImage...
g.getTransform().setToIdentity();

Offline thez3r0312

JGO n00b
*

Posts: 18



« Reply #28 on: 2012-01-23 00:41:16 »

ok so i have some rotation but its very random and all over the place, and when i place a second tower it rotates around the first one. Anyone see why?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
//Tower
           double rot;
            Graphics2D g2d = (Graphics2D) g;
            for(int i = 0; i < tower.length; i++){
               
               rot = Math.atan2(mobs[i].y - tower[i].y, mobs[i].x - tower[i].y);
               if(towerID[i] != air) {
                  g2d.rotate(rot, tower[i].x + tower[i].width / 2, tower[i].y + tower[i].height / 2);
                  g.drawImage(aa.f.bp.tower[towerID[i]], tower[i].x, tower[i].y, tower[i].width, tower[i].height, null);
            }
            }
Online ra4king

JGO Kernel
*****

Posts: 3156
Medals: 196


I'm the King!


« Reply #29 on: 2012-01-23 00:48:57 »

You need to reset the transform like I showed you in the previous post! Tongue

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.173 seconds with 19 queries.