We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Does anyone have a code for PacMan Level Editor
Pages: 1 2 
Does anyone have a code for PacMan Level Editor ? (Read 5889 times)
Does anyone have a code for PacMan Level Editor ?
May 16th, 2010, 2:04am
 
Quote:
Your program should present a window which displays a 19x19 grid of cells into which
users can place characters and scenery pieces, called tiles, from the PacMan game.
Users should be able to pick the particular tile they wish to add to the level being edited
using a palette of toggle buttons along the bottom of the screen. Placement of these tiles
should be achieved using the mouse, by clicking on the cell into which the tile should be
placed. Clicking and dragging should allow the user to place multiple tiles.

Your program should also allow users to save and load PacMan game levels to and from
text files stored on disk. These files should contain text in XML format. The precise formal
details of the XML elements and attributes which should be present in these files and of
the way in which those structures should be nested within each other is described in a
separate section below.


basically it should look similar to this
...

does anyone have a similar code ?
Re: Does anyone have a code for PacMan Level Editor ?
Reply #1 - May 16th, 2010, 3:51am
 
Not to my knowledge.
To do your assignment, you should start progressively, eg. displaying the grid, drawing the buttons and finding if user clicks on them, finding how to drag shapes, etc.

An ambitious assignment, I hope you have plenty of time to finish it.
Re: Does anyone have a code for PacMan Level Editor ?
Reply #2 - May 17th, 2010, 7:25pm
 
Pacman? PACMAN? PACMAN IS STUPID!!!!!!

Real men play... TIC-TAC-TOE!

Quote:
int [] data = new int[9];
int selected = 1;

void setup(){
  size(300,400);
}

void draw(){
  background(255);
  // Draw the tiles.
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      drawTile(i,j);
    }
  }

  // Draw the buttons.
  stroke(0);
  
  fill(200,255,200);
  if( selected == 1){
    fill(100,255,100);
  }
  rect(20, 295, 80, 80 );
  
  fill(200,255,200);
  if( selected == 2){
    fill(100,255,100);
  }
  rect(110, 295, 80, 80 );
  
  fill(200,255,200);
  if( selected == 0){
    fill(100,255,100);
  }
  rect(200, 295, 80, 80 );
  
  noStroke();
  fill(255,0,0);
  ellipse(150,335, 60, 60 );
  fill(200,255,200);
  if( selected == 2){
    fill(100,255,100);
  }
  ellipse(150,335, 40, 40 );

  noStroke();
  fill(0,0,255);
  pushMatrix();
  translate(60, 335);
  rotate(HALF_PI/2.0);
  rect(-10,-30,20,60);
  rect(-30,-10,60,20);
  popMatrix();

  // Update tiles.
  if(mousePressed){
    if( mouseX > 30 && mouseX < 270 && mouseY > 30 && mouseY < 270 ){
      int tempi = (mouseX-30)/80;
      int tempj = (mouseY-30)/80;
      data[tempi+3*tempj] = selected;
    }
  }
}

void mouseClicked(){
  if( mouseX > 20 && mouseX < 100 && mouseY > 295 && mouseY < 375 ){
    selected = 1;
  }
  if( mouseX > 110 && mouseX < 190 && mouseY > 295 && mouseY < 375 ){
    selected = 2;
  }
  if( mouseX > 200 && mouseX < 280 && mouseY > 295 && mouseY < 375 ){
    selected = 0;
  }
}



void drawTile(int i, int j){
  drawBlank(i,j);
  if( data[i+3*j] == 1 ){
    drawCross(i,j);
  }
  if( data[i+3*j] == 2 ){
    drawCircle(i,j);
  }
}


void drawBlank(int i, int j){
  stroke(0);
  fill(200,255,200);
  rect(30+80*i,30+80*j,80,80);
}

void drawCross(int i, int j){
  noStroke();
  fill(0,0,255);
  pushMatrix();
  translate(70+80*i, 70+80*j);
  rotate(HALF_PI/2.0);
  rect(-10,-30,20,60);
  rect(-30,-10,60,20);
  popMatrix();
}

void drawCircle(int i, int j){
  noStroke();
  fill(255,0,0);
  ellipse(70+80*i,70+80*j, 60, 60 );
  fill(200,255,200);
  ellipse(70+80*i,70+80*j, 40, 40 );
}



You can make some sense of that, right?
Re: Does anyone have a code for PacMan Level Editor ?
Reply #3 - May 18th, 2010, 1:32am
 
a lot of stuff looks unfamiliar but that's because I'm a beginner...
thanks anyway man, I will try to work something out, this assignment is killing me slowly  Cheesy
Re: Does anyone have a code for PacMan Level Editor ?
Reply #4 - May 18th, 2010, 8:26am
 
Well what looks unfamiliar? You'll probably need all the concepts posted in my Tic-tac-toe editor, and then a couple more.

When is your assignment due?
Re: Does anyone have a code for PacMan Level Editor ?
Reply #5 - May 18th, 2010, 8:39am
 
31th of May is a due date

I've no idea what "half_PI", "translate", "rotate" functions mean ... also I've never seen "pushMatrix" thing before...

Re: Does anyone have a code for PacMan Level Editor ?
Reply #6 - May 18th, 2010, 8:48am
 
"I've no idea what "half_PI", "translate", "rotate" functions mean ... also I've never seen "pushMatrix" thing before..."

Fantastic. These are the few functions that I did use that you shouldn't need at all. I only used them so that I could rotate the blue crosses so they were going diagonally.

Just assume that anything between a call to pushMatrix() and popMatrix() is magic that helps draw blue crosses.
Re: Does anyone have a code for PacMan Level Editor ?
Reply #7 - May 18th, 2010, 9:37am
 
loso25 wrote on May 18th, 2010, 8:39am:
I've no idea what "half_PI", "translate", "rotate" functions mean ... also I've never seen "pushMatrix" thing before...

That's HALF_PI, capitalization is... capital! in Java.
You should take a look at the Reference page when you find something unknown, it is a good way to progress. (But focus on the task, since TfGuy44 says you can ignore them.)
Re: Does anyone have a code for PacMan Level Editor ?
Reply #8 - May 18th, 2010, 9:54am
 
Quote:
capitalization is... capital! in Java.

*groan*

I mentioned a few other concepts that you'd need. These include file operations ("loadStrings()" and "saveStrings()"), some code to work with the little icons for the ghosts, dots, Pacman, etc. ("PImage", "loadImage()", and "image()"), and some code to put that text on those two other buttons ("PFont", "loadFont()", and "text()")

All of which can be found easily in the Reference page:
http://processing.org/reference/alpha.html

If you run into problems, we can help - just be sure to post the code that you've got so far, so we can easily identify the issue.
Re: Does anyone have a code for PacMan Level Editor ?
Reply #9 - May 18th, 2010, 12:59pm
 
i am wondering what his prof teaches his students when giving such assignments. i mean this task is not easy and i am wondering why he doesnt know some of the basic commands.

Just curious, what do you study? and do you have a processing or programming class? how is it and how and when did you start with your programming class.

Re: Does anyone have a code for PacMan Level Editor ?
Reply #10 - May 18th, 2010, 1:55pm
 
i doubt he'd need half the things he thinks he needs, TFGuy threw him quite a tangent there. no fonts, no rotations, no translations, no pushMatrix.

drawing a grid, working out which square the mouse is in, filling it with a graphic. that's pretty much the bones of it.

outputting as xml is another nested loop and some printlns. reading it back in is the tricky part, but XMLElement will help.

i think it's a nice little project - i always start with a game when i'm learning a new language / platform - keeps it interesting.

(i'd question the prof's use of copyrighted character though. plus a pacman grid isn't 19x19...)
Re: Does anyone have a code for PacMan Level Editor ?
Reply #11 - May 19th, 2010, 12:30am
 
Yeah, well, I was making a quick Tic-Tac-Toe level editor. I didn't want to bother with actually working out where the cross's points were. The draw-a-grid-and-buttons was mainly what I was trying to show him - a good starting point for this project, you know?
Re: Does anyone have a code for PacMan Level Editor ?
Reply #12 - May 19th, 2010, 2:33am
 
koogy wrote on May 18th, 2010, 1:55pm:
(i'd question the prof's use of copyrighted character though. plus a pacman grid isn't 19x19...)

Well, they are almost in the public domain, now... Smiley I wouldn't dare to count the unofficial Pacman clones!

19x19 That's a go-ban!
Re: Does anyone have a code for PacMan Level Editor ?
Reply #13 - May 19th, 2010, 3:10am
 
hey guys, just a quick question...how to place a text inside a button ?
Quote:
int [] data = new int[361];
int selected = 1;

PFont font;
PImage a;


void setup(){
 size(650,650);
 font = loadFont("Aparajita-20.vlw");
 a = loadImage("Erase.png");

}

void draw(){
 background(255);
 textFont(font, 20);
 // Draw the tiles.
 for(int i=0; i < 19; i++){
   for(int j=0; j < 19; j++){
     drawTile(i,j);
   }
 }
 
 // Draw the buttons.
 stroke(0);
 
 fill(255, 255, 255);
 if( selected == 1){
   fill(0);
 }
   image (a, 30, 580);
   fill(255);

 rect(20, 610, 40, 40 );

 fill(47, 19, 235);
 if( selected == 2){
   fill(100,255,100);
 }
 rect(60, 610, 40, 40 );
 
 fill(158,158,160);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(100, 610, 40, 40 );
 
 fill(255, 255, 255);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(140, 610, 40, 40 );
 
 fill(255, 255, 255);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(180, 610, 40, 40 );
 
 fill(255, 255, 255);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(220, 610, 40, 40 );
 
 fill(255, 255, 255);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(260, 610, 40, 40 );
 
 fill(255, 255, 255);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(300, 610, 40, 40 );
 
 fill(255, 255, 255);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(340, 610, 40, 40 );
 
 fill(255, 255, 255);
 if( selected == 0){
   fill(100,255,100);
 }
 rect(380, 610, 40, 40 );
 
}
void drawTile(int i, int j){
 drawBlank(i,j);
 if( data[i+3*j] == 1 ){
   drawCross(i,j);
 }
 if( data[i+3*j] == 2 ){
   drawCircle(i,j);
 }
}


void drawBlank(int i, int j){
 stroke(0);
 fill(200,255,200);
 rect(30+30*i,30+30*j,30,30);
}

void drawCross(int i, int j){
 noStroke();
 fill(0,0,255);
 rect(-10,-30,20,60);
 rect(-30,-10,60,20);

}

void drawCircle(int i, int j){
 noStroke();
 fill(255,0,0);
 ellipse(70+80*i,70+80*j, 60, 60 );
 fill(200,255,200);
 ellipse(70+80*i,70+80*j, 40, 40 );
}



the text "erase" should be placed in the first button as shown in picture in my first post
Re: Does anyone have a code for PacMan Level Editor ?
Reply #14 - May 19th, 2010, 3:28am
 
oh I've worked it out guys... don't worry
Pages: 1 2