Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Pacman with processing help

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Pacman with processing help

    I'm trying to make a pacman game in which he eats the dots and he is lined up to the grid. can anybody please help? So far
    I want him to collide with the boxes and I can't figure out why he isn't lined up with the grid. Any help would be greatly appreciated. This is my first java project.
    I have:

    final static int B = 40, H = 25, SPD = 1;
    final static byte[][] area = new byte[B][H];
     
    int x = 1, y = 1, z = 0;
    float rot = 0;
     
    void setup() { 
      size(256, 256);
      smooth(); 
      frameRate(11);
     
      for (int i = 0; i!=B; i++)   for (int j = 0; j!=H; j++)
        area[i][j] = (byte) random(5);
    }
     
    void draw() {
      background(0);
     
      for (int i=0; i!=B; i++)   for (int j=0; j !=H; j++) {
        if (area[i][j] == 1) { 
          fill(-1);
          ellipse(20*i + 10, 20*j + 10, 10, 10);
        }
     
        else if (area[i][j] == 1) { 
          fill(#0000FF); 
          rect(20*i, 20*j, 20, 20);
        }
     
        else if (area[i][j] == 5) { 
          fill(0200); 
          ellipse(20*i + 10, 20*j + 10, 10, 10);
        }
     
        else if (area[i][j] == 4) { 
          fill(150, 255, 255); 
          rect(20*i, 20*j, 20, 20);
        }
      }
     
      fill(#FFFF00);
     
      if (z == 0) {
        z = 1;
        arc(20*x, 10*y, 20, 20, QUARTER_PI + rot, TWO_PI - QUARTER_PI + rot);
      }
     
      else if (z == 1) {
        z = 2;
        arc(20*x, 10*y, 20, 20, QUARTER_PI -.4 + rot, TWO_PI-QUARTER_PI + .4 +rot);
      }
     
      else {
        z = 0;
        arc(20*x, 10*y, 20, 20, 0 + rot, TWO_PI + rot);
      }
    }
     
    void demolish (int x, int y) {
      if (x>=0 & y<H) {
        switch(area[x][y]) { 
        case 1: 
        case 2: 
        case 3: 
          area[x][y]=0;
        }
      }
    }
     
    void move(int x1, int y1) {
      x1 = (x1 + B)%B;
      y1 = (x1 + H)%H;
     
      switch(area[x1][y1]) {
      case 1:
        area[x1][y1] = 0;
        break;
     
      case 2:
      case 3:
        x1 = x;
        y1 = y;
        break;
     
      case 4:
        for (int i=-1; i<2; i++)  for (int j=-1; j<2; j++)
          demolish(x1+i, y1+j);
      }
     
      x = x1; 
      y = y1;
    }
     
    void keyPressed() {
      if (key != CODED)  return;
     
      final int k = keyCode;
     
      if (k == RIGHT) {
        x += SPD;
        if (area[x][y] == 1)   area[x][y] = 12;
        rot=0;
      }
     
      else if (k == LEFT) {
        x -= SPD;
        rot = PI;
      }
     
      else if (k == UP) {
        y -= SPD;
        rot = -HALF_PI;
      }
     
      else if (k == DOWN) {
        y += SPD;
        rot = HALF_PI;
      }
    }
    Last edited by mcpherson; May 11th, 2014 at 09:10 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Pacman with processing help

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Do you have any specific questions about the code?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Pacman with processing help

    Yes. How do I make pacman collide with the boxes and interact with the dots. Again this is my first jaa game.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Pacman with processing help

    How do I make pacman collide with the boxes and interact with the dots
    Those are high level, not specific questions.
    Have it move and detect when it collides with the objects.

    Can you post a complete program that compiles and executes for testing?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: Pacman with processing help

    Please post the whole code and commenting on what you think each method is doing would be appreciated.

Similar Threads

  1. Help with File Processing
    By quu in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 17th, 2013, 12:59 PM
  2. Pacman ghost help
    By Daryn in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 9th, 2012, 09:15 AM
  3. Pacman issue with walls
    By mightyking in forum What's Wrong With My Code?
    Replies: 11
    Last Post: November 30th, 2011, 02:21 PM
  4. Processing
    By KevinWorkman in forum Other Programming Languages
    Replies: 4
    Last Post: September 6th, 2011, 10:30 AM
  5. Making a pacman game having some problems with drawing
    By Matta in forum What's Wrong With My Code?
    Replies: 22
    Last Post: June 9th, 2011, 06:18 PM

Tags for this Thread