Jump to content
  • Advertisement

ProgrammerGuy123

Member
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

127 Neutral

About ProgrammerGuy123

  • Rank
    Member
  1. 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.
  2. 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.
  3. ProgrammerGuy123

    Hovercraft Physics

    Ah yes thank you. Very informative links.
  4. ProgrammerGuy123

    Hovercraft Physics

    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.
  5. ProgrammerGuy123

    Whats Wrong With My Perlin Noise Function?

    Thank you and everyone else I just need the /100 and it works perfectly now!
  6. ProgrammerGuy123

    Whats Wrong With My Perlin Noise Function?

    That is indeed how I'm called the method: byte[,] temp = new byte[height, width]; for(int x = 0; x < width; x++) { byte value = (byte)((PerlinNoise2D((double)x) * 64) + 64); temp[value, x] = 1; } This is exactly why I was using integers in my pervious attempts for everything and not decimals. Is there any way I could efficiently convert the integers into decimals and back into inegers again? Or should I go back to the way I was doing it and have everything calculated with integers. Right now I'm multiplying the perlin value by 64 just for testing as you can see then adding the same value to get rid of any negatives. But like you said I'm only going to get values based on integer boundries so what should I do?
  7. ProgrammerGuy123

    Whats Wrong With My Perlin Noise Function?

    Ok so I tried to fix a lot all of these problems but the function is still acting up and I'm really confused on why because I scrapped the whole thing to use double values instead of integers and I even took the complete RNG from this article about perlin noise. This solves the problem of having to use hash tables because now I'll get a random number where x and x+1 is a completely different number. However now it seems to return negative values which makes absolutely no since considering I use his RNG not .NET's. Also the InterpolatedNoise method is almost the exact same I'm just not smoothing the values because I want to simplify it. Then there is the CosineInterpolate method. To me logically this must be the reason for my negative values because as stated before I took the entire RNG from the article so it can't be that. The CosineInterpolate method was taken from this article. I've made no methods all the methods responsible for generating perlin values are from reliable sources. What is going on? public double PerlinNoise2D(double x) { int octaves = 1; double freq = 16; double amp = 1; double total = 0; for(int i = 0; i < octaves; i++) { total += InterpolateNoise(x * freq) * amp; } return total; } double InterpolateNoise(double x) { int xInt = (int)x; double xFrac = x - xInt; double v1 = Noise(xInt); double v2 = Noise(xInt + 1); return CosineInterpolate(v1, v2, xFrac); } double Noise(int x) { x = (x<<13) ^ x; return ( 1.0 - ((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); } double CosineInterpolate(double a, double b, double x) { double f = (1 - Math.Cos(x * Math.PI)) / 2; return (a * (1 - f) + b * f); }
  8. ProgrammerGuy123

    Whats Wrong With My Perlin Noise Function?

    The values were not changing because I only had one octave for simplicity therefor there was no need for them to change. This was a mistake on my part I was thinking I needed a random value based on "x" which mean if "x" is ever the same it should generate the same number. I have revised the code I think to fix this problem but no luck. First I need just one octaves to work then I can generate more and add them up but for now I'm focusing on one octave which you will see in my code: public int PerlinNoise2D(int x) { int total = 0; int octaves = 1; //only one octave for simplicity for(int i = 0; i < octaves; i++) { int freq = 16;//16 for simplicity I only have one octave so it doesn't need to change int amp = 1; //1 for simplicity again ^^^ total += InterpolateNoise(x * freq) * amp; } return total / octaves; } int InterpolateNoise(int x) { int v1 = random.Next(64); int v2 = random.Next(64); return CosineInterpolate(v1, v2, x, 16); // the 16 is from the frequency } int CosineInterpolate(int a, int b, int x, int length) { return (int)((1 + Math.Cos(3.1415f * x / length)) / 2 * (a - b) + b); }
  9. 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.
  10. ProgrammerGuy123

    2D Perlin Noise

    What do you mean by "corner values"? The octaves are made up of multiple squares. Am I getting the corner values of those squares? Wouldnt they be the same value then? Could you explain what you mean by this?
  11. ProgrammerGuy123

    2D Perlin Noise

    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: Obviously this is not coherent and I need to interpolate to get something similar to this: 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.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!