Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Still Not Understanding the Whole "Fix" For Flickering Animation on: 2012-03-03 20:39:36
I've now read at least 3 different tutorials on how to get rid of flickering animation, all using slightly different methods, and all making almost no sense to me. So alas, I am stuck with a broken game. So my question is, how do you guys personally get rid of flickering animation?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
public class Game extends Canvas implements ActionListener, KeyListener {
   
   Level level;
   Timer timer;
   Player player;
   boolean started;
   
   public Game() {
      started = false;
      level = new Level();
      level.constructLevel();
      player = new Player(150, 425);
      addKeyListener(this);
      player.genCollisionPoints();
      timer = new Timer(50, this);
      timer.start();
   }
   
   public void paint(Graphics g) {
      g.setColor(Color.GRAY);
      g.fillRect(0, 475, 1200, 25);
     
      for(int x = 0; x < level.map.size(); x++) {
         if(level.map.get(x).x >= -100)
            level.map.get(x).drawBlock(g);  
         else
            level.map.remove(x);  
      }
     
      if(level.map.size() == 0)
         timer.stop();
           
      player.drawPlayer(g);
     
      for(int x = 0; x < player.health; x++) {
         g.setColor(Color.RED);
         g.fillRect(x * 30 + 15, 25, 25, 50);
      }
      g.setFont(new Font("Custom", Font.BOLD, 18));
      g.setColor(Color.BLACK);
      g.drawString(Integer.toString((int)player.score), 700, 25);
   }
   
   public void actionPerformed(ActionEvent e) {
      for(int x = 0; x < level.map.size(); x++) {
         if(collision(level.map.get(x).genRect()) && level.map.get(x).isExist()) {
            player.health--;
            level.map.get(x).setExist(false);
         }
         if(player.health <= 0)
            timer.stop();
         }
     
      for(int x = 0; x < level.map.size(); x++)
         level.map.get(x).x = level.map.get(x).x - 15;
     
      if(player.isJumping  && player.y > player.maxHeight)
         player.y -= 30;
     
      if(player.isJumping && player.y <= player.maxHeight)
         player.isJumping = false;
     
      if(!player.isJumping && player.y != 425)
         player.y += 30;
     
      if(player.y > 425)
         player.y = 425;
     
      player.score += .1;
     
      repaint();
   }
   
   public boolean collision(Rectangle rec) {
      boolean collision = false;
      player.genCollisionPoints();      
      for(int x = 0; x < player.xValues.length; x++)
         for(int y = 0; y < player.yValues.length; y++) {
            collision = rec.contains(player.xValues[x], player.yValues[y]);
            if(collision)
               break;
         }
      return collision;
   }
   
   public void keyTyped(KeyEvent e) {
      char pressed = e.getKeyChar();
      player.canJump = (player.y == 425);
      if(player.canJump && pressed == ' ')
         player.isJumping = true;
   }
}
2  Game Development / Newbie & Debugging Questions / Re: JFrame Size on: 2012-03-02 03:56:51
Also, don't draw on a JPanel! I'm trying to eradicate this practice T____T

What should I draw on then?
3  Game Development / Newbie & Debugging Questions / Re: JFrame Size on: 2012-03-02 01:21:56
Wow, lots of replies! I'm not sure who's solution I like the best.  Roll Eyes
4  Game Development / Newbie & Debugging Questions / JFrame Size on: 2012-02-29 20:47:27
I set the size of my JFrame to 1000x500 but it is obvious to me through the use of my drawing methods that the actual size is not 1000x500 but something slightly smaller. Why is this?

1  
2  
3  
4  
5  
JFrame frame = new JFrame("Jumper");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(1000, 500);
frame.add(new Game());
frame.setVisible(true);
5  Games Center / Showcase / Re: TBS on: 2012-02-23 20:50:27
Well I'm pretty much done with this project. Was a nice way to learn tile map system, packages, image/sound handling, writing custom algorithms, etc. The final jar's for both the game and the editor have been uploaded, links can be found in the original post. And you now have the option of using a custom map seed, so the editor actually has a purpose now. I'll only make changes if bugs are found or if I feel like adding something.

If anyone would like to have the source code, for whatever reason, I'll upload it. Just make sure you give credit where due.  Smiley

Thanks for all the help on the final touches. I'll be starting a new project soon.
6  Games Center / Showcase / Re: TBS on: 2012-02-23 03:54:04
That's because there is no AppletContext if you are adding it to the JFrame. Use the static "newAudioClip" method instead.

You so smart!   Grin
7  Games Center / Showcase / Re: TBS on: 2012-02-23 02:57:52
Is there a reason Java sucks at handling sound files? I have a copy of the sound files in my source folder, in their own source folder, in the package the class is in, and in the general project folder. Yet neither method of retrieving them works.
 Huh Huh Huh
1  
2  
3  
4  
5  
6  
System.out.println(Main.class.getResource("tank_fire.wav"));
System.out.println(Main.class.getClassLoader().getResource("tank_fire.wav"));

//tank_fire = getAudioClip(Main.class.getResource("tank_fire.wav"));
tank_fire = getAudioClip(Main.class.getClassLoader().getResource("tank_fire.wav"));
//both give the same error

1  
2  
3  
4  
5  
6  
7  
8  
file:/H:/Eclipse%20Workspace/TBS/bin/com/rolledback/game/tank_fire.wav
file:/H:/Eclipse%20Workspace/TBS/bin/tank_fire.wav
java.lang.NullPointerException
   at java.applet.Applet.getAppletContext(Unknown Source)
   at java.applet.Applet.getAudioClip(Unknown Source)
   at com.rolledback.game.Main.declareImages(Main.java:102)
   at com.rolledback.game.Main.init(Main.java:62)
   at com.rolledback.game.Game_Frame.main(Game_Frame.java:18)
8  Games Center / Showcase / Re: TBS on: 2012-02-22 20:45:22
So obviously this won't work since I'm no longer working in an applet:
1  
2  
tank_fire = getAudioClip(getCodeBase(), "tank_fire.wav");
tank_destroyed = getAudioClip(getCodeBase(), "tank_destroyed.wav");

But neither does this:
1  
2  
tank_fire = getAudioClip(Main.class.getClassLoader().getResource("tank_fire.wav"));
tank_destroyed = getAudioClip(Main.class.getClassLoader().getResource("tank_destroyed.wav"));  

I have used System.out.println() to confirm that the code is pointed to the correct file, yet I keep getting a null pointer exception.

Any ideas?
9  Games Center / Showcase / Re: TBS (working title) on: 2012-02-22 20:11:30
How do you end turn?

Either press "End Turn" or hit your space bar.

I've also updated the JAR. Why is it that JFrame size and Applet size do not end up being equal?
10  Game Development / Game Play & Game Design / Taking Damage on: 2012-02-21 06:06:39
Any suggestions on fair ways to calculate damage that isn't too complicated? At the moment I'm using:

1  
2  
3  
4  
5  
6  
7  
8  
9  
public void damaged(int amount) {
   Random random = new Random();
   double damage;
   int maxDef = defense + getDefBonus();
   double percMinus = random.nextInt(maxDef - (maxDef / 2)) + (maxDef / 2);
   damage = amount - Math.ceil(amount * (percMinus / 100));
   hp -= (int)damage;
   alive = hp > 0;
}
11  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-21 04:49:29
Thanks!

http://www.java-gaming.org/topics/iconified/25799/view.html
12  Games Center / Showcase / TBS on: 2012-02-21 04:45:32


This a continuation of the thread found here: http://www.java-gaming.org/topics/applet-to-application/25794/view.html

Simple turned based strategy game, still in development. My goal at the moment is to finish getting the UI sorted out. I'd like the info/dashboard thing at the bottom to be an independent window of the game screen. The would allow the player the ability the scroll around the game screen, which would also allow for any sized map, regardless of the user's screen size.

So if anyone has any ideas on how to implement this, I'm open to suggestions. I don't know much about java graphics aside from applets.

Game .jar file updated 2/23/12:
http://www.mediafire.com/?i6mid44e31i3x1m

Editor .jar file updated 2/23/12
http://www.mediafire.com/?ucpwfwukq20a1jc

Editor Controls:
1  
2  
3  
4  
-Click on tile to cycle through terrain types
-Press key of first letter of tile type to fill map(ex, p, f, l, m)
-Space bar to change to base editing mode, allows you to place bases on first and last columns
-Right click to export map (need the 2 bases before you can export)
13  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-21 01: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?
14  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-21 01: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.
15  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-21 00: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.
16  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-21 00: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.
17  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-21 00: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.



18  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-20 22: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
19  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-20 22: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
20  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-20 21: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
21  Game Development / Newbie & Debugging Questions / Re: Applet to Application on: 2012-02-20 21: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)

22  Game Development / Newbie & Debugging Questions / Applet to Application on: 2012-02-20 20: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!

Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (12 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (27 views)
2014-08-22 19:31:30

atombrot (40 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (34 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!