Skip to content

Commit

Permalink
Added changes we made during today's meeting. The PlayerSprite now
Browse files Browse the repository at this point in the history
checks to make sure the instance it is colliding with is of the type
"model.Merchant". If it is of a different type, it will stop movement,
but not give the option for a transaction. This will allow us to add
objects such as trees, houses, etc. to our Map.
  • Loading branch information
john committed Apr 19, 2015
1 parent 4db0bfd commit 3adc0a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions MerchantRPGCSE2102/src/model/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@ public boolean isOccupied(int col, int row) {
if (row < 0 || col < 0 || row >= _rows || col >= _cols)
return false;
else {
setCurrentNearbyMerchant((Merchant) _mapGraph.getVertex(row*_cols + col).getOccupant());
return _mapGraph.getVertex(row*_cols + col).getOccupant() != null;
if (_mapGraph.getVertex(row*_cols + col).getOccupant() != null) {
System.out.println(_mapGraph.getVertex(row*_cols + col).getOccupant().getClass().getName());
if (_mapGraph.getVertex(row*_cols + col).getOccupant().getClass().getName().equals("model.Merchant"))
setCurrentNearbyMerchant((Merchant) _mapGraph.getVertex(row*_cols + col).getOccupant());
return true;
}
}

setCurrentNearbyMerchant(null);
return false;
}

public boolean collisionTo(String direction) {
Expand Down
4 changes: 2 additions & 2 deletions MerchantRPGCSE2102/src/sprites/PlayerSprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public void keyReleased(KeyEvent e) {
}
if (e.getKeyCode() == KeyEvent.VK_F){
if((mapui.getMap().collisionTo("east"))||(mapui.getMap().collisionTo("west"))||(mapui.getMap().collisionTo("south"))||(mapui.getMap().collisionTo("north"))||(mapui.getMap().collisionTo("northeast"))||(mapui.getMap().collisionTo("northwest"))||(mapui.getMap().collisionTo("southeast"))||(mapui.getMap().collisionTo("southwest"))){
System.out.println("Transaction starting"); // For testing purposes
mapui.game.createTransaction(mapui.map.getPlayer(), mapui.map.getCurrentNearbyMerchant());//RPGame initialize Trade
if (mapui.getMap().getCurrentNearbyMerchant() != null)
mapui.game.createTransaction(mapui.map.getPlayer(), mapui.map.getCurrentNearbyMerchant());//RPGame initialize Trade
}
else{
return;
Expand Down

0 comments on commit 3adc0a3

Please sign in to comment.