Sup /prog/
I've been working on and off on a simple RPG game in Java (as that was the language I was learning at school when I started). By simple, I mean that so far it lacks any sort of "cut scene" support. There are quests (but no pretty way of introducing them), map switches, levelling up, character classes, but no cut scenes (and of course no physics simulation since it's just a little RPG game). Anyway.
The non-graphical stuff was fun and easy, as was making the actual graphics, but integrating the images into the game has proved a pain in the ass. I pulled it off, but this required making the game an applet and redrawing that applet either at timed intervals or when an action was performed, depending on what was going on (intervals when walking on the overworld map, on action when in battle). Animations are also a major pain. ideally I would simply load the various frames of every animation into arrays and loop through them when I need to, but this would require timed refreshing which hasn't been working for me (honestly I don't even know why, it seems to be random, as if JRE just has bad days sometimes).
So basically, what do I do, /prog/, what do I do? How do I make the damn thing refresh every 10ms or so regardless of what's going on (the navigation and battling are done by different classes with very different thread managing, but I want them to have identical functions for that, or better yet, a timer that refreshes the applet independently of the current JFrame that is active)?
Heck, even better, I'd rather write this without the use of applets. I don't care if it means rewriting everything graphics-related. Making it without applets was my original intent, but I simply had no idea where to start. I still don't. Any tips? I tried googling for ways to deal with graphics without the use of applets, but failed. I'd prefer to do this in Java or C, though the former is more familiar to me (I do intend to learn C properly, just not this year, thanks to college).
>>2
Looks like the second one is about applets, but you can combine the two and you'll know what's up.
Name:
Anonymous2007-10-28 17:19
I was just on that second site, but didn't see the article. Part I is a little too basic, but parts II and III might be useful (don't have the time to read them right now, sadly).
Thanks for these. The 10ms thing was a typo, I meant 100. 10fps would be fine for this, since I don't want the characters walking any faster than that anyway. Oh, speaking of moving... is there a way to limit the amount of times the directional buttons are reacted to? That is, if you press the Left button every 10ms (just pretend you're some crazy fast motehrfucker), it would only actually move the character left every 10th press. Threads don't actually stop the ActionListeners (unless they can and I don't know about it, which is entirely possible), so if I have a low framerate and press a directional key lots of times, by the next refresh, the character will simply be a bunch of tiles away.
Run this code in a thread: while (gameRunning()) {
handleInput();
updateState();
redraw();
sleep(100);
}
In the ActionListeners don't handle the events, but instead set a flag that a key was pressed or add the events to some list, then in the handleInput() function you process the events.
Name:
Anonymous2007-10-28 18:10
>>4
It sounds like you either want to poll the key somewhere during your main loop or listen for keydown/up events rather than paying attention to what letters would by typed by that series of keypresses. I've forgotten Java, so I can't help you with the specifics.
The thread from today, asking about help with Java, with helpful replies...
What the fuck? Did I accidentally go to GameDev? No, the location bar says /prog/...
What the fuck.
SUSSMAN JAVA SUCKS MY OTHER CAR IS A CDR READ SICP TUNE FISHES WOKON BBCODE
There, that's more like it.
Name:
Anonymous2007-10-28 20:05
>>9
When I see questions begging to be answered
I can't stop myself
I can't stop myself!
I guess I just lost it when I saw a question that was written coherently and actually included enough relevant information to be answered.
Name:
Anonymous2007-10-28 20:09
>>9
I actually invented the ``you can't tune a fish'' meme
Name:
Anonymous2007-10-28 23:43
Just use a game library. That is, if you want to actually finish a game, and not just spend the next 5 years fucking around with tons of little GUI event methods.
Name:
Anonymous2007-10-29 0:12
>>12
This is true. If you want to make a game then writing the engine yourself is misguided and writing the library yourself is nuts. It can be fun though.
Name:
Anonymous2007-10-29 4:46
Stop having a coherent debate at my /prog/ >:(
Name:
Anonymous2007-10-29 6:37
>>12,13
Seriously, I cringe all the time whenever people ask to do x, y or z for their game. I recommend some gpl game that is perfect for their requirements but they go wahhhhhhhhhh i dun wana do open sores
Name:
Anonymous2007-10-29 7:07
>>15
It's worth keeping in mind that this is /prog/ though. It's possible that someone who actually wants to learn to program games for the sake of it (rather than just to make their shitty design a reality) might come here.
Name:
Anonymous2007-10-29 7:45
OP here. This game is a programming exercise for me rather than "trying to make my shitty design a reality." If I just wanted to get this thing done without caring how, I'd just make it in flash or some pre-made thing... or I'd leave it the way it is (except add cutscenes), since it looks cute and it actually fun to play. I would however, like to make it better, because I think it would help me in the future to know this stuff.
>>6
Thanks for the tip for not handling the actions in the listener. I'll try it this evening when I get home.
>>12 >>13
I realized that doing this was scratch (aside from standard Java libraries, of course) was a bad idea a few hours into starting the coding, and this was a year and a half ago (a very on-and-off project, it started as my final for 11th grade programming, a better version served as my final for 12th grade programming, and now I'm trying to get back to working on it for fun in my spare time). Since I'm not going for a commercial, polished game here, I don't mind spending the extra time doing it from scratch.
I'll probably keep it as an applet to keep it simple, at least until the game is finished (and then I can think about ports, even though it's more work in the end), and so far the actual input handling hasn't been a problem at all, and really all of my current problems stem from two things. The drawing of images (which I think I can fix, it was bad writing on my part), and a few minor errors in processing the user's in-game actions (like whether they are done targetting a monster or not, I need to go through the code, comment the hell out of it, and find where the little mistakes are, debugging this has been a pain since I have a very hard time replicating the errors).
Thanks for your help guys. Honestly, this was much more than I expected from /prog/ because it's been... shitty lately (I don't normally post, but I do lurk occasionally). Actual good tips from /prog/? Whoa.
Name:
Anonymous2007-10-29 9:57
>>17
Don't forget to post us all a link to your game when it's done, for beater testing and so on.
Name:
Anonymous2007-10-29 10:43
>>18
Sure. If you don't mind waiting about five years. I only have maybe an hour or two every month to work on this. ...and usually I waste those hours on playing this game instead of working on it.
Name:
Anonymous2007-10-29 12:39
It is pretty obvious you fail to do any necessary abstraction. Think about how you want to use it and then mold it to your requirements. Stop being a fucking baby stuck in implementation. This is an abstract machine you can do just about anything with as long as you give up this stupidity.
Graphics should be running in a separate thread. It should redraw the screen endlessly. This ensures that the game doesn't slow down when graphics slows down, and this is how FPS will make sense.
You can stop this thread when your engine does the necessary calculations, and restart it afterwards.
Use double buffering.
You should use Directx instead of the java drawing functions, it's MUCH faster.
Name:
Anonymous2007-10-31 13:23
>>29 You should use Directx instead of the java drawing functions, it's MUCH faster.
Yeah, more FPS are totally going to make his RPG better. And it's a good thing DirectX is portable if he ever wants to run it under another OS!