Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  Well, here's our story - help us write the rest of it!  (Read 1416 times)
0 Members and 1 Guest are viewing this topic.
Offline Trosters

Junior Member


Projects: 1



« Posted 2011-03-24 17:44:50 »

So me and a friend recently began (trying) to develop some basic 2d games, we feel like we've been doing ok considering the short time we've been doing this for. Now we ask ourselves, how do we continue to learn and improve? What would you have done next if you were in our inexperienced shoes? Any tips or ideas are greatly appreciated!

What we've made so far is(And what problems we have with them, please do help!):

A puzzle game inspired by a memory we made for school - the game's basically a grid of (objects extending) JButtons and you move your character around trying to solve different puzzles to advance to the next level. Here's some screen shots of the game:

There's also a basic map editor which saves the maps into .txt files which in turn can be read as custom maps in the game. (And to develop the actual maps of the 'campaign')

I've also made a chess game using the same technique with them JButtons, you press a piece you want to move, if its your turn, and it will show you all the available moves for that piece - nothing worth showing.

We've made a basic Super Mario kind of platform game - beat the map, jump on enemies to kill them. Some enemies patrol until they can not continue any further and then turn around and go the other way, some enemies jump on the spot until they've been killed. We came across a big problem here: When we move outside the main picture - the frame you see when you first start the game, and we want the 'camera' to follow: We did this the following way:
If  you are moving to the right, instead of moving the characters X position 1 pixel to the right, we move every other object one pixel to the left. This same goes for if we move left, up or down - works great BUT if we move and an enemy moves on the same time they can sometimes fall through the ground or move through a wall because:
We start to move all the objects one by one. We move a wall one step down, then the gravity pulls the enemy down to the wall, then we move the enemy one step down - and blam he's past the floor and floating towards eternity!:( How can we solve this? Any ideas? I was thinking of using JLayeredPane but I cant get it to work and I've never used it before so I don't even know if it would of worked!

We then started to think about some network programming, had some trouble until we found 'Kryonet' (god what a relief - it's awesome!), and made a chat server and client:


And started making a small two player online game where you're supposed to be a ninja (atm you're just a green (or red, depending on damage taken) square!) throwing knifes on your opponent until hes dead and you've won the game! You can jump on the knifes - but if their edge hits you you will take damage, and throw slow knives if you want to (to make it easier to jump on them to avoid your opponents knives!).



Now when we started doing the later kind of games we've run into a bit of trouble. We have all of our knives, characters and walls in a ArrayList<GameObject> go, but when we try to iterate through this array to check collisions we got all sorts of different weird errors - we managed to remove most of them but we're still stuck with a "No such element exception" in a for each loop:
temp = (ArrayList<GameObject>) go.clone();
for (GameObject gs : temp) {
   if (temp.contains(gs) && !(gs == null)) {
      if (gs instanceof Wall || gs instanceof Knife || gs instanceof Character) {
         if (gs.getY() ==  ypos) {
            if (gs.getX() < xrightpos && gs.getX() + gs.getWidth() > xleftpos) {
               standingOnWall = true;
            }
         }
      }
   }
}

The game runs smooth in most cases, we've been testing it online versus each others and we can complete most games without any errors - even if we in some games have up to (probably) 100 knives(and threads) active on the same time! But sometimes we get the error I mentioned above and we have absolutely no idea on how to solve this. If you've got any ideas on this then please help me out!:)
Offline aazimon
« Reply #1 - Posted 2011-03-24 18:08:39 »

I would recommend reading over David Brackeen's Developing Games and Java and Andrew Davison's Killer Game Programming in Java. Both are listed at amazon http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=java+games&x=13&y=24 They also have their own web pages. That will give you more information on game programming.
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2011-03-24 18:15:21 »

For the "No such element exception", you're using clone() wrong:
http://ra4king.is-a-geek.net/javadocs/java/util/ArrayList.html#clone%28%29

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #3 - Posted 2011-03-24 18:30:33 »

 
For the "No such element exception", you're using clone() wrong:
http://ra4king.is-a-geek.net/javadocs/java/util/ArrayList.html#clone%28%29

I believe he should not be using clone() at all.  


You should just stop using one hundred threads !
When you have multiple Threads fatally one time or another one of the knifes will be removed from your gameObjects collection while in the other thread you are iterating over this array, and you'll get this exception .

You should have a single thread to manage the logic of your game, and each game object should have an update() which is called each iteration. This has been discussed in this forum several times .

If you still want to go using lots of threads (which I highly discourage if you want to be a "good" game developer), try using the "Concurrent..." collections (i.e. http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html ) .

Read this thread . (Though it's about graphics, the same applies for logic) .


 

Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2011-03-25 02:40:51 »

Yeah, there is no point in ever using ArrayList.clone().

What puzzles me is the NoSuchElementException. If he removed an element in another thread while this for each loop was running, he would get a ConcurrentModificationException. Weird...

Lastly: 100 threads?!?!?!? Try optimizing your code a bit, preferably 1 thread for game loop Grin

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2011-03-25 08:12:04 »

What puzzles me is the NoSuchElementException. If he removed an element in another thread while this for each loop was running, he would get a ConcurrentModificationException. Weird...

ConcurrentModificationException is not guaranteed, it is thrown on a best effort basis.

the enhanced-for-loop requests an Iterator from an Iterable, when concurrently accessing your backing data structure you can get 'true' from iter.hasNext() and NoSuchElementException from iter.next()

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

Junior Member


Projects: 1



« Reply #6 - Posted 2011-03-25 08:19:53 »

thank you for the replies! I can really see the reasons to only use one thread and instead use update methods! I'm sure this will eliminate many of my problems! Damn teacher for makin' me think threads were too good not to use!

I started to rewrite the game using this 'new' method and I am pretty sure it will work much better now! Thanks a lot guys!:)
Offline lhkbob

JGO Knight


Medals: 32



« Reply #7 - Posted 2011-03-25 13:56:12 »

Threads are really good to use, but they are really complex to do right and it takes time to know when is the right situation to use them.  I would recommend sticking to one main thread (although that's a little difficult because you're using Swing which uses its own threads), but don't think that you should completely ignore threads.

Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2011-03-25 17:49:57 »

What puzzles me is the NoSuchElementException. If he removed an element in another thread while this for each loop was running, he would get a ConcurrentModificationException. Weird...

ConcurrentModificationException is not guaranteed, it is thrown on a best effort basis.

the enhanced-for-loop requests an Iterator from an Iterable, when concurrently accessing your backing data structure you can get 'true' from iter.hasNext() and NoSuchElementException from iter.next()
But this doesn't make sense, the javadoc says that "hasNext()"  returns true if there are more elements, while "next()" throws NoSuchElementException if there are no more elements to return. So in the time between the calls to "hasNext()" and "next()", another thread edited the list? Seems like that's what happened.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2011-03-25 18:05:34 »

Eh... so you make a post only to say that what I said didn't make sense, and then explaining to yourself what must cause it, which is basically what I explained in the first place? Ok.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2011-03-25 18:08:40 »

I was trying to get clarification if my thoughts were correct Grin

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.

atombrot (25 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!