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 (603)
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 4
1  Java Game APIs & Engines / OpenGL Development / Re: How can I improve my rendering? (VAO/VBO) on: 2014-05-02 09:20:41
If you are only using static images/tiles, you can use DisplayLists
Basically what it does is to pre-process your opengl vertices/normals etc.
So instead of letting opengl process everything realtime(every frame), DisplayLists computes it at startup.
BUT
If you have any animations, you should not use DisplayLists.
As DisplayLists only support static data.

You can also use VAO/VBO, but Display Lists are easier to setup.
And it can also be faster on older computers(at least in my experience)

TODO:
  • Create a Display list for every texture/tile
  • Use DisplayList instead of vertives (glBegin & glEnd)
  • Done! Cheesy

Take a look HERE or HERE for an example.
Or you can search google for Examples/Tutorials Smiley
2  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Font Rendering Practices on: 2014-04-29 08:57:00
If you're looking for the one you explained, here's a messy TextRenderer: TextRenderer.java
The font image:

Link to image: font.png
I know the image is not easy to see, but trust me it's there Tongue

I don't think this is the best way to render text...
But it worked in my case Smiley
3  Game Development / Newbie & Debugging Questions / Re: Reading files within an Executeable JAR file on: 2014-04-29 08:35:46
Thanks everyone for your help.
Does anyone happen to know how to write a text file to the same place as I'm been loading them from (the "res" folder inside the JAR)? It would be nice to be able to save a game easily.

As far as I know that is not directly possible.
But considering a Jar is simply a Zip file, this should/may be possible if you use a ZIP library for java to read and write to the jar.

I do not recommend writing to the jar file, instead use
1  
System.getProperty("user.home") + "/GameName"
or something similar.
And write your files there instead.
4  Game Development / Newbie & Debugging Questions / Re: server for a java game on: 2014-04-28 12:44:58
thats 1 incredibly helpful answer... U Rock Smiley Smiley Smiley

last thing,
my game is logic is as such :

player1(host)
player2(client)

-1st player1 choose game type and setting, and send details to server.
-server pu host & game detail in a list (available game)
-client(player2) pick game from list and request server for conection detail to host(player1)
-server send connection detail to both host and client so they can create a connection between them
-host and client initiate connection and start game

during the game the only data exchange is a small array
from what i just read, i think TCP and writing the server in java will be okay.

i would like to to get your opinion orogamo



How i understand it, you have:
  • A Server for giving out host informtion to clients
  • The host for hosting the game (obviously Tongue)
  • A client for having fun Smiley

For simplicity you can use Json (Google GSON), and create wrapper classes for the JSON parser.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
package com.something.cool
public class HostInformation {
    private String GameName; // Custom game name, like: "Orogamos amazing server with cats and meow"
    private String HostAddress; // Host IP or Hostname, like: "192.168.0.1", "localhost" or what ever...
    private int HostPort; // Port to connect to host

    public void setGameName(String name) {GameName = name;}
    public String getGameName() {return GameName;}
    ...
    //Add more fields if necessary
}

And the Game State
1  
2  
3  
4  
5  
6  
7  
8  
9  
package com.something.cool
public class GameState{
    private ArrayList<Integer, Integer> positions;

    public void setPositions(ArrayList<Integer, Integer> pos) {positions = pos;}
    public ArrayList<Integer, Integer> getPositions() {return positions;}
    ...
    //Add more fields if necessary
}


You can fill out the classes convert them to json:
1  
2  
3  
4  
5  
6  
7  
HostInformation hostInfo = new HostInformation();
hostInfo.setGameName("Orogamos amazing server with cats and meow");
...
Gson gson = new Gson();
String json = gson.toJson(hostInfo);

sendToServer(json); //Example function


EDIT START
And parse them back:
1  
2  
3  
String json = receiveHostInformationFromServer(); //Example function
Gson gson = new Gson();
HostInformation hostInfo = gson.fromJson(json, HostInformation.class);


You can use these classes as a guide:
MojangAuthentication.java // the json sender, receiver and parser. Ignore saveCredentials and loadCredentials those are local filesystem Smiley
Authentication.java // Wrapper classes for json
This method uses HTTP Post, but can easily be converted to Java Sockets using byte[] and Streams
EDIT END

I hope this helps you, if you have any questions feel free to ask Smiley
5  Game Development / Newbie & Debugging Questions / Re: server for a java game on: 2014-04-28 12:09:14
hello all, am new to java programming.. pardon the siliness of my question :
 i made a java game, involving moving some object (class name piece)
every location of every pieces is stored inside an Array.

i am switching my game into a multiplayer one, for that i'll need to create a server.
am confused about the server Huh
my server should be developped in java itself right?
using socket programming Huh

Well it depends on the Game.
If it's a simplistic game, you could use TCP. (I think minecraft still uses TCP, correct me if I'm wrong)
But for more advanced games you should use UDP. (Like games that are network heavy, f.ex Call Of Duty, Battlefield etc.)

At first I would choose TCP + DataStream (DataInputStream & DataOutputStream).

TCP is easier to learn for someone new to networking, because DataStreams contains functions like: readInt(), readLong(), writeInt(), writeLong() etc.

UDP is a bit more advanced were you receive/send Datagram Packets which contains bytes only.
But if you wrap that in a ByteArrayStream(or whatever its called) it's just as easy(just a bit more code) Smiley

Read up on TCP & UDP and find out which protocol works for your game Smiley

EDIT:
Quote
my server should be developped in java itself right?
It would be easier to create the server in java (atleast when the game is), but you're free to choose which ever language you want Smiley
6  Game Development / Newbie & Debugging Questions / Re: Reading files within an Executeable JAR file on: 2014-04-28 11:02:11
@orogamo
THANK YOU!! It works like a charm. The only files I need to load in right now is text and image files so your solution covers everything. Later I'll need to be able to do the same with music files (WAV files) and hopefully I'll be able to adapt this to load those. I know how to play them if I just get a Stream open to them so if you have a particular way of opening a stream for music I'd be very happy.


Depends on which library you use.
If you use OpenAL(Like in LWJGL), this should do it:
1  
2  
3  
4  
5  
6  
7  
InputStream myAudioStream = MyClass.class.getResourceAsStream("/res/myaudio.wav");

//You could either read all the bytes and:
WaveData.Create(myAudioBytes);

//Out just pass the InputStream:
WaveData.Create(myAudioStream);

I haven't tested this code, i just read the documentation. So i hope it works Cheesy

EDIT:
If you want to use standard java libraries, something like this might work:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
import javax.sound.sampled.*;
InputStream myAudioFileStream = MyClass.class.getResourceAsStream("/res/myaudio.wav");

AudioInputStream myAudioStream = AudioSystem.getAudioInputStream(myAudioFileStream);

AudioFormat myAudioFormat = myAudioStream.getFormat();

DataLine.Info myAudioInfo = new DataLine.Info(Clip.class, myAudioFormat);

Clip myAudioClip = (Clip) AudioSystem.getLine(myAudioInfo);

myAudioClip.open(myAudioStream);

myAudioClip.start();
7  Games Center / WIP games, tools & toy projects / Re: [MineCraft Bot] McBotty on: 2014-04-28 10:30:08
The main goals of this framework is to:
  • Take care of all networking code (Receiving, Parsing and Sending packets)
  • Have a Bot class which easily let's you program the bot (like Bot.walkTo(x, y, z), Bot.digBlock(x, y, z), and maybe something like Bot.nukeArea(x, y, z, radius), etc...)

I will also try to add support for blueprints.
For example Bot.loadBlueprint("BigHouse.bp") and Bot.placeBlueprint(bluePrint, x, y, z)
Then the bot will dig out the area and start gathering resources to build the bluePrint Smiley

I will also add a console, so that the Bot can receive commands.

I just now realized what a good idea this is :O

Imagine... You could make so awesome adventure maps with this. You could finally program NPC's that do stuff, help you or die or whatever Cheesy

Yeah, that is kinda the meaning of this framework. Smiley
Only that what you describe would be better to implement either client-side or server-side.

This bot could for example be used to mine out a big area(which you are to lazy to dig yourself Tongue), on a public server.
You can finally have a companion on your public server adventures Cheesy
8  Game Development / Newbie & Debugging Questions / Re: Problems rendering .obj file on: 2014-04-28 10:10:58
BUMP, anyone could help me solve my problem  Huh

Have you tried to "reconstruct" the code in OpenGL 1.1 Immidiate Mode.
If it works then, there might be a problem with your shaders/shaderfactory(or perhaps you projection matrix, etc?).
I have not worked to much with any of the versions above OpenGL 1.1, so I can't help to much on that part Sad

But if you have a Source package I can take a look at, I can try to debug your code for you Smiley

EDIT:
I have made a simple engine EzEngine.
You can take a look at that and see if you can use some in your own engine/library Smiley
It's primarily for my own personal use, but i upload all the code changes when they happen.
9  Game Development / Newbie & Debugging Questions / Re: Reading files within an Executeable JAR file on: 2014-04-28 09:08:29
The way you should do this depends on the resource.

If it's an image use:
1  
2  
3  
4  
5  
6  
/* Package structure
 * com.mypackage - Contains f.ex MyClass
 * res - Contains all resources
 */

URL myImageURL = MyClass.class.getResource("/res/myimage.png");
BufferedImage myImage = ImageIO.read(myImageURL);


But if its a file f.ex Settings.json: (I find it easier with streams, for some reason)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
/* Package structure
 * com.mypackage - Contains f.ex MyClass
 * res - Contains all resources
 */

InputStream mySettingsStream = MyClass.class.getResourceAsStream("/res/settings.json");

//Option 1:
String mySettingsString = "";
int len;
byte b[];
while((len = mySettingsStream.available()) > 0) {
   b = new byte[len];
   r.read(b, 0, len);
   mySettingsString  += new String(b);
}

//Option 2:
int i = 0;
String mySettingsString = "";
while((i = mySettingsStream.read()) != -1 /*EOF*/) mySettingsString += (char)i;

//Close the stream when done
r.close();
10  Game Development / Newbie & Debugging Questions / Re: OpenGL textures rendered onto a quad? on: 2014-04-26 22:47:27
Ok so I know how to render a texture on a quad, thats not what I'm asking here. It appears that if I initialize a texture (loaded with Slick Util library) and then try to draw a quad, some weird stuff takes place. I never called glColor3f or glColor4f, and I didn't write any shaders, so you would think the color of the quad would be white right? WRONG! It uses one of the colors from the texture I loaded. This is kind of hard to visualize so here's some pseudocode:

Texture texture = new Texture("blue_texture.png");

//didn't bind, or use the texture in any way

glBegin(GL_QUADS);
(specify 4 vertices here)
glEnd();

Output: blue quad

Why is the quad using the color of the texture? Even if I do specify a color, it still uses the one from the texture. Blending is enabled btw. Any way to avoid this?


glBindTexture(GL_TEXTURE_2D, 0) would be the easiest fix.
There might be a bug in Slick where it doesn't unbind the texture.

EDIT:
OpenGL Texture Loading (under the hood):
1  
2  
3  
4  
int texture = glGenTextures();
glBindTexture(GL_TEXTURE_2D, texture);
// Load texture, blah blah
glBindTexture(GL_TEXTURE_2D, 0); //Maybe this is missing?
11  Games Center / WIP games, tools & toy projects / Re: [MineCraft Bot] McBotty on: 2014-04-26 16:32:08
Forgetting that this is just a project related to one game, it sounds actually pretty useful for some stuff.
A minecraft forum is probably an a little bit better place for this though.

I'm probably going to post this on a MineCraft forum too. But i want it to be more complete first. Smiley
Because most(if not all) people on this forum knows java. And on for example MinecraftForums there are only a few(mostly modders and toolmakers) which knows java Smiley
12  Games Center / WIP games, tools & toy projects / Re: [MineCraft Bot] McBotty on: 2014-04-26 15:26:07
So, what will you focus this on? A spammer bot? Or something else?

My main focus will be to create a framework for others to create bots.
As the subtitle says, "A MineCraft Bot Framework..."

The main goals of this framework is to:
  • Take care of all networking code (Receiving, Parsing and Sending packets)
  • Have a Bot class which easily let's you program the bot (like Bot.walkTo(x, y, z), Bot.digBlock(x, y, z), and maybe something like Bot.nukeArea(x, y, z, radius), etc...)

I will also try to add support for blueprints.
For example Bot.loadBlueprint("BigHouse.bp") and Bot.placeBlueprint(bluePrint, x, y, z)
Then the bot will dig out the area and start gathering resources to build the bluePrint Smiley

I will also add a console, so that the Bot can receive commands.
13  Games Center / WIP games, tools & toy projects / Re: [MineCraft Bot] McBotty on: 2014-04-25 13:13:56
And voil√£, happy? Wink
14  Games Center / WIP games, tools & toy projects / Re: [MineCraft Bot] McBotty on: 2014-04-25 12:53:31
Your going to want a picture if you want any feedback, no one can give feedback on just a few words.

Well, there are no graphics/gui(yet), so what should I take a picture of? (The source code?)
15  Games Center / WIP games, tools & toy projects / ENDED on: 2014-04-25 12:16:35
ENDED
16  Game Development / Shared Code / Re: RPG Engine [Updated 4/16/2014] on: 2014-04-25 08:54:55
A little heads up Smiley
You should not base your random terrain generation on my implementation. (It does not work properly)
You can copy these classes, they are not made by me, but i have slightly tweaked them to my liking.
Everywhere where it says something like
1  
WorldGenerator.chunkSize // or anything from this class

you should change to your own values Smiley

The worldgenerator class is quite messy, but if studied you would get some knowledge of how it works(and how it should be implemented)

When used properly this is the result of a river filled terrain
Example map
Green = Grass
Dark Green/Brown = Trees
Yellow/White = Sand
Blue = Water

EDIT
You should also implement a minimap feature like this
Something along these lines:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public void renderMap() {
    for (int x = 0; x < 30; x++)
        for (int y = 0; y < 30; y++) {
            int block = ChunkManager.getBlock(World.player.pos.x - 14 + x, World.player.pos.y - 14 + y);
            if (x == 14 && y == 14) setColor(Color.WHITE);
            else if (block == -1) setColor(Color.BLACK);
            else if (block == Resources.WATER) setColor(Color.BLUE);
            else if (block == Resources.SAND || block >= Resources.WATER_NW && block <= Resources.GRASS_W) setColor(World.worldGen.sand);
            else if (block == Resources.GRASS) setColor(World.worldGen.grass);
            else if (block == Resources.TREE) setColor(World.worldGen.tree);
            else if (block == Resources.CASTLE) (Color.CYAN);
            if (World.enemies.size() > 0)
                for (Enemy e : World.enemies.toArray(new Enemy[World.enemies.size()]))
                    if (World.player.pos.x - 14 + x == e.pos.x && World.player.pos.y - 14 + y == e.pos.y) setColor(Color.RED);
                        fillRect(mapX + (x * 3), mapY + (y * 3), 3, 3);
                        glColor3d(0, 0, 0);
                        fillRect(mapX + (x * 3) + 1, mapY + (y * 3) + 1, 1, 1);
                    }
}
17  Game Development / Shared Code / Re: RPG Engine [Updated 4/16/2014] on: 2014-04-23 12:52:03
Have you though about using Procedural Terrain Generation?
If so you can take a look at my code.
It also has other "cool" features implemented Smiley

edit:
Link to the "Game"
18  Game Development / Game Play & Game Design / Re: [LibGDX] 2D (top down) procedurally generated terrain. on: 2013-08-07 12:43:05
A little snippet of code to not render tiles outside specific radius.
1  
2  
3  
public static double calcDistance(double x1, double y1, double x2, double y2) {
   return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}


Usage:
1  
2  
3  
4  
5  
6  
final static double RADIUS = 25.0; //25 tiles
final static double TILESIZE = 1.0;
final static double RENDERDISTANCE = TILESIZE * RADIUS;
if(calcDistance(playerPos, tileX, tileY) <= RENDERDISTANCE) {
    //Render tile here.
}


This might not be the fastest way, but it gets the job done.
Hope it helps Smiley
19  Game Development / Newbie & Debugging Questions / Re: load wavefront obj in jogl on: 2013-07-17 06:16:00
A simple google Search gives you what you need.
https://www.google.com/search?q=Wavefront+obj+jogl
20  Games Center / WIP games, tools & toy projects / Re: [Open Source] RandomRPG on: 2013-07-16 21:42:59
Regarding the graphics, I am not going to worry about them just yet.
Currently I only create/draw new tiles or edit old ones when I need to(for example when adding new features, like the transition tiles).

NEW FEATURE:
I have implemented a map(pressing 'M').
Example:

(Black areas are chunks not generated/discovered)
21  Games Center / WIP games, tools & toy projects / Re: [Open Source] RandomRPG on: 2013-07-15 18:51:45
I have only one question: how you managed to get that transition from grass to sand and sand to water? Are you using a sprite for every type of transition (i.e. every tile to every other tile and every position (N S W E)) ?

I have 4 tiles which I rotate to all angles.
Look at the top right tiles here:

Source Code:
Resources.java

I first draw grass and then the transition tile over it.
22  Games Center / WIP games, tools & toy projects / Re: [Open Source] RandomRPG on: 2013-07-15 07:58:54
UPDATE:
Fixed the World Generator so that it almost smoothly connects the chunks.
One step closer to Infinite Terrains Cheesy

Example
Chunks are 32x32 and World size is 1024x1024
23  Games Center / WIP games, tools & toy projects / Re: [Open Source] RandomRPG on: 2013-07-12 10:38:43
Hey I kind of recognise the character where did you get it?

I don't quite remember, i got it somewhere off the internet Tongue
This is not the final character model, this is temporary.
24  Games Center / WIP games, tools & toy projects / Re: [Open Source] RandomRPG on: 2013-07-10 12:34:49
UPDATE. FINALLY Cheesy
After all these months i finally redid the rendering system.
The game now uses LWJGL to render and handle input.
Not much else has happened.

Planning on trying to release more updates very soon.
25  Game Development / Shared Code / Re: EzEngine - Easy Wrapper for LWJGL on: 2013-04-19 08:44:33
Added for loops to TextRenderer.java, it now contains 70% less code Tongue
100 - (538 / (1771 / 100)) = 69,621682665160926030491247882552% reduction
26  Game Development / Shared Code / Re: EzEngine - Easy Wrapper for LWJGL on: 2013-04-17 11:43:07
hi I took a quick look at the source of your textrenderer and you probably should take a look at for loops

I know, just threw that TextRenderer together for an other project. (It's actually my first working text renderer Cheesy)
plus there are some font alignment issues(if you scroll down you'll see).
There were alot of copy-paste, but i'll probably look into adding some for loops at a later date.
27  Game Development / Shared Code / Re: EzEngine - Easy Wrapper for LWJGL on: 2013-04-17 10:00:31
After some a long time in the dark, this engine is now back.
I have already implemented TextRenderer and a 2D Graphics lib  Shocked

Example:
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  
import org.ezlwjgl.GL.*;
import org.lwjgl.input.Keyboard;

public class Example {

   public static void main(String[] args) {
      WindowManager.enableMouse = true;
      WindowManager.mouseGrab = true;
      WindowManager.enableKeyboard = true;
      WindowManager.createWindow("Test", 800, 600, 60);
      int texture = TextureLoader.loadTexture("/shop.png");
      while (true) {
         Renderer.make3D();
         Renderer.make2D();
         /**
          * ALIGN_CENTER align the text to center of screen
          * drawString(String text, int align) */

         Graphics.drawString("Center Aligned Text", Graphics.ALIGN_CENTER);

         /* drawString(String text, int textSize, double x, double y, double z) */
         Graphics.drawString("Absolute Coordinate Text", 1, 32, 250, 0);

         Graphics.drawString("Small text", .5, 32, 265, 0);

         Graphics.drawString("Big text", 2, 32, 275, 0);

         /* drawTexture(int textureID, double x, double y, double width, double height) */
         Graphics.drawTexture(texture, 0, 0, 32, 32);
         Graphics.drawString("<- Full texture draw", 1, 40, 8, 0);
         
         
         /**
          * Renders a tile from texture tile_x = tile x coordinate in pixels, tile_y = tile y coordinate in pixels, tile_w = tile width in pixels,
          * tile_h = tile height in pixels, size_x = texture width, size_y = texture height.
          *
          * drawTexture(int textureID, int tile_x, int tile_y, int tile_w, int tile_h, int size_x, int int size_y, double x, double y, double width, double height) */

         Graphics.drawTexture(texture, 0, 0, 16, 16, 32, 32, 0, 40, 32, 32);

         Graphics.drawString("<- Tiled texture draw", 1, 40, 48, 0);
         if (WindowManager.update() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
            break;
         }
      }
      WindowManager.destroyWindow();
   }
}

Produces:
28  Games Center / WIP games, tools & toy projects / Re: [Open Source] RandomRPG on: 2013-04-04 11:44:30
Bug Fix:
Fixed problem where smoothing would pick the wrong tile.
Bug occured when two blocks(shore lines) were "touching".
29  Games Center / WIP games, tools & toy projects / Re: [Open Source] RandomRPG on: 2013-04-04 10:45:00
UPDATE:
Added smooth textures, which are a little buggy.


Upcoming features:
Skill & Attributes system
Inventory & Equipment
Combat system

Possibly future features:
Convert rendering system to OpenGL(LWJGL or similar)
30  Game Development / Game Mechanics / Re: Smooth Graphics Algorithm? on: 2013-04-03 07:21:55
EDIT: Just to be clear, i already had the tiles. I only needed the code  Pointing

ME FIX Cheesy


Code: http://pastebin.java-gaming.org/24c7c4b2954
Pages: [1] 2 3 4
 

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 (29 views)
2014-12-14 19:50:38

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

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

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

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

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

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

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

toopeicgaming1999 (37 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!