Board game -alternate way to draw

Thanks for reading,
im relatively new to game devpmt, i am making a board game similar to pool.
the board background is a JPanel on which a fixed image is drawn .i want to make a ball moving on it.The ball's image is loaded from a file .since the image is rectangular in boundary,ball when drawn on the board,displays the rectangular boundaries around it.
is there any way to overcome this problem,
all the drawings of board_backround_image and ball_image takesplace when the paintComponent() of the boardpanel is called.
Any suggestions would b great helpful.....

If you are reading from gif or png, make the background of the source image transparent. Otherwise, color the background with some unused palette color, search through the pixels after loading, and replace those pixels with transparent ones.
If using jpg or some other lossy compression scheme, you'll not only need to have a transparency marker, but it will not always have the same RGB to compare with. Here's a quick snippet that will covert a particular color in an image to transparent pixels. The fuzziness variable is how far the red, green, and blue channels may be to still be considered marked as transparent.
public BufferedImage transparify(Image sourceImage, Color replaceColor, int fuzziness)
   int imageWidth = sourceImage.getWidth(null);
   int imageHeight = sourceImage.getHeight(null);
   // ensure we are using a ARGB BufferedImage
   BufferedImage returnImage = new BufferedImage(imageWidth,imageHeight, BufferedImage.TYPE_INT_ARGB);
   Graphics imageG = returnImage.getGraphics();
   imageG.drawImage(sourceImage, 0, 0, null);
   imageG.dispose();
   // extract pixel data
   int[] pixels = new int[imageWidth * imageHeight];
   returnImage.getRGB(0, 0, imageWidth, imageHeight, pixels, 0, imageWidth);
   int transRed   = replaceColor.getRed();
   int transGreen = replaceColor.getGreen();
   int transBlue  = replaceColor.getBlue();
   for (int pixIndex = 0; pixIndex < pixels.length; pixIndex++) {
      // sum the difference of this pixel with the transparency marker
      int diffRed   = transRed   - ((pixels[pixIndex] >> 16) & 0xFF);
      int diffGreen = transGreen - ((pixels[pixIndex] >> 8) & 0xFF);
      int diffBlue  = transBlue -  (pixels[pixIndex] & 0xFF);
      // if close to the marker, set pixel to transparent
      boolean closeEnough = (diffRed >= 0 ? diffRed : -diffRed) <= fuzziness &&     
                      (diffGreen >= 0 ? diffGreen : -diffGreen) <= fuzziness &&  
                      (diffBlue >= 0 ? diffBlue : -diffBlue) <= fuzziness;
      if (closeEnough) {
         pixels[pixIndex] = 0; // 0 alpha makes transparent
   returnImage.setRGB(0, 0, imageWidth, imageHeight, pixels, 0, imageWidth);
   return returnImage;
}

Similar Messages

  • Tables and Rounding Errors on Board Game Gui

    Hello,
    So I am in a software development class , and my team and I are developing a software version of a board game that uses numbered tiles placed on a board in a somewhat scrabble-esque way.
    Here is a picture of the game board:
    [http://img90.imageshack.us/img90/1052/untitledqv3.png|http://img90.imageshack.us/img90/1052/untitledqv3.png]
    Currently, a problem that we are working on is that as the tiles get further and further away from the center of the board, they are displayed further and further askew from the board lines. I have another picture to demonstrate what I'm talking about more clearly.
    [http://img225.imageshack.us/img225/4605/untitled2nn0.png|http://img225.imageshack.us/img225/4605/untitled2nn0.png]
    As the tiles get further away from the center, they are displayed more askew.
    We think that this happens because we are using a gridbag layout to add tile objects to, which displays the tiles in a certain spacing and orientation, and then we draw the board ourselves. When we draw the board, we get rounding errors inherent in the use of ints, and the lines become a bit off, with the problem getting worse as it gets further and further away from the center.
    Here is the code that we use to initialize the layout and add the tiles to it:
         //set the layout
    setLayout(new GridLayout(7, 7, 7, 7));
    //initialize the array with the references to all the tiles that we are going to add
    //to the layout
    squares = new SquareView[7][7];
    for (int i = 0; i < 7; i++) {
         for (int j = 0; j < 7; j++) {
              //create the tile, put a reference to it in the array
              squares[i][j] = new SquareView(boardModel.getSquare(new Point(j, i)), listener, handler);
              //add the tile to the layout
              add(squares[i][j]);
    }And here is the code that we are using to draw the lines for the board:
    GridLayout layout = (GridLayout) getLayout();
    //getting the dimensions of the board
    int rows = layout.getRows();
    int columns = layout.getColumns();
    int width = (getWidth() / columns);
    int height = (getHeight() / rows);
    g2.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), null);
    for (int i = 0; i < 8; i++) {
         // Vertical lines
         g2.drawLine(i * width, 0, i * width, rows * height);
         // Horizontal lines
         g2.drawLine(0, i * height, columns * width, i * height);
    }I think that our problems come from the innacuracy of ints, but if there is some addition or subtraction trick that we could pull, then let me know.
    Also, I was sort of looking into tables, and I was wondering if maybe we could use tables to do this, and have Java do our resizing for us.

    j.law wrote:
    We think that this happens because we are using a gridbag layout to add tile objects to, From the snippets of code, it's looking as though you're using GridLayout. But that's OK as GridLayout should work fine here.
    GridLayout layout = (GridLayout) getLayout();
    //getting the dimensions of the board
    int rows = layout.getRows();
    int columns = layout.getColumns();
    int width = (getWidth() / columns);
    int height = (getHeight() / rows);
    g2.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), null);
    for (int i = 0; i < 8; i++) {
         // Vertical lines
         g2.drawLine(i * width, 0, i * width, rows * height);
         // Horizontal lines
         g2.drawLine(0, i * height, columns * width, i * height);
    }I have no idea of this will improve things, but what about:
    GridLayout layout = (GridLayout) getLayout();
    int rows = layout.getRows();
    int columns = layout.getColumns();
    double width = (getWidth() / columns); //** how about using doubles here
    double height = (getHeight() / rows);  //** how about using doubles here
    g2.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), null);
    for (int i = 0; i < 8; i++) {
         // Vertical lines
         g2.drawLine(i * width, 0, (int)(i * width), (int)(rows * height)); // and casting?
         // Horizontal lines
         g2.drawLine(0, (int)(i * height), (int)(columns * width), (int)(i * height));
    }

  • Fastest way to draw a grid

    What is the best or quickest way to draw the walls on PacMan
    Making the game pacman and wondering is there a fast way to draw the board...
    instead of loads of lines saying
    g.drawLine(......);

    Uh, I was asking if there was another way...
    fillrect/drawrect are the only other ways to do it
    lol... and I've tried Graphics2D.How about drawOval or drawPolygon (doubt that)?
    >
    I was wondering if there was maybe another class/set
    of functions... etc?You could drop down to some native library like DirectX or OpenGL or some such, but I don't know of any other way to paint the screen with Java. (but then, I'm certainly not a "screen painting" sorta guy, so take that for what it's worth)

  • How to create board game in InDesign

    I
    am trying to create a board game in InDesign, similar to the trivial pursuit board game. In other words, an outer wheel that has been
    divided up in sectionsand then spoes to the center. I think I can figure out how to do the spoes and the center, but I am having problems doing the outer wheel.
    Any ideas? Should I be doing this in photoshop instead?
    Thanks,
    FG

    Pretty much the same thing in Illustrator or ID, but Illy has more sophisticated drawing tools, including things like polar coordinates and duplication that will allow you to drag a copy of one of the line segments around an arc, then repeat at the same angle.
    In any case, you want to make two concentric circles, then draw a series of radial line segments between them. I'd then select all and creat a compound path.

  • Making a Board Game

    I wasn't really sure where to place this thread but here goes. I want to make a simple board game (Checkers or maybe Chess) in two player mode only (One player will come later). I am not sure how exactly to go about it. Are there any special methods or classes I have to implement? I would like to build it so that the pieces, when released, go to the center of the square they are held over. Does this involve any special mapping of the board image? Would it be better to create the board in a paint program and implement it that way or should I use java.awt.geom to do that? And since I don't want to copy somebody else's chess pieces (that would be cheating) is there a way, in java, to create images like that? and if not what imaging program should I use (definitely not adobe photoshop)? Should I even be attempting to do this kind of thing yet?

    Here is the code I have so far:
    import java.awt.geom.*;
    import java.awt.*;
    import javax.swing.*;
    public class JChess extends JPanel {
        BasicStroke three;
        public JChess() {
         super();
        public void paintComponent(Graphics g) {
         Graphics2D g2d = (Graphics2D) g;
         three = new BasicStroke(3);
         g2d.setColor(Color.white);
         g2d.fillRect(-100, -100, getSize().width + 100, getSize().height + 100);
         g2d.setColor(Color.black);
         g2d.setStroke(three);
         g2d.translate(75, 75);
         g2d.drawLine(0, 0, 600, 0);
         g2d.drawLine(0, 0, 0, 600);
         g2d.drawLine(0, 600, 600, 600);
         g2d.drawLine(600, 0, 600, 600);
         //first row
         g2d.fillRect(0, 75, 75, 75);
         g2d.fillRect(0, 225, 75, 75);
         g2d.fillRect(0, 375, 75, 75);
         g2d.fillRect(0, 525, 75, 75);
         //second row
         g2d.fillRect(75, 0, 75, 75);
         g2d.fillRect(75, 150, 75, 75);
         g2d.fillRect(75, 300, 75, 75);
         g2d.fillRect(75, 450, 75, 75);
         //third row
         g2d.fillRect(150, 75, 75, 75);
         g2d.fillRect(150, 225, 75, 75);
         g2d.fillRect(150, 375, 75, 75);
         g2d.fillRect(150, 525, 75, 75);
         //fourth row
         g2d.fillRect(225, 0, 75, 75);
         g2d.fillRect(225, 150, 75, 75);
         g2d.fillRect(225, 300, 75, 75);
         g2d.fillRect(225, 450, 75, 75);
         //fifth row
         g2d.fillRect(300, 75, 75, 75);
         g2d.fillRect(300, 225, 75, 75);
         g2d.fillRect(300, 375, 75, 75);
         g2d.fillRect(300, 525, 75, 75);
         //sixth row
         g2d.fillRect(375, 0, 75, 75);
         g2d.fillRect(375, 150, 75, 75);
         g2d.fillRect(375, 300, 75, 75);
         g2d.fillRect(375, 450, 75, 75);
         //seventh row
         g2d.fillRect(450, 75, 75, 75);
         g2d.fillRect(450, 225, 75, 75);
         g2d.fillRect(450, 375, 75, 75);
         g2d.fillRect(450, 525, 75, 75);
         //eighth row
         g2d.fillRect(525, 0, 75, 75);
         g2d.fillRect(525, 150, 75, 75);
         g2d.fillRect(525, 300, 75, 75);
         g2d.fillRect(525, 450, 75, 75);
    }As you can see I don't know what I am doing or what I am supposed to do LOL. = )

  • Designing a board game

    Is there anychance anyone out there can help me with the design of a risk board game in java - obviously. I am a complete rookie so if you can keep it as simple as possible I will be very greatful.
    Cheers!

    I'm designing a board game called othello. The thing
    is,
    i'm using something minimax, where the computer thinks
    ahead
    in the number of moves. Now, i'm having problems doing
    this,
    as I am using an array of weighted board values
    indicating
    which part of the board are more advantageous than
    others.
    The problem i'm having is to decide how to use this
    function.
    I am designing the game, so that it looks like 3 moves
    ahead.
    Do i call the weighted board values, once it's at the
    3rd move,
    so it then calls the minimax function and decides what
    move is best?
    Basically, does anyone know how to use these weighed
    values, and
    exactly when to call them. If someone could explain
    this in simple
    terms, it would be great.
    thank you so muchone way of handling this is adding up the weights of the possible moves up to the third move ahead, but do this as "branches". Meaning, if you take this first move what moves will it give you, and what moves will those moves give you. Once you have the current moves to third moves branches mapped out, then total the weights of all the moves and that will give you a branch weight. The better the weight branch will then tell your program which current move to make.
    Another thing to consider in your program is not just which spots are best (like corners are advantageous) because I can play the game, give someone a corner and still beat win, it is a simple strategy. There are plenty of other things to consider, for instance, consider mobility in your wieghts. How many moves does this give and how many moves does it take away or give to my opponent.

  • Cerating a board game

    I am creating a board game using net beans ide 5.0. I really don't undestand how to catch the mouse click event.can some one
    send me a url or some way to implement this game.
    And also in my program once click in a box in game i need to dispaly a image on that box. can some one help me. Any one know how to implementing this in web services

    double post
    http://forum.java.sun.com/thread.jspa?messageID=4350445

  • Question about creating a traditional board game with

    I'm creating a classic board game (i.e. monopoly, sorry,
    mouse trap) where the users will move based on the random result of
    a roll of dice. The board has 100 squares that the piece can land
    on.
    What's the best way to give all 100 squares a value so that I
    can take the current value of the player piece (movieclip) and add
    the result of the dice roll?
    Thanks in advance for your assistance.
    Note: I'm developing this game for Flash Lite.

    use array t store value of squares n then add the
    corresponding value t the value of dice generated randomly using
    math.random fuction. -- atulag

  • RISK board game

    I am hoping to get some help on how to make the user interface for a java based version of the RISK board game. If there are any sites, tips or books that will guide me on the way to program this I would be greatful to know. Also, if it is possible to use a graphic file for the user to see whilst the game runs in the background.
    I am not the best programmer so the easier the better.
    Cheers for any help!!

    I am not the best programmer so the easier the
    better.At this rate, you wouldn't expect to be the best.

  • Pogo board games. What they are using?

    Hi,
    I been to Pogo.com and tested board games. All are made with JAVA.There games are 2D.
    1 - Can some one tell me what mix of techonologies they are using. Board, Poker games? .
    2 - Can we made these games with Java 2D library?
    3 - What multiplayer server they are using for multiplayer games. Any idea?
    4 - How do you find creating games with Java 2D instead of flash (any idea). Is it easy to use 2D library?
    5 - If we use 2D library than we need to know Java to work on that?
    thanks in advance.

    Pirzada wrote:
    Hi,
    I been to Pogo.com and tested board games. All are made with JAVA.There games are 2D.
    1 - Can some one tell me what mix of techonologies they are using. Board, Poker games? . Well, I would think you have answered your own question before you have even asked it--Java.
    2 - Can we made these games with Java 2D library?Yes.
    3 - What multiplayer server they are using for multiplayer games. Any idea?Are you asking if there are multiplayer gaming engines that you can incorporate into your software instead of programming it yourself?
    4 - How do you find creating games with Java 2D instead of flash (any idea). Is it easy to use 2D library?You lean Java, study the tutorials on Graphics and 2D, then write what you like.
    5 - If we use 2D library than we need to know Java to work on that?Ummm... well, yes, of course: do you have to know French to speak it?
    thanks in advance.

  • About MultiplayerOnline Flash Board game

    Here is my three tier applcation:
    Client Layer : Flash AS3
    Application Layer: Asp.net
    Database Layer: SQL Server
    i have created my websites for asp.net, game programming has
    been done, but the only problem is i want a real time basis for
    creating a MMO Flash board game. But, how am i going to do that? I
    tried webservice package, but It only have PULL technology which is
    not suitable for real time basis. Is there any good ideas on what i
    should use? i heard about Sockets, XMLSockets, .NET Flash
    Remoting..but i am confused on what to use.

    Basically you can use anything that uses the rtmp protocol,
    like FMS, Red5, Wowza, SmartfoxServer and you can have a look at
    WebORB, a remoting package that also has a Publisher/Producer
    (comes in a .net flavor too).

  • About flash Board game

    Hi all , i wanna ask a question regarding flash board game.
    i have an online flash application of chinese checkers board
    games that can be allowed up to 12 games rooms maximum.
    The question i wanted to ask is that if i got 12 game rooms ,
    do i need 12 different swf files for 2 players , another 12
    different swf files got 3 players , another 12 different swf files
    for 4 players and 6 players ?
    Please someone can enlighten me ? thank you

    I think this has more to do with the domain logic (how you
    structure your game and what you want it to do) than it does
    ActionScript.
    There is no reason you couldn't write a chinese checkers game
    with a dynamic amount of rooms all in one swf.

  • Creating a board game

    I'm making a "board game" in Flash with Actionscript 3.0.
    When the player lands on a certain space, I want a window to pop up
    & they complete a word search game. The faster they complete
    the word search, the more points they would earn. I already have it
    working so that the word search swf pops up at the right time, but
    I'm not sure how to grab the time they completed the game in &
    send it back to the main movie. I got the word search code from
    here:
    http://www.subtangent.com/flash/
    and it's written in Actionsript 2.0. Is it still possible to use
    both together? If so, how can I send the time back to my main movie
    to figure out their score?
    Thanks,

    an as2 swf will work when loaded by an as3 swf. the two can
    communicate using the localconnection class.

  • Is there a way to draw a straight line from one point to another?

    Is there a way of drawing a straight line from one point to another please?

    Yes.  First click on this icon:
    Now select the line drawing icon:
    Now press a shift key and drag your mouse on the image to draw a straight line.
    These instructions are for Windows system so you need to adapt the method for Macs.  I can't afford to by an Apple Mac!!!!!
    Good luck.

  • What is the ABSOLUTE FASTEST way to draw a point on a JFrame in Java?

    I am currently using:
    g.drawLine(x,y,x,y);with g being a Graphics object. Is there any faster way to draw a point in Java?

    Uh, I was asking if there was another way...
    fillrect/drawrect are the only other ways to do it
    lol... and I've tried Graphics2D.How about drawOval or drawPolygon (doubt that)?
    >
    I was wondering if there was maybe another class/set
    of functions... etc?You could drop down to some native library like DirectX or OpenGL or some such, but I don't know of any other way to paint the screen with Java. (but then, I'm certainly not a "screen painting" sorta guy, so take that for what it's worth)

Maybe you are looking for