yothsoggoth's Profile User Rating: -----

Reputation: 23 Tradesman
Group:
Contributors
Active Posts:
61 (0.04 per day)
Joined:
19-June 12
Profile Views:
2,069
Last Active:
User is offline Apr 23 2016 07:50 AM
Currently:
Offline

Previous Fields

Country:
GB
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
50

Latest Visitors

Icon   yothsoggoth has not set their status

Posts I've Made

  1. In Topic: Nested For Loop for 2D Collision Detection

    Posted 23 Apr 2016

    View PostPanksie, on 17 April 2016 - 02:20 PM, said:

    //=============================================================================
    // Handle collisions
    //=============================================================================
    void Spacewar::collisions()
    {
    	VECTOR2 collisionVector;
    	for (int i = 0; i < 2; i++)
    	{
    		if (ship[i].collidesWith(planet, collisionVector))
    		{
    			// bounce off planet
    			ship[i].bounce(collisionVector, planet);
    			ship[i].damage(PLANET);
    
                            // -------------------------------------------
                            // NOTE:
                            // This code is only reached if ship[i] collided with the planet
                            // -------------------------------------------
    
    			// if collision between ships
    			for (int j = i + 1; j < 2; j++)
    			{
    				if (ship[i].collidesWith(ship[j], collisionVector))
    				{
    					// Bounce off ship
    					ship[i].bounce(collisionVector, ship[j]);
    					ship[i].damage(SHIP);
    					// change the direction of the collisionVector for ship2
    					ship[j].bounce(collisionVector*-1, ship[i]);
    					ship[j].damage(SHIP);
    				}
    				else
    				{
    					ship[j].bounce(collisionVector, ship[i]);
    					ship[j].damage(SHIP);
    
    					ship[i].bounce(collisionVector*-1, ship[j]);
    					ship[i].damage(SHIP);
    				}
    			}
    		}
    	}
    }
    


    See the note that I added to your code sample above.

    You're only checking collision between ships, if the ship has collided with the planet. If no ships collide with a planet, you won't check collision between any ships.

    Consider changing the flow to the following, instead:
    for (int i = 0; i < 2; i++)
    {
    	if (ship[i].collidesWith(planet, collisionVector))
    	{
    		// ... handle collision with planet
    	}
    	else
    	{
    		// ... check for collision with other ships
    	}
    }
    


    Also, another thing that I'd to improve your code, is to remove the "magic numbers".
  2. In Topic: char string array problem

    Posted 7 Oct 2015

    I'd recommend you do some reading on C-strings (which is a name commonly used for char array strings).
    http://www.cprogramm.../c/lesson9.html seems reasonable (which is also the first result on google, by the way.)

    Firstly, using round brackets is not the correct notation for an array in C. You should be using square brackets, for example char fame[14];

    Secondly, you cannot set the contents of a C-string using the assignment operator (=), because it's not really a string type, it's actually an array of chars. You probably want strcpy. strcat or sprintf depending on your needs (see the link I gave for some examples of using those).

    If you want a non-modifiable (literal) string you can store is as a pointer to a char array, as follows char const* fame = "Bucky Roberts";

    [Edit] In fact, you should look at the count-limited versions of those functions strncpy. strncat or snprintf which allow you to ensure you don't write outside the bounds of your array.
  3. In Topic: code Is right but get unresolved ES error....

    Posted 6 Sep 2015

    "unresolved external symbol" means that you're not linking against the required library (or if it's an unresolved symbol in your own code you haven't defined the symbol, but that isn't the case here).
    It looks like you've correctly set up the include paths for Allegro, but haven't set the library path, or aren't linking against it's library.

    What platform/IDE/tools are you using? Also, if you could provide a link to the tutorial you said you followed we may be able to advise based on that.

    If you're using something like Visual Studio, it should be a case of ensuring you've correctly set the Library Directories and Additional Dependencies in the project settings.
  4. In Topic: DirectX11 Shader issue (DX11, HLSL, C++)

    Posted 5 Apr 2015

    Even though you've already answered your question, this may be useful to point out...

    If I recall correctly, HLSL structures are actually aligned to 16-byte boundaries, and by default MSVC compiler will align data to 4-byte boundaries.

    You can change this behaviour by adding the following to your structs in C++:
    __declspec(align(16))
    


    For example:
    __declspec(align(16)) struct FrameData
    {
    	Vector3	SomeVector;
    	float	Time;
    	float	AnotherVar;
    	// ...
    };
    


    Further reading:
    https://msdn.microso...y/83ythb65.aspx
    https://msdn.microso...v=vs.85%29.aspx
  5. In Topic: Should i migrate to android studio?

    Posted 1 Mar 2015

    If you're hesitant, and you're comfortable with Eclipse, you may as well stay with Eclipse.


    If I were trying to decide I'd just download both and try them and use whichever I prefer.

My Information

Member Title:
D.I.C Head
Age:
23 years old
Birthday:
October 14, 1992
Gender:
Location:
England
Full Name:
Joe
Years Programming:
9
Programming Languages:
C++, C#, Python, PHP, Javascript, Java, VB.Net

Contact Information

E-mail:
Private
Website URL:
Website URL  http://www.robotgoblin.co.uk/
Twitter:
joeydotnet

Comments

yothsoggoth has no profile comments yet. Why not say hello?