In-Game Level Editor Help

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 7
Reputation: BBaller1211 is an unknown quantity at this point 
Solved Threads: 0
BBaller1211 BBaller1211 is offline Offline
Newbie Poster

In-Game Level Editor Help

 
0
  #1
May 17th, 2008
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:

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. public class LevelEditor extends Board
  5. {
  6. public static final String row1 = "::::gggggggggggggggggg";
  7. public static String row2 = "::::g::::::::::::::::g";
  8. public static String row3 = "::::::::::::::::::::::";
  9. public static String row4 = "::::::::::::::::::::::";
  10. public static String row5 = "::::::::::::::::::::::";
  11. public static String row6 = "::::::::::::::::::::::";
  12. public static String row7 = "::::::::::::::::::::::";
  13. public static String row8 = "::::::::::::::::::::::";
  14. public static String row9 = "::::g::::::::::::::::g";
  15. public static final String row10 = "::::gggggggggggggggggg";
  16. String name = "YOUR LEVEL";
  17. String[] definitions = {row1, row2, row3, row4, row5, row6, row7, row8, row9, row10};
  18. public LevelEditor(Component parent, Applet applet)
  19. {
  20. super(parent, applet);
  21. super.initializeBoard(definitions);
  22. super.setDefinitions(definitions);
  23. super.setName(name);
  24. }
  25. public void resetLevel(String [] definitions)
  26. {
  27. super.initializeBoard(definitions);
  28. super.setDefinitions(definitions);
  29. super.setName(name);
  30. }
  31. }

And in the Board class, the parts you might need to know:

  1. import java.applet.*;
  2. import java.awt.*;
  3.  
  4. public abstract class Board
  5. {
  6. private Elements elementArray [][];
  7. private Component parent;
  8. private Applet applet;
  9. private String[] definitions;
  10. private String name;
  11. public Board(Component parent, Applet applet)
  12. {
  13. this.parent = parent;
  14. this.applet = applet;
  15. }
  16. public void setDefinitions(String [] definitions)
  17. {
  18. this.definitions = definitions;
  19. }
  20. public void setName(String name)
  21. {
  22. this.name = name;
  23. }
  24. public void initializeBoard(String [] definitions)
  25. {
  26. elementArray = new Elements[StaticPong.NUMBEROFLINES][StaticPong.NUMBEROFCOLUMNS];
  27. for (int j=0; j<StaticPong.NUMBEROFLINES; j++) {
  28. char [] elements = definitions[j].toCharArray();
  29. for (int i=0; i<StaticPong.NUMBEROFCOLUMNS; i++) {
  30. if (elements[i] == ':') {
  31. elementArray[j][i] = null;
  32. }
  33. else if (elements[i] == 'g') {
  34. Walls element = new Walls(Color.black, 1);
  35. elementArray[j][i] = element;
  36. }
  37. else if (elements[i] == 'p') {
  38. BWalls element = new BWalls(Color.blue, 2);
  39. elementArray[j][i] = element;
  40. }
  41. else if (elements[i] == 'e') {
  42. EWalls element = new EWalls(Color.red, 3);
  43. elementArray[j][i] = element;
  44. }
  45. else if (elements[i] == 'i') {
  46. Walls element = new Walls(Color.gray, 1);
  47. elementArray[j][i] = element;
  48. }
  49. else if (elements[i] == 'm') {
  50. MWalls element = new MWalls(Color.yellow, 4, 3);
  51. elementArray[j][i] = element;
  52. }
  53. else if (elements[i] == '-') {
  54. Path element = new Path(Color.gray, 5);
  55. elementArray[j][i] = element;
  56. }
  57. }
  58. }
  59. }
  60. public void editLevel(int x, int y)
  61. {
  62. int row = x/StaticPong.NUMBEROFCOLUMNS;
  63. int col = y/StaticPong.NUMBEROFLINES;
  64. if (row!=1 && row!=10) {
  65. char[] line = definitions[row].toCharArray();
  66. if (line[col] == ':') {
  67. line[col] = 'g';
  68. }
  69. else if (line[col] == 'g') {
  70. line[col] = 'p';
  71. }
  72. else if (line[col] == 'p') {
  73. line[col] = 'e';
  74. }
  75. else if (line[col] == 'e') {
  76. line[col] = ':';
  77. }
  78. definitions[row] = line.toString();
  79. }
  80. resetLevel(definitions);
  81. }

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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: In-Game Level Editor Help

 
0
  #2
May 20th, 2008
Try debugging !
Code isn't complete ? where is StaticPong?
Do simple step by step debugging using some debugger like Eclipse. Put a break point in the handler.
Otherwise do it old style, put some traces in your handler function and the editxx() function to see where it is hung.
Are you Agile.. ?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC