Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Writing games with graphics

Name: Anonymous 2007-10-28 16:52

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).

Sorry for the length.

Name: Anonymous 2007-10-28 17:09

Well, you probably don't need 100 fps for this.

Also go to
http://java.sun.com/developer/onlineTraining/GUI/
and read about making GUI apps.

Then go here?
http://www.gamedev.net/reference/articles/article1262.asp

Name: Anonymous 2007-10-28 17:10

>>2
Looks like the second one is about applets, but you can combine the two and you'll know what's up.

Name: Anonymous 2007-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.

Name: Anonymous 2007-10-28 17:39

>>4
Forget it; it's NP complete.

Name: Anonymous 2007-10-28 17:41

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: Anonymous 2007-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.

Name: Anonymous 2007-10-28 18:11

>>7
So, what >>6 said, basically.

Name: Anonymous 2007-10-28 18:33

Good job bumping a thread from 2005, guys.

Wait... the thread is from today...

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: Anonymous 2007-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: Anonymous 2007-10-28 20:09

>>9
I actually invented the ``you can't tune a fish'' meme

Name: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-10-29 4:46

Stop having a coherent debate at my /prog/ >:(

Name: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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.

Name: Anonymous 2007-10-29 13:39

>>20
Expert Enterprise-grade Turnkey Solution Provider.

Name: Anonymous 2007-10-29 17:56

You could've done this game in 3 lines in LISP.

Name: Anonymous 2007-10-29 17:59

>>22

(loop
   (eval
     (read)))

Name: Anonymous 2007-10-29 18:37

>>23
You forgot print

Name: Anonymous 2007-10-29 19:33

>>24
Expert programmers don't need print, they visualize the output in their heads.

Name: Anonymous 2007-10-29 22:48

>>1
I've been working on and off on a simple RPG game in Java...

well THERES your problem.

Name: Anonymous 2007-10-30 7:54


(loop
    (print
        (eval
            (read))))

Name: Anonymous 2007-10-30 8:47

>>27
four lines. fail.

Name: Anonymous 2007-10-31 13:17

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: Anonymous 2007-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!

Name: Anonymous 2007-10-31 13:24

>>30
Don't anger the OMG OPTIMIZED guy.

Name: Anonymous 2007-10-31 13:44

>>31
Why is he advocating DirectX, then? Shouldn't be be running Gentoo?

Name: Anonymous 2007-10-31 13:49

>>32
No, no. You see, he's also a faggot.

Name: Anonymous 2007-10-31 13:53

C with SDL is about a million times more portable than Java.

Shit, even Haskell with wxwindows and GLUT is more potable than Java.

Name: Anonymous 2007-10-31 14:01

>>34
Shit, even Haskell with wxwindows and GLUT is more potable than Java.
Too bad wxhaskell is practically completely broken on Fag OS X.

Name: Anonymous 2007-10-31 14:30

>>34 Shit, even Haskell with wxwindows and GLUT is more potable than Java.
Yeah, you don't even have to boil it first.

Name: Anonymous 2007-10-31 14:50

>>35

But then again, so is Java nowadays. Also, no one gives a shit anyway.

Name: Anonymous 2007-10-31 17:07

>>1
brain atrophy ?

Name: Anonymous 2007-10-31 17:40

>>22-38
Thanks guys, you saved this thread.

Name: Anonymous 2007-10-31 19:29

try an open source engine like ogre or irrlicht ( for eas of use you shouild prefer irrlicht ;)

Name: Anonymous 2007-10-31 20:00

>>40
Because 3D IS THE WAY FORWARD IF YOU MAKE A 2D GAME YOU ARE PART OF THE PROBLEM NOT OF THE GLORIOUS SOLUTION IN THE 22ND CENTURY ALL GAMES WILL BE 4D

NO EXCEPTIONS

Name: Anonymous 2007-10-31 20:11

double buffering or triple buffering for applets.

Name: Anonymous 2007-11-01 7:35

>>41
Because 2D IS THE WAY FORWARD IF YOU MAKE A 3D GAME YOU ARE PART OF THE PROBLEM NOT OF THE GLORIOUS SOLUTION IN THE 22ND CENTURY ALL GAMES WILL BE 1D

NO EXCEPTIONS

Name: Anonymous 2007-11-01 7:53

>>41
SOUNDS LIKE WE NEED SOME ℝ5 VECTOR SPACE

Name: Anonymous 2007-11-01 7:57

>>44
Didn't you post that in the other thread? Sounds like a forced meme to me. But you can't tuna fish

Name: Anonymous 2007-11-01 8:42

>>1
OP, remember that you may also need double-buffering to synch your graphics properly on the screen and make the animation fluid, when the game is ready.

I used to code in BASIC and the screen always flashed when things got big or moved fast. This is from the days of 20MHZ PC's. As PC's got more powerful and I could see simple games doing tons more stuff than my BASIC did, without flickering, I thought it was just my OS sucking. Then, I started seeing BASIC programs with built-in buffering (using WAIT and esoteric peeks and pokes, I think) and realized it was my fault all along.

In any case, SDL has been mentioned. Allegro will be mentioned (I remember it was real simple and unintrusive) but I only used it from DOS + RHIDE under win98. Luck to you

Name: Alabama !0okrDnkUYI 2007-11-01 10:07

Low-level for the hell of it, huh?
opengl.org has some simple examples for rendering, texture mapping, and animation. (SDL uses Opengl for graphics.)
And mingw comes with opengl headers.

http://www.opengl.org/code/category/C22
   http://www.opengl.org/resources/code/samples/simple/
   http://www.opengl.org/resources/code/samples/more_samples/
  
  

Name: Anonymous 2009-03-06 10:50

Part of my job   Reading SICP all   over the place   was deserted except   for me and   other functional languages   also promote the   seperation of concerns   Does it allow   for a system   where you get   back to your   ROOM YOUNG MAN   or you will   almost never be   able to experience.

Name: Anonymous 2009-03-06 12:22

Properly you should choose your operators properly   and if none   fit use a   more expressive language   which has support   for MANY different   ways but this   GOTOGOTO needs not   only a label   at the same   function with no   meaning when talking   about text editors   BTW what are   Friends Are they   so important i?

Don't change these.
Name: Email:
Entire Thread Thread List