From 3adc0a303cd93f1fa7b7b003c8ff573863974bd1 Mon Sep 17 00:00:00 2001 From: John Bojorquez Date: Sat, 18 Apr 2015 20:36:32 -0400 Subject: [PATCH] Added changes we made during today's meeting. The PlayerSprite now 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. --- MerchantRPGCSE2102/src/model/Map.java | 11 +++++++++-- MerchantRPGCSE2102/src/sprites/PlayerSprite.java | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/MerchantRPGCSE2102/src/model/Map.java b/MerchantRPGCSE2102/src/model/Map.java index 4a23275..a878598 100644 --- a/MerchantRPGCSE2102/src/model/Map.java +++ b/MerchantRPGCSE2102/src/model/Map.java @@ -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) { diff --git a/MerchantRPGCSE2102/src/sprites/PlayerSprite.java b/MerchantRPGCSE2102/src/sprites/PlayerSprite.java index 0a0007e..2026507 100644 --- a/MerchantRPGCSE2102/src/sprites/PlayerSprite.java +++ b/MerchantRPGCSE2102/src/sprites/PlayerSprite.java @@ -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;