Home | About | Account | Forums | Games
Guest   | Login
  Index  | Recent Threads  | Register  | Search  | Help  | RSS feeds  | View Unanswered Threads  
  Search  


Quick Go »
Thread Status: Normal
Forum Status: Locked
Total posts in this thread: 3
[Add To My Favorites] [Watch this Thread]
Author
Previous Thread This topic has been viewed 2591 times and has 2 replies Next Thread
RazaHel
Stranger
Member's Avatar


Joined: Sep 11, 2006
Posts: 18
Status: Offline
boardview does not paint and update all sprites

first off: sorry for x-posting, but i cannot edit or delete my other postings :(
(I think this forum fits better to my problem than game design)

Now to my problem

I created a small game which uses a sprite to show a die and other sprites for the game pieces.
The thing is, the board and the pieces are shown correctly even the cursor,but the die is not visible.
If i go back to the lobby and then watch the table the die sprite is shown,
but not updated (if you click the die a new number is generated and should be shown). You only see the update if you go back to the lobby and then watch again the table.

Here the Code for the Die:

import java.awt.Color; import java.awt.Graphics2D;
import com.threerings.media.sprite.Sprite;
/**
* Displays a die on the board view.
*/
public class DieSprite extends Sprite
{
/** The dimensions of our sprite in pixels. */
public static final int SIZE = PieceSprite.SIZE;

/**
* Creates a die sprite to display the supplied game die.
*/
public DieSprite (JostleObject.Die die)
{
super(SIZE, SIZE);
updateDie(die);
}

/**
* Called when the die we are displaying has been updated.
*/
public void updateDie (JostleObject.Die die)
{
// keep track of our die
_die = die;

// set our location based on the location of the die
setLocation(_die.x * SIZE, _die.y * SIZE);

// force a redraw in case our color changed but not our location
invalidate();

}

@Override // from Sprite
public void paint (Graphics2D gfx)
{
// set our color depending on the player that owns this die
switch (_die.owner) {
case JostleObject.RED:
gfx.setColor(Color.red);
break;
case JostleObject.GREEN:
gfx.setColor(Color.green);
break;
case JostleObject.BLUE:
gfx.setColor(Color.blue);
break;
default:
gfx.setColor(Color.pink);
break;
}
// draw a filled in rounded rectangle in our die color
int px = _bounds.x + 3, py = _bounds.y + 3;
int pwid = _bounds.width - 6, phei = _bounds.height - 6;
gfx.fillRoundRect(px, py, pwid, phei,3,3);

// then outline that rounded rectangle in black
gfx.setColor(Color.black);
gfx.drawRoundRect(px, py, pwid, phei,3,3);


if (_die.value <= 6 && _die.value >= 1){
gfx.drawString(" "+_die.value+" ", px+SIZE/2-5, py+SIZE/2+5);
} else {
gfx.drawString(" :( ", px+SIZE/2-5, py+SIZE/2+5);
}
}

protected JostleObject.Die _die;
}



and here is the code from the board view:

public class JostleBoardView extends VirtualMediaPanel
implements PlaceView, SetListener
{

/**
* Link to the Board.xml
*/
public static String _boards="data/Jostle_Board_v1.xml";
/**
*TODO later replacement of static number of players per table
*/
public static int _numplayers=3;

/**
* Constructs a view which will initialize itself and prepare to display
* the game board.
*/
public JostleBoardView (ToyBoxContext ctx, JostleController ctrl)
{
super(ctx.getFrameManager());
_ctx = ctx;
_ctrl = ctrl;
_xmlLoader=new XmlDataLoader();
_xmlLoader.parse(_boards);
_size=_xmlLoader.getJostleBoardDim();
_stones=_xmlLoader.getJostleStones();
_reverseStones=createReverseBoardMap(_stones, _xmlLoader.getJostleBoardPlayersStack());
_logic=new JostleLogic(_size,_stones, _xmlLoader.getJostleBoardPlayersStack());
// listen for mouse motion and presses
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed (MouseEvent e) {
int tx = e.getX() / PieceSprite.SIZE;
int ty = e.getY() / PieceSprite.SIZE;
// if mouse is pressed check if the piece under the mouse is owned by player
for(JostleObject.Piece piece : _gameobj.pieces)
if (piece.x==tx && piece.y == ty &&
_gameobj.die.owner == _ctrl._color &&
_ctrl._color == piece.owner){
_selectedPiece=piece;
if (_reverseStones.get(new IntTuple(tx,ty)).intValue()+_gameobj.die.value <= _stones.size()){
_cursor.setPosition(_stones.get(
_reverseStones.get(new IntTuple(tx,ty)).intValue()+_gameobj.die.value).right.left);
_newPiecePosition=new IntTuple(_cursor.getX(),_cursor.getY());

} else {
_newPiecePosition=new IntTuple(_selectedPiece.x,_selectedPiece.y);
}
break;
}


}
//TODO
@Override
public void mouseReleased (MouseEvent e) {
int tx = e.getX() / PieceSprite.SIZE;
int ty = e.getY() / PieceSprite.SIZE;
if (_selectedPiece instanceof JostleObject.Piece &&
_ctrl._color == _selectedPiece.owner &&
_newPiecePosition instanceof IntTuple &&
_newPiecePosition.left==tx && _newPiecePosition.right==ty )
{
_ctrl.pieceMoved(_selectedPiece,_newPiecePosition);
}
_selectedPiece=null;
_newPiecePosition=null;
}
@Override
public void mouseClicked (MouseEvent e) {
int tx = e.getX() / PieceSprite.SIZE;
int ty = e.getY() / PieceSprite.SIZE;
if (_gameobj.die.x== tx && _gameobj.die.y== ty){
_ctrl.rollDie();
}
}

});

// listen for mouse motion
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged (MouseEvent e) {
int tx = e.getX() / PieceSprite.SIZE;
int ty = e.getY() / PieceSprite.SIZE;
_cursor.setPosition(tx, ty);
}
});

}

private HashMap<IntTuple,Integer> createReverseBoardMap( HashIntMap<Tuple<String, Tuple<IntTuple,IntTuple>>> stones, HashIntMap<Tuple<IntTuple, IntTuple>> jostleBoardPlayersStack ) {
HashMap<IntTuple,Integer> output=new HashMap<IntTuple,Integer>();

for (int st=0;st< stones.size();st++)
output.put(stones.get(st).right.left,new Integer(st));

for (int st=0;st < jostleBoardPlayersStack.size(); st++)
output.put(jostleBoardPlayersStack.get(st).left, -1);

return output;
}

// from interface PlaceView
public void willEnterPlace (PlaceObject plobj)
{
_gameobj = (JostleObject)plobj;
_gameobj.addListener(this);

// creates the die for the players to use
if (_gameobj.die instanceof JostleObject.Die)
addDieSprite(_gameobj.die);

// create sprites for all pieces currently on the board
for (JostleObject.Piece piece : _gameobj.pieces) {
addPieceSprite(piece);
}

}

// from interface PlaceView
public void didLeavePlace (PlaceObject plobj)
{
_gameobj.removeListener(this);
_gameobj = null;

}
// from interface SetListener
public void entryAdded (EntryAddedEvent event)
{
if (event.getName().equals(JostleObject.PIECES)) {
// add a sprite for the newly created piece
addPieceSprite((JostleObject.Piece)event.getEntry());
}
if (event.getName().equals(JostleObject.DIE)) {
// add a sprite for the newly created piece
addDieSprite((JostleObject.Die)event.getEntry());
}

}

// from interface SetListener
public void entryUpdated (EntryUpdatedEvent event)
{
if (event.getName().equals(JostleObject.PIECES)) {
// update the sprite that is displaying the updated piece
JostleObject.Piece piece = (JostleObject.Piece)event.getEntry();
_sprites.get(piece.getKey()).updatePiece(piece);
}
if (event.getName().equals(JostleObject.DIE)) {
// update the sprite that is displaying the updated piece
JostleObject.Die die = (JostleObject.Die)event.getEntry();
_die.updateDie(die);
}

}

// from interface SetListener
public void entryRemoved (EntryRemovedEvent event)
{
// nothing to do here
}

/**
* Activates "placing" mode which allows the user to place a piece of the
* specified color.
*/
public void setPlacingMode (int color)
{
if (color != -1) {
_cursor.setColor(color);
addSprite(_cursor);
} else if (isManaged(_cursor)) {
removeSprite(_cursor);
}
}

/**
* Adds a sprite to the board for the supplied piece.
*/
protected void addPieceSprite (JostleObject.Piece piece)
{
PieceSprite sprite = new PieceSprite(piece);
_sprites.put(piece.getKey(), sprite);
addSprite(sprite);
}

/**
* Adds a sprite to the board for the supplied piece.
*/
protected void addDieSprite (JostleObject.Die die)
{
DieSprite sprite = new DieSprite(die);
_die=sprite;
addSprite(sprite);
}


@Override // from JComponent
public Dimension getPreferredSize ()
{
return new Dimension(_size.width * PieceSprite.SIZE + 1,
_size.height * PieceSprite.SIZE + 1);
}

@Override // from MediaPanel
protected void paintBehind (Graphics2D gfx, Rectangle dirtyRect)
{
super.paintBehind(gfx, dirtyRect);
drawBoard(gfx, dirtyRect);
}


private void drawBoard(Graphics2D gfx, Rectangle dirtyRect){


// fill in our background color
gfx.setColor(Color.lightGray);
gfx.fill(dirtyRect);

// draw our grid
for (int number=0;number<_stones.size();number++){
if (number % 2 == 0 )
gfx.setColor(Color.darkGray);
else
gfx.setColor(Color.lightGray);
gfx.fillRect(_stones.get(number).right.left.left * PieceSprite.SIZE,
_stones.get(number).right.left.right * PieceSprite.SIZE,
PieceSprite.SIZE, PieceSprite.SIZE);
gfx.setColor(Color.black);
gfx.drawRect(_stones.get(number).right.left.left * PieceSprite.SIZE,
_stones.get(number).right.left.right * PieceSprite.SIZE,
PieceSprite.SIZE, PieceSprite.SIZE);
}


gfx.setColor(Color.black);

for (int num=0;num<_numplayers;num++){
gfx.drawRect(_xmlLoader.getJostleBoardPlayersStack().get(num).left.left * PieceSprite.SIZE,
_xmlLoader.getJostleBoardPlayersStack().get(num).left.right * PieceSprite.SIZE, PieceSprite.SIZE, PieceSprite.SIZE);
}
gfx.setColor(Color.black);
for (int number=0;number<_stones.size();number++)
gfx.drawString(_stones.get(number).left,
_stones.get(number).right.left.left * PieceSprite.SIZE + PieceSprite.SIZE/4,
_stones.get(number).right.left.right * PieceSprite.SIZE + PieceSprite.SIZE/2);

}


/** The game controller to which we dispatch user actions. */
protected JostleController _ctrl;

/** Displays a cursor when we're allowing the user to place a piece. */
protected CursorSprite _cursor = new CursorSprite();

/** Contains a mapping from piece id to the sprite for that piece. */
protected HashMap<Comparable,PieceSprite> _sprites =
new HashMap<Comparable,PieceSprite>();

/**
* user selected piece on board
*/
protected JostleObject.Piece _selectedPiece;
/**
* new piece position on board
*/
protected IntTuple _newPiecePosition;

/** Provides access to client services. */
protected ToyBoxContext _ctx;

/** A reference to our game object. */
protected JostleObject _gameobj;

/** The size of the Jostle board. */
protected Dimension _size;

/**
* the Sprite for the die Object
*/
protected DieSprite _die;
/** The xmlLoader. */
protected XmlDataLoader _xmlLoader;

/**
* the xml Board representation
*/
protected HashIntMap<Tuple<String, Tuple<IntTuple,IntTuple>>> _stones;

/** The xml Board representation
* upper left corner of stepping stones
* and the int value of the game path
* */
protected HashMap<IntTuple,Integer> _reverseStones;

protected JostleLogic _logic;
}





It would be really nice if somebody has a hint.

Ohh and another thing if the players join the table there is a message on the table chatbox saying:
*** player left

but the player is still at the table and there is no error output.
[Jun 13, 2008 10:15:32 AM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
RazaHel
Stranger
Member's Avatar


Joined: Sep 11, 2006
Posts: 18
Status: Offline
Re: boardview does not paint and update all sprites

SOLVED in game design forum :)
[Jun 16, 2008 11:41:45 AM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
cicadess
Stranger



Joined: Sep 28, 2008
Posts: 11
Status: Offline

Re: boardview does not paint and update all sprites

One of the Most reliable and honest Power Leveling sellers is world of warcraft power leveling
These companies, for a fee will help you enhance your wow gold character. They log into your World of warcraft account and play your gamepowerlevel.com character either for a certain amount of time or until a certain level or objective is achieved. l2 power leveling While you character is being leveled you are required not to login to your account. Most offer the following power leveling (powerleveling) services:
Customized Packages, buy wow gold you specific what type of character development you are looking for and work with the company to create a package.
[Nov 25, 2008 6:42:02 PM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
[Show Printable Version of Thread]

Home | About | Account | Forums | Games           ©2005 Three Rings Design, Inc