Voxel Engine Zombies Game - Problem

So after a few days of pondering around ideas for a game so I can learn LWJGL I though of doing as many have in the past a minecraft style voxel engine and then I thought what would make this different from other voxel games out there. That is where I came up with the idea of incorporating a zombie survival / map like CoD zombies with a voxel engine since I don’t want to dive into the deep end of LWJGL.

I am always looking for constructive criticism and ideas on how to improve the game in anyway possible.

Tasks

  • save and load chunks
  • make model making more easier so it allows anyone to create models
  • player controlled model
  • zombies and any other mobs
  • Map and doors

Concept
So as I said it is a voxel zombie survival game where the player has to survive rounds of the undead for survival or have an objective to reach that will cause the game to end. I also want it so anyone can be able to make maps and so I want to make a way for the player to be able to customize the maps to the way they want it to be played.

Screenshots

Been playing around with 2D spritesheet to 3D models. Models and names of weapons can be changed before the final game is released.

I adapted my model class to accommodate for terrain as well so now I can generate walls which are very cool and I am happy I got this working.

I also worked on a quick item drop class a few mins ago and its very badly coded atm but what it does as you can see is it gets a 2D sprite and converts it into a 3D representation and this has to be the best thing I have coded so far.

A small look at my player model since I just implemented it and though I would create something that can be compared to with the size of the worlds blocks.

Some simple terrain generation just to handle chunks and also develop on the voxel engine aspect of the game.

One function now controls everything from the x,y,z position to the size of the shapes and also the colours and alpha channel and with little to no frame drop and if anyone wants to know the details it is rendering 25 blocks for that model :slight_smile:

Problem
The problem that I currently face are as followed;

  • Rotating weapon

That looks good.

Maybe you could serialize your blocks - use some form of xml?

It is best to have minimum data in your block structure.

Do you have your camera working?

Looking good!

As steg mentions having a serialzable form of data would help really cut down the amount of loading.

you could use a id-number for the block, and a second number for its value…? I guess it depends on how many variable you think you will need? or how large the variables would be. Maybe you can get away with 2 bytes?
I just used 1 byte per block for my game. ID=3 is stone etc…

I just saved a serialized array of bytes. Im at work at the moment but I can paste my code here that will save this information for you later if you need it.

This sounds super cool, you gotta keep us all posted :slight_smile:

Thanks I have been working on it or a few hours and XML would of been my next approach since I would store the x y z and block ID for each block inside the chunk and if needed the price e.g a door. I also got camera moving and have the pitch locked so you can’t keep rotating. :slight_smile:

Thanks Vermeer and yea if you show me the code that would help a lot. Much appreciated. :slight_smile:

It sound cool but its if I can do it and with other stuff I have done I hope I can since a lot of people like it and I will decently keep this thread updated.

Hi

As promised. This does work, but it may not be the best way of doing it. Also its has poor exception handling, and you would need something more robust, but it may help you get it working.
Or it may prompt others to add more robust sugestions.Please ask questions if you cant get it to work.

public void writeChunk (int chunkNumber){
		
		
		
		byte[][][] writeChunk = new byte[16][16][16];
		
		//write the data into a temp array
		for (int xC = 0; xC < 16; xC++) {
			for (int zC = 0; zC < 16; zC++) {			
				for (int yC = 0; yC < 16; yC++) {
				
					writeChunk[xC][yC][zC] = (byte) chunks[chunkNumber].getblockID(xC, yC, zC);
								
				}
			}
		}
		
		//output file
		String file = new String(chunks[chunkNumber].getName()+".dat");
		try {
			ObjectOutputStream objOut = new ObjectOutputStream( new FileOutputStream(file));
			objOut.writeObject(writeChunk);
			objOut.close();
		} catch (Exception e) {
			
		e.printStackTrace();
		}
		
		System.out.println("Written chunk "+ file);
		
	}
	
	
public void readChunk (int chunkNumber){
		
		byte[][][] readChunk = new byte[16][16][16];
		
		
		
		//inputfile file
		String file = new String(chunks[chunkNumber].getName()+".dat");
		try {
			
			FileInputStream fileIn = new FileInputStream(file);
			ObjectInputStream in = new ObjectInputStream(fileIn);
			readChunk = (byte[][][])in.readObject();
			in.close();
			fileIn.close();
		
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
		//send the read chunk array
		for (int xC = 0; xC < 16; xC++) {
			for (int zC = 0; zC < 16; zC++) {			
				for (int yC = 0; yC < 16; yC++) {
				
				 chunks[chunkNumber].setblockID(xC, yC, zC, readChunk[xC][yC][zC]);
								
				}
			}
		}
		System.out.println("Opened chunk "+ file);
		
	}

Thanks so much Vermeer, I could kiss you. No homo. I have implemented it into make game and made a few tweaks and now the saving is working nicely I will probably end up adding another save file that will probable hold the map data such as door costs and spawning points for zombies and other mobs. Each chunk takes up 7kb.

In other news I improved my model creating method I made.

So after playing around with my modeling code I ordinarily setup to make mobs and players more detailed and just to overall create stuff I have finally settled on a nice and easy method that works for me.
One function controls everything from the x,y,z position to the size of the shapes and also the colours and alpha channel and with little to no frame drop and if anyone wants to know the details it is rendering 25 blocks for that model :slight_smile:

So the past few days I havent done much as in coding wise but I have some nice stuff to show for it tho.

I adapted my model class to accommodate for terrain as well so now I can generate walls which are very cool and I am happy I got this working.

I also worked on a quick item drop class a few mins ago and its very badly coded atm but what it does as you can see is it gets a 2D sprite and converts it into a 3D representation and this has to be the best thing I have coded so far.

Also guys im still open to some suggestions on what I can add later :).

You could add block picking :wink:

What about some mobs that walk around?

Looking good and you have made some great progress. Must ask, how did you do the model for your player and how did you set the camera for it?

I do plan on having a block picker but since I want to work on a survival zombie game 1st like cod zombies I will probably have just weapon selector then when im finish just work on a voxel engine. I also do plan on adding mobs probably zombies but not just zombies as in the walking dead but zombie dogs and other animals I can think would fit the game.

The model for the player is me just playing around with my own model class I made which just sets the
x,y,z,sizeX,sizeY,sizeZ,R,G,B,alpha

and for the camera is not bound the the player its more or less a 3D vector that when it comes to render I call this method within my camera class;

	public void setView() {
		glRotatef(_rx, 1, 0, 0);
		glRotatef(_ry, 0, 1, 0);
		glRotatef(_rz, 0, 0, 1);
		glTranslatef(_x, _y, _z);
	}

If you want to know about my model class just ask and ill share it

Thanks,

Yes, would like to know more about your model class :slight_smile:

I’ve just added some pyramid type landscape:


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

Looking at doing some domes next, half a sphere or even a cardioid (r=2a(1+cos theta) )…

Now domes added :slight_smile: :


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

Code to do this:


public int SetUpDome() {
		for (int x = 0; x < CHUNK_SIZE; x++) {
			for (int y = CHUNK_SIZE - 1; y > CHUNK_SIZE / 2; y--) {
				for (int z = 0; z < CHUNK_SIZE; z++) {
					
					if (Math.sqrt((float) (x - CHUNK_SIZE / 2)
							* (x - CHUNK_SIZE / 2) + (y - CHUNK_SIZE / 2)
							* (y - CHUNK_SIZE / 2) + (z - CHUNK_SIZE / 2)
							* (z - CHUNK_SIZE / 2)) <= CHUNK_SIZE / 2) {
						Blocks[x][y-8][z].SetActive(true);
						Blocks[x][y-8][z].SetType(BlockType.BlockType_GoldBlock);

					} else {
						Blocks[x][0][z].SetType(BlockType.BlockType_Grass);
						Blocks[x][0][z].SetActive(true);
					}

				}
			}
		}
		return this.rebuildChunk();
	}


Nice and here is the code;
The addblock class


import java.util.ArrayList;
import java.util.List;

import org.lwjgl.util.vector.*;

public class addBlock {

	public Vector3f pos1;
	private Vector3f pos2;
	private Vector4f colour = new Vector4f(0.0f, 0.0f, 0.0f, 1.0f);
	public List<float[]> vertexArray = new ArrayList<float[]>();
	public List<float[]> colourArray = new ArrayList<float[]>();

	public addBlock(float x, float y, float z, float xSize, float ySize, float zSize, int r, int g, int b, float a) {
		
		float red = (float)r/255;
		float green = (float)g/255;
		float blue = (float)b/255;
		colour = new Vector4f(red, green, blue, a);
		
		pos1 = new Vector3f(x, y, z);
		pos2 = new Vector3f(x + (xSize / 10), y + (ySize / 10), z + (zSize / 10));
		vertexArray.add(new float[] { pos2.x, pos2.y, pos1.z, pos1.x, pos2.y, pos1.z, pos1.x, pos2.y, pos2.z, pos2.x, pos2.y, pos2.z });
		vertexArray.add(new float[] { pos2.x, pos1.y, pos2.z, pos1.x, pos1.y, pos2.z, pos1.x, pos1.y, pos1.z, pos2.x, pos1.y, pos1.z });
		vertexArray.add(new float[] { pos2.x, pos2.y, pos2.z, pos1.x, pos2.y, pos2.z, pos1.x, pos1.y, pos2.z, pos2.x, pos1.y, pos2.z });
		vertexArray.add(new float[] { pos1.x, pos2.y, pos1.z, pos2.x, pos2.y, pos1.z, pos2.x, pos1.y, pos1.z, pos1.x, pos1.y, pos1.z });
		vertexArray.add(new float[] { pos2.x, pos2.y, pos1.z, pos2.x, pos2.y, pos2.z, pos2.x, pos1.y, pos2.z, pos2.x, pos1.y, pos1.z });
		vertexArray.add(new float[] { pos1.x, pos2.y, pos2.z, pos1.x, pos2.y, pos1.z, pos1.x, pos1.y, pos1.z, pos1.x, pos1.y, pos2.z });
		colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
		colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
		colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
		colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
		colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
		colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
	}

}

Anything im doing I will do this for them.
Create an array of parts and assign each part to a new addblock then from that do a loop to assign the vertex and colour to the vertext and colour array


List<float[]> vertexArray = new ArrayList<float[]>();
	List<float[]> colourArray = new ArrayList<float[]>();
	addBlock[] parts = new addBlock[3];

parts[0] = new addBlock(0, 18.15f, 0.3f, 4, 4, 4, 237, 198, 123, 1);
		parts[1] = new addBlock(0, parts[0].pos1.y - .6f, parts[0].pos1.z + .1f, 4, 6, 2, 36, 70, 157, 1);
		parts[2] = new addBlock(parts[1].pos1.x - .201f, parts[1].pos1.y + 0.4f, parts[1].pos1.z + 0.2f, 2, 2, -5.5f, 14, 84, 102, 1);

for (addBlock b : parts) {
			vertexArray.addAll(b.vertexArray);
			colourArray.addAll(b.colourArray);
		}

Thanks,

How do you animate the model?

No I haven’t done that but all you probably need to do is have a timer and change the values every few seconds

PS - did you put in collision detection and any culling?

I’m doing collision detection at the moment - the joy of it!

I haven’t done collision yet and for culling yes the engine does have culling, if it didn’t I would be running at like 5fps :stuck_out_tongue:

Ok, did you use frustum culling against the viewing planes? I’m using some basic distance check at the moment as my frustum culling isn’t working correctly!

Just using

glEnable(GL_CULL_FACE);

Same here.

Mmmmm, what about only drawing blocks you can see - i.e not hidden by other blocks? And only drawing faces of those blocks that have no neighbors blocking them?

You still need to cull your chunks against the viewing frustum :wink: