By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

code works but why?

P: 59

hi I am following a tutorial which shows how to create tileMap game in java. But i cant seem to understand some of the methods and variables. main code i post it on take a look.

problem is I cant seem to understand what is method calculateCorners is doing.

Expand|Select|Wrap|Line Numbers
  1. calculateCorners(x, toy);
  2.         /*******************************/
  3.     /*** calculateCorners method ***/
  4.     public void calculateCorners(double x, double y) {
  5.         int leftTile = tileMap.getColTile((int) (x - width / 2));
  6.         int rightTile = tileMap.getColTile((int) (x + width / 2) - 1);
  7.         int topTile = tileMap.getColTile((int) (y - height / 2));
  8.         int bottomTile = tileMap.getColTile((int) (y + height / 2) - 1);
  10.         // check if player can move to tiles
  11.         // 0 = cant move up
  12.         topLeft = tileMap.getTile(topTile, leftTile) == 0;
  13.         topRight = tileMap.getTile(topTile, rightTile) == 0;
  14.         bottomLeft = tileMap.getTile(bottomTile, leftTile) == 0;
  15.         bottomRight = tileMap.getTile(bottomTile, rightTile) == 0;
  16.     }// End of calculateCorners

first question is:
i understand that topLeft, are booleans to check if player can move there or not. But why only 4 boolean? dont you need "top, topLeft, topRight, etc" what is player just jump up? than dont you get boolean "top".

2nd question is:
can you guys explain "int leftTile, rightTile .. etc" variables?

also why we are doing (x-width/2)?

also try to explain as much as you can bc i dont understand this.
Oct 3 '13 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 3,112
Without knowing the context it is difficult to tell you what anything in your code is for. Is the tutorial online and if so, can you paste a link to it? You don't even say what kind of game we're talking about. Also, where is the implementation of the TileMap class? With more information, I'm sure we'll be able to help you understand the code.
Oct 4 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.