Game Maker's Garage Forum

Game Creation => Code Exchange => Topic started by: Connors on November 20, 2012, 03:19:07 PM

Title: [Processing] New Level Editor
Post by: Connors on November 20, 2012, 03:19:07 PM
I've decided to make my own program to make levels for my SC game. Chances are if I do it right it could be reprogrammed to work for Space Marines or other games.

The following code lets you select a text file and imports that data:

Code: [Select]
  
void setup() {
  selectInput("Select a file to process:", "fileSelected");
}

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
  }
  String lines[] = loadStrings(selection);
  println("there are " + lines.length + " lines");
  for (int i =0 ; i < lines.length; i++) {
  println(lines[i]);
}
}

I think Processing will be perfect since it has a lot of convenient functions for file I/O. And real 2D arrays.
Title: Re: [Processing] New Level Editor
Post by: Gan on November 20, 2012, 04:34:46 PM
Cool stuff.
Title: Level Editor Progress!
Post by: Connors on November 21, 2012, 12:51:21 PM
(http://i.imgur.com/cGxxY.png)
The editor, with space on the right for an interface. Processing is fantastic for making simple programs with graphics.
So far I can draw with the mouse, but the controls are all the keyboard.
Eventually I want it to be user friendly with buttons rather than a read-me listing all the key shortcuts.

Next step: Program functions to save and load via .txt files (ugh) :)
Title: Re: [Processing] New Level Editor
Post by: Gan on November 21, 2012, 03:14:25 PM
Ooooh.
Does processing have networking support?
Title: Re: [Processing] New Level Editor
Post by: Connors on November 21, 2012, 04:00:12 PM
I don't know the specifics but you could check http://processing.org/ (http://processing.org/). I do know that it has separate modes for Java, Javascript or Android and you can import libraries. So you could probably use the same libraries you have before.
Title: Re: [Processing] New Level Editor
Post by: Gan on November 21, 2012, 06:19:30 PM
This processing is looking fantastic! Apparently it can run in the browser as well as an application. And it can handle 2D and 3D.

Connors, Imma read more on this but if you could make a video on how you made the level editor, I'd be very interested.
Title: Re: [Processing] New Level Editor
Post by: Connors on November 21, 2012, 06:36:59 PM
It's not an extremely complex program, I just referred to the command reference on the site. I can post the project file soon. Maybe I will make a video about setting up the grid and stuff.
Title: Re: [Processing] New Level Editor
Post by: Gan on November 21, 2012, 08:08:19 PM
I must learn more!

I have ideas. Good ideas. Ideas of greatness. Using processing I can make a Java server. Also in processing I can probably make a Javascript client. Therefore making an online game using processing alone!
Of course the game could also be made as Java. Oh man this is exciting.

Learn, I must.
Title: Re: [Processing] New Level Editor
Post by: Circuit on November 22, 2012, 09:28:35 PM
This is interesting.  I'll be keeping an eye on this.
Title: Re: [Processing] New Level Editor
Post by: Connors on November 22, 2012, 10:52:39 PM
Well, it now has functions to save and load .txt files that can be pasted right into the code of my game so I can finally get to work on making more content. I've attached my source code below.

Use number keys 0-4 to select objects:

0 - empty
1 - solid
2 - deadly
3 - player start
4 - goal

Pressing down arrow will create and save to a file called output.txt in the same directory as the app (I'll change this so it brings up a dialogue later).

Pressing up arrow will allow you to select a file to open.

I plan on changing the controls and adding some more to the game so you can try to make levels but they may not work the same in the final game.
Title: Re: [Processing] New Level Editor
Post by: Connors on December 15, 2012, 06:57:41 PM
I'm very proud of this latest development. I'm making a mockup of a game concept that will hopefully be complete enough in a couple days for me to submit as a Ludum Dare/Jam entry. What I've done today is I began to port my "grid-nav" engine to Processing, beginning with a way to store levels. I just got a function working which reads files from the sketch data folder line by line. The input is of course the filename to load. Most of the following is borrowed directly from the reference page on createReader().

Code: [Select]
void loadLevel(String lvl) {
  String line;
  boolean loop = true;
  BufferedReader reader = createReader(lvl);
  while (loop) {
    try {
      line = reader.readLine();
    } catch (IOException e) {
      e.printStackTrace();
      line = null;
    }//catch
    if (line == null) {
      loop = false;
    } else {
      println(line);
    }//if
  }//while loop
}
Title: Re: [Processing] New Level Editor
Post by: Gan on December 15, 2012, 07:30:46 PM
Lookin good.