Creeper World 3D.... again

Started by Grun, April 02, 2013, 09:20:15 AM

Previous topic - Next topic

Grun

Hey all, been a while.

Some may remember this thread...
http://knucklecracker.com/forums/index.php?topic=7465.0

and in that these videos...




Well I left it there and been getting on with real life things, as per original thread I got married and since had a baby :) little girl who nearly 12 months old now.

But was just killing time and was playing CW and thought lets check out any updates and CW3 :O but I have to wait so till then I been doing a little more on that 3D demo sim...

http://www.youtube.com/watch?v=OR44Y0lj8_o&feature=youtu.be

What people think??? I know things like the lazer postion compltly needs reworking and scale/timings need fine tuning and its still my legendary art work :P

Hope all enjoy and looking for ideas about what to include next

Grun

Grauniad

Well, congratulations with your "real life". :) Little kids are fun!

I'm sure you have checked out the Knuckle Cracker blog to see where Vigil has gotten to. Still 2D, but with some light and shadow effects to give some 3D feeling to the game. There is still the requirement that the game be written in something that can be supported from a browser and on some of the gaming websites such as Kongregate, so not all the freedom to choose platforms that one may have wished for. The new Unity3D platform gives a lot better performance and that you will see in the increased detail and general feel for the game when you watch the videos.
A goodnight to all and to all a good night - Goodnight Moon

Grun

Yeah have watched all vids (some a few times :P ) and love the new look and feel, this program I have written is sort of a test bed to test skills.

There a lot lot more to it than what you see such as lighting effects i been messing with, colour picking (for unit selection), UI overlay etc. I just find programming I need some results I can see and show off etc so CW works well.

Grun

TrickyDragon

Interesting,  do you have variables for liquid thickness and whatnot?
This is Life,  Life happens.

Grun

Well sort off, its a calculation of height aboved terrain making it easyer when doing the calculations for the creeper to climb/fall over cliffs. This also works nicly for the blaster to do calculation for damage done as a reduction in height of creeper at area hit.

Grun

thepenguin

#5
1. what language is this in?  I beleive it was some kind of basic, but I'm not sure...
2. any chance of source code getting shared?
3. is this just a height map, like virgil's "3D creeper", or is it a real 3D simulation? I beleive that it was just a height map last I checked, but I want to make sure it hasn't changed.
4. your blasters are beyond awesome looking (i don't know what it is about them.)
We have become the creeper...

Grun

Hi Penguin,

Its written in c++ using openGL,

As for source code there a lot that needs rewriting and sutff unrelated to it as it is at the moment and well its huge :P

As for the creeper covarage, its simply a triangle strip for the terrain and one of same dimensions just below which raisees for where the creep is raising increasing the opacity and distance between terrain and creep as it rises. So it is 3d in respect that you can look at diffrent angles and it will display as such. Will go into more detail at bottom of post....

As for the blaster model, well it took about 20 minutes but was created in 3DsMax and a simple texture just put on. Im not as good as I use to be at modeling but have used models with up to 5000 poly count and still get high FPS so to swap it out is just a simple case of creating a new model which looks better and done.

Grun.


Firstly the terrain, creeper very similar code.... ignore the stuff relating to parent unless you know much OO, but as you can see it uses GL_TRIANGLE_STRIP which works like this image..(scroll about half way down for image)

http://stackoverflow.com/questions/2954349/when-should-i-use-indexed-arrays-of-opengl-vertices#

Terrain Constructor
Spoiler

Terrain::Terrain(const char* filename, const char* texture)
{
   
   baseHeight = 8;

   Image* image = loadBMP(filename);

   //width + length taken from size of bitmap
   w = image->width;
   l = image->height;
         
   hs = new float*[l];
   for(int i = 0; i < l; i++) {
      hs = new float[w];
   }
   normals = new Vector*[l];
   for(int i = 0; i < l; i++) {
      normals = new Vector[w];
   }
   
   for(int y = 0; y < image->height; y++) {
      for(int x = 0; x < image->width; x++) {
         unsigned char color =
            (unsigned char)image->pixels[3 * (y * image->width + x)];
         float h = baseHeight * ((color / 255.0f));
         hs[y]
  • = h;
          }
       }
       
       g_Game.addRenderComponent(this);
       

       mTexture.Load(texture);
       
          
    }
[close]
Terrain::Render
Spoiler

void Terrain::Render()
{
   // dont render if we dont have a parent (so we dont have a transform)
   if(!getParent()) return;
   
   mTexture.MakeCurrent();
   
   for(int z = 0; z < w - 1; z++) {
      //Makes OpenGL draw a triangle at every three consecutive vertices
      glBegin(GL_TRIANGLE_STRIP);
      for(int x = 0; x < l; x++) {

         Vector normal = getNormal(x, z);
         glColor4f((getHeight(x,z)/baseHeight),(getHeight(x,z)/baseHeight),(getHeight(x,z)/baseHeight),1.0f);
         glTexCoord2f(x/w, z/l);
         glNormal3f(normal.x, normal.y, normal.z);
         glVertex3f(x, getHeight(x, z), z);
         
         normal = getNormal(x, z + 1);
         glColor4f((getHeight(x,z)/baseHeight),(getHeight(x,z)/baseHeight),(getHeight(x,z)/baseHeight),1.0f);
         glTexCoord2f(x/w, (z+1)/l);
         glNormal3f(normal.x, normal.y, normal.z);
         glVertex3f(x, getHeight(x, z + 1), z + 1);
      }
      glEnd();
   }
}
[close]

As you can see in the constructor it passes 2 arguments for the 2 textures needed, 1 used for the height map and the other the texture to render over the top.

Creeper is created and drawn in almost same way, just has a pointer to the created terrain and is able to use function getHeight(float X, float Y) and the creates the height at each point like 0.001 below. Then the emmiter gets the creeper height at its position and adds to this height at set values and time intervals. This then causes it to go into calculations for how much to pass to ajoining areas. This code is messy and still being worked on.

Also for all these people looking at this code and seeing stuff like, g_Game.addRenderComponent(this); , yes i know its nasty using external reference and there better ways but im still learning :P

Grun

#7
Still working on it :)

have added a UI with buttons which show when highlighted and detect click, now I just need to make the click do somthing :P

Will keep you up to date with any other advances.

Grun

quick edit...

Just for people who dont know/remember...
this is just for fun im doing this and have no intention of doing anything with, other than mess about with myself, have spoken to Virgil about such back when I first started :)

Then again.... if I made like the best of games to beat even the $100000000000 games out there im sure Virgil would be happy to negotiate :P

Kingo


Grun

Pretty boring stuff unfortunatly.

Been altering the code for models to allow for each model to be made up of multiple models with multiple textures, allows for a lot more detail.

Also looking to add other units, but to do so need to rewrite older code (making a factory class for anyone who knows about programmining). This will allow me to say build unit A at location X,Y in one line of code which can then be execuited at any time through commands while its running. Once this sorted will tie it in with the UI elements I introduced so it works like it would in game, click what to build and click where to build it.

Im also in process of looking at introducing the variables to be taken from external file, this will allow for easyer changes to behaviors of things rather than looking through 10,000s of lines of code :P

Grun

Kingo

What can the program do?
I myself am into programming right now, so it isn't boring for me :)

Grun

Ok lets see......

Well it basic openGL framework which handles, well openGL and some of the lighting etc...

Then there a base class which holds a Matric and virtual routines for creation, destruction, update and render if it inherits of a render component. All classes that inherit of this class get added to a list, a seperate list for anything which is rendered. The each frame each item in these lists get the function update(time) and where applicable renter() run.

From there a simple camera class which uses external references to the mouse position (I know this nasty needs changing) but each aspect of the camera (XY movement, zoom etc) which alter the inherited Matrix to then be passed to open GL to set camera.

Next there a terrain class which uses openGL triangle strips setting the height via a BMP using RGB to determin the height.

Directly below that is a 2nd plane which is like .01 below the terrain which acts as the creeper. This is then set globaly via the main game class to allow all to have access (again nasty) so other classes such as the emmiter can increase. This class also then references the terrain class to calculate if above the terrain to have the spread logic take place.

Then the cannons (and similar for others), well at min they take and X Y position and take the terrain height from such position and place a model which im currently using Quate models. There is multiple models so the turret can be rotated spearatly through the inherited base class for rotation and can allow for more detail and easyer UV mapping. There then a further component which looks to see if any creeper above terrain within a set radius to the rotate the top half/set parts of the model to face this area and then fire, setting of a timer till nexxt shot available and reducing the creeper level at that point.

The UI stuff etc im working on cant explaing much as messing about with that quite a bit.

Depeding on your level of programming you may or may not follow or understand why having both the terrain and creeper being global (well not global it just having reference to it in the main game class).

If there any specific aspect you want more on just ask and will try and explain.

Grun

Kingo

I understand the need for global and local variables :) definitely annoying, but essential.
I can see with making them global, you don't need to run a calculation (if it is as simple as that) to continuously check each terrain height for whether the creeper should rise...

I ran into this problem when I was considering trying to emulate CW in Excel using VBA.

Grun

Global variables are not essectial, there is always ways around such as sending pointers to what the class needs. I didnt actualy set them as global I set the main game class as external in the class so the classes that needed access could do so through the main game classes pointers, so for the terrain creeper and mouse etc. 

As for doing such in excell, dam would be pretty hard.

If there any more detail about any aspect just ask and will try and explain in more detail or provide some of the code to show how i done it.

Grun

Kingo

#14
Currently I've been trying to make Galaga (anyone here know what it is?) work in excel, it's actually doing good... I am a bit wet behind the ears in terms of general programming and its terms, but I am picking it up time to time :)

What programming language and/or API are you using?