Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Oct 2013
Offline Last Active Today, 05:00 PM

#5311574 Find angle to get from point A to B with x amount of bounces

Posted by on 20 September 2016 - 03:18 AM

You could shoot in 4 directions, not just 2.


Before morning caffeine, I believe you can do something like this...


In the selected direction, calculate the "effective" end point, as if this were just a huge box, with no bounces.

Basically, add get the distance to the border in your selected direction, multiply it by the amount of bounces, and add that to your endpoint.

Then just get the angle between the start point and that "effective" end point.


EDIT: You might have to add a different distance on odd/even bounces -- (absolute) distance to border in selected direction for odd bounces, (absolute) distance to border in opposite direction for even bounces.

So 5 bounces gives you an effective end point that is offset by (3*absolute_distance_to_border_in_selected_direction + 2*absolute_distance_to_border_in_opposite_direction).

EDIT 2: The previous edit wasn't quite correct -- which you can see in Nanoha's image below, but I think you're able to get a rough understanding of what you need to change in order for it to work :)

#5311517 Unity : OnPointerUp is firing at same time as isPointerDown on UI Button

Posted by on 19 September 2016 - 05:06 PM

Looks right to me, but a thought I had was... is this script attached to multiple things?

#5311450 Two classes relying on each other

Posted by on 19 September 2016 - 11:04 AM

Split things into .h and .cpp files.

Forward-declare classes in the .h where you can, and #include where you have to.


There is no reason for bullet.h having to know the implementation details of aggressive just to have a pointer to the owner.



In bullet.h, just forward-declare aggressive. Also declare the functions for bullet, but don't define them.

In bullet.cpp, include aggressive.h, and do the function implementations there.

#5311190 Game works when built in the IDE, but crashes when I run it from the .exe file.

Posted by on 17 September 2016 - 05:51 AM

that's why I will just keep it this way and not waste time to understand why it works or why it doesn't.

Just changing things randomly is not fixing a bug.


There is a chance the bug was fixed, in which case, you should still understand what caused the bug in order to prevent similar things later.

There is also a huge chance that the bug wasn't fixed, simply masked. If so, what you've done is hide the bug. Currently, you have a guaranteed way of reproducing and fixing it properly (i.e. not by guesswork). If all you've done is hide the bug, it will show up again later. This time, maybe it only crashes once every 10 runs, or sometimes when you press a specific key, or whatever.


You have the option to fix it properly right here and now, and gain some understanding and experience with handling error codes. I would suggest you take advantage of that. 

#5311121 Game works when built in the IDE, but crashes when I run it from the .exe file.

Posted by on 16 September 2016 - 02:08 PM

Yeah, it's because the if statement is always true, and the if-block always tries to access a texture, it doesn't care if there is a texture there or not, and I get a segfault.


I'm still on the opinion that this is a compiler/debugger problem( facepalm from Lactose :lol:  ), because it should notify me when I get segfaults, and not run the game like nothing happened.

To me, it doesn't sound like you know what a compiler does.


Your code is valid, for certain data. Your code is invalid for other data. When it's invalid, it will try to read and use garbage data (random data, can be anything, not guaranteed to be of use or valid for what you're using it for). This is essentially undefined behaviour, and is something you'll always want to avoid.

Sometimes, undefined behaviour will (seem to) work.

Sometimes, undefined behaviour will not work.


Why doesn't it always crash/segfault? Because randomly, the garbage data could be harmless.

Why doesn't the compile catch this compile time? Because the compiler doesn't know what kind of data will run through the code. The data can be files from disk, user input, retrieved from true random generators, etc.


A compiler's job isn't to magically look at all your code and find everything that could be wrong with it ever.

A compiler is (roughly speaking) something which translates the code you've written, into instructions and commands the computer can understand.

This means that you can tell the computer to do something, and make it understand you (compile success!), but what you're telling it to do doesn't work (crash/segfault).


EDIT: This is also why the crashes/segfaults don't occur until the application is running. Until that point, the problem hasn't been triggered yet.

There are loads of horror stories about code that's worked for years, until someone poked in a value that made it all crash -- just changing some data.

#5311088 Game works when built in the IDE, but crashes when I run it from the .exe file.

Posted by on 16 September 2016 - 11:09 AM

I guess there is a problem with the codeblocks compiler

I highly recommend you stop this line of thought immediately.

Compiler bugs are extremely rare, especially for common/simple cases people code every single day.

The problem is in your code. If you can't find it, it's still in your code -- not the compiler.


In my last post I gave you advice to step through/into as much of the code as possible, but you said everything compiles.

This is not what I'm talking about. What I'm talking about is setting breakpoints, which allow you to go through the application line by line and inspect the variables.


When it crashes, you should be able to see exactly which line is causing it. That line + the exact error message will provide you with a lot of information.

#5311082 Game works when built in the IDE, but crashes when I run it from the .exe file.

Posted by on 16 September 2016 - 10:11 AM

Can it be a compiler bug?

Highly doubtful.

Step through (and into) as much as you can, and provide the exact error messages you get, and the line of code that makes it occur.

#5311076 Game works when built in the IDE, but crashes when I run it from the .exe file.

Posted by on 16 September 2016 - 09:35 AM

And one more thing. You're not initializing your Vector/Array.

That's a C# thing, not a C++ thing, I believe? 

#5310736 Frame skips and Object jumps problem.

Posted by on 14 September 2016 - 05:57 AM

Does it also occur if you do not print the frame rate?

The skipping seems to coincide with the frame rate counter updating -- it could be directly linked, or just something else that happens every second.


I'd be tempted to just output the positions every frame to a log, and use information from there to set some conditional breakpoints.

#5309559 space game

Posted by on 05 September 2016 - 04:20 PM

Updates on how your projects are going are very well suited for game dev journals -- you can see what other people have written here:


And you can create your own here:



This forum is mainly for asking questions and getting help with technical questions, and not really for posting status updates on your projects.

#5309152 What to do if I cannot finish my game for a competition before deadline?

Posted by on 02 September 2016 - 06:46 AM

Options are:

1) Prioritize features/content. Keep removing the least important bits until you are able to reach the deadline. Accept that your finished project isn't what you planned originally.

2) Get help creating features/content so you reach the deadline (note: this is often hard/impossible if you are close to the deadline).

3) Accept that you are unable to finish the project in the time given.


In any case, use this as a learning experience when it comes to scope/deadlines and project management.

Things always take longer than you think, even when you schedule for it.


You mentioned you can update later on. Create the most basic version you're able to complete, then add stuff to it with any time you have remaining/available.

#5308456 Splitting an image into chunks of a specified size?

Posted by on 29 August 2016 - 06:29 AM

EDIT: I really need to try harder before asking. Sorry! It was really easy to do, but I just missed it somehow.

Care to share? In case others find this thread by searching :)

#5308329 vector of blocks spawn x and y issue

Posted by on 28 August 2016 - 04:08 AM

It looks like you're trying to set positions every frame (when you draw/update?).

Only set the positions once, e.g. at start-up (or tied to a button press or similar).


You said you wanted to randomly generate x and y, but you never do anything related to random. Here's a reference talking about a simple way to implement random. It also contains links to further reading (<random>).



I'd start there, and try generating random coordinates.

Something you will run into very quickly is the same location being chosen multiple times (causing overlapping blocks), which you will have to deal with somehow.

This can be either by verifying after generating the coordinates that they aren't in use, or maybe having a separate list of coordinates and randomly flag them first before placing, or some other solution.

If you get stuck, post here -- but I would recommend trying to solve it on your own first.

#5308054 Game architecture

Posted by on 26 August 2016 - 10:00 AM

Tile as class or Tile as struct

Classes and structs are essentially the same.


There is a slight difference that default accessors are private for classes and public for structs and things inheriting from them, but that's all.

You can use functions, variables and constructors the same way.

class MyClass
    int x;
    int y;

Is the same as

struct MyStruct
    int x;
    int y;

EDIT: Added a missing word.

#5307146 C++ class properties initialization order on constructor?

Posted by on 22 August 2016 - 02:35 AM

Initializer lists are done in the order of the declarations, not in the order you put them in the initializer list.

If you need to initialize things out of order, you'll need to put it in the constructor body instead of in the initializer list.