Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
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]
  ignore  |  Print  
  Applet to Application  (Read 4208 times)
0 Members and 1 Guest are viewing this topic.
Offline rolledback

Junior Member


Projects: 1



« Posted 2012-02-20 21:53:05 »

Hello, so after about a month of work I have created my first Java game on my own. It is a 2D turn based strategy, don't laugh too hard when you see it. Right now though it is run through an applet, but I wish to move it to a application before I continue with development.

It's a lot of code so I've posted the source below [removed] if you care to take a look at it. I'm essentially looking to have the bottom 1/4 of the screen with all the info be static, while you could scroll around the actual game window. I know this might seem quite ambiguous, but if you run the applet I think you'll get what I'm saying. Also, willing to post pictures if needed.

Thanks!

Offline ra4king

JGO Kernel


Medals: 338
Projects: 2
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-02-20 22:04:51 »

You can create an instance of the class that extends Applet and add it to a JFrame. However, the init(), start(), stop(), and destroy() methods are not called so you will have to manually call them after you add it Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
JFrame frame = new JFrame("My Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(WIDTH,HEIGHT);

final MyApplet applet = new MyApplet();
frame.add(applet);

frame.setVisible(true);

applet.init();
applet.start();

frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
        applet.stop();
        applet.destroy();
    }
});


Note: if you only use init(), then you don't need to call the rest Smiley

Offline rolledback

Junior Member


Projects: 1



« Reply #2 - Posted 2012-02-20 22:24:19 »

Ok did that, but I seem to be getting null pointer errors from a method that declares all my images and audio files:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void declareImages() {
      tr = new MediaTracker(this);
     
      tank_fire = getAudioClip(getCodeBase(), "tank_fire.wav");
      tank_destroyed = getAudioClip(getCodeBase(), "tank_destroyed.wav");
     
      plains1 = getImage(getCodeBase(), "plains.png");
      tr.addImage(plains1, 0);
      tiles[0] = plains1;

                //similar code below
}


EDIT: first of many errors

1  
2  
3  
4  
5  
Exception in thread "main" java.lang.NullPointerException
   at java.applet.Applet.getCodeBase(Unknown Source)
   at com.rolledback.game.Main.declareImages(Main.java:103)
   at com.rolledback.game.Main.init(Main.java:62)
   at com.rolledback.game.Frame.main(Frame.java:20)

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 338
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-02-20 22:50:17 »

Ah yes getCodeBase() won't work. Use System.getProperty("user.dir") instead. Smiley

Offline rolledback

Junior Member


Projects: 1



« Reply #4 - Posted 2012-02-20 22:58:46 »

Ah yes getCodeBase() won't work. Use System.getProperty("user.dir") instead. Smiley

 Huh
1  
plains1 = getImage(System.getProperty("user.dir"), "plains.png");

1  
The method getImage(URL, String) in the type Applet is not applicable for the arguments (String, String)


PS: thank you for such patience
Offline ra4king

JGO Kernel


Medals: 338
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-02-20 23:22:12 »

Ah, then just do this: getImage(<ClassName>.class.getResource("plains.png"));

getResource returns a URL and searches for the file relative to the class.

Offline rolledback

Junior Member


Projects: 1



« Reply #6 - Posted 2012-02-20 23:29:48 »

Ah, then just do this: getImage(<ClassName>.class.getResource("plains.png"));

getResource returns a URL and searches for the file relative to the class.

Bleh, also does not work, it may have to do with how I've organized my images.

1  
plains1 = getImage(Main.class.getResource("plains.png"));


http://gyazo.com/ed98477ac89861ff82e6c7cbef98e49a
Offline Z-Man
« Reply #7 - Posted 2012-02-20 23:33:52 »

Just put them in packages in your src folder, like this or something like this:
1  
2  
3  
4  
5  
6  
src
|--> code packages
|--> images
     |--> tiles
     |--> sprites
|--> sounds
Offline rolledback

Junior Member


Projects: 1



« Reply #8 - Posted 2012-02-20 23:50:36 »

Did not solve the issue...could you maybe show me what you want with a screenshot, just in case I did not do what you meant?

 Emo
Offline ra4king

JGO Kernel


Medals: 338
Projects: 2
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-02-21 00:22:45 »

Well it is best to use javax.imageio.ImageIO instead of createImage, but either way, you'll need to do:
1  
BufferedImage image = ImageIO.read(Main.class.getClassLoader().getResource("tiles/plains.png"));


Class.getClassLoader().getResource(...) returns a URL relative to the root of your project.

EDIT: It looks like you've added "tiles", "original_models", "team1_models", "team2_modes" as source folders. Don't do that, change them to normal folders under "src".

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Man
« Reply #10 - Posted 2012-02-21 00:35:29 »

This is how I do it. All of the code is in "zman.example" and it's sub directories, and all the resources go in "resources" and it's sub directories. I just have eclipse treat them as packages in the src folder.
Offline rolledback

Junior Member


Projects: 1



« Reply #11 - Posted 2012-02-21 01:04:33 »

I LOVE YOU GUYS!

It took a bit of messing around, but the end result was this declaration:
1  
plains1 = ImageIO.read(Main.class.getClassLoader().getResource("plains.png"));


I guess I didn't have to reference the folder the image was in. Applet runs great. Now I just need to separate the 2 parts of the game screen.



Offline evilfrenchguy

Junior Member


Medals: 3



« Reply #12 - Posted 2012-02-21 01:06:30 »

That looks neat.

Did it take you long?
Offline rolledback

Junior Member


Projects: 1



« Reply #13 - Posted 2012-02-21 01:16:22 »

The project was started about a month and 2 weeks ago. All the artwork you see is original. I'm a senior in high school, so I'm pretty impressed on what I've been able to do with only 2 years of formal CS/Java and about a year of self taught under my belt. There is no animation though. I'll see if I can export it to an .exe and I'll put it on mediafire.
Offline rolledback

Junior Member


Projects: 1



« Reply #14 - Posted 2012-02-21 01:37:08 »

Here's the jar file for anyone who wants to play around with this, comments and suggestions are appreciated. Smiley

Bleh, having bugs with the sounds. I'll eventually reexport it. Too lazy though. So any ideas on how I could go about separating the dashboard looking thing from the map? I want to be able to have unlimited map sizes.
Offline ra4king

JGO Kernel


Medals: 338
Projects: 2
Exp: 5 years


I'm the King!


« Reply #15 - Posted 2012-02-21 01:53:27 »

Where's the JAR? Wink

Offline UprightPath
« Reply #16 - Posted 2012-02-21 02:10:31 »

Just a quick question! Are those trees in the water?

Offline rolledback

Junior Member


Projects: 1



« Reply #17 - Posted 2012-02-21 02:46:45 »

Where's the JAR? Wink

Ok fine, I'll reupload it. The sounds have been removed since I can't figure out how to declare them in a way that won't give me errors and exceptions. I'll figure that out tomorrow.  Grin

http://www.mediafire.com/?97kb0wayagm00rq

Just a quick question! Are those trees in the water?

No they are islands. MS Paint is only so amazing.
Offline UprightPath
« Reply #18 - Posted 2012-02-21 02:51:24 »

Oh, I was talking about the image that you posted earlier. It looks like you're painting your water (With a slight transparency) on top of various other ground types (Plains, Plains with big, fluffy trees, Plains with conifers.)

Offline rolledback

Junior Member


Projects: 1



« Reply #19 - Posted 2012-02-21 02:56:28 »

Oh, I was talking about the image that you posted earlier. It looks like you're painting your water (With a slight transparency) on top of various other ground types (Plains, Plains with big, fluffy trees, Plains with conifers.)

Oh no. That is showing you where you can move your unit. And since this thread is starting to move onto the general development of this game, I feel like I should start a new more permanent thread. What forum should I put it in?
Offline ReBirth
« Reply #20 - Posted 2012-02-21 05:07:15 »

Showcase Pointing

Offline rolledback

Junior Member


Projects: 1



« Reply #21 - Posted 2012-02-21 05:49:29 »

Thanks!

http://www.java-gaming.org/topics/iconified/25799/view.html
Pages: [1]
  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.

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

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

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

E.R. Fleming (31 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 (41 views)
2014-07-23 21:16:32

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

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (60 views)
2014-07-18 06:55:21
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!