Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  How would you design this game?  (Read 2704 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Member





« Posted 2010-08-19 19:42:41 »

One day when I wasn't at a computer I began to write down how I would design a very basic "game" and was curious as to how you guys would do it.

Basically, the idea is that there is a player who can walk around a world and there will be items that he can pick up and use against other items, one of which would be a Door, that the player can bash open with the hammer and that is basically it. I wanted to keep it simple so I can just try and see how I would do this and make it expandable.

The way I decided was to have an Entity class that would represent all of the Objects in the game which would contain information such as location, bounding box, and "Strength" which every entity will have (if you hit the door with a hammer it will compare strengths and break) and then the player, item and Door would extend that.

Some problems I have had was that if the Player has a hammer "inHand" and hits a door, do I tell the door it was hit with a hammer or do I tell the hammer it hit a door? I figured I will tell the Door, because the Door will know what to do if it is hit, while the hammer does not care what it is hitting. Although I guess you could tell both objects?

And also, if someone wanted to turn this into a Tile Based game, how would they do so, would the levels just be a 2D array of "Entities"? on the item layer? that way if the player clicks on a tile, it will cycle through all of the items on the Item Layer and then do whatever it needs to do?

I dont know, I just like to think about these kind of things and see how other people would implement them, hopefully some of you find it somewhat interesting Tongue
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #1 - Posted 2010-08-19 20:14:02 »

You might want to check out Scribblenauts implementation :

http://en.wikipedia.org/wiki/Scribblenauts#Engine


(though the Physics in Scribblenauts are quite messy, the rest may be useful)

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2010-08-19 20:27:43 »

Uh, you need to provide more details on what you want.

I'm assuming a 2D tile-based game. In which case, I would have a 1D array of whatever you want. Locations in the array are x*width+y, as in instead of myArray
  • [y] you say myArray[x*width+y]. It's much more efficient.

Here are some considerations deciding what you want the array to be composed of:
- How big is your world going to be? If it's going to be massive (like Minecraft), filling it with Entity pointers is impractical.
- How different is each block going to be? If each block is from a simple factory type (i.e. no door is different from another door) then there is no need to store a new Entity in every single space.

If you answered yes to either of the two questions, then you should think about a 1D array of either ints or bytes. Then when drawing and doing actions, you do a check against the type to decide what to do.

As for the gameplay type you're looking for, it sounds like it can be distilled down to a very simple mechanic: A + B = C. All you need to do is come up with a lot of different objects (or entity types or whatever) and then come up with a lot of combinations. I would store all of the possible combinations in a file that is easy to edit, like a text file. Then you just see what the player has in their hand, try to combine it with what's in front of them, and if it yields a result put that in front of them.

In your example, Hammer + Door = Broken Door. The expanding on that, maybe Broken Door + Saw = Wood Planks, Wood Planks + Nails = Door. Etc.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2010-08-20 01:09:53 »

The way I decided was to have an Entity class that would represent all of the Objects in the game which would contain information such as location, bounding box, and "Strength" which every entity will have (if you hit the door with a hammer it will compare strengths and break) and then the player, item and Door would extend that.

Some problems I have had was that if the Player has a hammer "inHand" and hits a door, do I tell the door it was hit with a hammer or do I tell the hammer it hit a door? I figured I will tell the Door, because the Door will know what to do if it is hit, while the hammer does not care what it is hitting. Although I guess you could tell both objects?

I've been planning how to do item-item interaction in Albion, which is a similar problem. I want lots of different items (and item types) and a handful of different actions (throw, attack, eat, etc). which can be performed with them.

I think I'm going to go for something that uses reflection to map unique pairs of items to a 'action' class. Something like:
1  
2  
3  
ActionMap map = new ActionMap();
map.addActionMapping(Hammer.class, Door.class, new BreakDoorAction()); // Hammer + Door means run the 'break door' action
map.performAction(new Hammer(), new Door()); // find the hammer + door action and runs it

Then I'll have a seperate ActionMap for each type of action (throw, attack, etc.).

This means I can put the actual 'do stuff' code in a seperate class (no worrying about is it Hammer.break(door) or Door.hitBy(hammer)), and I can add specific mappings for each new object type easily. For more generic stuff I'll be mapping things onto interfaces (eg. actionMap.addActionMapping(Hammer.class, Breakable.class, new BreakAction())), which can be used as a fallback if a more specific mapping isn't found.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 748
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2010-08-20 10:10:58 »

If the only thing you have is a hammer, everything looks like a nail.

This is a problem that should not be solved using Java types.
What if you want to craft an item that requires N items of type X, and M items of type Y *or* type Z?
What you need is a database, probably some simple txt or xml file


Quote
1  
map.performAction(new Hammer(), new Door()); // find the hammer + door action and runs it
What if you have two items that have multiple ways to interact?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2010-08-20 10:55:57 »

What if you have two items that have multiple ways to interact?

Well as I said, I'm going to have multiple ActionMaps for each type of action that can be performed (which the user has to select, like attacking, or throwing, or eating).

This is just the core idea of what I've got planned, as I didn't want to flood the thread with details. The final thing will be driven by an xml file, and it'll be keyed off more than just the java type, but the core concept of moving all the 'doStuff()' logic into separate classes and choosing which to call based on the objects involved (rather than trying to manage Hammer.break(Door) and Door.hitBy(Hammer)) is sound I think.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Swattkidd7

Junior Member





« Reply #6 - Posted 2010-08-20 13:18:10 »

Uh, you need to provide more details on what you want.

I was intentionally keeping it pretty vague that way you guys could just kind of take it your own way and post how you would do things, kind of like you guys have, so thanks a lot! It is always nice to hear/see how people would do things to help yourself think clearly about the way you are doing it.

If the only thing you have is a hammer, everything looks like a nail.

This is a problem that should not be solved using Java types.
What if you want to craft an item that requires N items of type X, and M items of type Y *or* type Z?
What you need is a database, probably some simple txt or xml file


Hmm could you elaborate a bit more? I am not sure I completely understand what you mean.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #7 - Posted 2010-08-21 02:02:00 »

He's basically saying what I said above, except in more detail. You want your file that contains all the possible combinations to be simple to edit and to have more options then just one of this and one of this equals one of this.

For example, you might want something to happen if you have at least 5 of this and no more than 3 of this, or maybe you need 10 total different items to do something.

Here's a quickly thought up example. Let's say we have a text file that defines every type of thing you can have. Each thing has a unique integer to make it easier / faster to store them in-game. They also have a list of tags that can be used in other objects.

1  
2  
3  
4  
Object,identifier,tag1 tag2 tag3,operator:count:tag operator:count:tag ...,operator:count:tag operator:count:tag
Door,0,wood openable entrance door crushable,atleast:1:hammer atleast:15:nail atleast:10:plank atleast:1:handle atleast:3:hinge
Hammer,1,tool wieldable hammer,atleast:1:stick atleast:1:rock
BrokenDoor,2,debris wood,atleast:1:hammer atleast:1:door,atleast:1:axe atleast:1:door,atleast:1:ram atleast:1:door


Obviously there are a lot more things you might want to include in there, like consumables (when I create this, does it use up this), as well as multiple outputs (a broken door probably would give you nails, wood, and a handle), getting more than 1 of something, etc. But the main point is that just by making some sort of text format, you can do whatever you want very very quickly. XML, imo, is unwieldy, annoying to edit without an editor, and wasteful of memory.

But this should give you an idea, no?

See my work:
OTC Software
Offline Swattkidd7

Junior Member





« Reply #8 - Posted 2010-08-21 06:12:24 »

But this should give you an idea, no?

Wow, thanks a lot, this gives me a great idea of what to do, and in a method I have never tried before. I really appreciate you guys taking the time to explain how you would do things or the other methods because I have been finding myself getting stuck in the same garbage way of doing things without really expanding and this looks like something new and fresh to try out. So once again, thanks!

(just to make sure I got it)
In the text file you have Door, 0 etc, etc. So that would mean in the 2D array (or 1D like you showed) wherever we have 0's we create doors. However, as typing this, it brings up yet another question (sorry Grin) lets say you do destroy the door and it is suppose to drop 5 nails and some wood, how would I express that on the map? Since each "tile" holds only one integer.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #9 - Posted 2010-08-21 06:19:02 »

Since each "tile" holds only one integer.
Just get rid of this arbitrary constraint.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Swattkidd7

Junior Member





« Reply #10 - Posted 2010-08-21 08:36:51 »

Just get rid of this arbitrary constraint.
Hmm, now that I think about it a bit, I would use the 2D array to see where to place objects (doors, or whatever) and add them to an Entities list or something since collision will be handled using Rectangles, so essentially when the door gets smashed, I could just drop the doors and nails, right there at that location, never needing to touch the map data? (this idea is just something I was thinking of, might be some flaws with it).
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #11 - Posted 2010-08-21 11:51:17 »

Each position in your map could hold multiple objects. You don't have to use ints. You could have an array at each position, or an instance of a class that has an ArrayList of objects at that position.

Offline Swattkidd7

Junior Member





« Reply #12 - Posted 2010-08-21 12:12:34 »

Each position in your map could hold multiple objects. You don't have to use ints. You could have an array at each position, or an instance of a class that has an ArrayList of objects at that position.

Oh well yea, but I was just going off of Demonpant's who said having the map made up of Objects might become too much with huge maps.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #13 - Posted 2010-08-21 14:34:22 »

Are huge maps one of your requirements? If not, then don't worry about it. Even if you do want huge maps, optimizing for it at this point is premature. You are at the "get something working" stage.

Offline Swattkidd7

Junior Member





« Reply #14 - Posted 2010-08-21 14:48:15 »

Are huge maps one of your requirements? If not, then don't worry about it. Even if you do want huge maps, optimizing for it at this point is premature. You are at the "get something working" stage.

Thats true, for me personally huge maps are not necessary. But mainly for this thread I was just curious as to how other people would do it as I am not really working on anything at the moment.

How would you go about it Nate? Are you saying you would just have an ArrayList of entities and when you collide with them check and see what to do based on what type of Entity it is?
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #15 - Posted 2010-08-21 20:37:17 »

I think he is saying that he would ahve an array of arraylists, and that each arraylist hold the objects on the tile.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #16 - Posted 2010-08-21 20:43:59 »

Typically I have two ways of storing objects in a world:

- The first is the array (1D, 2D, 3D, whatever) that holds objects which are mostly static. I don't even instantiate these, I just do the int thing and draw a different sprite based on what int is found. I only need to worry about the type otherwise for the object(s) that the player is interacting with. This has the constraint of 1 thing per space. I call this the "static entity" collection.
- I have a big list of stuff that can be moved around, picked up, etc. This is the "active entity" collection. These are not confined to grid spaces and can overlap, move around, etc. This is where you would put nails, as nails wouldn't make sense to be in the static entity list - they are more like items you can pick up. The broken door, however, would probably go in the static list because it's just another tile type.

Does that make sense? Obviously do it however is best for you, and a bucket array (array of lists, or "buckets") works fine if you aren't making a big world (which you're not). I personally find it slightly more confusing to deal with, though. Also for collision data, etc., tiles are much better.

See my work:
OTC Software
Offline markus.borbely

Junior Member





« Reply #17 - Posted 2010-08-22 18:44:07 »

This is how I do it:

Store all Entities in a list.
Entity is abstract, but Creature, Door, Weapon, Obstacle are not.
More detailed it is like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
Entity
   Physical (this object have a corresponding body in the physics engine I use. The position of a physical is retrieved from its physical body)
       Creature
       Projectile
       Obstacle
           Door
   SimplePositionedEntity (these are not physical objects, rather effects (like explosions)).
       Effect
           Sparks (instantiated when a bullet strikes a wall for instance, also used for gushing blood etc)
           Explosion
           ...  lots of other effects
       Pickup
           ItemOnFloor
           Powerup
               .... Lots of different powerups



Also, every such subclass of Entity can implement the Damageable interface. Also, an Entity can own a DamageSource.
DamageSources (not a subclass of Entity) defines how much damage and pain are dealt. The Damageable interface have methods for getting armour, and applying the dealt damage.

When two bodies collide I check a number of things. This is done in separate classes under a package "rules".
Is one of them a projectile? Then maybe it should be destroyed (like when a bullet hits a wall). If the other is a Damageable, apply the projectiles DamageSource to it.
Is one of them a Pushable (interface meaning that the object can be pushed) it is pushed (this is what opens doors, empties crates pushes buttons etc).
Is any one of them trying to hit the other with a melee attack? In that case, apply the melee attack.

Apart from all this. The GameMap class holds a grid with tiles. A tile can be open, mapped explored etc. Open defines if it is walkable, also if you can see through it and shoot through it. The rest is just for visuals.
Offline Swattkidd7

Junior Member





« Reply #18 - Posted 2010-08-24 13:53:47 »

Thanks a lot guys, this is really helping me see all of the different ways to do things.

Also Markus.Borbley, that is a similar way as to how I have been doing it, although you cleared/cleaned it up very nicely for me, thanks.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (12 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!