Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Oct 2013
Online Last Active Today, 07:07 PM

#5203128 GLSL simple shader help

Posted by Lactose! on 09 January 2015 - 12:09 PM

I would gladly delete if there were an option but I cannot find it

There is no option to delete posts, because other people might gain something from your posts even if you consider them solved.

The proper etiquette (on this forum, as it may vary from forum to forum), is to post the solution, and let the thread die on its own. By doing so, it is possible for others who might experience the same problem to also find your solution.

It is also possible that your solution wasn't a complete fix, which someone else might assist you with, or discuss alternatives.

#5202594 Drawing Multiple Sprites (projectiles)

Posted by Lactose! on 07 January 2015 - 08:12 AM

Your "spacebar to fire" code loops will set all projectiles to fire, using the same position. The keydown check will be the same for the entire loop, so if it's true for the first iteration of the loop, it will be true for all of them.


What you could do instead is something like:

- Check if spacebar is pressed.

- If it is, iterate over the array, checking if the projectile is not launched.

- If a projectile is not launched, launch it, and stop looping through the array.


You will need to clear the "launched" flag when the projectile has done whatever it should be doing.

And, as already mentioned, you shouldn't update logic in your draw code.


Another way of doing this would be to e.g. have a std::vector of projectiles, and add a new projectile to the vector when you press the spacebar.

#5202070 Angle of Direction, Velocity, and Acceleration

Posted by Lactose! on 05 January 2015 - 03:20 PM

Why can't this be done? 

It can! However the wind then counts as acceleration upwards, and you need to include it in the calculations before updating the velocity.


For example, the car might have an acceleration value of 20 units in the x direction, and the wind might be act as an acceleration value of 3 units in the y direction.

This leads to a final acceleration of x = 20, y = 3 (which is an angle of roughly 9 degrees). It's this final acceleration you use to update the car's velocity (and in turn, the car's position).

#5201954 Angle of Direction, Velocity, and Acceleration

Posted by Lactose! on 05 January 2015 - 09:01 AM

If you use an angle for acceleration, you don't need X and Y acceleration values. You only need a single acceleration value; the X and Y components are then derived from the angle.

Wanting to move with angle 0 (which would be horizontal), and having a Y acceleration of 1 (moving vertically) does not work or make sense.



acceleration = 1; //In the direction indicated by the 'angle' variable.
velocityX += cos(angle * PI/180) * acceleration;
velocityY += -sin(angle * PI/180) * acceleration;
PositionX += velocityX; //Minor note -- inconsistent capitalization here, 'Position' vs 'velocity' and 'acceleration'
PositionY += velocityY;


Alternatively, keep accelerationX and accelerationY, and compute the angle from the X and Y components.



That said, I'd recommend you look into vectors and use those instead of splitting variables per axis.

With that, acceleration would be a single variable containing both the direction and the magnitude.

Something like...

velocity += acceleration;
//Potentially clamp velocity if it's higher than a desired max
position += velocity;

#5199411 Where should I start learning game development?

Posted by Lactose! on 21 December 2014 - 09:17 AM

So back to the OP, if you want to make games, in a nutshell you'll need to know C++ and linear algebra.

You do not need to know C++ to make games. That's clearly a false statement, proven by the many, many games made in other languages/engines.


For AAA studios, knowing C++ might be a requirement, but the original post specifically mentions indie studios, which typically do not have the same criteria for e.g. performance as AAA studios have.


I also don't agree with your claim that saying "C++ is harder to learn" is equivalent of saying "you are too stupid to learn this, go look at something else".

#5199191 Chess moves

Posted by Lactose! on 19 December 2014 - 06:18 PM

Could you fit all possible chess moves on a 5TB external hard drive, excluding repeating states and stalemates? And then use that as a lookup table for an unbeatable AI?

No. There's just too many moves.

#5198940 better way of loading images? SDL2

Posted by Lactose! on 18 December 2014 - 08:25 AM

So basically, for loading images, pointers are pretty much great? I guess I can carry on using them then

Pointers are a powerful tool, and they are well suited for this (and other) uses.

However, like most other powerful tools, they can also be used in horrific ways. In software development, they are often the source of bugs that can be both hard to track down and application-fatal.


You should definitely consider spending time on learning how pointers work, if you don't understand them right now.

You might also want to look into the newer pointer "versions", which aim to make development easier and less bug-prone. These pointer types are called "smart pointers".

#5198488 SDL2.0 Character Jumping & Gravity

Posted by Lactose! on 16 December 2014 - 03:26 AM

Pasting the error message (along with the line it's complaining about) would be preferable to a screenshot of the error message.


Based on lordconstant's code, I would guess it's complaining about the player.y variable.

Your sprite code seems to indicate you don't have a y variable for your sprites, but you do have a rect.y variable. Try that.


That said, I would second the suggestion that you look at some tutorials, like the lazyfoo one that was already linked. It will guide you through a lot of these initials issues you're likely to face/question.

#5198203 Do the programming department add collision to areas if the character cannot...

Posted by Lactose! on 14 December 2014 - 04:29 PM

Short answer:

It depends.


Longer answer:

For games with 3D movement and collision detection, collision data is usually not hard coded (live in the code as pre-determined values) at all. Instead, collision data lives in the data files loaded while playing the game. This can be e.g. a mesh that's used to represent collision surfaces (potentially with different materials or other ways of distinguishing behaviour).

The collision data is usually not a 1 to 1 representation of the visual data. The collision data is usually a lot simpler -- think boxes and planes instead of intricately detailed corners.


This is often the case for pure 2D games as well, but 2D games tend to be less performance heavy, and can often-times afford more detailed collision data (e.g. pixel perfect collision).


The extent of collision data will vary from game to game. Some games probably have collision in areas you're never able to reach, because it was put in and there was no reason (performance not critical or time not allowing) to remove it again. This is especially true if the components are made by e.g. the art department, and later placed by level designers. The art assets might have included more collision data than was strictly speaking required, due to not knowing in advance how the assets were going to be used in every scenario.


Other games might have a much more aggressive stance, pruning away all unneeded collision data in order to reduce file/memory usage, performance, or other causes.


Something you might see, from the code side, is hard-coded limits to how high and/or low you can go. This can e.g. be used if you happen to fall through the floor, hitting the hard-coded limit might signal "kill the player and respawn him somewhere safe", basically as a "just in case" measure.

#5197885 Strange SDL Display Problem

Posted by Lactose! on 12 December 2014 - 05:02 PM

  #ifndef MANAGER_H
    #define MANAGER_H
    class Manager
        Manager() {}

I don't see an #endif. Verify that it's there.

#5197673 how to pass global struct into my class function?

Posted by Lactose! on 11 December 2014 - 04:13 PM

structs aren't variables they are like classes without functions.

Emphasis mine.


Structs can have functions, just the same way classes can.

The difference between classes and structs is that classes default to private for members, while structs default to public. This also applies to inherited objects.

#5197040 Can anyone give a small developer any tips on how to make a small game

Posted by Lactose! on 08 December 2014 - 03:48 PM

I suggest you start with the FAQ and take it from there. It might be able to help answer some of your questions.

#5195717 Crash with <unable to read memory> error

Posted by Lactose! on 01 December 2014 - 09:29 AM

Because your code just results in a pointer to something which is invalid (you haven't created an instance yet). It hasn't been set to anything, and you try to access it.

You should be able to do this:

GameMap *Map = new GameMap;
Map->CreateMap(5, 5);


Remember to delete the Map instance when it's no longer needed, to avoid leaking memory.

#5195518 Unity or C++?

Posted by Lactose! on 30 November 2014 - 12:04 PM

Choose one of the above options.  I, personally, would recommend the first one but the second is very popular.

To be fair, option 2 includes looking at kitties on the internet. That's hard to turn down!

#5194805 SDL Pausing game help?

Posted by Lactose! on 26 November 2014 - 12:21 PM

is paused already in the sdl library?



His suggestion is to create a bool variable called "paused".

Toggle the variable when Escape is pressed.

Check the state of the variable in your update loop to determine what updates.