Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lactose!

Member Since 16 Oct 2013
Offline Last Active Yesterday, 06:40 PM

#5174856 Apparently, no so simple Math.....

Posted by Lactose! on 19 August 2014 - 04:18 PM

I see your min/max ops and raise you blocking logic!

 

int damageTaken = attack - defense;
if (damageTaken > 0)
    health -= damageTaken;
else
    Console.WriteLine("Attack blocked!");



#5174845 Apparently, no so simple Math.....

Posted by Lactose! on 19 August 2014 - 03:42 PM

Something like this should do the trick:

int damageTaken = attack - defense;
if (damageTaken > 0)
    health -= damageTaken;



#5174832 storing level data

Posted by Lactose! on 19 August 2014 - 03:03 PM

Tiled level layouts do not mean movement has to be from tile to tile. You can still have positions stored as float, and adjust position gradually within a tile, without having to snap to up/left/right/down tiles on movement.

 

In a topdown (non-isometric) level, with each tile being e.g. 128x156 pixels in size, you can move around as if the level weren't tiled. You can, however, use the tile system to figure out e.g. collisions.

Using some simple math you can figure out which tile you're standing on, and only check for collisions or whatever in tiles that are adjacent (or otherwise interesting).

In this case, you could figure out the tile by using pos.x / 128 and pos.y / 156.

 

This also works for isometric layouts, but the math is (slightly) more involved.




#5174524 Help me, i can't understand well :)

Posted by Lactose! on 18 August 2014 - 01:57 PM

You seem to be having problems with all the code in the tutorial you are following. Have you considered slowing down and going through it more thoroughly? Even if that means taking longer, or even going back a few steps, I'm fairly certain you would benefit from it in the long run.

Alternatively, supplement your reading with an additional tutorial or something similar?

 

That said, I agree with cavendert -- it's impossible for us to guess at what you don't understand if you don't tell us. If there is something you don't understand, state explicitly what it is. If you get errors, state what you expect to happen, and what happens instead. If there are errors listed, include them so we can help out.




#5174165 How do I achieve these type of Graphics?

Posted by Lactose! on 16 August 2014 - 05:01 PM

Draw the art in a program of your choosing.

Put the art into a suitable game engine.




#5173714 Animation Plays, Character Stays In Place

Posted by Lactose! on 14 August 2014 - 03:59 PM

That sounds like you set position to 0 somewhere in the code you haven't posted.

 

You're also doing some very strange things here, indicating you might want to slow down and be a bit more thorough. For example, you have a lot of gPlayer.XPos = gPlayer.XPos; which changes nothing. This to me suggests that you might want to clean up your code a bit -- it might even help you fix some bugs you have in the process.




#5173707 Animation Plays, Character Stays In Place

Posted by Lactose! on 14 August 2014 - 03:46 PM

Except for initialization, you never set the velocities to a non-zero value. This is also a place where it doesn't make sense to initialize it.

Upon key release, you do set the velocoties to zero.

 

In addition, a likely issue is also that your position variables are int, and your DeltaTime variable might be a float with value equal to something like 0.016.

If so, the velocity * DeltaTime code will be cast into an int that's zero (unless your velocities are very large), meaning no position change.

 

You'll need to have your position values as type float, to be able to move in most velocities.

If you need the position in ints due to rendering positions and such, you can cast it from float to int when you need it,




#5173410 Crashes When Character Walks

Posted by Lactose! on 13 August 2014 - 12:50 PM

gPlayer.CurrentFrame = 0x00000008 means gPlayer.CurrentFrame is equal to hexadecimal (hex) 8. Hex 8 is equal to 8 in our normal counting system as well. You might want to brush up on hexadecimal numbers if this is new to you. You might also have the option to turn off hex display of values in your IDE, which can make some values easier to read (although some numbers are easier to read in hex in certain contexts).

 

This means, as I guessed, that you're indexing into the array which has size 8 (and maximum index 7) with the invalid index 8.

The cause is also what I guessed, the appropriate "facing/idle" if checks are always executed, even when the player is moving. This causes the gPlayer.CurrentFrame value to increment (although in a strange matter, which I also touched on in the previous post), up to 8.

After the facing/idle checks, you do the movement anim checks. This part will simply explode if gPlayer.CurrentFrame is 8, and as we see above, it clearly can be.

 

A simple way to verify (verifying is not fixing) this would be to put the gPlayer.CurrentFrame = SDL_GetTicks() / 150 % 8 (or 9) stuff directly before the SDL_RenderCopy calls, forcing the gPlayer.CurrentFrame value to be valid before you use it.

 

It should no longer crash, but your code should still be fixed properly. I'd recommend trying to find a tutorial or similar for this. The way you're doing animations and drawing now doesn't really work well for a game, in my opinion.




#5173308 Crashes When Character Walks

Posted by Lactose! on 13 August 2014 - 04:50 AM

Print the value of gPlayer.CurrentFrame (right before each RenderCopy call) so you can see in a log/output window what the last value is.

You could also hover the variable when the application crashes, to see its value. This might be IDE specific, but the ones I know about support this.

 

You're only posting snippets, which makes it impossible to guess the overall flow of the thing, but if the last code you posted is directly copied, I think i see the reason for it, plus some other issues:

gPlayer.CurrentFrame++;
gPlayer.CurrentFrame = SDL_GetTicks() / 150 % 8; //Also in the facing code, with the % 9

You first increment the frame by one, but this is a complete waste. The very next line you set the variable directly, overwriting the increment operation.

gPlayer.CurrentFrame = SDL_GetTicks() / 150 % 8;
if (gPlayer.CurrentFrame >= 8)
// ...

If I'm reading this correctly (I can't recall the operator precedence rules here), this if will never trigger.

I'm reading it as equivalent to (SDL_GetTicks() / 150) % 8, which means that the result will always be between (and including) 0 and 7. Your if check checks for 8 and higher, which is never true.

if (gPlayer.Facing == gPlayer.RIGHT)
//stuff
if (gPlayer.CurrentState == gPlayer.WALK_LEFT)
//Stuff that crashes

I'm assuming you also have a facing == gPlayer.LEFT somewhere. If you actually execute the facing (idle?) drawing always, and the overwrite with the walking animation, this will result in out of bounds reading.

The % 9 in the facing/idle code will make gPlayer.CurrentFrame be between (and including) 0 and 8. If it's set to 8, and then the walking animation code is run directly after, you will be indexing into your 8 large array (with max valid index = 7) with the invalid index 

--> Crash, access violation.




#5173215 Do i need to know physics before using Unity3D?

Posted by Lactose! on 12 August 2014 - 05:44 PM

I would suggest taking a look at some Unity tutorials. It's been a while since I checked personally, but I seem to remember Unity's official tutorials being fairly decent at introducing basic concepts like this.




#5172967 Getting direct acces to vector<unique_ptr<My_Class>> but ther...

Posted by Lactose! on 11 August 2014 - 06:16 PM


I feel that map will be slow.

If you found a solution that works for you, great!

 

However, this kind of reasoning is something you should avoid. Whether you feel, think or guess something is slow is highly irrelevant. The compiler might do all kinds of magic to make any assumptions you have invalid, or your assumptions might be wrong from the get-go.

 

If you think something is too slow, profile it. That'll tell you if it actually is too slow, or if your bottleneck is elsewhere. If the bottleneck is somewhere else, all your optimizations, time spent and hair loss due to tearing at your own skull scalp might be for nothing.

If the code is too slow, then profiling before and after changes will tell you if the change actually made it better or worse. In a lot of cases, "clever optimizations" from a programmer can cause the application to run slower.

Of course, this isn't to say that e.g. algorithm knowledge is bad or wasteful -- high level changes related to algorithms are probably one of the best ways of optimizing something, and knowing whether an algorithm is O(n) or O(n^n) can matter a lot.

 

Also, another quote which might be of relevance:

Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.

- Donald Knuth

 

And, just to re-iterate: the only way to know which parts are critically in need of optimization is by using some sort of profiling tool.




#5172619 Intersting Game Idea

Posted by Lactose! on 10 August 2014 - 10:47 AM

If you want to make games yourself, put that game idea away for a while and start smaller. A lot smaller. Pong complexity is what you'll be focusing on for quite a while.

See the FAQ for more details.

 

If you want to get a team to join you, you'll need to bring more to the table than just an idea. Be it art skills, programming, level design abilities, etc.

While it might seem a bit harsh, you would probably benefit from reading this as well.

 

Making games is difficult, and will require a lot of time. If you stick to it, you can achieve quite amazing things, either on your own or as a part of a team, but the likelyhood of you basically starting from nothing and pursuing a dream project with no prior experience AND finishing it are practically zero.




#5172576 Getting started

Posted by Lactose! on 10 August 2014 - 04:17 AM

The FAQ might also nudge you along the path to your goal.




#5172575 Where do I start?

Posted by Lactose! on 10 August 2014 - 04:14 AM

I would suggest starting with the FAQ.

It should help you a bit further on the way.




#5171157 Where should I start? (2D Game Programming)

Posted by Lactose! on 02 August 2014 - 12:38 PM

 


Java will most likely never be secure enough to make video games due to the fact that .JAR files are very VERY VERY VERY easy to decompile and hack

 

Not necessarily true. You might want to google up the term "obfuscation".

 

Code obfuscation, in this case, would be an example of security through obscurity.

I would advise against relying on security through obscurity.

 

Other than that, Eck posted valuable information.






PARTNERS