Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / A* pathfinding in slick on: 2013-05-03 20:20:34
So I figured out my A* pathfinding, and I want to figure out how to move my entity there! Here is a movement code for the player which happens when you press "up"
1  
2  
3  
trans.y = -speed * delta;
            sprite = up;
            sprite.update(delta);

and when you press down
1  
2  
3  
trans.y = speed * delta;
            sprite = down;
            sprite.update(delta);

Because I want my player/ another entity to just walk there, not instantly show up there, and these are the codes I use for arrows keys.
And here is my pathfinding which I want the player to move through, nice and smooth like.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public static void PathFind(int startx, int starty, int endx, int endy) {
if (SimpleMap.MAP[endx][endy] == 1) {
AStarPathFinder pathFinder = new AStarPathFinder(mapd, 100, false);
        Path path = pathFinder.findPath(null, startx, starty, endx, endy);

        int length = path.getLength();
        System.out.println("Found path of length: " + length + ".");

        for(int i = 0; i < length; i++) {
            System.out.println("Move to: " + path.getX(i) + "," + path.getY(i) + ".");
        }
      } else {
      System.out.println("You can not move here!");
      }
}
2  Game Development / Newbie & Debugging Questions / Re: Tile Based Map Slick2d on: 2013-05-02 18:38:59
bump
3  Game Development / Newbie & Debugging Questions / Re: Tile Based Map Slick2d on: 2013-05-01 21:11:33
I'm not really sure if I'm loading the data in to the array properly?
4  Game Development / Newbie & Debugging Questions / Re: Tile Based Map Slick2d on: 2013-05-01 18:57:14
bump
5  Game Development / Newbie & Debugging Questions / Tile Based Map Slick2d on: 2013-05-01 06:09:13
So I have a tiled map, that is 98x98 in length.(actually it's 99x99, but the whole outside border in unwalkable.)
I'm going through with A* pathfinder to find paths,
and I have set in the .tmx map some tiles blocking to 1, and walkable tiles to 0, that way I can use it with A*
So First of all, I just want to make sure my int[][] gets the right values,
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public static int[][] mapdata = new int[98][98];

public static void MapInit() throws SlickException {
   TiledMap map = new TiledMap("res/testmap.tmx");
   int tryingx = 0;
   int tryingy = 0;
   System.out.println(map.getHeight() + "" + map.getWidth());
        for (int x=0;x<((int)map.getWidth() / 32);x++) {
        for (int y=0;y<((int)map.getHeight() / 32);y++) {
            System.out.println(x + " " + y);
            int id = map.getTileId(x, y, 0);
            String value = map.getTileProperty(id, "blocked", "true");
            if (value.equalsIgnoreCase("true")) {
               mapdata[tryingx][tryingy] = 1;
            } else {
            mapdata[tryingx][tryingy] = 0;
         }
          }
        }
        for (int x=0;x<98;x++) {
        for (int y=0;y<98;y++) {
                  System.out.println(mapdata[x][y]);
                }
              }

A= the row
B= the tile of the row
I actually want to make mapdata[ A ][ B ],
So, per say:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
mapdata = {
        {1,1,1,1,1,1,1,1,1,1},
        {1,0,0,0,0,0,1,1,1,1},
        {1,0,1,1,1,0,1,1,1,1},
        {1,0,1,1,1,0,0,0,1,1},
        {1,0,0,0,1,1,1,0,1,1},
        {1,1,1,0,1,1,1,0,0,1},
        {1,0,1,0,0,0,0,0,1,1},
        {1,0,1,1,1,1,1,1,1,1},
        {1,0,0,0,0,0,0,0,0,1},
        {1,1,1,1,1,1,1,1,1,1}
    };

The above code is just an example, but I want my mapdata to be read from the tmx file, not hardcoded like that.
I figured storing all of this data in an array would be easier than a text file, because after that is loaded into the array, I want to be able to set entities to something like "2" for interactable, etc. Is there anyway someone can direct me in the right path so i will be able to load the above mapdata correctly?
6  Game Development / Newbie & Debugging Questions / Jesus, seperate entities PLEASE on: 2013-04-30 03:04:32
Been going at this for a couple of hours on JUST this, and I can't seem to figure it out.
using it for debugging on collision detection.
well, I have an entity class, and all npcs and the player are entities, I keep all the entities in an arraylist except for the player.
my problem is, there is a method in the entity class that has their Rectangle, and since I'm debugging, I go to the render method and do, g.draw(rectangle), and it only draws it for the one entity, then I tried looping it from a different class eg.(for(Entity e : ents) {g.draw(e.getRectangle());}, and STILL only draws one of the entitys. This is really pissing me off.
Let me know if you need some of the code, or you could just explain to me what could be causing it.
And let me know if you need more info.
Thanks.
7  Java Game APIs & Engines / Java 2D / Re: slick2d animation. probably a simple error. on: 2013-04-28 03:18:53
Also just realized this is the wrong section >>
8  Java Game APIs & Engines / Java 2D / slick2d animation. probably a simple error.[solved] on: 2013-04-28 02:49:37
solved, needed a sprite.update method.
thanks!
9  Game Development / Newbie & Debugging Questions / Re: [Slick2D] coordinate checking on: 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.
10  Game Development / Newbie & Debugging Questions / Re: [Slick2D] coordinate checking on: 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?
11  Game Development / Newbie & Debugging Questions / [Slick2D] coordinate checking on: 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
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (80 views)
2014-11-01 23:36:41
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!