Show Posts
|
|
Pages: [1] 2 3 ... 63
|
|
2
|
Game Development / Newbie & Debugging Questions / Re: Finding the time at which intersection takes place.
|
on: 2013-04-15 14:12:37
|
|
Here's some keywords to set you on the right track:
swept volume, convex polygon, separating axis theorem.
As to the issue of multiple collisions between more than 2 actors;
- check all collisions that occur within the next frame, looking for the earliest. - step your simulation to that point, and resolve the single collision that occurs. - repeat until you've processed all collisions that occur that frame.
|
|
|
|
|
5
|
Game Development / Newbie & Debugging Questions / Re: how to draw Sprites that turned to the left.
|
on: 2012-12-08 04:32:15
|
|
You should have additional data that goes alongside that sprite sheet, defining the bounds for each frame (and possibly separate collision bounds too). For rotating or flipping you'll want each frame to have an anchor point defined too, around which the operations are performed.
How you store that additional data is up to you; artists tend to like using paint packages, so having the bounds & anchor points defined as additional layers in the same image file can be a neat solution. (though obviously needs a little pre-processing in your code to extract the numerical offsets of the various pixel flags)
|
|
|
|
|
6
|
Game Development / Newbie & Debugging Questions / Re: Slick input keys
|
on: 2012-12-06 00:12:25
|
This did the trick. 1 2 3 4 5 6 7 8
| @Override public void keyPressed(int key, char c) { if (c == 'Æ') { tekst += "Æ"; } else if (c == 'æ') { tekst += "æ"; } } |
It's good practice to use the unicode character escape codes rather than embedding the characters themselves in your source files; so that your source files make sense to people not using ISO 8859-1 or UTF-8. In your case that'd be '\u00C6' and '\u00E6' respectively.
|
|
|
|
|
8
|
Discussions / General Discussions / Re: What's your preference is spacing
|
on: 2012-11-06 14:10:15
|
My preference: Ctrl+Shift+f Though I wish formatters would detect uses of the fluent interface pattern, as I prefer to see method chaining broken 1 per line (or some other constant, if logical), rather than after an arbitrary number of chained invocations determined by the line width. e.g. this: 1 2 3 4 5 6 7
| sb.append(callStart.toString(outputFormat)).append(',') .append(dataDuration).append(',') .append(callDuration).append(',') .append(destination).append(',') .append(area).append(',') .append(charge).append(',') .append(balance).append(','); |
not this: 1 2
| sb.append(callStart.toString(outputFormat)).append(',').append(dataDuration).append(',').append(callDuration).append(',').append(destination) .append(',').append(area).append(',').append(charge).append(',').append(balance).append(','); |
|
|
|
|
|
9
|
Discussions / General Discussions / Re: The hidden cost of C++
|
on: 2012-10-30 18:28:43
|
- Array syntax is counterintuitive. int array[] rather than int[] array.
Want to see something really weird? C++ lets you write the array access backwards. ie. 1 2 3 4 5
| char[] array = "hello"; int index = 4;
char ch1 = array[index]; char ch2 = index[array]; |
No, I have never found a use for this. If my understanding is correct, that only holds true for when the sizeof() the datatype of the array is equal to 1? Otherwise the pointer arithmetic would be wrong.
|
|
|
|
|
11
|
Discussions / General Discussions / Character could (should?!) implement CharSequence?
|
on: 2012-10-18 19:36:54
|
I came across this when helping a noobie understand why this doesn't compile: 1
| someString.replace('A',"BB") |
It got me thinking; why doesn't the Character class implement CharSequence. Logically a Character is a sequence of 1, thus there's no reason it shouldn't implement it. Doing so would have interesting consequence when mixed with autoboxing. Thanks to autoboxing, the uncompilable code above would start compiling. (char autoboxes to Character, which would implement CharSequence & thus meet the contract of replace(CharSequence,CharSequence)) I'm obviously not advocating such a change, as it'd introduce all sorts of potential confusion as to precisely what method was being invoked, and possible performance problems in the event of typos. Still, it was something I hadn't noticed or considered before.
|
|
|
|
|
12
|
Discussions / Java Gaming Wiki / Re: ArrayList vs LinkedList
|
on: 2012-09-19 02:24:28
|
I think this might go back to that fascinating talk given by Jon Blow on making computer games. Please watch it. It is massively significant to how good you will be at making games, or even just software. Cas  I appreciate what he's talking about, and when you're hand-coding the data structures in question then it makes sense to keep it simple. However, we have access to Java's wonderful Collections api; so using a HashXYZ is no more effort than using a less complex structure like an ArrayList.
|
|
|
|
|
16
|
Discussions / General Discussions / double-checked locking... in the JDK core?!
|
on: 2012-09-04 13:19:47
|
While doing something completely unrelated, I ended up inadvertently browsing java.util.Random src, and noticed.... 1 2 3 4 5 6 7 8 9 10 11 12
| private static Random randomNumberGenerator;
private static synchronized Random initRNG() { Random rnd = randomNumberGenerator; return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd; }
public static double random() { Random rnd = randomNumberGenerator; if (rnd == null) rnd = initRNG(); return rnd.nextDouble(); } |
Isn't that an obtuse implementation of double-checked locking? I thought out of order writes made the double-checked locking idiom all kinds of bad? No doubt if it is a bug it'd be hideously complicated to detect it in any kind of unit test.
|
|
|
|
|
17
|
Discussions / Business and Project Discussions / Re: Closed for business - Android vs. iOS
|
on: 2012-08-16 05:49:29
|
|
Entertainment media (films/music/games) are luxury goods. Thus I believe people will only pay what they think the product is worth. If they can't get it for this, they'll walk away. Once this happens you've already lost the sale, so it's mostly irrelevant if they subsequently pirate it or not.
I believe attempting to fight piracy directly is costly, counter-productive and ultimately futile.
|
|
|
|
|
18
|
Game Development / Newbie & Debugging Questions / Re: help ! stuck with maths problem i think..
|
on: 2012-07-22 23:48:27
|
foreachThe important part is this: When you see the colon ":" read it as “in”. Applying this to the example: 1
| for(Pixel p: panel.pixels) |
...should be read as... for each(Pixel p in panel.pixels) I personally hated it at first, but now I've come to like it. My only gripe with it is the occasional problem it causes when bodging new functionality into old code. You'll sometimes find you need access to the Iterator or the iteration index and have to re-factor the loop construct - which can be a bit of a faff.
|
|
|
|
|
21
|
Discussions / General Discussions / Re: Oracle vs Google
|
on: 2012-05-08 13:38:55
|
The jury also found that Android infringes on nine lines of Java coding, but that claim probably won't be worth more than $150,000 in damages, based on statements made earlier in the trial. When an Oracle lawyer suggested Monday that the infringement verdict on the nine lines could be worth substantially more, Alsup said the idea "borders on the ridiculous." This makes the "What Religion Are You?" thread somewhat more pertinent 
|
|
|
|
|
22
|
Game Development / Game Mechanics / Re: Random thoughts: Extreme speed 2D physics
|
on: 2012-05-01 13:01:46
|
Forgot to add that if you are doing a galactic simulation i would galaxy centered coordinates, almost all the mass is in the center. But you can't then also simulate solar systems on each star without some difficulty. For a solar system sun centered works well enough for many things, but don't forget that say Jupiter moons will have issues if you don't deal with numerical errors.
....and when you're traveling through a nebula cloud, you fudge it. 
|
|
|
|
|
23
|
Discussions / General Discussions / Re: Oracle vs Google
|
on: 2012-04-30 10:36:13
|
(I assume the they didn't drop the patent bits.)
The slides seemed to only focus on the copyright infringement of the API design and implementation. On a side-note this slide puzzles me: (Oracle's Slide 76) Java Specification License Requirements Are Designed To Avoid Fragmentation
License Requirements:
• Adhere to Java requirements • Don’t do less or more than what is required • Do a “clean room” implementation • License and pass compatibility tests How does requiring a "clean room" implementation reduce fragmentation? 100 monkeys writing 100 independent implementations of any given method will result in 100(+) different bugs. J2ME is a perfect example of this; it's API might have been consistent across the many hundreds of different handsets, but each implementation was so riddled with unique bugs that the platform itself became nonviable due to fragmentation. Perhaps this is a failing of the compatibility tests (or Sun's historically lackluster enforcement of them), rather than a problem with clean room implementations per se. Though if that's the case, I think it's naive to expect even the most thorough of compatibility tests to catch all problems.
|
|
|
|
|
24
|
Discussions / General Discussions / Re: Oracle vs Google
|
on: 2012-04-30 00:44:18
|
Obviously Google are in the wrong, but in this case I simply don't care. This might strike at the very heart of copyright law itself, but I don't feel the law is serving it's intended purpose. The United States Constitution Article I, Section 8, Clause 8 empowers the United States Congress
To promote the progress of science and useful arts, by securing for limited times to authors and inventors the exclusive right to their respective writings and discoveries. Sun's repeated failures at creating a viable consumer platform for Java development are evidence enough that penalizing Google's success does not serve scientific progress. It's the dichotomy of where to draw the line between the word of the law Vs the spirit of the law.
|
|
|
|
|
25
|
Game Development / Newbie & Debugging Questions / Re: Switch Statement Versus If Statements
|
on: 2012-04-09 03:05:51
|
For strings (1.7 and up) it switches on the string's hashCode, which should be a great deal faster than testing them in series. The important part is not which is faster, it's which is appropriate. I'm torn as to whether that's a 'good thing' (tm). I'm sure there are a few useful situations where it's perfectly reasonable to switch on Strings, and doing so will no doubt avoid some boiler plate. However I've a feeling it'll be misused to create bad, or poorly structured code. Using Strings where enums would be a better fit for instance.
|
|
|
|
|
26
|
Game Development / Newbie & Debugging Questions / Re: When to reset input
|
on: 2012-03-13 01:04:55
|
But I would just use a mouse listener. If you need them you can also have state variables that you set from within the listeners. e.g. 1 2 3 4 5 6 7 8 9 10
| boolean leftMouseDown = false; ... panel.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if(e.getButton() == MouseEvent.BUTTON1) leftMouseDown = true; } public void mouseReleased(MouseEvent e) { if(e.getButton() == MouseEvent.BUTTON1) leftMouseDown = false; } }); |
Now I'm starting to feel like I'm going in circles cause that's pretty much what I had. And I was told that the methods need to be synchronized, and the variables volatile. I was also told I was mixing polling and event based , and that it was a fragile solution. I'd love to see code for an input class that a few people could agree that was a good solution. If I don't, I think I will just have to go ahead with something like was already doing but with synchronized methods. Yes, that is fragile code. Your game code will undoubtably be assuming that the mouse/keyboard state remains the same throughout the duration of 1 game loop iteration. This would not be the case using the above code. If you were to implement your keylistener like that you'd need to take a copy of the mouse/keyboard state @ the start of each game loop so the value seen by your game code remained constant for the duration.
|
|
|
|
|
28
|
Game Development / Newbie & Debugging Questions / Re: Yet another game loop ><
|
on: 2011-12-24 00:18:09
|
Thread.sleep is very inaccurate on most hardware/OSs, use this trick to force the OS to use the high precision timer: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| new Thread() { { setDaemon(true); start(); }
public void run() { while(true) { try { Thread.sleep(Long.MAX_VALUE); } catch(Exception exc) {} } } }; |
Put this in your main. Also different computers run at different speeds, so it is best to use a deltaTime when moving your sprites. DeltaTime is the time that last frame took to complete. You then pass this number to your update method. To use this deltaTime value, you divide it by 1e9 (nanoseconds per second) and multiply it by the speed at which you want to move per second. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| long lastTime = System.nanoTime(); long frameTime = (long)(FPS/1e9); while(true) { long now = System.nanoTime(); long deltaTime = now - lastTime; lastTime += frameTime; gameUpdate(deltaTime); .... }
public void gameUpdate(deltaTime) { speed += accelPerSecond * deltaTime / 1e9; playerPos.x += (speed * deltaTime / 1e9) * Math.cos(direction); playerPos.y += (speed * deltaTime / 1e9) * Math.sin(direction); } |
Setting a minimum of 10 milliseconds is also not good because if the game loop is late and needs to catch up, it will never be able to. Don't set a minimum at all. Calling repaint() every frame and letting another thread to draw the screen is called passive rendering. The best way to render is active rendering. This is where you call paint in your game loop. There are schools of thought that disagree with everything (except the sleep daemon Thread to force high precision timer) you've said there  It depends upon what you are doing as to the best approach.
|
|
|
|
|
29
|
Game Development / Game Mechanics / Re: Circle collision response
|
on: 2011-12-19 15:18:39
|
|
Last time I approached this problem, I made it so only 1 collision could occur per iteration by reducing the delta t of the timestep to equal the earliest collision that frame & resolved the collision. I then continued the remainder of the frame as a new iteration (which might again be subdivided if further collisions are detected).
Thinking about it, there was a flaw in my implementation - I only ever calculated the collision response with two actors; when three or more actors intersected each other at precisely the same time there was a potencial it'd screw up. Not an insurmountable problem, it'd just have made my collision response calculation a bit more complicated.
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|