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 5888 times)
Re: Does anyone have a code for PacMan Level Editor ?
Reply #15 - May 19th, 2010, 4:22am
 
Ok guys.. I'm stuck right now

this is my code so far:

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

PFont font;
PImage a;
PImage b;
PImage c;
PImage d;
PImage e;
PImage f;
PImage g;
PImage h;
PImage i;
PImage j;

void setup(){
 size(650,650);
 font = loadFont("Aparajita-20.vlw");
 a = loadImage("Erase.png");
 b = loadImage("Wall.png");
 c = loadImage("Door.png");
 d = loadImage("Pacman.png");
 e = loadImage("Blinky.png");
 f = loadImage("Clyde.png");
 g = loadImage("Inky.png");
 h = loadImage("Pinky.png");
 i = loadImage("Big-Fruit.png");
 j = loadImage("Small-Fruit.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);
 if (selected == 1) {
   fill (100, 255, 100);
 }
 rect (20, 610, 32, 32);
 image (a, 20, 610);
 
 if (selected == 2) {
 fill (100, 255, 100);
 }
 rect (52, 610, 32, 32);
 image (b, 52, 610);
 
 if (selected == 3) {
 fill (100, 255, 100);
 }
 rect(84, 610, 32, 32 );
 image (c, 84, 610);
 
 if (selected == 4) {
 fill (100, 255, 100);
 }
 rect(116, 610, 32, 32 );
 image (d, 116, 610);
 
 if (selected == 5) {
 fill (100, 255, 100);
 }
 rect(148, 610, 32, 32 );
 image (e, 148, 610);
 
 if (selected == 6) {
 fill (100, 255, 100);
 }
 rect(180, 610, 32, 32 );
 image (f, 180, 610);
 
 if (selected == 7) {
 fill (100, 255, 100);
 }
 rect(212, 610, 32, 32 );
 image (g, 212, 610);
 
 if (selected == 8) {
 fill (100, 255, 100);
 }
 rect(244, 610, 32, 32 );
 image (h, 244, 610);
 
 if (selected == 9) {
 fill (100, 255, 100);
 }
 rect(276, 610, 32, 32 );
 image (i, 276, 610);
 
 if (selected == 10) {
 fill (100, 255, 100);
 }
 rect(308, 610, 32, 32 );
 image (j, 308, 610);
 
// 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 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 );
}


I think I don't need the last 3 functions (void drawCircle, void drawCross, void drawBlank), but without them my code doesn't display 19x19 grid of cells for some reason...

here is a zip file of all images : http://rapidshare.com/files/389117381/PacManImages.zip.html

any ideas ?

and again big thanks to TfGuy44, without your code I would probably die
Re: Does anyone have a code for PacMan Level Editor ?
Reply #16 - May 19th, 2010, 10:39pm
 
What block of code is drawing the 19x19 grid of cells?
What function does that block use?
What functions does that function use? Does it need to use those?
What should it do instead?
Re: Does anyone have a code for PacMan Level Editor ?
Reply #17 - May 20th, 2010, 12:17am
 
void drawTile ?
I can do all the basic stuff but when it comes to assigning buttons and all that, I get stuck instantly ...
Re: Does anyone have a code for PacMan Level Editor ?
Reply #18 - May 22nd, 2010, 7:52am
 
Quote:
int [] data = new int[361];
int selected = 1;

PFont font;
PImage a;
PImage b;
PImage c;
PImage d;
PImage e;
PImage f;
PImage g;
PImage h;
PImage i;
PImage j;

void setup(){
size(650,650);
font = loadFont("Aparajita-20.vlw");
a = loadImage("Erase.png");
b = loadImage("Wall.png");
c = loadImage("Door.png");
d = loadImage("Pacman.png");
e = loadImage("Blinky.png");
f = loadImage("Clyde.png");
g = loadImage("Inky.png");
h = loadImage("Pinky.png");
i = loadImage("Big-Fruit.png");
j = loadImage("Small-Fruit.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++){

   drawBlank(i, j);
  }
}

// Draw the buttons.
stroke(0);

fill (255);
if (selected == 1) {
  fill (100, 255, 100);
}
rect (20, 610, 32, 32);
image (a, 20, 610);
 
if (selected == 2) {
fill (100, 255, 100);
}
rect (52, 610, 32, 32);
image (b, 52, 610);

if (selected == 3) {
fill (100, 255, 100);
}
rect(84, 610, 32, 32 );
image (c, 84, 610);

if (selected == 4) {
fill (100, 255, 100);
}
rect(116, 610, 32, 32 );
image (d, 116, 610);

if (selected == 5) {
fill (100, 255, 100);
}
rect(148, 610, 32, 32 );
image (e, 148, 610);

if (selected == 6) {
fill (100, 255, 100);
}
rect(180, 610, 32, 32 );
image (f, 180, 610);

if (selected == 7) {
fill (100, 255, 100);
}
rect(212, 610, 32, 32 );
image (g, 212, 610);

if (selected == 8) {
fill (100, 255, 100);
}
rect(244, 610, 32, 32 );
image (h, 244, 610);

if (selected == 9) {
fill (100, 255, 100);
}
rect(276, 610, 32, 32 );
image (i, 276, 610);

if (selected == 10) {
fill (100, 255, 100);
}
rect(308, 610, 32, 32 );
image (j, 308, 610);

// 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 drawBlank(int i, int j){
stroke(0);
fill(200,255,200);
rect(30+30*i,30+30*j,30,30);
}


seems like I've managed to figure this out...all I need to do is to assign each button... can anyone give me a hint ?
Re: Does anyone have a code for PacMan Level Editor ?
Reply #19 - May 22nd, 2010, 9:47am
 
> all I need to do is to assign each button...

the bit you use to work out which button is pressed is very similar to the bit you use to determine which square has been clicked... it's this bit:

Code:

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;
}
}


but you need to modify the numbers to reflect the button positions rather than the squares.

btw, if you find yourself writing huge blocks of text where only a few bits differ between each block then that's usually a clue you're doing it inefficiently. also,  if you find yourself typing the same numbers again and again (32, 610...) then these should be constants

private static final int BUTTON_SIZE = 32;
private static final int BUTTON_Y = 610;

then use rect(244, BUTTON_X, BUTTON_SIZE, BUTTON_SIZE); etc

that way, if you decide you want to move all the buttons down a couple of pixels you only need change the number in one place.

(it looks like more typing, but the whole thing should be in a loop anyway)
Re: Does anyone have a code for PacMan Level Editor ?
Reply #20 - May 28th, 2010, 12:12am
 
this is hard how u going with it loso?
Pages: 1 2