Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (702)
Games in Android Showcase (203)
games submitted by our members
Games in WIP (774)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Game design  (Read 1437 times)
0 Members and 1 Guest are viewing this topic.
Offline _Al3x

Senior Devvie

Medals: 7

Indie Games FTW!

« Posted 2012-03-18 14:35:18 »

Hello everyone! I'm here once again to ask you something!    Roll Eyes

I'm going to try to implement ALL the things you guys been suggesting me. Starting from GAME STATES.

So I took what ra4king and zngga told me here and try to implement it.

This is what I have so far.

|- engine
||- GameEngine: Creates a JFrame and adds a canvas in it. Has the main loop |(while (isRunning)), inside it, there's the time handling, the update and the |render methods.
|- entities
||- Entity: Base class for every object.
||- All other entities that extends Entity.
|- main
||- Main: A simple main method that turns on the GameEngine and runs the |run() method.
|- states
||- ScreenState: Base class for evey state in the game, has update(), ||render(), enterState(), leaveState() and mouse and keyboard handling.
||- Other states are GameMapViewState, GameMenuState and GamePlayState

Is this ok? Am I on the right track?
How do I implement the KeyInputHandler? And if I want to add a mouse input handler?

Things to do:
- Change between states (100%)
- Support mouse and keyboard input (100%)
- Fix time managment (ticks, fps, anything else) (70%)
- Add animation (0%)
- Support spritesheets (0%)
- Add sounds & music (10%)
- Separate core engine from game engine (45%)

Edit: 6/4/12: Modified the OP to add TODO things and made the "design tree"
Edit: 9/4/12: Added things to the TODO list, plus % done and colors Smiley

Offline 65K
« Reply #1 - Posted 2012-03-18 17:31:24 »

Two points from me:
- sleep(10) is not that good (precision is platform dependent, not reliable). I think there is a verbose thread somewhere here about timing
- I wouldn't expose attributes of class Entity as public attributes

Mouse and keyboard input ?
Just call addMouseListener() or addKeyListener on your UI component. But be careful about threading issues. Listeners will be called from the AWT thread.
Offline _Al3x

Senior Devvie

Medals: 7

Indie Games FTW!

« Reply #2 - Posted 2012-03-18 17:44:12 »

Thanks for your reply  Cheesy

- I'll look later about timing, right now I'm working just on design, but thanks, I'll keep it in mind (and noted on my to-do list).
- Class Entity was very quick made by copy pasting things, I will make it better soon!

So, every game state should have a mouse and keyboard listener?
And about threading, I'll keep it very simple for now Smiley

Thanks again! Cheesy

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 65K
« Reply #3 - Posted 2012-03-18 17:52:56 »

So, every game state should have a mouse and keyboard listener?
You could add one pair of listeners once and forward events to the current state. Otherwise you would rather have to attach and detach listeners on every state change.

And about threading, I'll keep it very simple for now Smiley
That's good. Nevertheless you have to be aware of the issues of Swing not being threadsafe, how to update the UI, about visibility of variables and locking maybe.
Offline ra4king

JGO Kernel

Medals: 467
Projects: 3
Exp: 5 years

I'm the King!

« Reply #4 - Posted 2012-03-18 17:54:33 »

Awesome looking code, couple thoughts from me too:
- You don't have to get the screen size and do all that math to center the window, a simple call to frame.setLocationRelativeTo(null) does just that.
- Use this code to force Windows to use the high resolution timer so sleep(10) would become more accurate, like 65K mentioned.
- To get events, just create an inner class in GameEngine that implements KeyListener, MouseListener, and MouseMotionListener. This way, you can just propagate the events to the currentState's appropriate methods.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Lunch (31 views)
2016-12-06 16:01:40

ral0r2 (257 views)
2016-11-23 16:08:26

ClaasJG (392 views)
2016-11-10 17:36:32

CoffeeChemist (486 views)
2016-11-05 00:46:53

jay4842 (534 views)
2016-11-01 19:04:52

theagentd (546 views)
2016-10-24 17:51:53

theagentd (540 views)
2016-10-24 17:50:08

theagentd (492 views)
2016-10-24 17:43:15

CommanderKeith (488 views)
2016-10-22 15:22:05

Roquen (456 views)
2016-10-22 01:57:43
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!