Jump to content

  • Log In with Google      Sign In   
  • Create Account

ProgrammerGuy123

Member Since 06 May 2012
Offline Last Active Nov 02 2013 03:05 PM

Topics I've Started

Updating Entities in a Chunk Based System

08 August 2013 - 07:44 PM

I need help on how I should go about updating entities in my game with a chunk based approach. It's a 2D tile based side scroller. This is about updating the entity logic not drawing tiles.

 

My game is going to have different entities like monsters and projectiles. I don't wan't to update all the hundreds of entities in the map at the same time so I need some sort of chunk system, where I split the map up into chunks and only update the chunks that are visible.

 

With this in mind I thought about giving each chunk a list of entities that belong to it. Then I could update each visible chunk, which would cycle through the chunk's list and update each individual entity. If an entity like a monster moves from one chunk to another I could remove it from the previous chunk's list and add it two the new chunk's list.

 

However, say I shoot a projectile off my screen, then the entity would not get updated until the chunk is able to update which means making that chunk visible. I guess I would just have to force update the chunks the projectile is in then.

 

It seems like that could work, but there are probably more efficient ways to handle cutting down hundreds of entity updates to tens of entity updates, which is why I'm asking. This is a very fundamental concept to any large tile based game, so I want to here what your method is. How do you handle updating entities in a efficient matter?

 

Thanks.


Game Design With Update and Draw Functions

17 July 2013 - 04:10 PM

Objects in my game have both update and draw functions as expected, the update function sometimes need a delta time variable and the draw function sometimes needs a window object.

 

I have seen lots of engines pass in the delta time variable through every update function and pass in the window object through every draw function like so:

//C++
void State::update(float deltaTime)
{
     sprite.pos += vel * deltaTime;
}

void State::draw(Window window)
{
     window.draw(sprite);
}

The problem with passing these objects through every single update and draw method is that sometimes the're not used. For example, a main menu does not need a delta time variable but does need a window object, but you can't just omit the parameter if you don't need it because the main menu inherits from the game state object which contains the parameters.

 

So would it be better in design to never pass these objects into functions but instead make them static like so?

//C++
void State::update()
{
     sprite.pos += vel * GameManager::deltaTime;
}

void State::draw()
{
     GameManager::window.draw(sprite);
}

I'm asking because this is a very fundamental concept to game engines and the latter example just seems to make more since but it seems like the former example is favored.

 

Which is better code design? Thanks.


Hovercraft Physics

21 July 2012 - 01:47 PM

I'm trying to implement hovercraft like physics into my game but I need help. An improtant thing to note is that the hovercraft will be pretty high off the ground unlike realistic hovercrafts. After searching and asking questions I arrived at this source code:

       double g = 9.8d; //gravity
       double m = 1.0d; //mass
       double fMax = 15; //maximum upwards force
       double idealHeight = 100; //ideal height the craft should be off the ground
       double v; //velocity
	   void Update() {
			double h = Math.Abs((craft.Y + craft.Height) - ground.Y); //determin the craft's height from the ground.
			double a = (g - f(h)) * m; //acceleration
			v += a; //velocity
			v = MathHelper.Clamp((float)v, -15.0f, 15.0f); //make sure the acceleration doesn't get out of hand
			craft.Y += (int)v; //assign the velocity
		}
		double f(double h) { //this function return the amount of upwards force
			return Math.Max(0, h * (g - fMax) / idealHeight + fMax);
		}

One cunfusing thing to note is that my game is 2D with (0, 0) being the top left corner of the window and (100, 100) being accrosed and down 100 pixels. This is why I have the Math.Abs(craft.Y + craft.Height) - ground.Y whole thing.

Now the problem:
This code works but the craft just goes up and down up and down up and down enlessly. I would like the craft's velocity to diminish over time to equal out with the idealHeight. Like this picture shows.

How would I do that?
Thanks.

Whats Wrong With My Perlin Noise Function?

30 May 2012 - 06:06 PM

I understand the concept behind perlin noise but I can't understand why the method doesn't return perlin values:


public int PerlinNoise2D(int x) {
			int freq = 4;//initFrequency;
			int amp = 1;//initAmplitude;
			int total = 0;

			for(int i = 0; i < octaves; i++) {
				total += InterpolateNoise(x * freq) * amp;
			}

			return total;
		}

		int InterpolateNoise(int x) {

			int v1 = new Random(x).Next(64);//this returns a pseudo-random number less than 64 with "x" as the seed
			int v2 = new Random(x + 1).Next(64);

			return CosineInterpolate(v1, v2, x, 4);
		}

		int CosineInterpolate(int a, int b, int x, int length) {
			return (int)((1 + Math.Cos(3.1415f * x / length)) / 2 * (a - b) + b);
		}

It generates repeating values that are not perlin and as explained before I need help on fixing it.

Thanks.

2D Perlin Noise

06 May 2012 - 10:48 AM

I'm trying to create perlin noise but I'm having trouble understanding how interpolation works. I understand how to do it in a single dimension but can't wrap my head around it in two. Right now I have this for an octave:

Posted Image

Obviously this is not coherent and I need to interpolate to get something similar to this:

Posted Image

Most sources such as this explain how to do it one dimension but don't in two. Quote: "You can, of course, do the same in 2 dimensions." So could someone explain the concept of how linear interpolation works in two dimensions?

Thanks.

PARTNERS