Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (604)
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] 2 3
1  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-11-04 07:25:32
So now I have almost fixed it. I converted the xScroll and yScroll into isometric co-ordinates, and changed the nested-for-loop from cartesian into isometric, and then converted the x and y (in isometric co-ordinates) into cartesian and called the the getTile(cartX,cartY).render(cartX,cartY,screen);

My problem now is, that the screen doesn't scroll fast enough, when you walk left and right. I think that it is the xScroll, that doens't get the right update. The code follows:

Setting the xScroll and yScroll in Games render method:
1  
2  
3  
4  
5  
int xScroll = (int) Math.round((_player.getX() - _player.getY())
            - (_screen.getWidth() / 2));
int yScroll = (int) Math.round((_player.getX() + _player.getY())
            - (_screen.getHeight() / 2));
_level.isometricRender(xScroll, yScroll, _screen);


Render method in Level:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public void isometricRender(int xScroll, int yScroll, Screen screen) {
      screen.setOffsets(xScroll, yScroll);
      int x0 = xScroll / Tile.WIDTH - 4;
      int x1 = x0 + 11;
      int y0 = yScroll / Tile.HEIGHT;
      int y1 = y0 + 7;

      int cartX = 0;
      int cartY = 0;

      for (int y = y0; y < y1; y++) {
         for (int x = x0; x < x1; x++) {
            cartX = (2 * y + x) / 2;
            cartY = (2 * y - x) / 2;
            getTile(cartX, cartY).isometricRender(cartX, cartY, screen);
         }
      }
}


A little help on understanding how to update the xScroll would be nice.

Thanks in advance Smiley
2  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-11-04 05:24:10
Thank you for the help so far. I willt ake a closer look at your code Smiley Thnks.
3  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-11-02 08:20:33
Yes, and it getting me weird outputs Tongue

I think my problem is understading the logic in how to approach this matter. I know that I should figure out the top left corner tile on the scrren, but I am unsure  on how to select the right tiles to draw. Smiley
4  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-11-01 12:18:52
If I remove the lines which using the offsets in renderTile. It renders the player in the top left corner (0,0) but no tiles. :/
5  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-11-01 10:26:58
Quote
sure, but how do the two methods interact.... i.e. does calling setOfffsets mean that the later render call has these offsets applied to isoX and isoY? if so then you are doubly taking scrolling into account. The isoX and isoY values already have scrolling taken into account and should be used directly when rendering.

Levels isometricRender method:
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  
public void isometricRender(int xScroll, int yScroll, Screen screen) {
      screen.setOffsets(xScroll, yScroll);
      int VIEW_PORT_HEIGHT = 5; // in cartesian map scale
      // minus one. assuming square map.
      int VIEW_PORT_WIDTH = 5; // in cartesian map scale

      float scrollYScreenUnit = 0; // should be updated when scrolling the
      // view port. the unit is in cartesian
      // map scale. i.e. 1 unit = 1 tile
      float scrollXScreenUnit = 0; // should be updated when scrolling the
      // view port. the unit is in cartesian
      // map scale.

      // determine whether to start on an "alternative" line. i.e. offset x by
      // half the tile width
      int alternateScanline = (int) ((scrollYScreenUnit % 1) * 2);
      // determine the cartesian co ordinate of the top left corner of the
      // current view.

      int scrollMapX = (int) ((scrollYScreenUnit + 0.5F) + 0.5F * (scrollXScreenUnit));
      // determine the cartesian co ordinate of the top left corner of the
      // current view.

      int scrollMapY = (int) ((scrollYScreenUnit + 0.5F) - 0.5F * (scrollXScreenUnit));

      for (int y = -1; y < VIEW_PORT_HEIGHT * 2; y++) {
         alternateScanline = (++alternateScanline) % 2;
         // cartesian co-ordniate of current tile to be rendered
         int xGame = scrollMapX;
         // cartesian co-ordniate of current tile to be rendered
         int yGame = scrollMapY;

         for (int x = -2; x < VIEW_PORT_WIDTH; x++) {
            // convert to isometric X
            int isoX = (int) ((xGame - yGame - scrollXScreenUnit - 1.0F)
                  * Tile.WIDTH / 2);
            // convert to isometric Y
            int isoY = (int) ((0.5F * (xGame + yGame) - scrollYScreenUnit - 0.25F)
                  * Tile.HEIGHT / 2);

            if (xGame > 0 && yGame > 0 && xGame < _width - 1
                  && yGame < _height - 1) {
               getTile(x, y).render(isoX, isoY, screen);
            }
            xGame++;
            yGame--;
         }
         // update the statring point of the next line of tiles based on
         // whether it is an alternative line
         scrollMapY += alternateScanline;
         // or not. if it is then the line is shifted out of phase by half.
         scrollMapX += 1 - alternateScanline;
      }

      for (int i = 0; i < _entities.size(); i++) {
         _entities.get(i).isometricRender(screen);
      }

      for (int i = 0; i < _players.size(); i++) {
         // _players.get(i).isometricRender(screen);
      }

      for (int i = 0; i < _projectiles.size(); i++) {
         _projectiles.get(i).isometricRender(screen);
      }
      for (int i = 0; i < _particles.size(); i++) {
         _particles.get(i).isometricRender(screen);
      }
   }



Render method in Tile:
1  
2  
3  
public void render(int x, int y, Screen screen) {
      screen.renderTile(x * WIDTH, y * HEIGHT, this);
   }


Screens renderTile method:
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 void renderTile(int xp, int yp, Tile tile) {
      xp -= _xOffset;
      yp -= _yOffset;
      int color;
      for (int y = 0; y < tile.getSprite().getHeight(); y++) {
         int ya = y + yp;
         for (int x = 0; x < tile.getSprite().getWidth(); x++) {
            int xa = x + xp;
            if (xa < -tile.getSprite().getWidth() || xa >= _width || ya < 0
                  || ya >= _height) {
               break;
            }
            if (xa < 0) {
               xa = 0;
            }
            color = tile.getSprite().getPixels()[x + y
                  * tile.getSprite().getWidth()];

            if (color != 0xffff00ff) {
               _pixels[xa + ya * _width] = color;
            }
         }
      }
   }


The render method for player:
1  
2  
3  
4  
5  
public void isometricRender(Screen screen) {
      int isoX = (int) Math.round(_x - _y);
      int isoY = (int) Math.round((_x + _y));
      screen.renderNPC(isoX - (SIZE / 2), isoY - (SIZE / 2), _sprite, 0);
   }
6  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-11-01 05:32:55
Quote
I am not sure what effect the call to screen.setOffsets(xScroll, yScroll) has...
xScroll and yScroll is the top-left corner of the cartesian map, with the player centered.

Quote
I am suspicious of what getTile(x, y).render(isoX, isoY, screen)
This method gets the Tile at x,y (cartesian) in the map array, and on that Tile it calls the renderTile method on screen, which draws it to the screen in isometric coordinates.
7  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-10-31 21:40:42
I've implemented you solution into my game, but now it doesn't render any Tiles on the screen. Maybe some offSet isn't right? The player is rendered in the middle of the screen, but the screen doesn't follow the player, when the player moves, also the movement isn't right... Tongue

Quote
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  
public void isometricRender(int xScroll, int yScroll, Screen screen) {
      screen.setOffsets(xScroll, yScroll);
      int VIEW_PORT_HEIGHT = 5; // in cartesian map scale
      int VIEW_PORT_WIDTH = 5; // in cartesian map scale

      float scrollYScreenUnit = 0;
      float scrollXScreenUnit = 0;
      int alternateScanline = (int) ((scrollYScreenUnit % 1) * 2);

      int scrollMapX = (int) ((scrollYScreenUnit + 0.5F) + 0.5F * (scrollXScreenUnit));

      int scrollMapY = (int) ((scrollYScreenUnit + 0.5F) - 0.5F * (scrollXScreenUnit));

      for (int y = -1; y < VIEW_PORT_HEIGHT * 2; y++) {
         alternateScanline = (++alternateScanline) % 2;
         int xGame = scrollMapX;
         int yGame = scrollMapY;

         for (int x = -2; x < VIEW_PORT_WIDTH; x++) {
            int isoX = (int) ((xGame - yGame - scrollXScreenUnit - 1.0F)
                  * Tile.WIDTH / 2);
            int isoY = (int) ((0.5F * (xGame + yGame) - scrollYScreenUnit - 0.25F)
                  * Tile.HEIGHT / 2);

            if (xGame > 0 && yGame > 0 && xGame < _width - 1
                  && yGame < _height - 1) {
               getTile(x, y).render(isoX, isoY, screen);
            }
            xGame++;
            yGame--;
         }
         scrollMapY += alternateScanline;
         scrollMapX += 1 - alternateScanline;
      }
   //Code for render other objects...
}
8  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-10-31 21:03:43
Quote
1  
2  
3  
int alternateScanline = (int) ((scrollYScreenUnit%1) * 2); // determine whether to start on an "alternative" line. i.e. offset x by half the tile width
      int scrollMapX = (int) ((scrollYScreenUnit+0.5F)+0.5F*(scrollXScreenUnit)); // determine the cartesian co ordinate of the top left corner of the current view.
      int scrollMapY = (int) ((scrollYScreenUnit+0.5F)-0.5F*(scrollXScreenUnit)); // determine the cartesian co ordinate of the top left corner of the current view.

alternateScanline <- this is for figuring out if its an odd line right?

scrollMapX and scrollMapY <- these are the coordinates of the top left corner tile in the cartesian map?

Thank you for the help, I really appriciate it Smiley
9  Game Development / Newbie & Debugging Questions / Re: Isometric game get what tiles to draw to the screen on: 2014-10-31 07:28:02
Quote
1  
2  
3  
4  
   private static final int VIEW_PORT_HEIGHT = 20; // in cartesian map scale
   private static final int TILE_SIZE_DIV_2 = 16; // in pixels. half of the tile size
   private static final int MAP_SIZE_MINUS_ONE = 99; // maximum size of the map to be rendered minus one. assuming square map.
   private static final int VIEW_PORT_WIDTH = 30; // in cartesian map scale

VIEW_PORT_HEIGHT is that the total height of Tiles? And is it the isometric-tiles height?
MAP_SIZE_MINUS_ONE is that the number of tiles to be rendered?
And the same for VIEW_PORT_WIDTH Smiley

Quote
1  
2  
      float scrollYScreenUnit=0; // should be updated when scrolling the view port. the unit is in cartesian map scale. i.e. 1 unit = 1 tile  
      float scrollXScreenUnit=0; // should be updated when scrolling the view port. the unit is in cartesian map scale.

Are these 2 variables for the Screen top-left corner?
10  Game Development / Newbie & Debugging Questions / [SOLVED]I sometric game get what tiles to draw to the screen on: 2014-10-29 08:38:47
I just finish drawing a 2d cartesian tile array to an isometric screen.

I now wonder how to get what tiles to draw. As my code is now it draw the tiles within the screen, but it takes the cartesian coordinates, and not the isometric tiles within the screen.

My code for selcting what tiles to draw follows here:

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  
   public void isometricRender(int xScroll, int yScroll, Screen screen) {
      screen.setOffsets(xScroll, yScroll);
      int x0 = xScroll / Tile.WIDTH;
      int x1 = (xScroll + screen.getWidth() + Tile.WIDTH) / Tile.WIDTH - 1;
      int y0 = yScroll / Tile.HEIGHT;
      int y1 = (yScroll + screen.getHeight() + Tile.WIDTH) / Tile.WIDTH + 1;

      for (int y = y0; y < y1; y++) {
         for (int x = x0; x < x1; x++) {
            getTile(x, y).isometricRender(x, y, screen);
         }
      }

      for (int i = 0; i < _entities.size(); i++) {
         _entities.get(i).isometricRender(screen);
      }

      for (int i = 0; i < _players.size(); i++) {
         // _players.get(i).isometricRender(screen);
      }

      for (int i = 0; i < _projectiles.size(); i++) {
         _projectiles.get(i).isometricRender(screen);
      }
      for (int i = 0; i < _particles.size(); i++) {
         _particles.get(i).isometricRender(screen);
      }
   }


I need help to set the offsets so that it draws the tiles within the screen.

The game looks like this:



Really appriciate you help Smiley
11  Game Development / Newbie & Debugging Questions / Re: Think im rendering wrong womehow (isometric) on: 2014-10-29 07:21:43
Well that looks like its working? What is the array your providing look like?

Yes, now it actually looks right.

The map array is a 2d array in cartesian coordinates, and is stoed in the Level class.

Now I need to increase the area of tiles that is drawn, and fix the controls. Smiley
12  Game Development / Newbie & Debugging Questions / Re: Think im rendering wrong womehow (isometric) on: 2014-10-29 06:21:16
I've changed the redering method in Tile to (got it from the link above (thanks):

1  
2  
3  
4  
5  
   public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y);
      int isoY = (x + y);
      screen.renderTile(isoX * (WIDTH / 2), isoY * (HEIGHT / 2), this);
   }


I get the follwing when I use the code from above:

13  Game Development / Newbie & Debugging Questions / Re: Think im rendering wrong womehow (isometric) on: 2014-10-29 05:56:27
I don't have time atm to read through much, but take a scroll through this thread: http://www.java-gaming.org/topics/isometric-game-design/33434/view.html

Found one mistake more. The Tiles render method now looks like:
1  
2  
3  
4  
5  
   public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y);
      int isoY = (x + y) / 2;     //Was - (minus) before
      screen.renderTile(isoX * WIDTH, isoY * HEIGHT, this);
   }


Now it looks like this:


It is like every second row hasn't the right offset?
14  Game Development / Newbie & Debugging Questions / Re: Think im rendering wrong womehow (isometric) on: 2014-10-29 05:26:17
Here is a link that really helped me with my now dead isometric game : http://gamedevelopment.tutsplus.com/tutorials/creating-isometric-worlds-a-primer-for-game-developers--gamedev-6511

If you really want here is the render code I had per tile (note 64 is the width of my tiles)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void render(float ZOOM,float DISPLACEMENT_X,float DISPLACEMENT_Y,SpriteBatch batch){
   
   
   renderX = x * (64 - ZOOM);
   renderY =  y * (64 - ZOOM);
   

   
   batch.draw(spr,/* X position */ (renderX - renderY) + DISPLACEMENT_X, /* Y position */ ((renderX + renderY) / 2) + DISPLACEMENT_Y ,width - (ZOOM * 2), ((width - (ZOOM * 2)) * ratio) );
   
}


If you are looking at the code, the only things that will matter are where I've put the comments



That is the tutorial I've been using, but when I apply the math (as in the code for the render method in Tile. I now see that I divide by 2 in the isoX, that I have ficed now, but it still looks very weird:



the code for rendering tiles now looks like this:
1  
2  
3  
4  
5  
   public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y);
      int isoY = (x - y) / 2;
      screen.renderTile(isoX * WIDTH, isoY * HEIGHT, this);
   }


Maybe I should mention that the map is loaded into an 2d array, so the map is in cartesian coordinates.
15  Game Development / Newbie & Debugging Questions / Re: Think im rendering wrong womehow (isometric) on: 2014-10-29 04:29:17
Thank you! Smiley

Well it draws something. I have a picture of what it draws. The player is located at (0,0), but as you see, the drawing is wrong in some way Smiley

16  Game Development / Newbie & Debugging Questions / [SOLVED]Think im rendering wrong womehow (isometric) on: 2014-10-28 16:35:37
Hi, this is my first post. I really hope you can help me.

Im making a isometric game, with a cartesian map. the map is loaded from an image file into an array. The screen class stands for the renderen and gets the pixels from a pixel array saved in a Sprite, and put that pixel value into the Screens pixel array, and the screens draws its own array onto the screen.

Screens renderTile method gets the isometric coordinates, and draws them onto the screen.
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 void renderTile(int xp, int yp, Tile tile) {
      xp -= _xOffset;
      yp -= _yOffset;
      int color;
      for (int y = 0; y < tile.getSprite().getHeight(); y++) {
         int ya = y + yp;
         for (int x = 0; x < tile.getSprite().getWidth(); x++) {
            int xa = x + xp;
            if (xa < -tile.getSprite().getWidth() || xa >= _width || ya < 0
                  || ya >= _height) {
               break;
            }
            if (xa < 0) {
               xa = 0;
            }
            color = tile.getSprite().getPixels()[x + y
                                                 * tile.getSprite().getWidth()];

            if (color != 0xffff00ff) {
               _pixels[xa + ya * _width] = color;
            }
         }
      }
   }


Tiles render method takes the cartesian coordinates and convert them into isometric coordinates, and sends them into Screen, where they are draw as in the method above:
1  
2  
3  
4  
5  
public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y) / 2;
      int isoY = (x - y) / 2;
      screen.renderTile(isoX * WIDTH, isoY * HEIGHT, this);
   }


I really appriciate your help Smiley
17  Game Development / Newbie & Debugging Questions / Re: Tile based movement (Bomberman style) on: 2011-12-07 02:20:00
I think it works, cant test it yet though, cause I have some bug in my code, the units moves downwards by default, and never reaches their destination, but I have given you an appreciate Smiley
18  Game Development / Newbie & Debugging Questions / Re: Tile based movement (Bomberman style) on: 2011-12-07 01:44:34
yes I did that:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
        public void headTowardsDestination(){
      if(!this.destinationReached){
         int currentX = this.currentPosition.getX();
         int currentY = this.currentPosition.getY();
         int destinationX = this.destinationPosition.getX();
         int destinationY = this.destinationPosition.getY();
         if(currentX < destinationX){
            this.currentPixelX++;
         }else if(currentX > destinationX){
            this.currentPixelX--;
         }else if(currentY < destinationY){
            this.currentPixelY++;
         }else if(currentY > destinationY){
            this.currentPixelY--;
         }
      }
   }


But where should should I assign destinationReached = false; ?
19  Game Development / Newbie & Debugging Questions / Re: Tile based movement (Bomberman style) on: 2011-12-07 01:25:59
[EDIT] Well it kinda works!

My only problem is that it never stops moving now :S
Can't figure out where to put the check if the destination is reached....?
20  Game Development / Newbie & Debugging Questions / Re: Tile based movement (Bomberman style) on: 2011-12-06 23:01:58
This is my unit class, and the getters and setters for each field:

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  
public abstract class Unit implements WorldObject{
   private Position currentPosition;
   private Position destinationPosition;
   private String name;
   private String type;
   private int strength;
   private int agility;
   private int vitality;
   private int xp;
   private int level;
   private int chips;
   private double health;
   private double attackDamage;
   private double dodgeRating;
   private int luck;
   private int attackRange;
   private double maxHealth;
   private String unitClass;
   private Vector direction;
   private int energy;
   private BufferedImage image;
   private int currentPixelX;
   private int currentPixelY;
   private boolean visible;
   private boolean isMoving;

   public Unit(Position p, String name, String type) {
      this.currentPosition = p;
      this.setCurrentPixelX(0);
      this.setCurrentPixelY(0);
      this.name = name;
      this.type = type;
      this.direction = new Vector(1,0);
      loadImage();
   }

   private void loadImage() {
      this.image = null;
      try{
         this.image = ImageIO.read(new File("bin/image/unit/" + this.type + ".png"));
      }catch (Exception e) {
         System.out.println("Couldn't find " + this.type + "'s image file");
      }
   }
}
21  Game Development / Newbie & Debugging Questions / Re: Tile based movement (Bomberman style) on: 2011-12-06 04:52:11
So I'm back to square one, tried to draw units in a separate loop, but couldn't get it to work. Is there any other approach, or would you get me started at drawing them the correct way?

This is my "old" render method:

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  
   public void render() {
      Graphics2D bbg = (Graphics2D) this.backBuffer.getGraphics();
      BufferedImage image = null;

      this.player = this.game.getTileMap().getPlayer();
      this.inventory = player.getInventory();
      nullTile = new Tile(position, "WATER");
      this.unitHeightOffset = 0;
      for(int y = 0; y < 24; y++){
         for(int x = 0; x < 42; x++){
            int unitHeightOffset = 0;
            position.setX(x + player.getPosition().getX() - this.xOffset);
            position.setY(y + player.getPosition().getY() - this.yOffset);
            //Draw tiles
            Tile tile = this.game.getTileMap().getTileAt(position);
            if(tile != null){
               image = tile.getImage();
            }else{
               image = nullTile.getImage();
            }

            //Draw items
            Item item = this.game.getTileMap().getItemAt(position);
            if(item != null){
               image = item.getImage();
            }

            //Draw buildings
            Building building = this.game.getTileMap().getBuildingAt(position);
            if(building != null){
               image = building.getImage();
            }

            //Draw units
            Unit unit = this.game.getTileMap().getUnitAt(position);
            if(unit != null){
               image = unit.getImage();
               unitHeightOffset = -40; //Unit height
               unit.setVisible(true);
            }

            bbg.drawImage(image, x*tileDimension, y*tileDimension+unitHeightOffset, this);

         }
      }
     

      bbg.drawImage(inventory.getImage(), 400, 480, this);

      bbg.setColor(Color.WHITE);
      bbg.fillRect(0, 580, 40, 20);
      bbg.setColor(Color.BLACK);
      bbg.drawString(String.valueOf(gui.getFps()), 10, 595);

      bbg.dispose();
   }
22  Game Development / Newbie & Debugging Questions / Re: From Full Screen mode to windowed mode (and reverse) how? on: 2011-12-05 22:37:32
Will start off by saying, that I have not read it, but some of my friends have found it very usefull, I find this online version a bit incomplete though, but it might help Smiley

http://fivedots.coe.psu.ac.th/~ad/jg/ch03/index.html
23  Game Development / Newbie & Debugging Questions / Re: From Full Screen mode to windowed mode (and reverse) how? on: 2011-12-05 22:34:52
I think killers game guide explains it... I'll try to find the link Smiley
24  Game Development / Newbie & Debugging Questions / Re: Tile based movement (Bomberman style) on: 2011-12-05 08:55:37
This is now my render method:

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  
   public void render() {
      Graphics2D bbg = (Graphics2D) this.backBuffer.getGraphics();
      BufferedImage image = null;

      this.player = this.game.getTileMap().getPlayer();
      this.units = this.game.getTileMap().getUnits();
      this.inventory = player.getInventory();
      nullTile = new Tile(position, "WATER");
      for(int y = 0; y < 24; y++){
         for(int x = 0; x < 42; x++){
            position.setX(x + player.getPosition().getX()-xOffset);
            position.setY(y + player.getPosition().getY()-yOffset);
            //Draw tiles
            Tile tile = this.game.getTileMap().getTileAt(position);
            if(tile != null){
               image = tile.getImage();
            }else{
               image = nullTile.getImage();
            }

            //Draw items
            Item item = this.game.getTileMap().getItemAt(position);
            if(item != null){
               image = item.getImage();
            }

            //Draw buildings
            Building building = this.game.getTileMap().getBuildingAt(position);
            if(building != null){
               image = building.getImage();
            }

            //Old draw units
            /**
            Unit unit = this.game.getTileMap().getUnitAt(position);
            if(unit != null){
               image = unit.getImage();
               yOffset = -40; //Unit height
            }
            **/

            bbg.drawImage(image, x*tileDimension, y*tileDimension, this);

         }
      }
     
      for(Unit unit : units){
         image = unit.getImage();
          bbg.drawImage(image, unit.getPosition().getX() + unit.getCurrentPixelX() + (xOffset * tileDimension), unit.getPosition().getY() + unit.getCurrentPixelY() + (yOffset * tileDimension) - unitHeightOffset, this);
      }

      bbg.drawImage(inventory.getImage(), 400, 480, this);

      bbg.setColor(Color.WHITE);
      bbg.fillRect(0, 580, 40, 20);
      bbg.setColor(Color.BLACK);
      bbg.drawString(String.valueOf(gui.getFps()), 10, 595);

      bbg.dispose();
   }


My move method:

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  
   public boolean moveUnitToAnimated(Position from, Position to){
      Tween tween = new Tween();
      if(isAllowedUnitPosition(to)){
         Unit unit = this.tileMap.getUnitAt(from);
         this.tileMap.removeUnit(from);
         unit.setDirection(new Vector(to.getX()  + from.getX(), to.getY() + from.getY()));
         //Going left
         if(to.getX() < from.getX() && to.getY() == from.getY()){
            tween.tweenUnitLeft(unit);
         }
         //Going right
         else if(to.getX() > from.getX() && to.getY() == from.getY()){
            tween.tweenUnitLRight(unit);
         }
         //Going up
         else if(to.getX() == from.getX() && to.getY() < from.getY()){
            tween.tweenUnitUp(unit);
         }
         //Going down
         else if(to.getX() == from.getX() && to.getY() > from.getY()){
            tween.tweenUnitDown(unit);
         }
         this.tileMap.addUnitAt(to, unit);
         this.tileMap.getTileAt(from).setOccupied(false);
         this.tileMap.getTileAt(to).setOccupied(true);
         return true;
      }
      return false;
   }


And my tween class:

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  
public class Tween {

   public void tweenUnitLeft(Unit unit){
      for(int i = 20; i > 0; i--){
         unit.setCurrentPixelX(i);
      }
      unit.setPosition(new Position(unit.getPosition().getX() - 1, unit.getPosition().getY()));
      unit.setCurrentPixelX(0);
   }
   
   public void tweenUnitLRight(Unit unit){
      for(int i = 0; i < 0; i++){
         unit.setCurrentPixelX(i);
      }
      unit.setPosition(new Position(unit.getPosition().getX() + 1, unit.getPosition().getY()));
      unit.setCurrentPixelX(0);
   }
   
   public void tweenUnitUp(Unit unit){
      for(int i = 20; i > 0; i--){
         unit.setCurrentPixelY(i);
      }
      unit.setPosition(new Position(unit.getPosition().getX(), unit.getPosition().getY() - 1));
      unit.setCurrentPixelY(0);
   }
   
   public void tweenUnitDown(Unit unit){
      for(int i = 0; i < 20; i++){
         unit.setCurrentPixelX(i);
      }
      unit.setPosition(new Position(unit.getPosition().getX(), unit.getPosition().getY() + 1));
      unit.setCurrentPixelY(0);
   }
}




Is that anything what you meant? Tongue
25  Game Development / Newbie & Debugging Questions / Re: Tile based movement on: 2011-12-04 23:39:26
unit.setPosition(to) sets the unit on the next tile, no?  You need to just set the unit's position (say) 1 pixel towards the destination.

Yes it does, it is that which gives the teleporting effect, but I think my problem is, that I draw not in pixels, but tiles:

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  
   public void render() {
      Graphics2D bbg = (Graphics2D) this.backBuffer.getGraphics();
      BufferedImage image = null;

      this.player = this.game.getTileMap().getPlayer();
      this.inventory = player.getInventory();
      nullTile = new Tile(position, "WATER");
      for(int y = 0; y < 24; y++){
         for(int x = 0; x < 42; x++){
            int yOffset = 0;
            position.setX(x + player.getPosition().getX()-21);
            position.setY(y + player.getPosition().getY()-12);
            //Draw tiles
            Tile tile = this.game.getTileMap().getTileAt(position);
            if(tile != null){
               image = tile.getImage();
            }else{
               image = nullTile.getImage();
            }

            //Draw items
            Item item = this.game.getTileMap().getItemAt(position);
            if(item != null){
               image = item.getImage();
            }

            //Draw buildings
            Building building = this.game.getTileMap().getBuildingAt(position);
            if(building != null){
               image = building.getImage();
            }

            //Draw units
            Unit unit = this.game.getTileMap().getUnitAt(position);
            if(unit != null){
               image = unit.getImage();
               yOffset = -40; //Unit height
            }

            bbg.drawImage(image, x*20, y*20+yOffset, this);

         }
      }

      bbg.drawImage(inventory.getImage(), 400, 480, this);

      bbg.setColor(Color.WHITE);
      bbg.fillRect(0, 580, 40, 20);
      bbg.setColor(Color.BLACK);
      bbg.drawString(String.valueOf(gui.getFps()), 10, 595);

      bbg.dispose();
   }


Or am I totally wrong? Tongue

I really want a bomberman like movement. If you press a movement key, then it animates a movement between tiles...
26  Game Development / Newbie & Debugging Questions / Re: Tile based movement on: 2011-12-04 23:17:06
This is my move method so far, it's kind of teleporting from one tile to another... I can't figure out to do those tweens, as my draw method draws in tiles, and not pixels. How do I get started? Smiley


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public boolean moveUnitTo(Position from, Position to) {
      if(isAllowedUnitPosition(to)){
         Unit unit = this.tileMap.getUnitAt(from);
         this.tileMap.removeUnit(from);
         unit.setDirection(new Vector(to.getX()  + from.getX(), to.getY() + from.getY()));
         unit.setPosition(to);
         this.tileMap.addUnitAt(to, unit);
         this.tileMap.getTileAt(from).setOccupied(false);
         this.tileMap.getTileAt(to).setOccupied(true);
         return true;
      }
      return false;
   }
27  Game Development / Newbie & Debugging Questions / Re: Tile based movement on: 2011-12-04 17:32:12
I really want to implement all of the game myself, not using pre-coded stuff, but thanks for the link, will look into it... Smiley

But I think this is a really hard part to do, I might be back for more help Smiley
28  Game Development / Newbie & Debugging Questions / Re: Tile based movement on: 2011-12-01 12:25:08
Thanks so far, I will look into your suggestions Smiley
29  Game Development / Newbie & Debugging Questions / Re: Tile based movement on: 2011-12-01 08:31:03
That part I have done, I can move from tile to tile, but I can't make it smooth movement Smiley Sorry for not being clear about that Smiley
30  Game Development / Newbie & Debugging Questions / [SOLVED minor bugs] Tile based movement (Bomberman style) on: 2011-12-01 02:11:11
So I have this tile based game, with each tile being 20x20 pixels, and I draw them on a canvas in a loop like this:

1  
2  
3  
4  
5  
6  
7  
for(int y = 0; y < 24; y++){
         for(int x = 0; x < 42; x++){
            int yOffset = 0;
            position.setX(x + player.getPosition().getX()-21);
            position.setY(y + player.getPosition().getY()-12);
                                //drawing stuff from positions
}


I now wonder how to make my player move smoothly from tile to tile when I press a button on my keyboard
Any ideas how to start? To get me going? Smiley
Pages: [1] 2 3
 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (27 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (96 views)
2014-12-08 04:46:31

JscottyBieshaar (56 views)
2014-12-05 12:39:02

SHC (72 views)
2014-12-03 16:27:13

CopyableCougar4 (74 views)
2014-11-29 21:32:03

toopeicgaming1999 (134 views)
2014-11-26 15:22:04

toopeicgaming1999 (125 views)
2014-11-26 15:20:36

toopeicgaming1999 (35 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!