Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1422 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.)
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 Devvie

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 Devvie

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  

EgonOlsen (61 views)
2018-06-10 19:43:48

EgonOlsen (42 views)
2018-06-10 19:43:44

EgonOlsen (61 views)
2018-06-10 19:43:20

DesertCoockie (241 views)
2018-05-13 18:23:11

nelsongames (142 views)
2018-04-24 18:15:36

nelsongames (141 views)
2018-04-24 18:14:32

ivj94 (883 views)
2018-03-24 14:47:39

ivj94 (144 views)
2018-03-24 14:46:31

ivj94 (795 views)
2018-03-24 14:43:53

Solater (159 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!