| | |
In-Game Level Editor Help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 7
Reputation:
Solved Threads: 0
I'm trying to make a level that can be edited in game for a pong-like game.
So far, this is what I have:
And in the Board class, the parts you might need to know:
The editlevel method is called in Board when you click on a grid box in "leveleditor" mode (a gamestate).
This should change the row/col that you clicked on to a different element, but the applet freezes when you click on something.
Any help making the editor work?
So far, this is what I have:
Java Syntax (Toggle Plain Text)
import java.awt.*; import java.applet.*; public class LevelEditor extends Board { public static final String row1 = "::::gggggggggggggggggg"; public static String row2 = "::::g::::::::::::::::g"; public static String row3 = "::::::::::::::::::::::"; public static String row4 = "::::::::::::::::::::::"; public static String row5 = "::::::::::::::::::::::"; public static String row6 = "::::::::::::::::::::::"; public static String row7 = "::::::::::::::::::::::"; public static String row8 = "::::::::::::::::::::::"; public static String row9 = "::::g::::::::::::::::g"; public static final String row10 = "::::gggggggggggggggggg"; String name = "YOUR LEVEL"; String[] definitions = {row1, row2, row3, row4, row5, row6, row7, row8, row9, row10}; public LevelEditor(Component parent, Applet applet) { super(parent, applet); super.initializeBoard(definitions); super.setDefinitions(definitions); super.setName(name); } public void resetLevel(String [] definitions) { super.initializeBoard(definitions); super.setDefinitions(definitions); super.setName(name); } }
And in the Board class, the parts you might need to know:
Java Syntax (Toggle Plain Text)
import java.applet.*; import java.awt.*; public abstract class Board { private Elements elementArray [][]; private Component parent; private Applet applet; private String[] definitions; private String name; public Board(Component parent, Applet applet) { this.parent = parent; this.applet = applet; } public void setDefinitions(String [] definitions) { this.definitions = definitions; } public void setName(String name) { this.name = name; } public void initializeBoard(String [] definitions) { elementArray = new Elements[StaticPong.NUMBEROFLINES][StaticPong.NUMBEROFCOLUMNS]; for (int j=0; j<StaticPong.NUMBEROFLINES; j++) { char [] elements = definitions[j].toCharArray(); for (int i=0; i<StaticPong.NUMBEROFCOLUMNS; i++) { if (elements[i] == ':') { elementArray[j][i] = null; } else if (elements[i] == 'g') { Walls element = new Walls(Color.black, 1); elementArray[j][i] = element; } else if (elements[i] == 'p') { BWalls element = new BWalls(Color.blue, 2); elementArray[j][i] = element; } else if (elements[i] == 'e') { EWalls element = new EWalls(Color.red, 3); elementArray[j][i] = element; } else if (elements[i] == 'i') { Walls element = new Walls(Color.gray, 1); elementArray[j][i] = element; } else if (elements[i] == 'm') { MWalls element = new MWalls(Color.yellow, 4, 3); elementArray[j][i] = element; } else if (elements[i] == '-') { Path element = new Path(Color.gray, 5); elementArray[j][i] = element; } } } } public void editLevel(int x, int y) { int row = x/StaticPong.NUMBEROFCOLUMNS; int col = y/StaticPong.NUMBEROFLINES; if (row!=1 && row!=10) { char[] line = definitions[row].toCharArray(); if (line[col] == ':') { line[col] = 'g'; } else if (line[col] == 'g') { line[col] = 'p'; } else if (line[col] == 'p') { line[col] = 'e'; } else if (line[col] == 'e') { line[col] = ':'; } definitions[row] = line.toString(); } resetLevel(definitions); }
The editlevel method is called in Board when you click on a grid box in "leveleditor" mode (a gamestate).
This should change the row/col that you clicked on to a different element, but the applet freezes when you click on something.
Any help making the editor work?
![]() |
Similar Threads
- Game Development FAQ's, Books and Resources (Game Development)
- Maya Exporter Plugin for a game editor (DEdit) (Project Partners Wanted)
- Level editors (Game Development)
- Game Development (Game Development)
- Programmers needed for game dev. team (Software Development Job Offers)
- Desperately Seeking Old Apple Game (Community Introductions)
Other Threads in the Java Forum
- Previous Thread: Problem with slider (jQuery) containing scrool bar in Firefox
- Next Thread: detect when the song has finished playing (JMF)
| Thread Tools | Search this Thread |
6 actuate android api applet application array arrays automation balls binary bluetooth bold business c++ chat class classes client code codesnippet collections component coordinates database defaultmethod doctype dragging ebook eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui hql html ide image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list loop looping map method methods mobile mysql netbeans newbie nextline numbers parameter php print problem program programming project recursion recursive scanner screen sell server set size sms sort sql string sun swing swt threads time tree user websites windows





