Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (307)
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 / Game Mechanics / Making Rectangle fly in circles on: 2013-03-10 14:21:16
I'm currently working on some game where I want to throw entities off a cliff.
Now I need to make the entity move in 90 degrees in the arms of the "Thrower".
I've been testing some things but I can't really get to an idea how to get this entity move smooth.

This is what my Thrower class currently looks like:
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  
package nl.tdegroot.exgj.Justice;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;

public class Thrower {

   private final Vector2f velocity;
   private final Rectangle position;

   private boolean increment = true;
   private float minX = 470f;
   private float minY = 470f;
   private float maxX = 520f;
   private float maxY = 520f;

   private final float friction = 0.55f;
   private float movementSpeed = 5f;

   public Thrower() {
      velocity = new Vector2f();
      position = new Rectangle(500, 500, 50, 50);
   }

   public void update(GameContainer gc, int delta) throws SlickException {
      velocity.x *= friction;
      velocity.y *= friction;

      if (Math.abs(velocity.x) < friction) velocity.x = 0f;
      if (Math.abs(velocity.y) < friction) velocity.y = 0f;

      if (increment) {
         velocity.x += movementSpeed;
         velocity.y -= movementSpeed;
      } else {
         velocity.x -= movementSpeed;
         velocity.y += movementSpeed;
      }

      float newX = position.getX() + velocity.x;
      float newY = position.getY() + velocity.y;

      if (newX <= minX || newY <= minY) {
         increment = true;
      } else if (newX >= maxX || newY >= maxY) {
         increment = false;
      }

      System.out.println("" + newX + ", " + newY);

      if (newX != 0) {
         position.setX(newX);
      }

      if (newY != 0) {
         position.setY(newY);
      }

   }

   public void render(GameContainer gc, Graphics g) {
      g.fillRect(position.getX(), position.getY(), 50, 50);
   }

}


Any help would be highly appreciated!
2  Games Center / WIP games, tools & toy projects / Re: Dead Run 2 on: 2013-03-09 02:18:59
Awesome game!
3  Game Development / Newbie & Debugging Questions / Re: ConcurrentModificationException errors on: 2013-02-28 22:47:49
Alright, that was really helpful! It works now, but still I have the ConcurrentModificationException when I try to shoot really fast.
4  Game Development / Newbie & Debugging Questions / ConcurrentModificationException errors on: 2013-02-28 22:07:33
So I'm working on a little side-scrolling shooter and got some stuff working,
but now I got stuck in a problem. Whenever I want to remove something
from the bulletList, I get the ConcurrentModificationException. Also when
I want to shoot multiple bullets really fast, it crashes as well. I thought I
was doing this the right way, but it seems I'm doing something wrong.
bulletList declaration:
1  
private List<Bullet> bulletList = new ArrayList<Bullet>();

Iterator:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public void tick() {
      // tickCount++;

      p.tick();
      player.tick();
     
      Iterator<Bullet> it = bulletList.iterator();
      while (it.hasNext()) {
         Bullet bullet = it.next();
         bullet.tick();
         
         if (!bullet.living) {
            bulletList.remove(bullet);
         }
      }
   }

Bullet.tick()
1  
2  
3  
4  
5  
6  
7  
8  
9  
public void tick() {
      time--;
      if (time > 0) {
         moveBullet();
      } else {
         die();
      }
      System.out.println("Bullet Tick! Time: " + time);
   }

Die would only set the boolean living to false.
Does anyone know what I'm doing wrong?
Any help would be highly appreciated!
5  Game Development / Newbie & Debugging Questions / Re: Creating an ingame chat/console. on: 2012-11-10 19:28:51
This is my openGL console: https://github.com/Desmaster/Devio/blob/master/src/com/github/desmaster/Devio/cons/Console.java
6  Game Development / Newbie & Debugging Questions / Re: Console on: 2012-11-10 19:27:46
Use a switch:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
char key = ....

switch(key) {
    case 'w': up(); break;
    case 'a': left(); break;
    case 's': down(); break:
    case 'd': right(); break;
}

Thanks for confirmation as I applied this to the game!

7  Game Development / Newbie & Debugging Questions / Console on: 2012-11-09 17:23:01
At the moment I'm working on my console in the game. Now I want to be able to type commands etc. I entered my InputHandler and started writing some stuff, like outputting the name of the key. That pretty worked, but there's only one problem. I need to be filtering keys out of it. What is the best way how I can do this?

Thanks for any help!
8  Game Development / Newbie & Debugging Questions / Re: Why is this code producing a blank applet? on: 2012-11-09 12:59:23
Does the method init() get called?
9  Game Development / Game Play & Game Design / Re: Searching for a Tile based map editor on: 2012-11-09 10:22:45
So far I know Tiled is written in C++.
10  Game Development / Game Play & Game Design / Re: Searching for a Tile based map editor on: 2012-11-08 15:47:39
We already tried this one but we are not sure which map file we should use.
11  Game Development / Game Play & Game Design / Searching for a Tile based map editor on: 2012-11-07 22:15:22
While working on our game, we've decided to load maps i.o. randomly generating one. We are using Tiles for the ground and GameObjects for things that stay on the ground(Tile). What is the best map editor I should use for now? We also prefer GZip files. Thanks for any help! Smiley
12  Game Development / Newbie & Debugging Questions / Re: Disable glColor on: 2012-11-07 20:33:09
Yes I got it fixed! Thanks guys! Smiley
13  Game Development / Newbie & Debugging Questions / Re: Disable glColor on: 2012-11-07 20:29:27
Yes, I disable the blending with glDisable(GL11.GL_BLEND); first, after the drawing I enable it by glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
14  Game Development / Newbie & Debugging Questions / Re: Disable glColor on: 2012-11-07 20:15:09
That will give me this result: http://gyazo.com/cb93b18a1456f6e6c7f6d7ec95dda5ca
15  Game Development / Newbie & Debugging Questions / [FIXED] Disable glColor on: 2012-11-07 20:10:30
I am currently using a basic text drawing method, which pretty works. I set the color of drawing to white. Now all my textures I use, will have white spaces in the transparancy. How can I disable the color I set?
Source: https://github.com/Desmaster/Devio/blob/master/src/com/github/desmaster/Devio/Devio.java
16  Game Development / Newbie & Debugging Questions / Re: Smooth walking on: 2012-11-04 15:43:23
DO NOT use a thread per unit. That's a recipe for disaster.
Kk, can you tell me how I can make the delay better?
17  Game Development / Newbie & Debugging Questions / Lost track on: 2012-11-04 15:37:45
I lost track of what happens atm. I have to get the X and Y coordinates of my Player. After the first tick(Entity init) it logs that x = 288. After the second tick(Player tick()) it logs that x = 288. After the third tick(level tick()) it logs that x = 288. After the fourth tick(World render()) it logs that x = 0. This is weird because I didn't do anything with it after the third AND fourth tick.
Console log:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
Console: Loaded configurations
Sun Nov 04 15:34:26 CET 2012 INFO:Use Java PNG Loader = true
Console: Loaded player.png
Console: Loaded ninja.png
Console: Loaded billie.png
Console: Loaded grass.png
Console: Loaded water.png
Console: Loaded flower_red.png
Console: Loaded flower_yellow.png
Console: Loaded stone.png
Console: Loaded cobblestone.png
Console: Loaded moss_stone.png
Console: Enity X initialized: 288
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -8
   at com.github.desmaster.Devio.realm.World.render(World.java:60)
   at com.github.desmaster.Devio.realm.Level.render(Level.java:28)
   at com.github.desmaster.Devio.gfx.Screen.render(Screen.java:24)
   at com.github.desmaster.Devio.Devio.render(Devio.java:146)
   at com.github.desmaster.Devio.Devio.run(Devio.java:103)
   at com.github.desmaster.Devio.Devio.start(Devio.java:111)
   at com.github.desmaster.Devio.Devio.main(Devio.java:152)
Console: Player X: 288
Console: pX initialized! 288
Console: pX: 0

Source code: https://github.com/Desmaster/Devio/tree/master/src/com/github/desmaster/Devio
Is someone able to trace the little mistake in the source code? Thanks for any help!
18  Game Development / Newbie & Debugging Questions / Smooth walking on: 2012-11-03 22:29:57
After programming on my game for one day, I finally need some help.
What I'm trying to do is: to make my character walk everytime each 200 - 300 ms. I tried this with a thread by letting it sleep for that amount of miliseconds. This actually did work, but not really smooth. Sometimes it didn't really respond to my key input, only after holding it for a certain amount of miliseconds. What is the best way to solve this?
Location: https://github.com/Desmaster/Devio/blob/master/src/com/github/desmaster/Devio/entity/Player.java

Thanks for helping / reading!
19  Game Development / Newbie & Debugging Questions / Re: Texture is flickering, help? on: 2012-10-31 20:43:17
Read the tutorials and wiki. There are a few things wrong:

- You call Display.update at the beginning of your loop, and then again during render(). You should call this at the end of your loop (before sync), and probably not inside your render() method.
- You aren't using proper texcoords. See here.
- You are loading from a file, which won't work if you try packaging your resources into a JAR. You should be using MyGame.class.getResource().

Regarding triangles; true that the GPU will prefer triangles (since that's what it will be in the end), but that's the least of your worries. Right now you're using old-school immediate mode and fixed function; ideally you should be learning more modern OpenGL through shaders and VBOs. Understandably though, the "hello world" quad is a good starting point for newbies.

If you find these topics difficult to grasp, then you would be better off using a library like LibGDX which will cover the lower-level stuff for you.
Thank you! It was the Display.update() which made this fault. I just started with OpenGL, but I have alot of experience in making 2D and 3D games with the built-in graphics class. Thanks for this file tip as well, I just made this messy piece of code in about 15 mins. And I know, it's messy.
20  Game Development / Newbie & Debugging Questions / Re: Texture is flickering, help? on: 2012-10-31 20:19:52
This is the only texture I use. And Triangles just split it up. Or did you mean something else with tri?
<a href="http://www.youtube.com/v/pxiv6mqfrqs?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/pxiv6mqfrqs?version=3&amp;hl=en_US&amp;start=</a>
21  Game Development / Newbie & Debugging Questions / [SOLVED] Texture is flickering, help? on: 2012-10-31 19:52:52
My texture is flickering, it keeps showing up normal and after 5 seconds it starts to flicker again and then it shows up normal again. Is it my game loop or what is it?

Source code:
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  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

public class Main {

   public boolean finished = false;
   Texture texture;
   float x = 50.0f;
   float y = 50.0f;

   public Main() {

   }

   private void init(boolean fullscreen) {
      try {

         Display.setTitle("Test LWJGL");
         Display.setFullscreen(fullscreen);
         Display.setDisplayMode(new DisplayMode(480, 600));
         Display.setVSyncEnabled(true);
         Display.create();

         texture = getTexture("texture");

         GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
         GL11.glMatrixMode(GL11.GL_MODELVIEW);

         GL11.glMatrixMode(GL11.GL_PROJECTION);
         GL11.glLoadIdentity();
         GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
         GL11.glMatrixMode(GL11.GL_MODELVIEW);
         GL11.glEnable(GL11.GL_TEXTURE_2D);
      } catch (LWJGLException e) {
         e.printStackTrace();
      }
   }

   private Texture getTexture(String key) {
      try {
         return TextureLoader.getTexture("PNG", new FileInputStream(
               new File("res/img/" + key + ".png")));
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return null;
   }

   public void start() {
      init(false);
      run();
   }

   public void run() {
      while (!finished) {
         Display.update();
         if (Display.isCloseRequested()) {
            finished = true;
         } else {
            tick();
            render();
         }
      }
   }

   private void render() {
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

      draw();

      Display.update();
      Display.sync(60);
   }

   private void draw() {
      texture.bind();

      GL11.glBegin(GL11.GL_QUADS);
      GL11.glTexCoord2f(0, 0);
      GL11.glVertex2f(x, y);
      GL11.glTexCoord2f(1, 0);
      GL11.glVertex2f(x + texture.getTextureWidth(), y);
      GL11.glTexCoord2f(1, 1);
      GL11.glVertex2f(x + texture.getTextureWidth(),
            y + texture.getTextureHeight());
      GL11.glTexCoord2f(0, 1);
      GL11.glVertex2f(x, y + texture.getTextureHeight());
      GL11.glEnd();
   }

   private void tick() {

   }

   public static void main(String args[]) {
      Main main = new Main();
      main.start();
   }

}
22  Game Development / Newbie & Debugging Questions / Re: Collision Detection on: 2012-09-25 10:34:59

1  
2  
3  
4  
5  
      GL11.glMatrixMode(GL11.GL_PROJECTION);
         GL11.glLoadIdentity();
         GL11.glOrtho(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), 1, -1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
         GL11.glColor3f(1.0f, 1.0f, 1.0f);


I have no idea what your trying to do in your tick() function, but you should move your player and then theck collission with all objects in the room.
Just check the collission rectangle of the player with the collission rectangle of other objects / players.

If I would cut that part of code and put that into initGL(), it would give me plenty of errors.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void tick() {
   int colsens = (int) (width % (height * width)) / 2;
   rect.setX((int) x);
   rect.setY((int) y);
   colbox.setX((int) x);
   colbox.setY((int) y);
   colbox.setWidth((int) (width + width / colsens));
   Stibbs.say("set width!");
   colbox.setHeight((int) (height + height / colsens));
   Stibbs.say("set height!");
}


First of all, I'm setting my player(rect) to the x and y positions to keep them synced.
Same to colbox(collision box) which will be the area around my player which will detect collision.
After that, it sets the width and height of the collision box, divided by colsens(collision sensivity).
That's basically my tick method
23  Game Development / Newbie & Debugging Questions / Re: Collision Detection on: 2012-09-25 08:11:18
Sorry about that, I forgot to sync my git!
Please go look for it again,.

Thanks
24  Game Development / Newbie & Debugging Questions / Collision Detection on: 2012-09-24 23:22:25
I made a little Rectangle for my Player, I got it set up for a bit.
Can someone now tell me how I can listen to collisions from my Player?
You can find my source here: https://github.com/Desmaster/Stibbs
Biggest part of the Rectangle is in the class Player (*.player.Player)

Thanks for the help so far!
25  Game Development / Newbie & Debugging Questions / Re: LWJGL - Rendering on: 2012-09-24 15:55:11
Yes, it worked!
Thanks man! I believe this forum will teach me a lot of things Tongue.
26  Game Development / Newbie & Debugging Questions / [SOLVED] LWJGL - Rendering on: 2012-09-24 15:29:38
Well, I just started LWJGL so I can learn more stuff.
I've done some tutorials and stuff, added things to my game, so far, it's really basic.
Now my problem is, I just rendered out a square, with a diagonal square bitten out of it.
What have I done wrong in my code?
Source:
https://github.com/Desmaster/Stibbs/blob/master/src/com/github/desmaster/main/Stibbs.java
Thanks Smiley
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
mrbenebob (19 views)
2013-06-19 14:55:23

BrassApparatus (29 views)
2013-06-19 08:52:37

NegativeZero (32 views)
2013-06-19 03:31:52

NegativeZero (34 views)
2013-06-19 03:24:09

Jesse_Attard (39 views)
2013-06-18 22:03:02

HeroesGraveDev (75 views)
2013-06-15 23:35:23

Vermeer (76 views)
2013-06-14 20:08:06

davedes (77 views)
2013-06-14 16:03:55

alaslipknot (69 views)
2013-06-13 07:56:31

Roquen (92 views)
2013-06-12 04:12:32
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
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!