Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: A level format problem

  1. #1
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default A level format problem

    I'm not sure if this goes here, but lets hope so. Okay, so I've started making a game engine, and right now I'm working on the level format. Right now, I have one object to draw tiles based on a file, the player, the main Jframe and main Java object. Now I haven't coded collision with these graphic tiles yet, because I was thinking that I should make another object that reads from a similar file to draw the collision tiles. This way, I could make a tile act different from its default if I need it to (Example: A secret passageway behind a walk-through wall). Only problem: How do I get an object to spawn another object, and how do I get objects to interact with each other? I know these are probably simple questions, and I'm probably just being stupid; but I can't seem to figure it out. Also, if this isn't an efficient way to do things, please let me know. I'm making sure my game has a level editor, so efficiency is very important. Thank you for your time!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,176
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: A level format problem

    There are a few ways to do this. You could just use a single List (or 2d array, whatever) of tiles instead of parallel data structures (which is a sign of bad design), and each tile contains a boolean value deciding whether or not it's solid as well as how to draw it (an image, drawing code, whatever). Then your walk-through wall would just be a normal wall with the collision boolean equal to false.

    I'm not sure what you mean when you ask how to get an Object to spawn another or to get Objects interacting.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: A level format problem

    Quote Originally Posted by KevinWorkman View Post
    There are a few ways to do this. You could just use a single List (or 2d array, whatever) of tiles instead of parallel data structures (which is a sign of bad design), and each tile contains a boolean value deciding whether or not it's solid as well as how to draw it (an image, drawing code, whatever). Then your walk-through wall would just be a normal wall with the collision boolean equal to false.

    I'm not sure what you mean when you ask how to get an Object to spawn another or to get Objects interacting.
    Well, I guess I could try to get the collision to be part of the main level loading code, as for the object to spawn another, I mean to get my level class/object to place blocks, enemies and the player at certain spots. For the objects interacting, I mean like the player touching, say a coin, and having the coin disappear and add 1 to the coins variable.
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,176
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: A level format problem

    You fill a 2d array with game Objects. There is no spawning at that step, you just populate a data structure. During gameplay, you test which cell of the array the player is in, then take the appropriate action based on what kind of game Object is at that location.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: A level format problem

    Quote Originally Posted by KevinWorkman View Post
    You fill a 2d array with game Objects. There is no spawning at that step, you just populate a data structure. During gameplay, you test which cell of the array the player is in, then take the appropriate action based on what kind of game Object is at that location.
    So how do you actually list which game object goes where in the array? That's what I'm having trouble with. Do you just type in the object name, like "coin" instead of typing "Rectangle So and so" or "ImageIcon So and so"?
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,176
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: A level format problem

    Quote Originally Posted by Gravity Games View Post
    So how do you actually list which game object goes where in the array? That's what I'm having trouble with. Do you just type in the object name, like "coin" instead of typing "Rectangle So and so" or "ImageIcon So and so"?
    That part is really up to you. You can use some type of text system and read levels from files, or you can procedurally generate levels, or you can hardcode them. That's completely up to you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: A level format problem

    Quote Originally Posted by KevinWorkman View Post
    That part is really up to you. You can use some type of text system and read levels from files, or you can procedurally generate levels, or you can hardcode them. That's completely up to you.
    I'm already using a text based system (I'm loading my levels from a .txt file). I just can't figure out how to call a specific instance of an object/class to be placed at a certain spot.
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,176
    My Mood
    Hungover
    Thanks
    141
    Thanked 600 Times in 515 Posts

    Default Re: A level format problem

    You aren't going to like this answer, but if you're getting stuck on basic instantiation, then I'd really recommend taking a step back and going through the basic tutorials. I highly suggest taking on something a little simpler than a game engine. Start smaller and work your way up instead of diving right into the deep end. Try doing something like pong or breakout first.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Member Gravity Games's Avatar
    Join Date
    May 2012
    Posts
    152
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: A level format problem

    I've already gone through basic tutorials, I just don't get how to call an object from another object. But if you really think it would help, I'll see if there's a basic object tutorial...

    Edit: *Realizes that calling other objects is literally as easy as just typing in its name* *facepalm* ...I haven't felt this stupid since I forgot to import the Rectangle package trying to draw a rectangle...
    Last edited by Gravity Games; June 4th, 2012 at 02:30 PM. Reason: Epic facepalm moment...
    Current Projects (and planned release dates):

    Chomp's Wacky Worlds [???] (PC, Android and Ouya)
    Kyle the Caiman [???] (PC, Android and Ouya)
    KTC: King Crocko's Mystic Maze [???] (PC, Android and Ouya)

Similar Threads

  1. [SOLVED] Help Generating a level
    By Montario in forum AWT / Java Swing
    Replies: 22
    Last Post: April 12th, 2012, 07:22 AM
  2. Attempting to get to next level in API
    By meathead in forum The Cafe
    Replies: 8
    Last Post: October 12th, 2011, 11:17 AM
  3. Custom Log level help
    By seanman in forum Java SE APIs
    Replies: 1
    Last Post: September 25th, 2011, 08:55 PM
  4. need help w/ entry level homework...
    By rbread80 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 3rd, 2010, 10:24 PM