Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 / Re: please, help get started: choose the framework for 2d on: 2011-07-11 08:31:00
Another vote for slick 2d
2  Game Development / Newbie & Debugging Questions / Re: Slick2d smooth movement between tiles on: 2011-07-10 22:12:58
I've managed to get this working by using the following code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
if(moveInProgress == true){
         if(moveDirection.equalsIgnoreCase("a")){
               if(currentMoveStep <= 31 && currentMoveStep > 0){                  
               x = x-1;
               currentMoveStep--;
            }else if(currentMoveStep == 0){
               moveInProgress = false;
               currentMoveStep = 31;
            }  


Every update I'm incrementing the sprites position by one pixel, once a full tile has been moved a reset a boolean value to stop any further movement and accept another key press. It seems to work well, I just cant tell if there is a better solution to this.
3  Game Development / Newbie & Debugging Questions / Re: Slick2d smooth movement between tiles on: 2011-07-10 13:33:44
use setTargetFPS(int fps);

and maybe setVsync(boolean);

I already am, its not the issue that I have the logic and its not smooth, I dont know how to move the sprite gradually in the update method rather than moving it 32 pixels at a time.

For example, I want the player to press a key and it takes half a second or so for the sprite to move from tile to tile, rather then just suddenly appearing there as its being moved the full distance in one frame.
4  Game Development / Newbie & Debugging Questions / Slick2d smooth movement between tiles on: 2011-07-10 11:23:36
I've just started using Slick2d this week and have so far managed to put together the basics of a simple 2d top down game. I have a sprite moving around the screen and doing basic tile based collision detection. For the game mechanic that I eventually want restricting player/sprite movement to be tile by tile is sufficnet. However as you will see from the code below I dont have smooth movement between the tiles as during my collision detection if the target tile is not blocked I simply move the sprite 32 pixels (the size of a tile). I'm trying to figure out how can I keep my tile based collision detection by smoothly move the sprite from tile to tile, and then eventually animate it. I've some some experiments with multiplying by the delta in the update method but have not made any progress.

I'd be extremely grateful for any suggestions on how I should accomplish this. Source below.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
import org.lwjgl.util.vector.Vector2f;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

public class TestGame extends BasicGame{
   private boolean[][] blocked;
   Vector2f currentPosition = new Vector2f();
   Image characterFront = null;
   Image characterLeft = null;
   Image land = null;
   float x = 100;
   float y = 90;
   float scale = 1;
   TiledMap map = null;
   Player player;
   public TestGame()
   {
      super("Game");

   }

   @Override
   public void init(GameContainer gc)throws SlickException {
      //load played entity which handles resource loading for player sprite  
     player = new Player();
      //load the tiled map
     map = new TiledMap("data/untitled.tmx","/data");          
      // build a collision map based on tile properties in the tile map
     blocked = new boolean[map.getWidth()][map.getHeight()];
      //set starting position
     currentPosition.set(0f, 0f);
      //populate collision map
     for (int xAxis=0;xAxis<map.getWidth(); xAxis++)
      {
         for (int yAxis=0;yAxis<map.getHeight(); yAxis++)
         {                        
            int tileID = map.getTileId(xAxis, yAxis, 1);
            String value = map.getTileProperty(tileID, "blocked", "false");                        
            if (value.equalsIgnoreCase("true"))
            {
               System.out.println("tile id " + tileID + " at x=" + xAxis +" y="
                     + yAxis +" is BLOCKED");
               blocked[xAxis][yAxis] = true;
            }else{

               blocked[xAxis][yAxis] = false;
            }
         }
      }

   }

   @Override
   public void update(GameContainer gc, int delta)
   throws SlickException
   {
      Input input = gc.getInput();
      //check what key has been pressed then check if target tile is registered as blocked in collision map
     
      if(input.isKeyPressed(Input.KEY_A))
      {
         player.setPlayerImage("a");
         if(blocked[(int) Math.abs(currentPosition.getX() - 1f)][(int) Math.abs(currentPosition.getY())] == true){
            System.out.println("blocking movement");          
         }else{          
            x = x - 32;
            currentPosition.setX(currentPosition.getX() - 1);
         }          
      }

      if(input.isKeyPressed(Input.KEY_D))
      {
         player.setPlayerImage("d");
         if(blocked[(int) Math.abs(currentPosition.getX() + 1f)][(int) Math.abs(currentPosition.getY())] == true){            
            System.out.println("blocking movement");
         }else{
            x = x + 32;
            currentPosition.setX(currentPosition.getX() + 1);
         }
      }

      if(input.isKeyPressed(Input.KEY_W))
      {
         player.setPlayerImage("w");
         if(blocked[(int) Math.abs(currentPosition.getX())][(int) Math.abs(currentPosition.getY() - 1f)] == true){            
            System.out.println("blocking movement");                          
         }else{
            y = y - 32;
            currentPosition.setY(currentPosition.getY() - 1);
         }          
      }

      if(input.isKeyPressed(Input.KEY_S))
      {
         player.setPlayerImage("s");
         if(blocked[(int) Math.abs(currentPosition.getX())][(int) Math.abs(currentPosition.getY() + 1f)] == true){            
            System.out.println("blocking movement");                        
         }else{        
            y = y + 32;
            currentPosition.setY(currentPosition.getY() + 1);
         }        
      }
   }

   public void render(GameContainer gc, Graphics g)
   throws SlickException
   {
      map.render(100,100);
      player.getPlayerImage().draw(x, y, scale);

   }

   public static void main(String[] args)
   throws Exception
   {
      AppGameContainer app =
         new AppGameContainer( new TestGame() );
      app.setDisplayMode(800, 600, false);
      app.setVSync(true);
      app.setTargetFrameRate(60);
      app.start();
   }
}
5  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Extracting tiled metadata in slick2d on: 2011-07-07 11:30:29
Epic fail on my part as I've only just been introduced to tiled I was not aware that there was a distinction between a tile in the tileset having a property and the whole tileset having a property. Once I attached a property to the individual tile it worked.

What a crap first post Cheesy

 Roll Eyes
6  Java Game APIs & Engines / Engines, Libraries and Tools / Extracting tiled metadata in slick2d on: 2011-07-07 10:57:25
This is a cross post from the slick2d forums, I'm also posting it here as their forum does not appear to be very active.

     
Hi,

I'm attempting to implement some very basic collision detection for my tiled map. I've created a new map in tiled with two tilesets (each containing one image, grass and rocks). I've first drawn some grass tiles, and then some rocks above them. I then right clicked on the rocks layer and set layer properties to blocked and true. I've also inspected the XML in the file and the property is definitely there.

In my code I run the following nested for loop to build a two dimensional array of tiles that contain the blocked attribute.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
for (int xAxis=0;xAxis<map.getWidth(); xAxis++) 
        {
                     for (int yAxis=0;yAxis<map.getHeight(); yAxis++)
                     {
                         
                        int tileID = map.getTileId(xAxis, yAxis, 0);
                         String value = map.getTileProperty(tileID, "blocked", "false");
                         //System.out.println("value is " + value);
                        if (value.equalsIgnoreCase("true"))
                         {
                            System.out.println("tile id" + tileID + "is BLOCKED");
                             blocked[xAxis][yAxis] = true;
                         }
                     }
         }

However none of the tiles are ever detected as having the blocked attribute. I've confirmed the index of the layer rocks by calling getLayerIndex("rocks") however it still doesn't work.

I'd be extremely grateful for any suggestions as this is very very frustrating.
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.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!