From af546c7504e97042f4e2f2ca8ca3547f6be81d81 Mon Sep 17 00:00:00 2001 From: lul11003 Date: Sat, 25 Apr 2015 11:52:20 -0400 Subject: [PATCH] working Object collison --- MerchantRPGCSE2102/src/controller/RPGame.java | 7 ++++++- MerchantRPGCSE2102/src/view/MapUI.java | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index 8f5c926..3740343 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -74,8 +74,13 @@ public RPGame(int transactionLimit, int tileSize) { mapui = new MapUI(map, this, tileSize); mapui.createPlayerSprite(rows/2, cols/2); mapui.addMerchantSprite(rows/2, 1); + mapui.addCollison(rows/2,1); mapui.addMerchantSprite(rows-2, cols/2); + mapui.addCollison(rows-2, cols/2); mapui.addMerchantSprite(rows/2, cols-2); + mapui.addCollison(rows/2, cols-2); + + mapui.addCollison(rows/3, cols/3); // Creating JFrame window JFrame frame = new JFrame("Merchant RPG"); @@ -346,7 +351,7 @@ public static void main(String[] args) throws InterruptedException // MAIN GAME LOOP while (true) { rpgGame.updateMapUI(); - Thread.sleep(1000/144); // Controls the speed of the game (currently 144 frames/second) + Thread.sleep(1000/300); // Controls the speed of the game (currently 144 frames/second) } } } diff --git a/MerchantRPGCSE2102/src/view/MapUI.java b/MerchantRPGCSE2102/src/view/MapUI.java index 4e26292..bba61c8 100644 --- a/MerchantRPGCSE2102/src/view/MapUI.java +++ b/MerchantRPGCSE2102/src/view/MapUI.java @@ -29,7 +29,7 @@ public class MapUI extends JPanel { public int tileSize; private PlayerSprite player; private ArrayList merchants = new ArrayList(); - + private ArrayList collisons = new ArrayList(); public MapUI(Map map, RPGame Game, int tileSize) { @@ -99,7 +99,10 @@ public void addMerchantSprite(int row, int col) { MerchantSprite merchant = new MerchantSprite(row, col); merchants.add(merchant); } - + public void addCollison(int row, int col) { + MerchantSprite merchant = new MerchantSprite(row, col); + collisons.add(merchant); + } /** * Creates a player sprite to be painted on the canvas * @param row The row of the player @@ -177,7 +180,7 @@ public Map getMap() { } public ArrayList getMerchants() { - return merchants; + return collisons; }