Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Slick2D] coordinate checking  (Read 422 times)
0 Members and 1 Guest are viewing this topic.
Offline superhigh

Senior Newbie





« Posted 2013-04-27 02:06:35 »

Hey guys, first post here, and I got a question!
I made a slick2d game, and used the TilED map editor, and the tiles I want unwalkable I made them a setting where "block = true", and I can make my game read that, well; heres my code.
I have my sprite drawn in the middle of the screen, and he himself never moves. the map moves when he moves. (this might not be a good way of doing it, but I wanted it to be a scroller map, like you down get to the edge of the screen and have to load another map and it (eg, you got to the bottom of the first map, it loads the second map, and your sprite moves to the top because my map it bigger than the gameframe) right now my sprite is able to move around the whole map without re drawing a different map.
so basically, i guys the maps float x, y is the coordinates will be the players coordinates(if that makes sense.)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public boolean isBlock() {
         for (int i = 0; i < grassMap.getWidth(); i++) {
            for (int h = 0; h < grassMap.getHeight(); h++) {
               int tileID = grassMap.getTileId(i, h, 0);
               String v = grassMap.getTileProperty(tileID, "blocked", "false");
               if ("true".equals(v)) {
               return true;
               System.out.println("blocked? x:"+i+" y:"+h);
               } else {
               return false;
               }
            }
         }
     
      }

blocked = [grassmap.getwidth()][grassmap.getheight()]

the problem is that only returns positive values, but there are parts in the map where the coordinates I want blocked are (ex. -3, -5 )

let me know if I should explain more
Offline Axeman

Senior Duke


Medals: 7



« Reply #1 - Posted 2013-04-27 02:21:06 »

Why and how could the tilemap have negative coordinates? I think you´ll have to explain more... Smiley
Offline superhigh

Senior Newbie





« Reply #2 - Posted 2013-04-27 02:25:04 »

The map doesn't it return positives. but when I move around the map, (right when i spawn im at float x = 0;) so if I move left my float x goes negative, and in fact (int)x is still negative, I mean IN-GAME, the tiles that are supposed to be blocked are in a negative x/y of the map, and you cant put a negative in a new boolean[][] array!

Get it?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Axeman

Senior Duke


Medals: 7



« Reply #3 - Posted 2013-04-27 02:38:14 »

You need to put the player in the same coordinate system as your map so they have the same point of reference. Don´t spawn the player at zero, spawn the player at some coordinate on the map that´s... Not zero... Smiley
Offline superhigh

Senior Newbie





« Reply #4 - Posted 2013-04-27 02:42:49 »

oops, wait, he is spawned in the center of the screen
private float currentX = 304;
private float currentY = 224;
I just considder it 0, because he never moves.
and the map is at
private float x = 0, y = 0;
so when the left arrow key is pressed, x which is the map goes to -1 per say, and the character never moves, but the map does.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (54 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!