Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Minigame

#1
It has been a long long long time since I released this project, and I want to warn anybody who is interested in using it that:
* this was my first actual 3D game that got far - and a lot of code is hacky and amateur
* all models and game data are loaded at startup - and therefor there is in insane amount of overhead
* distance based rendering for models causes an excessive amount of unnecessary processing and could be done better
* it's best that if you like this game, you simply download it and extract the content you want, while writing your own client application
* it would be wise that if you use this, you run the game using a batch file and limit the amount of available memory
#2
Support / Re: Blit Textures
May 30, 2015, 12:00:39 AM
I'm not sure exactly how on-topic this is but I always used raft's 2 classes to render strings and sprites, instead of the standard jpct functions. http://www.jpct.net/forum2/index.php?topic=1074.0

Here's some crap class I used with them to load and cache sprites;



package com.jpct.twod;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.threed.jpct.FrameBuffer;

/*
* TODO : Refine this entire class. It's really old, and generic.. but it does the job for a spontaneous project.
*/
public class TwoD {

private TexturePack texturePack;
private String spriteIndex[];

public TwoD(final String fileStorage) {
try {
this.texturePack = new TexturePack();
this.spriteIndex = getSpriteIndex(fileStorage);
for (int i = 0; i < spriteIndex.length; i++) {
try {
File file = new File(fileStorage + File.separator + spriteIndex[i]);
texturePack.addImage(ImageIO.read(file));
} catch (IOException e) {
e.printStackTrace();
System.err.println("Unable to pack sprite: " + spriteIndex[i]);
System.exit(0);
}
}
if (spriteIndex.length > 0) {
texturePack.pack(true);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

private int getSpriteId(String sprite) {
sprite = sprite.replaceAll(".png", "");
String cleanSprite;
for (int i = 0; i < spriteIndex.length; i++) {
cleanSprite = spriteIndex[i].replaceAll(".png", "");
if (cleanSprite.equalsIgnoreCase(sprite)) {
return i;
}
}
System.err.println("Sprite '" + sprite + "' does not exist!");
System.exit(1);
return -1;
}

public void drawImage(FrameBuffer frameBuffer, String sprite, int x, int y, boolean transparent) {
try {
texturePack.blit(frameBuffer, getSpriteId(sprite), x, y, transparent);
} catch (Exception e) {
System.err.println("Error drawing sprite: " + sprite);
System.exit(1);
}
}

private String[] getSpriteIndex(final String assetPath) {
String path = assetPath + File.separator;
File file = new File(path);
if (file.isDirectory()) {
File images[] = file.listFiles();
String sprites[] = new String[images.length];
String sprite;
for (int i = 0; i < images.length; i++) {
sprite = images[i].getName();
sprite.replaceAll(".png", "");
sprites[i] = sprite;
}
return sprites;
}
return null;
}

}


Someone else will be a much better help haha but there are other options for drawing textures in a 2d manner :)
#3
Projects / Re: A game for Ludum Dare
May 29, 2015, 11:56:42 PM
Quote from: Gatobot14 on May 29, 2015, 10:20:00 PM
I made a game for mini LD is 2D so i only blit textures.
Its very simple but at least i finish one game  ;D
Hope to make better games, maybe i can add more features to this one... maybe.

the link
http://gatobot14.itch.io/pixel-defender

by the way is there a problem with  jpct license? shoul i put a warning or something?
because its already uploaded.....

I can't speak for Egon but its nice to see a link back to jPCT from your website ;) I always share the url personally myself because credit is given where it is due. Anyways here is a link to the jPCT license; http://www.jpct.net/license.html and Android; http://www.jpct.net/jpct-ae/license.txt
Good luck with your project. Looks neat I'll try it out later when I have time
#4
Projects / Re: Yet Another jPCT RPG
May 16, 2015, 12:04:50 AM
Quote from: EgonOlsen on May 15, 2015, 09:31:14 PM
Nice work. But what has happened to the "pure LWJGL" game that you were doing?

Thank you. Tried and could not succeed...  ::) I still love the idea of writing a game from scratch (as a personal achievement) but after so many road blocks I decided to take what I learned and come back to what I know  ;)
#5
Projects / Re: Yet Another jPCT RPG
May 14, 2015, 09:38:38 PM
I completed mob related code, and started a somewhat hefty item system system. I've updated the first post to show the projects full evolution this year.
#6
I ended up adding a focus point (invisible sphere) to the code, and translating it to the player's position. Here's the source if anybody wants an RPG-suitable camera foundation.



import org.lwjgl.input.Keyboard;

import com.threed.jpct.Camera;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.World;

/**
* An RPG style jPCT camera system.
*/
public class CameraManager {

private final Player player;
private final Object3D orb;
private final Camera camera;
private float cameraRotation = 0;
private float cameraRotationSpeed = 0.042f;
private boolean rotateCameraLeft;
private boolean rotateCameraRight;
private boolean firstPersonMode = false;

/**
* Initialize the camera manager.
*/
public CameraManager(final Camera camera, final Player player, final World world) {
this.camera = camera;
this.player = player;
this.orb = Primitives.getSphere(1);
orb.setVisibility(false);
orb.compile();
world.addObject(orb);
}

/**
* Poll keyboard input. Keyboard.KEY_'s used: KEY_LEFT, KEY_RIGHT, KEY_TAB
*/
public void pollKeyboard(int keyCode, boolean pressed) {
/*
* Let the user control camera rotation so they can have a 360 degree vision range.
* Also give them the option to view the virtual world using a third person camera.
*/
switch (keyCode) {
case Keyboard.KEY_LEFT:
rotateCameraLeft = pressed;
break;
case Keyboard.KEY_RIGHT:
rotateCameraRight = pressed;
break;
case Keyboard.KEY_TAB:
firstPersonMode = !firstPersonMode;
break;
}
}

/**
* Update the camera.
*/
public void update() {
if (rotateCameraLeft) {
if (firstPersonMode) {
player.rotateLeft(cameraRotationSpeed);
} else {
cameraRotation += cameraRotationSpeed;
}
}
if (rotateCameraRight) {
if (firstPersonMode) {
player.rotateRight(cameraRotationSpeed);
} else {
cameraRotation -= cameraRotationSpeed;
}
}

// Translate the cameras invisible focus point to the player position
orb.clearTranslation();
orb.translate(player.getModel().getTransformedCenter());

camera.setPositionToCenter(orb/*abstractHuman.getModel()*/);
camera.align(orb/*abstractHuman.getModel()*/); // Align the camera with the player
camera.rotateY(cameraRotation);

if (firstPersonMode) {
camera.rotateCameraX((float) Math.toRadians(10)); // angle
camera.moveCamera(Camera.CAMERA_MOVEUP, 3.8f); // height ("eye level")
camera.moveCamera(Camera.CAMERA_MOVEIN, 0.5f); // move camera slightly forward,
// so we're not seeing out from inside of the players head model..
} else {
camera.rotateCameraX((float) Math.toRadians(30)); // angle
camera.moveCamera(Camera.CAMERA_MOVEOUT, 45); // zoom
}
}

}
#7
Ok so I've perfected the movement system for my game, but it uses 8 directions for player rotations (A* paths) and my camera seems to be EXTREMELY twitchy / jerky because of that..

My question is how can I smooth the camera system? Here's the code I'm using to make the camera follow the player.



public void update() {
                // I think the following 3 lines is what makes the camera seem to jerk or twitch, since the player rotates in 1 of 8 directions.. and the camera snaps to the player
camera.setPositionToCenter(abstractHuman.getModel());
camera.align(abstractHuman.getModel()); // align the camera with the player
camera.rotateY(cameraRotation);

camera.rotateCameraX((float) Math.toRadians(30)); // angle
camera.moveCamera(Camera.CAMERA_MOVEOUT, 90); // zoom
}


I've tried timers for camera updating but they only cut down on the amount of twitchy/jerky camera movements. How can I make something smoother?
#8
Support / Re: Bots Animating With Player?
April 29, 2015, 04:16:44 AM
Thank you. That worked! I figured it was only a line or two of incorrect implementations..  :-[

And instead of creating another thread I figured I would reply to the same one and ask about performance... I'm using my own distance based visibility system. Basically.. I'm processing regularly to determine if tiles / trees, etc. should be visible and have collision enabled, based on distance; here's the code:

Would it be more efficient just to call compileAndStrip and merge all of the tiles into a singe terrain since the content is 100% static?


public void update(final AbstractHuman abstractHuman) {
if ((abstractHuman.getTransformedCenter() != cachedPlayerPosition)) {
cachedPlayerPosition = abstractHuman.getTransformedCenter();
visibilityUpdateFlag = true;
}
if (visibilityUpdateFlag) {
visibilityUpdateFlag = false; // reset

if (lastVisibilityUpdate < Main.getTime() - 1200) {
lastVisibilityUpdate = Main.getTime();
/*
* Only render the tiles which are in view.
* If the tile is not in view, it does not need collision detection enabled.
*/
for (Tile tile : tileCache) {
tile.setVisibility(GameUtil.inRange(96, false, abstractHuman.getTransformedCenter(), tile.getTransformedCenter()));
tile.setCollisionMode(tile.getVisibility() ?  Object3D.COLLISION_CHECK_OTHERS : Object3D.COLLISION_CHECK_NONE);
}
/*
* Only render the trees which are in view.
*/
for (Tree tree : treeCache) {
tree.setVisibility(GameUtil.inRange(96, false, abstractHuman.getTransformedCenter(), tree.getTransformedCenter()));
}
}
}
}


Considering a single region is only 32 * 32 tiles I'm not sure if this is beneficial or causes unnecessary overhead with jPCT? In a regular lwjgl app I was developing, this helped a lot. But I'm not sure whether it's necessary here..
#9
Projects / Yet Another jPCT RPG
April 27, 2015, 09:43:55 PM

Latest Build - May 2015


I've implemented a fair amount of detail into the game. Everything from smart movement and game controls, to a world editor tool and item support. The latest build is essentially just the foundation for an RPG, and does not represent an actual game... Once the code base is "finished" I will most likely invest into better assets.

Older Build - May 2015


First Prototype - February 2015
#10
Support / Bots Animating With Player?
April 26, 2015, 08:04:19 AM
It's been quite a while since I've posted, or even programmed! So hello again jPCT community.

Anyways, I picked up a project that was inactive for quite some time and tonight I've implemented bots which are meant to wonder the game world and do random things... as expected.

So the problem is that all bots animate with the player? Example: When I walk, the bots stay idle but perform the movement animation. The bots are meant to be their own entities, and not do as the player does. I believe the problem has something to do with the method I store and clone the model...

Here is some code:

snippet from model storage class


public ObjectCache() {
this.male = generateMale();
this.female = generateFemale();
    }

private Object3D generateMale() {
Object3D male = Loader.loadMD2("./res/md2/male.md2", .10f / 2);
textureManager.addTexture("male", new Texture("./res/md2/male.jpg"));
textureManager.addTexture("male-mask", new Texture("./res/md2/male.png"));
this.maleBaseTexture = new TextureInfo(textureManager.getTextureID("male"));
maleBaseTexture.add(textureManager.getTextureID("male-mask"), TextureInfo.MODE_ADD);
male.setTexture(maleBaseTexture);
male.rotateY((float) Math.PI * 1.5f); // Properly rotate the MD2 model
male.rotateMesh();
male.compile(true); // Compile dynamic object
return male;
}

private Object3D generateFemale() {
Object3D female = Loader.loadMD2("./res/md2/female.md2", .091f / 2);
textureManager.addTexture("female", new Texture("./res/md2/female.jpg"));
textureManager.addTexture("female-mask", new Texture("./res/md2/female.png"));
this.femaleBaseTexture = new TextureInfo(textureManager.getTextureID("female"));
femaleBaseTexture.add(textureManager.getTextureID("female-mask"), TextureInfo.MODE_ADD);
female.setTexture(femaleBaseTexture);
female.rotateY((float) Math.PI * 1.5f); // Properly rotate the MD2 model
female.rotateMesh();
female.compile(true); // Compile dynamic object
return female;
}
        // note "male" and "female" are models which are loaded and storaged once.
public Object3D getMob(boolean gender, final float[][] colors) {
Object3D obj = new Object3D(gender ? male : female, true);
obj.shareCompiledData(gender ? male : female);
GLSLShader shader = new GLSLShader(Loader.loadTextFile("./res/md2/player.vert"), Loader.loadTextFile("./res/md2/player.frag")) {
@Override
public void setCurrentObject3D(Object3D obj) {
setUniform("colorMul0", colors[0]);
setUniform("colorMul1", colors[1]);
setUniform("colorMul2", colors[2]);
setStaticUniform("map0", 0);
setStaticUniform("map1", 1);
}
};
obj.setRenderHook(shader);
return obj;
}



Player.java

public class Player {

private final World world;

// the model which represents our player
private Object3D model;

// position stuff
private SimpleVector cachedPosition = new SimpleVector(0, 0, 0);
private SimpleVector nextPosition = null;

// animation stuff
private float animationFrame = 0;
private int animationId = 1;

// name above head stuff
private String username = "Player Name";
private SimpleVector aboveHeadVector;
private int nameLength = 0;

// path finder stuff
private PathFinder pathFinder;
private Path path;
private long lastAutoWalTranslation = 0L;
private int currentStepIndex = 0;
private int pathTranslations = 0;
private Tile targetTile;

public Player(final World world, Terrain terrain) {
this.world = world;
this.pathFinder = new AStarPathFinder(terrain, 64 * 64, true);
}

public void setUsername(GLFont font, String username) {
this.username = username;
nameLength = font.getStringBounds(username).width / 2;
}

public void update() {
autoWalk(); // process auto walk
translate(); // do smooth translations
animate(); // animate
}

/**
* Translates the model in 3D space.
*/
public void translate(boolean smooth, float x, float y, float z) {
if (!smooth) {
/*
* Teleport the player to the destination.
*/
this.model.clearTranslation();
this.model.translate(x, y, z);
this.cachedPosition = model.getTransformedCenter();
resetPath();
} else {
/*
* Set the next position variable so that we can begin the auto walk
* process using a series of smaller, "smooth", translations.
*/
this.nextPosition = new SimpleVector(x, y, z);
}
}

private void translate() {
if (nextPosition != null) {
/*
* Check if we're within distance of the target destination.
*/
if (MathUtil.inRange(1.5f, false, cachedPosition, nextPosition)) {
/*
* If so, let's reset the nextPosition variable so that the player
* stops auto walking.
*/
nextPosition = null;
return;
}
/*
* Rotate towards next position.
*/
SimpleVector s = new SimpleVector(getX(), 0, getZ());
SimpleVector t = new SimpleVector(nextPosition.x, 0, nextPosition.z);
SimpleVector direction = new SimpleVector(t.calcSub(s)).normalize();
Matrix rotationMatrix = new Matrix(direction.getRotationMatrix());
model.setRotationMatrix(rotationMatrix);

/*
* Translate forward towards the destination.
*/
SimpleVector forward = model.getZAxis();
forward.scalarMul(.36f); // speed
SimpleVector moveVector = new SimpleVector(forward);
model.translate(moveVector);
this.cachedPosition = model.getTransformedCenter();
}
}

/**
* Here we're just using jPCT's md2 animation system.
*/
private void animate() {
animationFrame += 0.02f;
if (animationFrame > 1) {
animationFrame -= 1;
}
animationId = path != null ? 2 : 1; // walking or idle
if (model != null) {
model.animate(animationFrame, animationId);
}
}

/**
* Builds a new model instance.
*/
public void build(boolean male, float[][] colors) {
if (model != null) {
cachedPosition = model.getTransformedCenter();
world.removeObject(model);
model = null;
}
this.model = ObjectCache.getInstance().getMob(male, colors);
model.build();
model.compile(true);
world.addObject(model);
model.translate(cachedPosition);
}

/**
* Renders the users name above their head.
* @note: This MUST be called after rendering the jPCT world.
*/
public void renderAboveHeadText(GLFont font, Camera camera, FrameBuffer frameBuffer) {
try {
aboveHeadVector = Interact2D.project3D2D(camera, frameBuffer, model.getTransformedCenter());
if (aboveHeadVector != null && username != "" && username.length() > 0) {
font.drawString(frameBuffer, username, (int) aboveHeadVector.x - nameLength, (int) aboveHeadVector.y - 42, Color.WHITE);
}
} catch (Exception ignore) {
// This happens because the vector returned null - and cannot be avoided.
// Just ignore it.
}
}

/**
* Generates a new A* path to the supplied destination.
*/
public void generatePath(int snapped_x, int snapped_z) {
if (path != null) {
resetPath();
}
path = pathFinder.findPath(model, getX(), getZ(), snapped_x, snapped_z);
if (path == null) {
System.err.println("Cannot generate path!");
return;
}
currentStepIndex = 0;
pathTranslations = path.getLength();
setTargetTile(snapped_x, snapped_z);
}

/**
* Resets all of the auto walk related variables.
*/
private void resetPath() {
nextPosition = null;
path = null;
currentStepIndex = 0;
pathTranslations = 0;
}

/**
* If the player has a path to follow, let's loop through
* the steps and set the smooth translation request.
*/
private void autoWalk() {
if (path != null && lastAutoWalTranslation < (System.nanoTime() / 1000000) - 35) {
lastAutoWalTranslation = System.nanoTime() / 1000000;
currentStepIndex++;
if (currentStepIndex == pathTranslations) {
resetPath();
return;
}
translate(true, path.getX(currentStepIndex), 0, path.getY(currentStepIndex));
//setTargetTile(path.getX(currentStepIndex), path.getY(currentStepIndex));
}
}

private void setTargetTile(int x, int z) {
// update target tile
if (targetTile != null) {
world.removeObject(targetTile);
}
int targetX = x / 6;
int targetZ = z / 6;
targetTile = new Tile(targetX * 6, targetZ * 6);
targetTile.translate(0, -1, 0);
targetTile.setAdditionalColor(Color.YELLOW);
world.addObject(targetTile);
}

/**
* Returns the players current position.
*/
public SimpleVector getTransformedCenter() {
return model == null ? cachedPosition : model.getTransformedCenter();
}

/**
* Returns the model instance.
*/
public Object3D getModel() {
return model;
}

public Object3D getTargetTile() {
return targetTile;
}

/**
* Returns the players X coordinate.
*/
public int getX() {
return (int) cachedPosition.x;
}

/**
* Returns the players Z coordinate.
*/
public int getZ() {
return (int) cachedPosition.z;
}

}


I hope I've provided enough code for somebody to point out the technical issue with my application. As mentioned when I tell the local player to walk, the bots with the same gender will animate with it.. ex: all male bots will animate with my male player when the male player walks
#11
Support / 3D -> 2D mouse coords?
January 24, 2015, 10:48:53 AM
I've got the 2D -> 3D mouse coordinates concept down, but how can I reverse that? My goal is to set up a system where I can click on an entity, and a simple options box will be rendered in 2D space.

Here's a microsoft paint where red X = mouse position and the white box is what I want to accomplish..
#12
Quote from: EgonOlsen on January 20, 2015, 07:31:33 AM
I felt so free to edit this post and move the download away from uppit... ;)

Thanks for sharing!

Heh, I'm surprised you could find the real download button ;) Do you have a preferred file hosting website?
#13
Projects / Multi Player Sandbox RPG [video & source]
January 20, 2015, 12:05:13 AM
I was just about to delete this project from my eclipse directory and decided I would upload a copy for anybody who might be interested in using it.
Keep in mind this was my first (functional) mutli player 3D game so there is room for improvement, but at least the code is readable ;) I just posted this exact same thread on JGO

https://www.youtube.com/watch?v=kp6qlDwKJ6U

The video is probably not the same as the current build, so here's a screen shot I took which would be 100% accurate:


Download link:
http://jpct.de/download/others/MP3D.zip

How to host & join
First you'll need to open the project using Eclipse IDE, then refer to this image:


After you run the client you will be prompted for a username and hostname in the Eclipse console.

You can either type the desired name then press enter, or just press enter for a random username.
The same goes for hostname, where no hostname = localhost, etc. etc. You get the point.
#14
Quote from: CTucker1327 on December 30, 2014, 11:16:45 PM
Quote from: EgonOlsen on December 30, 2014, 01:33:20 PM
jPCT offers various blit-methods in FrameBuffer for rendering 2d images on top (or behind) the scene. You can render while textures, parts of textures both scaled and unscaled. That should actually be sufficient to create a simple 2d GUI framework. Are you missing something there?

After smashing my head against the wall for a few hours, and studying the code provided by corey I've managed to write my own loader for 2D assets, and drawing them has never been easier. I'll continue on with this for the next few days and attempt to make a nice little open-sourced interface library for people to use.

Open source  ;D
#15
I should mention the TwoD library I provided to OP is just an extension of raft's texture/font release, modified to make development a little easier for 3D beginners.