Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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] 2 3 ... 14
1  Game Development / Newbie & Debugging Questions / Re: Alt-f4 close with multiple threads on: 2013-02-11 23:26:42
Alt-f4 sends a close request message to the active window. That is handled by the operating system. The program that owns that window can ignore the message, close the window, ask the user if they really want to close something, or do something else entirely. Then the program has to clean things up behind the scenes even if the window disappears. So obviously alt-f4 cannot do anything disruptive on its own or automatically do anything.
2  Java Game APIs & Engines / Java 2D / Re: Canvas-based GUI on: 2013-02-09 22:58:20
On screen buttons is just a matter of testing to see if a mouse click event occurred inside a rectangle. If buttons can overlap, you need to define a z-order of each button and activate the closest one only. Keyboard input may as well be done exactly how AWT/Swing does it. Make sure you understand the difference between keyPressed/keyReleased events and keyTyped events. They are defined in the same interface, but have very different purposes.

If you use event listeners do not confuse the callback method for the action it is supposed to trigger. Mixing game logic with UI logic creates a mess and means you have to rewrite lots of code if you want to keep the same functionality but map it to a different input or sequence of inputs.

It's absolutely a good idea to split up a basic listener interface with individual "events". [But] a lot of people make the mistake of doing things like creating a public save() method of their component class instead of a protected saveButtonPressed() and a public saveProject() method in another class.
3  Discussions / General Discussions / Re: Java 7.10 Plugin blocked on Mac on: 2013-02-09 21:32:00
Search engines of all brands have gotten worse because they are allowed to do more nefarious things. It is an illusion that they are constantly improving their secret algorithms. The internet has just gotten bigger.

You can find what you're looking for because someone already thought of it and human web crawlers already did most of the work of indexing and judging the quality of web pages. Google actually goes out of its way to show you worse results for the purpose of making their side projects and partners more profitable but the average user does not notice because a crowd sourced website like Wikipedia, Stack Overflow, Youtube, or Yahoo Answers gives you a near word for word match when you type something in. If you take away those types of sites, the rest of Google's results are just ads. (That is, they privilege sites that have Google ads or work with Google and their algorithm is easily gamed by retail companies, so that most of the links are garbage unless you can find a good blog post buried in there.)
4  Discussions / General Discussions / Re: Why java over other languages? on: 2013-02-09 21:14:24
That is a good point. Maybe Oracle should be ditched. Smiley Of course, backwards compatibility is only helpful in the short run. C++11 is backwards compatible with B by virtue of being backwards compatible with C++ being backwards compatible with non-standard C++ being backwards compatible with C being being backwards compatible with pre-standardized-C being backwards compatible with B. Some backwards compatibility issues of Java are hurting us now and others may hurt us in the long term.

OpenGL is a little different, you need different hardware if you want to code in one or the other and need to code in whichever one your hardware supports. Java would not have that problem, since its syntax is sane and well structured enough that updating code would not be as insane as attempting to fix C code. And you could run both on the same computer or the same VM.

I usually think of a language as being a tool. It's okay to have more than one tool in a toolbox. I think that I would rather use multiple languages in the same project (for example, Java + OpenGL shaders, or C + SQL, or Java + ANTLR) instead of integrating junk that hinders efficiency just in case you need a hammer that can also file your taxes. Community is something I hadn't considered. Do you think it is worse to have language diversity (for lack of a better/neutral Sad term) or to have internal fragmentation like C++ is infamous for?
5  Game Development / Shared Code / Re: Instantiating Generic Arrays on: 2013-02-09 20:31:39
I am aware of the technical correctness but logical absurdity. Smiley (Technically I said type declarations and I would argue the definition of type.) I do not agree that assembly or dynamic languages or C take away the need of certain language features.

Dynamic languages and assembly language share something in common. They are perfectly fine if you develop code by entering one key at a time from start to finish with no breaks and no mistakes, but if you ever want to rewrite portions of the program, port it to a different platform, incorporate another person's code, or happen to be a mortal, then their practical utility is greatly diminished.
6  Discussions / General Discussions / Re: Why java over other languages? on: 2013-02-09 19:57:43
As for Java 2.x, I really just don't see that happening.  The only thing likely to break backward compatibility is going to be a whole new language, and I'm afraid that's likely to be some form of Javascript Tongue

Let it break backwards compatibility! It is a curse not a blessing. The mindset that languages must grow while maintaining source level backwards compatibility is ridiculous. It is not as if compilers for the old language versions disappear or that you could not write tools to at least partially automate conversion. On the other hand, if you have an ever growing "standard" language definition, you will not only have a poorly designed ad hoc language (like C++) but you will have a single de facto "official" compiler with lots of bloat and corporate lock in. (Think of Oracle's Hotspot being so irreplaceable and the battle of industry titans to prevent write once compile anywhere become a reality for anything besides their own basically proprietary technologies. (Flash, ObjectiveC, HTML5, C#.)) New changes involve making code harder for humans and computers to read. The alternative is to make language changes that can express programmer intent better, so code is still easy for humans to read (even if it is now only marginally harder to write the first time) and easy for the compiler to optimize (even if you had to add extra reserved words.)

So instead of having stateless types with static methods to mirror classes and interfaces, you get lambdas. Instead of structs, you get escape analysis (which is great, but would be expected even if the language had structs.) Instead of improving Generics, you get type inference. All these things make Java more complicated and make alternative runtime implementations harder. It is irritating that de facto standard makers waste their time pursuing half baked improvements when the same amount of time invested in improving the language's old features would solve the same problems in a straightforward way.

I agree with the sentiment that Java should not look like Javascript, but make super paranoid assumptions about the direction of Java and incompetence of Oracle. Could Java 1.X (as X approaches infinity) turn into that very same language? Wouldn't it be worse if Java gave you no option because there was never a fork?

Ideally Java 2.X would look like Java 1.7 without the mistakes and annoyances that are obviously undesirable in hindsight and less like Java 1.∞. Java 2.X could feature conservative changes to the language and major changes to the standard API. Java 1.∞ with it's abhorrent mix of C#, Python, Javascript, and other nightmares could be developed as a new JVM language with a new name. (Hey, that's a good idea!)
7  Game Development / Shared Code / Re: Instantiating Generic Arrays on: 2013-02-09 18:38:56
I actually like type erasure. Compared to how C# handles generics.

What is the benefit of type erasure? Would someone designing a language from scratch decide to include it? I thought it was just a hack to maintain backwards compatibility.

Dynamic languages at run time do not need templates.  Everything is an Object.  Templates for Dynamic languages are for noobs.

Machine code does not need types. Everything is a byte. Type declarations and variable declarations are for noobs.
8  Discussions / General Discussions / Re: Java 7.10 Plugin blocked on Mac on: 2013-02-09 17:29:42
Of course people used Ask. Back when Google was a terrible search engine with no influence in the ad market it was one of the best for a while. Now that Google is a terrible search engine that is omnipresent in the ad market, "competitors" end up doing things almost as shady as what Google does.

Speaking of plugins and search engines. I remember updating Flash once and being bestowed with a Google toolbar despite unchecking the box for it.
9  Discussions / General Discussions / Re: raytracing idea: might it work? on: 2013-02-04 03:37:28
Can you draw a diagram? What's the problem with per pixel?
10  Discussions / General Discussions / Re: New feature: appreciation results in post medals on: 2013-02-04 03:33:27
I wonder if you're confused about the time or number of posts I made. I habitually check the tooltips for my own awarded medals and other people's just to see who's given them so far, so I am pretty sure it worked last week. Six sounds high. I think I made 4 awards plus 1 more in another post. Did you delete my first five and mistake another person for me after that? I definitely noticed the changes at different times. I assumed you were making website feature changes when the link disappeared and was too intimidated to point such things out anymore.

How long did coding for the exception take versus coding for prevention of multiple medals? Isn't there a insert unique command in SQL?
11  Discussions / General Discussions / Re: Why java over other languages? on: 2013-02-04 03:13:22
boolean test(T t);
T get();
void accept(T t);
R apply(T t);
void apply(Collector<U> collector, T element);
T operate(T left, T right);

This is not normal Java. I remember reading that the exclusion of a Pair<A, B> class as in STL was deliberate. There is a Point class because it it is preferable to Pair<int, int> because the latter obfuscates meaning. The same was said to apply to methods. Even though you could make a generic Pair, Triple, Etc. or an interface with a generic public void method(A a, B, b) header, people advised others not to. I suspect duck typing will be the next addition because it's been hyped on C# blogs. Obfuscation is the main problem. The other is that a syntax sugar arms race that makes the language bloated. (Not that there isn't a need for certain new features.) Syntax should be simple and semantics should be obvious and accurate.

I worry we will see indefinite hacks and new Java 1.X versions. Java suffers from backwards compatibility like most languages. (C++ being most extreme.) It would be interesting if Java 2.X chose to re-implement features with a smaller but more powerful feature set overall. (And new API to take advantage of extra power.)
12  Discussions / General Discussions / Re: Why java over other languages? on: 2013-02-04 02:34:09
I am not a fan of function pointers, first class functions, or anything similar. For object methods, the exclusive use of interfaces is superior to what other languages do. It would be nice if the language supported interfaces with static functions defined in a different class. "Class" for lack of a better term. The benefit would be for stateless functions where there is no need to create new objects. Comparator objects for example usually doesn't benefit from having a state.

Maybe syntax like this could work.

Class<Comparator2<String>> c = String.Comparator.class; // No Object created
int i ="A", "B");

There are benefits, but I don't like exotic solutions. (Based on unrelated languages.) Time invested in making Java more like super theoretical hypothetical academic languages or a scripting language instead of trying to compete with C, C++, and C# bothers me. (When will structs be added?)
13  Discussions / General Discussions / Re: New feature: appreciation results in post medals on: 2013-02-04 02:16:09
He removed those medals a few days after the fact; and, that was that. I made my point with awarding Riven's post medals. I don't plan to award spam medals and still think that less is more with respect to recognition.

He removed my own medals and ability to award them very recently. Given what Riven has said about coding new website features and his hesitation to use heavy handed moderation and the fact that me awarding Riven too many medals is in the past, it seems like I was targeted. My last awarded meda (I think. I only vaguely remember.) was to another member's joke. Maybe it was something that could have been misconstrued as an insult to Riven. Or admin or anyone in power.

This decision seems unreasonable and unprecedented. I got the the message earlier when all my medals in that topic were removed (even to members that deserved medals.) I suspect there is a different subtext now with a message directed towards me. I want to know what it is or what happened if it was a misunderstanding.
14  Discussions / General Discussions / Re: New feature: appreciation results in post medals on: 2013-02-03 22:42:59
"Intended" being an unwritten rule with a precedent that suggests there is no rule in effect? I see plenty of people award frivolous medals, you said the thread (and thus medals) would disappear, and you waited until three weeks after the fact.

Is that the reason, or did something come up later that made you act on that, or was I guilty of something before that time that you still are not happy about that warrants belittling responses if you are courteous enough to respond to me?
15  Discussions / General Discussions / Re: New feature: appreciation results in post medals on: 2013-02-03 21:54:08
I would have appreciated a warning. You mean for the three week old incident where you wrote this?

This thread is hopeless either way. Eventually it will most likely be crushed by the jaws of the chitchat monster.
16  Discussions / General Discussions / Re: New feature: appreciation results in post medals on: 2013-02-03 04:33:11
I would appreciate if someone told me what my medal count was. The link has disappeared for me.
17  Game Development / Newbie & Debugging Questions / Re: Gradually slow an images movement. on: 2013-02-03 04:12:16
Uh. That's kind of bad practice. You should base your game mechanics on physics.

An object in motion stays in motion (Okay. It's already moving so I should not change an objects velocity.) unless acted upon by an outside force. (Okay. Friction is a force. I will use that.)

There are two types of friction. If you only care about coasting when the arrow key is released, then you only need to worry about kinetic friction. If you're moving across a solid surface, then friction is proportional to your speed. f = -k * x' = -k * v = -kinetic_friction_coefficient * speed. Force increases or (in this case) decreases speed in a given direction over time. So you just subtract more or less from the speed depending on the friction, which depends on the speed you are traveling.

if(right && !left)
  vx = 5;
else if(left && !right)
  vx = -5;
  vx -= 0.5 * vx;
x += vx;

If you wanted acceleration when the key is pressed, you would use vx += something instead of vx = something.

Changing k changes how slippery the surface is. A value of zero is frictionless, so you never lose speed. A value of 1 makes you stop instantaneously.
18  Discussions / General Discussions / Re: Screenshot Saturday on a Sunday on: 2013-02-03 00:09:33

I wanted to make a game involving a penguin. The penguin follows the mouse. I had a few ideas, but I think my interest in having the penguin element in game overrode my other decision making process for the game. I had the idea of pushing snowballs or other penguins around, but nothing specific.
19  Discussions / General Discussions / Re: Gaming contests for people under 18? on: 2013-02-02 22:53:01
That is only true for two player sports and board games. It's no fun to lose by sixty points, but such a situation occurs because the skill diference makes it easier to score 60 points. Contrast that with golf. The only theoretical limitation to contest entry is a minimum skill level. Another golfer's score does not change your own. I can think of a few titles of TV shows involving geeky contests with contestants age 10 to 80. They welcome anyone because the niche community is so small that they can't turn people away based on experience and they can't differentiate between ages because a 15 year old may just as likely have as much experience in medieval weaponry as a 40 year old.

"Large Dangerous Rockets" Exactly what it sounds like. (Separated by rocket fuel grade.)
"Chunkin Pumpkins" Launching pumpkins from trebuchets and cannons. (Separate by launching mechanism.)
"Kill Robots" Remote control robot contest involving flame throws, spikes, and saws. (Only one class; multiple contests. Many other robot related contests involve people of all ages.)
"Anvil Launching" People pack enough gun powder between two anvils to launch one of them a mile into the air and compete to see who can get the highest launch. (Separated into anvil weight classes.)
20  Game Development / Game Mechanics / Re: Tips for making underground caves, buildings? on: 2013-02-02 22:23:51
Search the following:

"Random cave generation"
"Procedurally generated cave"
"Random room generation"
"Procedurally generated rooms"
21  Games Center / 4K Game Competition - 2013 / Re: Rainbow Road on: 2013-02-02 18:26:40
Triple red shells work, but the green ones disappeared the first time I hit C. I first thought you gave items to any carts that passed a line of item boxes because I seemed to get them even when I obviously missed. Later the opposite occurred. Huh
22  Games Center / 4K Game Competition - 2013 / Re: 4096 B.C. on: 2013-02-02 01:25:42
You probably have noticed already, but when you get too close to a wall the graphics stretch out horizontally. Bullets fired at certain angles sometimes go through walls.
23  Games Center / 4K Game Competition - 2013 / Re: Legend of the package delivering hero on: 2013-02-02 01:07:03
The directions refer to shooting an enemy. You can only avoid things in the game though, right?
I like the background. The pink cloud looks a little to square.
24  Discussions / General Discussions / Re: Java 7.10 Plugin blocked on Mac on: 2013-02-01 23:25:51
@princec Bank security is actually pretty terrible. When it is the banks fault, they often put money back in the effected individuals' accounts without telling them the were a victim of hacking or social engineering. They prefer to keep customers in the dark because replacing the damages is more profitable than preventing them.

@Mads They should open source the software so that people do not need to run it in a browser.

@ Alan_W But Apple is so secure! Why would a computer with the same security mechanisms (or worse) of Windows and Linux and featuring such stylish rounded corners ever have to worry about malware?

I think a browser distributor has the "right" to choose not to load third party software; assuming the benevolence of the distributor. Web browser distributors do have agendas, though, and since Apple bundles it's web browser with its operating system there is even more reason to distrust their choices. Ideally they would temporarily disable something without breaking its functionality and explaining the situation in an unbiased and informative way.
25  Game Development / Shared Code / Re: How to Organize Event Listeners on: 2013-02-01 22:35:02
Good point. Action listeners are strange... Stare

I still like encapsulating UI input state in its own class/object. I like to think of the listener class as a plugin, so that even if I only write one, the user interface code can be written independently from the rendering and functional methods of the main class. This might be useful, for example, if you started with a applet supporting two button computers but later decide you want to expand the project to support touch screens. If you mixed the functionality of the two classes, you would have to rewrite most of your class and then you may need multiple versions of the same methods or similar variables. Noobs to that type of UI programming, including myself at one time, end up writing terrifying spaghetti code. When I don't need two implementations, it is still helpful in case I ever make a mistake that requires reworking part of the class and because I can write a crude interface using the easiest methods for quick testing and replace the listener/state-handler later with a more polished one.

It's absolutely a good idea to split up a basic listener interface with individual "events". A lot of people make the mistake of doing things like creating a public save() method of their component class instead of a protected saveButtonPressed() and a public saveProject() method in another class. You can use both methods, so I would not call it a fifth method. Smiley
26  Discussions / General Discussions / Re: Why java over other languages? on: 2013-02-01 05:37:15
A wild ThisLanguageUsesTheWrongAssignmentSymbol appeared. Fight, Switch, Item, or Run?
27  Game Development / Shared Code / Re: How to Organize Event Listeners on: 2013-02-01 05:26:44
... Yes? Java 2D requires an object implementing a listener interface. The fact that addMouseListener expects a custom implementation of a MouseListener interface means you will indeed have a class designed to handle input that implements stuff to do whatever you want.

The question is where you create that class. Do you want it in the same file or a separate file? If it is an inner class, do you want it to be static or non-static? Do you want an anonymous or general purpose class?

If you mean the mega input classes that noobs inevitably create to centralize input processing or emulate polling, then it depends on the situation. If your requirements are so simple that you can use polling exclusively, then you can use a centralized class. If you're creating a game with multiple types (uses) of input, then you will want a modular set up. Your input class or its clients would turn into a giant mess if you had to manage the state of every aspect of your UI in one object. It's the Java equivalent to a C programmer overusing global variables. Things would easily break if they were changed and it would be hard to read if you could not isolate the code relevant to what you were looking to read.

I presume the reader requires the use of a callback based interface in a library such as, but not necessarily, Java2D. And if not, it is still helpful for people that would not consider different styles of programming because they only know how to handle things like listeners using hacks. It is also good advice to Java programmers in general. (I write a lot of applets and desktop applications. I also use them to prototype physics simulations, algorithms, and control systems for games. Adapting between different styles of user interface libraries does not cost me any time.) I don't advocate or care if someone uses Java2D and this may be irrelevant to LWJGL users, but it would be better if people could use this as a reference or template.

It is embarrassing to be a Java programmer whenever someone releases source code with hacks to get listeners working.
Or, makes a terrible UI because the programmer spent too much time writing disorganized Swing code.
Or, reinvents the wheel be making their own input handling classes.
Or, complains about the problem of using ugly anonymous classes.
Or, says that Java needs duck typing or first class functions.
Or, says that Java projects have more source code files than other projects. (A myth true for C++ but not Java, contrary to popular misconception.)

For some reason, I do not see many other people store anonymous classes directly in fields or using the same layout as normal classes. They always stick them in local variables or directly in function parameters. It's one of the tricks I learned that probably is not standard Java practices but really improves your productivity. It also addresses one of the persistent criticisms/myths of Java that JDK programmers try to solve with language modifications based on truly bad programming languages.
28  Discussions / General Discussions / Re: Why java over other languages? on: 2013-02-01 00:26:02
So if the goal is to be able to write code that clearly shows developer intent and you knew for a fact that the following pieces of code produce the same bytecode:

// Without lambdas
button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    System.out.println("Button pressed: " + e);

// With lambdas
button.addActionListener(e -> System.out.println("Button pressed: " + e));

Which one would you prefer*?

The first is easier to read. If you're trained to recognize indents you can "read" it in one glance. For the second one, I have to scan the screen horizontally and let my eyes stop in 3 places. It would be worse with more than one line. Both are poor choices. The reason I use Java is because I can determine the function of a block of code in one second just be looking at the structure or quickly scanning over it and can hunt down the code I am looking for in two seconds. Defining event listener methods in the same place they're used means that, if I am looking for the initialization, I have to find it between irrelevant code for various event listener methods or, if I am looking for the implementation of the methods, I have to find it between irrelevant code in some constructor or initializer function.

Here is an alternative that is much easier to read.
29  Game Development / Shared Code / How to Organize Event Listeners on: 2013-02-01 00:11:16
I think a lot of people probably have trouble writing event listener code. It is awkward and error prone for new Java users. Here's how I deal with event listeners and other single purpose anonymous classes. Notice that the object/anonymous class looks a lot like a nested class. The code to attach the event listener is in the object's constructor and the code that defines the listener is in its own function. (This code is based on a file from a non-game project using Swing.)

I can think of four alternatives:
1) Make your class implement a listener interface and attach it by passing this as a parameter. -- This has the downside that you can only use one instance of a given listener type and that your event listener interface is exposed as public.
2) Use an inner class and create a new one the first time you use it. -- This code is essentially the same, but it is a little easier to use. You could attach or remove listeners if you had to. The addListener code is more concise and readable. It is the same number of lines or one fewer.
3) Declare your class in the same place as you first use it. -- It's harder to find the relevant code and is more difficult to read once you find it.
4) Use lambdas, anonymous functions, or other magic imported from scripting languages. -- Nope. It involves fewer characters, which is no practical benefit, but it is as bad as #3.

This method is easy to use. Takes only a few characters with the use of autocompletetion and could easily be made a code template. It is extremely readable and is consistent with Java's type system and its practical features. It is very easy to find the relevant code if you're used to the practice and can be found easier with IDE tools. The nested usage and scoping makes it easy to define methods and variables consistent with good object oriented programming practices. Using adapter classes instead of interfaces is helpful while developing since you can add functionality later without adding empty methods. (Use IDE code completion again to make that task even faster.)

public GridThingy extends JWhatever
  public GridThingy()
  public int yToRow()
    // Convert y position to row number
  public Object setValue(int row, Object value)
    // Set row data
  public void clearValue(int row)
    // Clear row data
   * Other methods ...

  private final MouseAdapter ml = new MouseAdapter()
    private final long doubleClickTime = 600;
    private long clickTime = System.currentTimeMillis() - doubleClickTime;

    @Override public void mouseClicked(MouseEvent e)
      long time = System.currentTimeMillis();
      int x = e.getX(), y = e.getY();
      boolean dbl = time - clickTime < doubleClickTime;
      clickTime = time;

      if(dbl && e.getButton() == MouseEvent.BUTTON1 && /* Omitted */ )
        int row = yToRow(y);
        Object o = promptValue(row);
        if(o != null) setValue(row, o);
      if(e.getButton() == MouseEvent.BUTTON3)

    @Override public void mouseMoved(MouseEvent e)

It looks a lot better than the alternatives, doesn't it?
30  Discussions / General Discussions / Re: Gaming contests for people under 18? on: 2013-01-31 22:42:53
In light of ra4king's relative seniority I propose the age restriction be lowered to < 17.5
Pages: [1] 2 3 ... 14
ivj94 (579 views)
2018-03-24 14:47:39

ivj94 (43 views)
2018-03-24 14:46:31

ivj94 (362 views)
2018-03-24 14:43:53

Solater (59 views)
2018-03-17 05:04:08

nelsongames (104 views)
2018-03-05 17:56:34

Gornova (138 views)
2018-03-02 22:15:33

buddyBro (681 views)
2018-02-28 16:59:18

buddyBro (89 views)
2018-02-28 16:45:17

xxMrPHDxx (491 views)
2017-12-31 17:17:51

xxMrPHDxx (727 views)
2017-12-31 17:15:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
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!