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!
|
|
|
|
|
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() { 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!
|
|
|
|
|
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!
|
|
|
|
|
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! 
|
|
|
|
|
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/DevioIs someone able to trace the little mistake in the source code? Thanks for any help!
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|