Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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
1  Game Development / Game Play & Game Design / Re: Slicing up sprite sheets for complex characters. on: 2012-01-01 16:38:21
Wow, there are so many ingenious tricks involving images. I'll have to check out this video, hopefully I can find some code samples?
2  Game Development / Game Play & Game Design / Slicing up sprite sheets for complex characters. on: 2011-12-31 05:57:45
If not best practices, could someone provide an example?

The issues that I'm facing are that the artist I'm working with and I have a player character that we want to animate that will be around 32 wide by 64 high.

He may have a spear, which may be 128 long.

Should we create one sprite sheet for that character with all of the animation stuff manually specified with xml or should we create three sheets, 64x64, 128x128, 256,256, etc?

EDIT: Think like secret of mana, evermore, beyond oasis.

The issue is since java draws from top left coordinates then we'll have to be constantly concerned about the offset of the sprite since his location will be in reality x and y away from the location that the top left of his sprite needs to be drawn at.
3  Game Development / Newbie & Debugging Questions / Re: I have lost my mind - Snake Game Design on: 2011-12-24 15:41:57
@ra4king I was thinking about how to do this last night and really couldn't conceptualize this. Until reading your comment. That really does seem like the way to do it.
4  Game Development / Newbie & Debugging Questions / Re: Yet another game loop >< on: 2011-12-24 15:12:27
Can't you just use system.getNanotime?
5  Game Development / Newbie & Debugging Questions / Re: Yet another game loop >< on: 2011-12-24 03:44:24
What is this Thread.sleep business? http://why.how.does.that.give.you.high.precision.timer.com/idontunderstand.html
6  Game Development / Game Mechanics / Small helper class for 2d binary island map generation on: 2011-12-23 07:25:04
My Helper Version:        http://pastebin.com/VCjU3NnK
Original:                      http://pastebin.com/n4b21FWg
Reddit Thread:             http://www.reddit.com/r/gamedev/comments/nn8hb/java_2d_island_generator_first_real_project_since/

A guy over at reddit.com/r/gamedev posted the source for an island generator:

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  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
package polytester;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Color;
import java.util.Random;
import java.awt.Font;
import java.util.Scanner;


/*
 * # # # # #
 * # # 1 0 0
 * # # # # #
 * # # # # #
 * # # # # #
 */

 
public class hola extends BasicGame {
   
   Polygon[][] rand = new Polygon[25][25];
   int[][][] grid = new int[5][25][25];
   int tempax = 0, tempay = 0;
   Random r = new Random();
   int time;
   Scanner input = new Scanner(System.in);
   Font font = new Font("Helvetica", Font.BOLD, 30);
   int x = 20, y = 20, number = 100, phase = 1;
   int xc = 32, yc = 24;
   String print;
   boolean next;
   int z, p, tempx, tempy;
   int timer;
   int checksum;
   int chance;
   int cursorx = 200, cursory = 200, cx = 1, cy = 1;
   int sex = 0;
   int countd=0;
   

 
   public hola() {
      super("polygontest");
   }
   public void init(GameContainer container) throws SlickException {  
     
      container.setVSync(true);
     
      for(int z = 0; z < 25; z++){
         for(int p = 0; p < 25; p++){

            rand[z][p] = new Polygon(new float[]{
               0,0,
               0,y,
               x,y,
               x,0
            });
           
            chance = r.nextInt(2);
            grid[0][z][p] = chance;
            if(chance == 1){
               rand[z][p].setLocation(z*x, p*y);
            }else{
               rand[z][p].setLocation(900, 900);
            }
            tempx++;
         }
     
         tempy++;
         tempx=0;
      }
     
     
     
      for(int dope = 0; dope < 4; dope++){
         for(int mattb = 0; mattb < 25; mattb++){
            for(int mattx = 0; mattx < 25; mattx++){
               if(mattb-1 >= 0 && mattb+1 <=24 && mattx-1 >= 0 && mattx+1 <= 24){
                  checksum=grid[dope][mattb-1][mattx-1]+grid[dope][mattb-1][mattx]+grid[dope][mattb-1][mattx+1]+
                        grid[dope][mattb][mattx-1]+grid[dope][mattb][mattx+1]+grid[dope][mattb+1][mattx-1]+
                        grid[dope][mattb+1][mattx]+grid[dope][mattb+1][mattx+1];
     
                  if(checksum >= 4 && grid[dope][mattb][mattx] == 1){
                     grid[dope+1][mattb][mattx] = 1;
                  }
                 
                  if(checksum >= 5){
                     grid[dope+1][mattb][mattx] = 1;
                  }                  
               }
            }
         }
      }

     
      for(int ax = 0; ax < 25; ax++){
         for(int ay = 0; ay < 25; ay++){
            if(grid[4][ax][ay] == 1){
               rand[ax][ay].setLocation(ax*x, ay*y);
               tempax++;
            }
         }
         tempay++;
         tempax=0;
      }
   }

   
   public void update(GameContainer container, int delta) {
      timer--;
      if(container.getInput().isKeyDown(Input.KEY_SPACE) && timer < 0){
         timer = 30;
         countd++;
         if(countd>4)countd=0;
         for(int ax = 0; ax < 25; ax++){
            for(int ay = 0; ay < 25; ay++){
               if(grid[countd][ax][ay] == 1){
                  rand[ax][ay].setLocation(ax*x, ay*y);
                  tempax++;
               }
            }
            tempay++;
            tempax=0;
         }
         
      }
   }
   
   public void render(GameContainer container, Graphics g)  {

     
      for(int d = 0; d < 25; d++){
         for(int o = 0; o < 25; o++){
   //         g.draw(rand[o][d]);
           if(grid[countd][d][o]==1){
               g.drawString("#", d*x, o*y);
               System.out.print("#");
            }else{
               g.drawString(" ", d*x, o*y);
               System.out.print(" ");
            }
         }
         System.out.println();
      }
      System.out.println("BREAKBREAKBREAK");
   }
   
   public static void main(String[] argv) throws SlickException {
      AppGameContainer container = new AppGameContainer(new hola(), 500, 500, false);
      container.setShowFPS(false);
      container.start();
   }
}






I attempted to make it a little easier to use but I have no idea what witchcraft was used in it's creation so I'm not sure how to tidy up the generation section but at least it's easy to use now.

If you're just looking for a 2d island map you want to call get2dClarifiedMap(width,height)

http://pastebin.com/VCjU3NnK
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  
package com.hadesvine.tiledgame.examples;

import org.newdawn.slick.geom.Polygon;
import java.util.Random;

public class MapHelper {

    public static final int DEFAULTWIDTH = 32;
    public static final int DEFAULTHEIGHT = 25;
    public static final int CLARIFICATION = 4;

    public MapHelper() {
    }

    public static int[][][] getNewMap(int width, int height, int clarification) {
        Polygon[][] rand = new Polygon[width][height];
        int[][][] grid;
        int tempax = 0, tempay = 0;
        Random r = new Random();
        int x = 20;
        int y = 20;
        int tempx = 0;
        int tempy = 0;
        int checksum = 0;
        int chance = 0;
        grid = new int[5][width][height];
        for (int z = 0; z < width; z++) {
            for (int p = 0; p < height; p++) {
                rand[z][p] = new Polygon(new float[]{
                            0, 0,
                            0, y,
                            x, y,
                            x, 0
                        });
                chance = r.nextInt(2);
                grid[0][z][p] = chance;
                if (chance == 1) {
                    rand[z][p].setLocation(z * x, p * y);
                } else {
                    rand[z][p].setLocation(900, 900);
                }
                tempx++;
            }
            tempy++;
            tempx = 0;
        }
        for (int i = 0; i < clarification; i++) {
            for (int mattb = 0; mattb < width; mattb++) {
                for (int mattx = 0; mattx < height; mattx++) {
                    if (mattb - 1 >= 0 && mattb + 1 < width && mattx - 1 >= 0 && mattx + 1 < height) {
                        checksum = grid[i][mattb - 1][mattx - 1] + grid[i][mattb - 1][mattx] + grid[i][mattb - 1][mattx + 1]
                                + grid[i][mattb][mattx - 1] + grid[i][mattb][mattx + 1] + grid[i][mattb + 1][mattx - 1]
                                + grid[i][mattb + 1][mattx] + grid[i][mattb + 1][mattx + 1];

                        if (checksum >= clarification && grid[i][mattb][mattx] == 1) {
                            grid[i + 1][mattb][mattx] = 1;
                        }

                        if (checksum >= 5) {
                            grid[i + 1][mattb][mattx] = 1;
                        }
                    }
                }
            }
        }
        for (int ax = 0; ax < width; ax++) {
            for (int ay = 0; ay < height; ay++) {
                if (grid[CLARIFICATION][ax][ay] == 1) {
                    rand[ax][ay].setLocation(ax * x, ay * y);
                    tempax++;
                }
            }
            tempay++;
            tempax = 0;
        }
        return grid ;
    }
   
    public static void main(String[] args) {
        //int [][][]testMap = getNewMap(32,24);
       printRandomMapToConsole(800,600,4);
    }
   
    public static void printRandomMapToConsole(int width, int height, int clarification){
        int [][][]grid = getNewMap(width, height,clarification);
                for (int d = 0; d < height; d++) {
            for (int o = 0; o < width; o++) {
                if (grid[clarification][d][o] == 1) {
                    System.out.print("#");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
    public static void printRandomMapToConsole(int width, int height){
        int [][][]grid = getNewMap(width, height,CLARIFICATION);
                for (int d = 0; d < height; d++) {
            for (int o = 0; o < width; o++) {
                if (grid[CLARIFICATION][d][o] == 1) {
                    System.out.print("#");
                } else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
   
    public static int[][] getClarified2DIslandMap(int width, int height){
        int [][][] gridWithClarification = getNewMap(width,height,4);
        int [][] clarifiedGrid = gridWithClarification[4];
        return clarifiedGrid;
    }
}


As a note, this works much better on smaller maps.
7  Game Development / Game Mechanics / Smooth animation on: 2011-12-20 04:51:37
I'm not sure what is wrong with my animation. It was smooth, now it's not, I only have two classes here. Is it something to do with my delay or is it something to do with how I'm using spritemanager.getSprite();

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  
package tiledgame;

import java.awt.Point;
import java.util.Map;
import org.newdawn.slick.Image;
import org.newdawn.slick.SpriteSheet;

/**
 * @author HadesVine
 */

public class CharacterEntity {
    public static final int UP = 0;
    public static final int RIGHT = 1;
    public static final int DOWN = 2;
    public static final int LEFT = 3;
    public static final int IDLE = 0;
    public static final int WALK = 1;
   
    private SpriteSheet spriteSheet;
    private int facing = 0;//The direction a sprite is facing;
   private int state = 0;
    private float locationX;
    private float locationY;
    private int walkDelay = 200;
    private int currentFrame = 0;
    private int timePassed = 0;
    private int walkColumn = 0;

    public CharacterEntity(SpriteSheet spriteSheet, float locationX, float locationY) {
        this.spriteSheet = spriteSheet;
        this.locationX = locationX;
        this.locationY = locationY;
    }

    public int getFacing() {
        return facing;
    }

    public void setFacing(int facing) {
        this.facing = facing;
    }

    public float getLocationX() {
        return locationX;
    }

    public void setLocationX(float locationX) {
        this.locationX = locationX;
    }

    public float getLocationY() {
        return locationY;
    }

    public void setLocationY(float locationY) {
        this.locationY = locationY;
    }

    public void setState(int state) {
        this.state = state;
    }

    public int getState() {
        return state;
    }

    public int getWalkDelay() {
        return walkDelay;
    }

    public void setWalkDelay(int walkDelay) {
        this.walkDelay = walkDelay;
    }
   

    public int getWalkColumn() {
        return walkColumn;
    }

    public void setWalkColumn(int walkColumn) {
        this.walkColumn = walkColumn;
    }

    public void tick(int delta) {
        if (this.state == WALK) {
            if (timePassed >= walkDelay) {
                timePassed = 0;
                if (this.currentFrame == 1) {
                    this.currentFrame = -1;
                } else {
                    this.currentFrame = 1;
                }
            } else {
                timePassed += delta;
            }
        }else{
            currentFrame = 0;
        }
    }
    public Image getSprite() {
        return this.spriteSheet.getSprite(this.currentFrame + this.walkColumn, this.facing);
    }
}




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  
package tiledgame;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

/**
 * @author HadesVine
 */

public class TiledGame extends BasicGame {

    private GameContainer gc;
    private float moveSpeed = 1;
    private CharacterEntity testEntity;
    private boolean playerIsMoving = false;

    public TiledGame() {
        super("Tiled game");
    }

    public static void main(String[] args) throws SlickException {
        AppGameContainer app = new AppGameContainer(new TiledGame());
        app.setDisplayMode(1024, 768, false);
        app.start();
    }

    @Override
    public void init(GameContainer gc) throws SlickException {
        testEntity = new CharacterEntity(new SpriteSheet("com/hadesvine/tilegame/tiles/crono.png", 24, 32), 400, 300);
        testEntity.setWalkColumn(4);
        testEntity.setWalkDelay(200);
    }

    @Override
    public void update(GameContainer gc, int delta) throws SlickException {
        playerIsMoving = false;
        Input input = gc.getInput();
        float rate = delta / 10;
        if (input.isKeyDown(Input.KEY_W)) {
            testEntity.setFacing(CharacterEntity.UP);
            testEntity.setLocationY(testEntity.getLocationY() - moveSpeed * rate);
            playerIsMoving = true;
        }
        if (input.isKeyDown(Input.KEY_D)) {
            testEntity.setFacing(CharacterEntity.RIGHT);
            testEntity.setLocationX(testEntity.getLocationX() + moveSpeed * rate);
            playerIsMoving = true;
        }
        if (input.isKeyDown(Input.KEY_S)) {
            testEntity.setFacing(CharacterEntity.DOWN);
            testEntity.setLocationY(testEntity.getLocationY() + moveSpeed * rate);
            playerIsMoving = true;
        }
        if (input.isKeyDown(Input.KEY_A)) {
            testEntity.setFacing(CharacterEntity.LEFT);
            testEntity.setLocationX(testEntity.getLocationX() - moveSpeed * rate);
            playerIsMoving = true;
        }
        if (input.isKeyDown(Input.KEY_2)) {
            if (moveSpeed != 500) {
                moveSpeed += 1;
            }
        }
        if (input.isKeyDown(Input.KEY_1)) {
            if (moveSpeed > 1) {
                moveSpeed -= 1;
            }
        }
        if (input.isKeyDown(Input.KEY_3)) {
            if (moveSpeed > 1) {
                moveSpeed = 1;
            }
        }
        if (playerIsMoving) {
            testEntity.setState(CharacterEntity.WALK);
        } else {
            testEntity.setState(CharacterEntity.IDLE);
        }
        testEntity.tick(delta);
    }

    @Override
    public void render(GameContainer gc, Graphics g) throws SlickException {
        testEntity.getSprite().draw(testEntity.getLocationX(), testEntity.getLocationY());
    }
}



Any help would be appreciated.
8  Game Development / Newbie & Debugging Questions / Re: Using LWJGL and Slick2d, how do I load and display sprites from a sprite atlas? on: 2011-12-19 18:11:36
We talked about this last night, thanks for posting it in the thread though so that other people will know. Grin
9  Game Development / Game Mechanics / How do I load from a sprite atlas? on: 2011-12-19 03:38:25
This was answered in another thread. I accidentally double submitted.
http://www.java-gaming.org/topics/using-lwjgl-and-slick2d-how-do-i-load-and-display-sprites-from-a-sprite-atlas/25325/view/topicseen.html
10  Game Development / Newbie & Debugging Questions / Using LWJGL and Slick2d, how do I load and display sprites from a sprite atlas? on: 2011-12-19 03:14:07
So I've got this small amount of code to load a grass tile and tile it over and over again on the screen and draw one tree in the top left, what I'd like to do is load a sprite sheet for a character. I've got one sheet with green as the transparent background and I want to load an image from that, how do I chop the image up, and should I still use a quad to draw it?

Summary:

  • Should I be using a quad with a texture to draw a sprite, same as I draw my tile?
  • How should I load the sprite atlas?
  • Once I have the sprite atlas loaded, should I then make a hasmap of subimages made from the spritesheet or do I load the whole image each time and have to tell it to ignore all but one section
  • Am I proceeding about this in the right way?
  • How can I teach this stuff to myself without posting? I can't find anything for animating sprites with these libraries and when I look at the javadoc, half the methods are undocumented. Do I need to get a book on just openGL or what? Should I know opengl first? I'd hate to think that I'd have to ask a question every time I try to draw something different but honestly I'd really like to know how to teach this stuff to myself. I'm not sure what the workflow for working with lwjgl is anyway.





Here is the little bit I've been working on.
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  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
package com.hadesvine.tiledgame.examples;

import java.io.IOException;
import java.util.Random;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class TextureExample {

    public static final int SCREENWIDTH = 1024;
    public static final int SCREENHEIGHT = 768;
    public static int numberOfTimesRun = 0;
    /** The texture that will hold the image details */
    private Texture grassTexture;
    private Texture treeTexture;
    /**
     * Start the example
     */

    public void start() {

        initGL(SCREENWIDTH, SCREENHEIGHT);
        init();

        while (true) {
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
            drawTiled(SCREENWIDTH, SCREENHEIGHT);
            drawSprite();
            //render();



            Display.update();
            Display.sync(100);

            if (Display.isCloseRequested()) {
                Display.destroy();
                System.exit(0);
            }
        }
    }

    /**
     * Initialise the GL display
     *
     * @param width The width of the display
     * @param height The height of the display
     */

    private void initGL(int width, int height) {
        try {
            Display.setDisplayMode(new DisplayMode(width, height));
           
            Display.create();
            Display.setVSyncEnabled(true);
        } catch (LWJGLException e) {
            e.printStackTrace();
            System.exit(0);
        }

        GL11.glEnable(GL11.GL_TEXTURE_2D);

        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        // enable alpha blending
       GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

        GL11.glViewport(0, 0, width, height);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, width, height, 0, 1, -1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
    }

    /**
     * Initialise resources
     */

    public void init() {

        try {
            // load texture from PNG file
           grassTexture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("com/hadesvine/alone/tiles/seamlessgrass.png"));
            treeTexture =  TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("com/hadesvine/alone/tiles/tree64x96.png"));

            System.out.println("Texture loaded: " + grassTexture);
            System.out.println(">> Image width: " + grassTexture.getImageWidth());
            System.out.println(">> Image height: " + grassTexture.getImageHeight());
            System.out.println(">> Texture width: " + grassTexture.getTextureWidth());
            System.out.println(">> Texture height: " + grassTexture.getTextureHeight());
            System.out.println(">> Texture ID: " + grassTexture.getTextureID());
           
            System.out.println("Texture loaded: " + treeTexture);
            System.out.println(">> Image width: " + treeTexture.getImageWidth());
            System.out.println(">> Image height: " + treeTexture.getImageHeight());
            System.out.println(">> Texture width: " + treeTexture.getTextureWidth());
            System.out.println(">> Texture height: " + treeTexture.getTextureHeight());
            System.out.println(">> Texture ID: " + treeTexture.getTextureID());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * draw a quad with the image on it
     */

    public void render() {
        Color.white.bind();
        grassTexture.bind(); // or GL11.glBind(texture.getTextureID());

        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(100, 100);
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex2f(100 + grassTexture.getTextureWidth(), 100);
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex2f(100 + grassTexture.getTextureWidth(), 100 + grassTexture.getTextureHeight());
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex2f(100, 100 + grassTexture.getTextureHeight());
        GL11.glEnd();
    }

    /**
     * Main Class
     */

    public static void main(String[] argv) {
        TextureExample textureExample = new TextureExample();
        textureExample.start();
    }

    public void drawTiled(int screenWidth, int screenHeight) {
        Color.white.bind();
        grassTexture.bind(); // or GL11.glBind(texture.getTextureID());
       int numberPerRow = (int) screenWidth / (int) grassTexture.getTextureWidth();
        double numberOfRows = screenHeight / grassTexture.getTextureHeight();
        GL11.glBegin(GL11.GL_QUADS);
        for (int j = 0; j < numberOfRows; j++) {
            //System.out.print("{");
           for (int i = 0; i < numberPerRow; i++) {

                //top left
               GL11.glTexCoord2f(0, 0);
                GL11.glVertex2f(grassTexture.getTextureWidth() * i, grassTexture.getTextureHeight() * j);

                //top right
               GL11.glTexCoord2f(1, 0);
                GL11.glVertex2f(grassTexture.getTextureWidth() * (i + 1), grassTexture.getTextureHeight() * j);

                //bottom right
               GL11.glTexCoord2f(1, 1);
                GL11.glVertex2f(grassTexture.getTextureWidth() * (i + 1), grassTexture.getTextureHeight() * (j + 1));

                //bottom left
               GL11.glTexCoord2f(0, 1);
                GL11.glVertex2f(grassTexture.getTextureWidth() * i, grassTexture.getTextureHeight() * (j + 1));
                //System.out.print("[]");
           }
            //System.out.println("}");
       }
        //close gl


        GL11.glEnd();
        System.out.println("numberOfTimesRun" + ++numberOfTimesRun);
    }

    public void drawSprite() {
        Color.white.bind();
        treeTexture.bind();
        GL11.glBegin(GL11.GL_QUADS);
       

       
       
        int i = 0;
        int j = 0;
       
       
       
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(treeTexture.getTextureWidth() * i, treeTexture.getTextureHeight() * j);

        //top right
       GL11.glTexCoord2f(1, 0);
        GL11.glVertex2f(treeTexture.getTextureWidth() * (i + 1), treeTexture.getTextureHeight() * j);

        //bottom right
       GL11.glTexCoord2f(1, 1);
        GL11.glVertex2f(treeTexture.getTextureWidth() * (i + 1), treeTexture.getTextureHeight() * (j + 1));

        //bottom left
       GL11.glTexCoord2f(0, 1);
        GL11.glVertex2f(treeTexture.getTextureWidth() * i, treeTexture.getTextureHeight() * (j + 1));
        GL11.glEnd();
    }
}


11  Discussions / General Discussions / Re: Go on, ask me anything. on: 2011-03-16 18:24:58
What were the major performance bottlenecks you experienced and what solutions helped you overcome them?
How solid is your math background?
12  Discussions / General Discussions / Re: Go on, ask me anything. on: 2011-03-15 15:17:06
Re: Source

Awesome. I don't think anyone expects art or sound assets, haha. Thanks to you and your comrades for their contribution to the community.
13  Discussions / General Discussions / Re: Go on, ask me anything. on: 2011-03-15 14:28:59
Cas,

Your answers have been awesome. Thanks so much for the insight. I didn't know that one could drive animations by xml. I will have to look that up. Sounds painful.
14  Discussions / General Discussions / Re: Go on, ask me anything. on: 2011-03-15 14:00:24
When you come across something you don't already know how to do, do you go to the googles or do you troll the api documentation of whatever library you're using first? What milestones do you think are important when starting a game?
15  Discussions / General Discussions / Re: Go on, ask me anything. on: 2011-03-15 13:55:09
Do you use SVG's or bitmaps? I know that java only has built in support for bitmaps but the art in revenge of the titans looks so smooth I wondered.
16  Discussions / General Discussions / Re: Go on, ask me anything. on: 2011-03-15 13:51:28
Also, are there any bookmarks, links, tutorials, resources, etc that you'd like to share?
17  Discussions / General Discussions / Re: Go on, ask me anything. on: 2011-03-15 13:48:00
I have a few:

Do you do any design docs first?
Do you do the art first?
When do you do sound?
Do you do your prototype in java, or another language, if at all?
What was the first game you've ever developed and how old were you?
How often do you get programmer's block?
Aside from here, are there other sites you frequent in search of java game dev answers or just plain old google?
Do you drink coffee?
Are there any libraries you use other than LWJGL, like, things for playing sounds, installers, etc?
Do you like green eggs and ham?

18  Discussions / General Discussions / Re: Tutorials on: 2011-03-15 12:56:30
Now with the only books anyone ever mentions!
19  Discussions / General Discussions / Re: Tutorials on: 2011-03-15 12:18:01
Thanks guys! I'll keep updating it. I'll dig up some libgdx. I gave you 2 or 3 because you answered like every thread I posted in for like a week.
20  Game Development / Articles & tutorials / Re: Basic Game on: 2011-03-15 03:06:38
Man, what you described is exactly what I've gone through.
21  Discussions / General Discussions / Re: Tutorials on: 2011-03-15 03:01:12
My first one!  Smiley
22  Discussions / General Discussions / Re: Tutorials on: 2011-03-15 02:26:07
Hours and hours of digging.
23  Discussions / General Discussions / Tutorials on: 2011-03-15 01:13:03
Tutorials

* [GameDev Java Game Programming 1](http://www.gamedev.net/page/resources/_/reference/programming/languages/java/java-game-programming-part-i-the-basics-r1262)
* [GameDev Java Game Programming 2](http://www.gamedev.net/page/resources/_/reference/programming/languages/java/java-game-programming-part-ii-making-a-simple-game-r1360)
* [GameDev Java Game Programming 3](http://www.gamedev.net/page/resources/_/reference/programming/languages/java/java-game-programming-part-iii-the-power-of-ar-r1383)
* [Keyboard and Mouse Input](http://www.gamedev.net/page/resources/_/reference/programming/languages/java/java-games-keyboard-and-mouse-r2439)
* [Active Rendering](http://www.gamedev.net/page/resources/_/reference/programming/languages/java/java-games-active-rendering-r2418)
* [Stone Paper Scissor](http://forum.codecall.net/java-tutorials/12858-game-stone-paper-scissor.html)
* [Open GL tutorials](http://www.leolol.com/tutorials/tutorials.html)
* [Double Buffering, Movement, Collision Detection](http://forum.codecall.net/java-tutorials/15969-double-buffering-movement-collision-detection.html)
* [Advanced Vectors](http://forum.codecall.net/java-tutorials/19090-more-about-vectors.html)
* [Regular Expressions](http://forum.codecall.net/java-tutorials/20181-regular-expressions.html)
* [Pong](http://forum.codecall.net/java-tutorials/14191-game-simple-pong.html)
* [2D Java Game Video Tutorials](http://www.youtube.com/user/Catkill666)
* [A few small game tutorials](http://zetcode.com/tutorials/javagamestutorial/)
* [NewBoston Game tutorials](http://www.youtube.com/user/thenewboston#grid/user/A331A6709F40B79D) : [source](http://thenewboston.com/forum/viewtopic.php?f=2&t=82)
* [BlackJack](http://forum.codecall.net/java-tutorials/10373-black-jack.html)
* [Poker](http://www.tweako.com/writing_a_complete_5_card_poker_game_in_java)
* [ApexJava Youtube tutorials](http://www.youtube.com/user/apexjava)
* [ThousandCodes Java Tutorials](http://www.thousandcodes.com/java/game/)
* [Dice Game](http://forum.codecall.net/java-tutorials/8520-tutorial-simple-dice-game.html)
* [Turk4n's game tutorials](http://forum.codecall.net/search.php?searchid=420375)
* [A few Java Game tutorials](http://forum.nystic.com/viewtopic.php?p=89493#p88684)
* [MrJavaHelp Tutorials](http://www.youtube.com/user/MrJavaHelp)
* [Mouse Acceleration](http://bigbanggames.ca/java-mouse-acceleration-tutorial/)
* [Java 2s Tutorials](http://www.java2s.com/Code/Java/Game/CatalogGame.htm)

---

Libgdx Specific

* [BadlogicGames](http://www.badlogicgames.com/wordpress/?category_name=libgdx-tutorial)
* [libgdx wiki intro tutorial](http://code.google.com/p/libgdx/wiki/MyFirstTriangle)
* [Updated tutorial based on above](http://www.dustypixels.com/blog/2010/11/24/libgdx-ogles2-my-first-triangle-tutorial-part-1/)

---
LWGJL Specific

* [Accelerated Java Game Tutorials](http://www.cokeandcode.com/tutorials)
* [LWJGL Ninja Cave Tutorials](http://ninjacave.com/tutorials)
* [SHMUP with source](http://www.fabiensanglard.net/Prototyp/index.php)
* [NeHe Tutorials](http://www.gamedev.net/topic/255734-lwjgl-nehe-tutorials-now-online/page__p__255734#entry255734)

---
Engines, Frameworks, Libraries

* [Slick2d](http://slick.cokeandcode.com/index.php)
* [Java Monkey Engine](http://jmonkeyengine.com/)
* [LWJGL](http://lwjgl.org/)
* [PulpCore](http://www.interactivepulp.com/pulpcore/)
* [JGame](http://www.13thmonkey.org/~boris/jgame/)
* [Golden T Game Engine](http://www.goldenstudios.or.id/products/GTGE/)
* [Espresso](http://www.espresso3d.com/)
* [Xith3d](http://xith.org/)
* [jPCT](http://www.jpct.net/)
* [Ardor3d](http://ardor3d.com/)

---
Source

* [Ultima Clone](http://min.us/mvknFCq#1)
* [A Link the the Past Clone](https://github.com/MrHus/Zelda)

---
Books

* [Killer Game Programming in Java](http://www.amazon.ca/Killer-Game-Programming-Andrew-Davison/dp/0596007302/ref=sr_1_1?ie=UTF8&s=books&qid=1300152540&sr=8-1)
* [Developing Games in Java](http://www.amazon.ca/Developing-Games-Java-David-Brackeen/dp/1592730051/ref=sr_1_1?ie=UTF8&qid=1300152577&sr=1-1)
* [Beginning Java Game Programming](http://www.amazon.ca/Beginning-Java-Game-Programming/dp/1435458087/ref=sr_1_fkmr0_1?ie=UTF8&qid=1300152676&sr=1-1-fkmr0)
* [Advanced Java Game Programming](http://www.amazon.ca/Advanced-Programming-David-Wallace-Croft/dp/1590591232/ref=sr_1_fkmr2_2?ie=UTF8&qid=1300152676&sr=1-2-fkmr2)
* [Pro Java 3D Game Development](http://www.amazon.ca/Pro-Java-3D-Game-Development/dp/1590598172/ref=sr_1_2?ie=UTF8&s=books&qid=1300152779&sr=1-2)
* [AI Algorithms for a Prototype Game Software in Java 1.6](http://www.amazon.ca/Algorithms-Prototype-Game-Software-Java/dp/3639171586/ref=sr_1_2?ie=UTF8&qid=1300152836&sr=1-2)
* [Introductory Programming with Simple Games: Using Java and the Freely Available Networked Game Engine ](http://www.amazon.ca/Introductory-Programming-Simple-Games-Available/dp/0470212845/ref=sr_1_1?ie=UTF8&qid=1300152923&sr=1-1)
24  Game Development / Newbie & Debugging Questions / Re: Should I be using java.awt for games? on: 2011-03-14 00:24:53
So, which should I use, JComponent + JFrame or Canvas with Frame? Which is the better way to work/learn/better performance/is what all the cool kids do/ and why?
25  Game Development / Newbie & Debugging Questions / Re: Should I be using java.awt for games? on: 2011-03-14 00:21:45
That's what I mean, maybe I didn't word it well enough.  Cheesy
26  Game Development / Newbie & Debugging Questions / Re: Should I be using java.awt for games? on: 2011-03-14 00:07:33
I think it's common practice to be only doing things to panels or components in the contentPane of a frame.
27  Java Game APIs & Engines / Java 2D / Re: BufferStrategy vs. BufferedImage on: 2011-03-13 23:58:18
So, let me get this straight: You can simply draw on the panel and it will auto double buffer? That sounds perfect.
28  Game Development / Newbie & Debugging Questions / Re: Actually got past newbie gamedev programmers block last night on: 2011-03-13 04:55:49
You hit the nail on the head. I wonder how many others are victim to this folley!
29  Game Development / Newbie & Debugging Questions / Re: Should I be using java.awt for games? on: 2011-03-13 04:54:27
Perfect! Thanks!
30  Java Game APIs & Engines / Java 2D / Re: BufferStrategy vs. BufferedImage on: 2011-03-13 04:53:12
It did! I think you are the flash, replying to all my threads.
Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (23 views)
2014-04-15 18:08:23

BurntPizza (18 views)
2014-04-15 03:46:01

UprightPath (32 views)
2014-04-14 17:39:50

UprightPath (16 views)
2014-04-14 17:35:47

Porlus (32 views)
2014-04-14 15:48:38

tom_mai78101 (58 views)
2014-04-10 04:04:31

BurntPizza (116 views)
2014-04-08 23:06:04

tom_mai78101 (216 views)
2014-04-05 13:34:39

trollwarrior1 (183 views)
2014-04-04 12:06:45

CJLetsGame (190 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!