Show Posts
|
|
Pages: [1]
|
|
1
|
Game Development / Newbie & Debugging Questions / Re: [SOLVED] Collision Issue on TiledMap (Slick2D)
|
on: 2012-12-22 15:07:21
|
Actually, my collision checking method was correct, but I used it in a wrong context, for the lack of a term. My new method of doing it is drawing rectangles on the blocked tile spots. Maps gets drawn on top of those rectangles, so they're not visible. It works like a charm! Here's the code: 1 2 3 4 5 6 7 8 9 10 11 12
| public boolean collides(float x, float y, Graphics g){ Rectangle player = new Rectangle(x, y, 32, 32); g.draw(player); for(int i = 0; i < rects.size(); i++){ if(player.intersects(rects.get(i))){ System.out.printf("Collision detected at (%s, %s).\n", x, y); return true; } } System.out.printf("No collision has been detected.\n"); return false; } |
Thank you for your help, anyway!
|
|
|
|
|
2
|
Game Development / Newbie & Debugging Questions / [SOLVED] Collision Issue on TiledMap (Slick2D)
|
on: 2012-12-21 07:53:00
|
Hello. I've tried my best to make this collision work, but I simply can't. I tried every method, even copied the code from internet tutorial, but it simply won't work. It seems as if when the player is in the middle of two tiles, it won't work. Uh, I don't know how to explain it right, so I'll post some screenshots. It works if the player is in a "full" tile. Click here to see the screenshot.But, if a player is kind of in a "half" tile, it doesn't. Click here to see the screenshot.The code I use to check for the collision: 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
| public void update(int delta, int direction, Map map){ speed = 0.2f; switch(direction){ case 1: sprite = up; if(!map.isBlocked(x, y - delta * speed)){ y -= delta * speed; } break; case 2: sprite = down; if(!map.isBlocked(x, y + Constants.TILE_SIZE + delta * speed)){ y += delta * speed; } break; case 3: sprite = left; if(!map.isBlocked(x - delta * speed, y)){ x -= delta * speed; } break; case 4: sprite = right; if(!map.isBlocked(x + Constants.TILE_SIZE + delta * speed, y)){ x += delta * speed; } break; default: System.err.println("Invalid direction."); break; } } |
My isBlocked(float, float) method (in Map class) is pretty simple: 1 2 3 4 5
| public boolean isBlocked(float x, float y){ int xTile = (int) (x / 32); int yTile = (int) (y / 32); return blocked[xTile][yTile]; } |
NOTE: In my map class I set up stuff with TiledMap, just so you know.
|
|
|
|
|
3
|
Games Center / Showcase / Re: Plague
|
on: 2012-09-29 19:57:31
|
Doesn't seem to work for me. Gets stuck on the "Plague is Loading" screen and then it turns grey. Command line shows 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
| java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unkno wn Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at sothatsit.plague.Sounds.load(Sounds.java:23) at sothatsit.plague.Plague.start(Plague.java:162) at sothatsit.plague.Plague.main(Plague.java:120) java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unkno wn Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at sothatsit.plague.Sounds.load(Sounds.java:35) at sothatsit.plague.Plague.start(Plague.java:162) at sothatsit.plague.Plague.main(Plague.java:120) java.io.IOException: mark/reset not supported at java.util.zip.InflaterInputStream.reset(Unknown Source) at java.io.FilterInputStream.reset(Unknown Source) at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unkno wn Source) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at sothatsit.plague.Sounds.load(Sounds.java:47) at sothatsit.plague.Plague.start(Plague.java:162) at sothatsit.plague.Plague.main(Plague.java:120) Exception in thread "Thread-5" java.lang.NullPointerException at sothatsit.plague.Sounds.setSoundVolume(Sounds.java:72) at sothatsit.plague.Plague.init(Plague.java:288) at sothatsit.plague.Plague.run(Plague.java:296) at java.lang.Thread.run(Unknown Source) |
|
|
|
|
|
5
|
Game Development / Newbie & Debugging Questions / Re: Tiled Map Level Editor Problem
|
on: 2012-09-28 22:44:57
|
I've wrapped JFrame in JScrollPane, but it's same. Here is the code snippet, I might be doing something wrong. 1 2 3 4 5
| public static void main(String[] args){ Start start = new Start(); JScrollPane pane = new JScrollPane(new Editor(start), ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); start.add(pane); } |
Here is constructor of Start class: 1 2 3 4 5 6 7
| public Start(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(800, 600); setLocationRelativeTo(null); setVisible(true); setResizable(false); } |
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / [SOLVED] Tiled Map Level Editor Problem
|
on: 2012-09-28 09:27:54
|
Hello, JGO community. I've been looking for solution a whole day yesterday, but found none. Basically I have window which is 800x600 and my tiled map is 30x30 (each tile is 32x32). I want to be able to scroll through my map using JScrollPane. I've looked in this thread, but Mr_Light's solution doesn't work for me. I've wrapped the JPanel in the JScrollPane, and I also forced those slide bars to always be visible, but I can do nothing with them. Here is the screenshot of level editor's JPanel:  [size=7pt] NOTE: Tiles were drawn by me, so please don't steal them.[/size] Thank you, in advance, to anyone who tries to help me!
|
|
|
|
|
8
|
Game Development / Newbie & Debugging Questions / Re: Warning Question
|
on: 2012-09-22 16:15:03
|
Also, why do you pass the name on to init? Why not just set the name in the constructor? It's not likely that you want your program to change its name in the middle of execution anyway. The other calls are sitting fine in the init, though.
Program's name is stored 'n' set in other class named Frame. That was JPanel's name. For some reason I want to set the name of JPanel.  Thank you all for showing the interest to help me. I will most likely break my habbit and leave the warning there, but I'm not sure yet. Once again, thanks.
|
|
|
|
|
9
|
Game Development / Newbie & Debugging Questions / Warning Question
|
on: 2012-09-22 11:42:13
|
Hello, JGO community. When I write (Java) applications, I really don't like having any warnings. Right now, I am working on a simple Breakout game and I decided to use Netbeans. Basically, I have a code that in Netbeans shows a warning, while in Eclipse it doesn't. I am wondering why. Here is the code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| package game;
import java.awt.Color; import javax.swing.JPanel;
public class Board extends JPanel{ public Board(String name){ init(name); } public void init(String name){ setName(name); setBackground(Color.WHITE); setFocusable(true); } } |
In NetBeans, there is the warning on this line: I understand that this is highly irrelevant, but I just want to know how can I fix that warning without suppressing the warnings for the constructor.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|