Show Posts
|
|
Pages: [1]
|
|
1
|
Game Development / Newbie & Debugging Questions / Still Not Understanding the Whole "Fix" For Flickering Animation
|
on: 2012-03-03 21: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; } } |
|
|
|
|
|
4
|
Game Development / Newbie & Debugging Questions / JFrame Size
|
on: 2012-02-29 21: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 21: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.  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 04: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! 
|
|
|
|
|
8
|
Games Center / Showcase / Re: TBS
|
on: 2012-02-22 21: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 21: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 07: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; } |
|
|
|
|
|
12
|
Games Center / Showcase / TBS
|
on: 2012-02-21 05:45:32
|
 This a continuation of the thread found here: http://www.java-gaming.org/topics/applet-to-application/25794/view.htmlSimple 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/?i6mid44e31i3x1mEditor .jar file updated 2/23/12http://www.mediafire.com/?ucpwfwukq20a1jcEditor 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 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?
|
|
|
|
|
15
|
Game Development / Newbie & Debugging Questions / Re: Applet to Application
|
on: 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.  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 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.
|
|
|
|
|
17
|
Game Development / Newbie & Debugging Questions / Re: Applet to Application
|
on: 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. 
|
|
|
|
|
20
|
Game Development / Newbie & Debugging Questions / Re: Applet to Application
|
on: 2012-02-20 22:58:46
|
Ah yes getCodeBase() won't work. Use System.getProperty("user.dir") instead.  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 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;
} |
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 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!
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|