Author

Topic: The Internet has been very stale lately. (Read 1841 times)

legendary
Activity: 1918
Merit: 1570
Bitcoin: An Idea Worth Spending
August 29, 2013, 02:42:49 AM
#27
Wait till the song B.DOUBLE O.T.Y comes out in both a rap and country version at the same time.
legendary
Activity: 4494
Merit: 3178
Vile Vixen and Miss Bitcointalk 2021-2023
August 28, 2013, 09:14:50 PM
#26
Collision is simple, assuming that your characters are rectangles here is a sample of my old code
Collision detection is simple (for simple shapes, anyway); it's collision response that's the hard part. Wink

For platform games, this depends on the type of objects that collided.

The simplest case is, of course, a bullet. A colliding bullet simply disappears and causes damage to whatever it collided with.

Enemy vs. player collisions are more complicated, since unless the player is a one hit-point wonder, both objects will still be around and still be intersecting unless you do something about it. Depending on the game, you may or may not want enemies to be solid (see below), and in either case, if the collision itself causes damage (as opposed to the more realistic case of requiring one actor to actually perform an attack in order to damage the other), then you need knockback and/or mercy invincibility to avoid repeating the damage on every frame.

Finally comes the platforms themselves (as well as anything else that functions as a solid platform). Here, it's important to know which direction the collision came from (whether you walked into a wall, bumped your head on the ceiling, or are standing on the floor). For square actors, this can be accomplished by checking which axis (X or Y) has the greatest absolute difference between the distance and the sum of the sizes of the actors (ie, how deeply they're interpenetrating) (for rectangular actors, you also need to take into account the actors' aspect ratio). The sign of the difference tells you the direction. Then it's just a simple matter for zeroing the moving actor's velocity in that axis, and clipping its position to the plane of the platform. For the special case of collisions from above (standing on the floor), you also want to set a flag saying that the actor is standing on a floor, so you can set appropriate animation, etc.

Note that all of the above only applies if no object can move fast enough to reach the other side of another within a single frame (mostly a problem for bullets, but can affect falling players if they have no terminal velocity). In that case, it gets even more complicated.
legendary
Activity: 1512
Merit: 1049
Death to enemies!
August 28, 2013, 07:41:32 PM
#25
Old school!


Now that's a real smoothie! New avatar anyone?
 
legendary
Activity: 2674
Merit: 2965
Terminated.
August 28, 2013, 05:42:14 PM
#24
If you think the Internet is stale, you haven't been to leekspin.com recently  Grin
Ty! I forgot about this site i find it funny, time to bookmark and hypnotise myself!  Cheesy
http://leekspin.com/
For link purposes.
legendary
Activity: 1904
Merit: 1005
PGP ID: 78B7B84D
August 28, 2013, 05:28:53 PM
#23
If you think the Internet is stale, you haven't been to leekspin.com recently  Grin
legendary
Activity: 2674
Merit: 2965
Terminated.
August 28, 2013, 03:59:09 PM
#22
Stop with this useless code.
hero member
Activity: 812
Merit: 1000
August 28, 2013, 03:45:18 PM
#21
Quote from: Remember remember the 5th of November
Those are just semantics, I write clean code, if you see how the MyBB team code it's just gorgeous.
[/quote

No, I haven't seen. Are you claiming your code is gorgeous?

Quote
Plus

if(eval)
{
    // code
}

is much better than

if(eval) {
    // code
}

It's much better? One of the reasons for putting the opening curly on the same line is to show a little more code per page, decreasing scrolling for comprehension. Note that I'm not using the word 'better'. I'm stating a reason for a preference.

Whitespace is good, and necessary, but not in this case.
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
August 28, 2013, 03:05:12 PM
#20
Code:
bool check_collision_rect(Rect *A, Rect *B)
{
    // The sides of the rectangles
    int leftA, leftB;
    int rightA, rightB;
    int topA, topB;
    int bottomA, bottomB;

    // Calculate the sides of rect A
    leftA   = A->x;
    rightA  = A->x + A->w;
    topA    = A->y;
    bottomA = A->y + A->h;

    // Calculate the sides of rect B
    leftB   = B->x;
    rightB  = B->x + B->w;
    topB    = B->y;
    bottomB = B->y + B->h;

    // If any of the sides from A are outside of B
    if(bottomA <= topB) {
        return false;
    }

    if(topA >= bottomB) {
        return false;
    }

    if(rightA <= leftB) {
        return false;
    }

    if(leftA >= rightB) {
        return false;
    }

    // If none of the sides from A are outside B
    return true;
}

and

Code:
double distance(int x1, int y1, int x2, int y2)
{
    // Return the distance between the two points
    return sqrt(pow(x2 - x1, 2) + pow( y2 - y1, 2));
}

bool collision_circle(Circle A, Circle B)
{
    // If the distance between the centers of the circles is
    // less than the sum of their radii
    if(distance(A.x, A.y, B.x, B.y) < (A.r + B.r)) {
        //The circles have collided
        return true;
    }
    
    // If not
    return false;
}

Fixed your code. Issues included no spaces between comments and double slashes, failure to put opening curly bracket for if/else/for/while constructs on same line as opening statement, failure to align assignment operator for variables belonging to a group, and excess spacing around parenthesis.
Those are just semantics, I write clean code, if you see how the MyBB team code it's just gorgeous.

Plus

if(eval)
{
    // code
}

is much better than

if(eval) {
    // code
}
legendary
Activity: 3066
Merit: 1147
The revolution will be monetized!
legendary
Activity: 2674
Merit: 2965
Terminated.
August 28, 2013, 12:57:27 PM
#18
9gag and 4chan.
hero member
Activity: 812
Merit: 1000
legendary
Activity: 3066
Merit: 1147
The revolution will be monetized!
August 28, 2013, 11:33:10 AM
#16
Old school!

legendary
Activity: 1540
Merit: 1000
August 28, 2013, 11:30:04 AM
#15
He did say it was old code you know Tongue
hero member
Activity: 812
Merit: 1000
August 28, 2013, 11:28:10 AM
#14
Code:
bool check_collision_rect(Rect *A, Rect *B)
{
    // The sides of the rectangles
    int leftA, leftB;
    int rightA, rightB;
    int topA, topB;
    int bottomA, bottomB;

    // Calculate the sides of rect A
    leftA   = A->x;
    rightA  = A->x + A->w;
    topA    = A->y;
    bottomA = A->y + A->h;

    // Calculate the sides of rect B
    leftB   = B->x;
    rightB  = B->x + B->w;
    topB    = B->y;
    bottomB = B->y + B->h;

    // If any of the sides from A are outside of B
    if(bottomA <= topB) {
        return false;
    }

    if(topA >= bottomB) {
        return false;
    }

    if(rightA <= leftB) {
        return false;
    }

    if(leftA >= rightB) {
        return false;
    }

    // If none of the sides from A are outside B
    return true;
}

and

Code:
double distance(int x1, int y1, int x2, int y2)
{
    // Return the distance between the two points
    return sqrt(pow(x2 - x1, 2) + pow( y2 - y1, 2));
}

bool collision_circle(Circle A, Circle B)
{
    // If the distance between the centers of the circles is
    // less than the sum of their radii
    if(distance(A.x, A.y, B.x, B.y) < (A.r + B.r)) {
        //The circles have collided
        return true;
    }
    
    // If not
    return false;
}

Fixed your code. Issues included no spaces between comments and double slashes, failure to put opening curly bracket for if/else/for/while constructs on same line as opening statement, failure to align assignment operator for variables belonging to a group, and excess spacing around parenthesis.
legendary
Activity: 1540
Merit: 1000
August 28, 2013, 10:49:29 AM
#13
I'm using SFML myself so the code is already there, I just need to implement it all into my game properly which is harder than it looks!
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
August 28, 2013, 10:31:20 AM
#12
Collision is simple, assuming that your characters are rectangles here is a sample of my old code

Code:
bool check_collision_rect(Rect *A, Rect *B)
{
    //The sides of the rectangles
    int leftA, leftB;
    int rightA, rightB;
    int topA, topB;
    int bottomA, bottomB;


    //Calculate the sides of rect A
    leftA = A->x;
    rightA = A->x + A->w;
    topA = A->y;
    bottomA = A->y + A->h;

    //Calculate the sides of rect B
    leftB = B->x;
    rightB = B->x + B->w;
    topB = B->y;
    bottomB = B->y + B->h;

    //If any of the sides from A are outside of B
    if(bottomA <= topB)
    {
        return false;
    }

    if(topA >= bottomB)
    {
        return false;
    }

    if(rightA <= leftB)
    {
        return false;
    }

    if(leftA >= rightB)
    {
        return false;
    }

    //If none of the sides from A are outside B
    return true;
}

and

Code:
double distance(int x1, int y1, int x2, int y2)
{
    //Return the distance between the two points
    return sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) );
}

bool collision_circle(Circle A, Circle B)
{
    //If the distance between the centers of the circles is less than the sum of their radii
    if(distance(A.x, A.y, B.x, B.y) < (A.r + B.r))
    {
        //The circles have collided
        return true;
    }
    
    //If not
    return false;
}

It's true actually Sad the internet isn't being as original as it used to be, maybe everyones working on news stuff or something, i need to hurry up and finish learning the coding I need so I can make some fun games to play and not be bored anymore lololool Cheesy
Already ahead of you Cheesy

Looks like space invaders + mario
Yeah, I was inspired by mario. At first I was going to make so you could walk up,down,left,right but then decided to make it like Super Mario from 84 for SNES.
legendary
Activity: 944
Merit: 1026
August 28, 2013, 10:13:57 AM
#11
The Internet is so 90's...   
legendary
Activity: 1540
Merit: 1000
August 28, 2013, 10:05:13 AM
#10
I know we just hijacked this thread but what the hell Tongue maybe we should make a thread just to show off our WIP games Cheesy, so far I've managed to make my rabbit thingy move across the screen, need to fix FPS and add collision in for it to properly work and of course put in some gravity.



The idea is it's a basic platformer and you play as a rabbit that has to jump up clouds to the moon, the stars are either powerups or bad guys depending on their emotions Tongue
b!z
legendary
Activity: 1582
Merit: 1010
August 28, 2013, 09:24:42 AM
#9
It's true actually Sad the internet isn't being as original as it used to be, maybe everyones working on news stuff or something, i need to hurry up and finish learning the coding I need so I can make some fun games to play and not be bored anymore lololool Cheesy
Already ahead of you Cheesy



Looks like space invaders + mario
legendary
Activity: 1540
Merit: 1000
August 28, 2013, 08:31:19 AM
#8
Hah! Bet you're not fixing the FPS issues yet Tongue
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
August 28, 2013, 07:34:21 AM
#7
It's true actually Sad the internet isn't being as original as it used to be, maybe everyones working on news stuff or something, i need to hurry up and finish learning the coding I need so I can make some fun games to play and not be bored anymore lololool Cheesy
Already ahead of you Cheesy

b!z
legendary
Activity: 1582
Merit: 1010
August 28, 2013, 06:01:09 AM
#6

the leethecking guides on ED are all from 2003 or something, they're hilarious to read
legendary
Activity: 1540
Merit: 1000
August 28, 2013, 01:57:34 AM
#5
It's true actually Sad the internet isn't being as original as it used to be, maybe everyones working on news stuff or something, i need to hurry up and finish learning the coding I need so I can make some fun games to play and not be bored anymore lololool Cheesy
sr. member
Activity: 252
Merit: 250
Still the Best 1973
August 28, 2013, 01:10:50 AM
#4
member
Activity: 112
Merit: 10
August 27, 2013, 11:41:41 PM
#3
go on 4chan
legendary
Activity: 1512
Merit: 1049
Death to enemies!
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
August 27, 2013, 09:26:39 PM
#1
I mean, since Antoine Dodson's Bed Intruder song, UCLA Alexandra Wallace and Harlem Shake, there has been for a long while...nothing trollish,racist,meme-like...
Jump to: