Water Physics (attempt) and faster collision free

Talk about making games.

Water Physics (attempt) and faster collision free

Postby jimmynewguy » Fri Sep 16, 2011 1:49 am

Hello, was messing with water physics just to see what would happen and a sorta nice looking thing came out of it as well as a useful thing. CollisionFree usually takes up a lot of memory and made things lag if used often. I replaced it using this code.
Code: Select all
int check(int posX, int posY)
{
     int temp;
     Actor * coll;
     coll = getactor(posX, posY);
    temp = (strcmp(coll->name, "") == 0);
    return temp;
}

Does the same thing, but instead of "Event Actor" just use x,y for posX and posY. Changed collsionfree to this and it ran at least twice as fast.

Anyway, this is sorta cool looking water here. It flows from an unknown source and fills the holes. Inevitably, after the first is filled and it moves on to the second, it starts to lag. :( Still neat, though! Check it out please! I'm still trying to optimize it fyi.
Attachments
Water.zip
(782.32 KiB) Downloaded 167 times
untitled.PNG
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby skydereign » Fri Sep 16, 2011 2:57 am

Just as an optimization to your check function, you can do this instead.
Code: Select all
int
check(int posX, int posY)
{
    return (getactor(posX, posY)->cloneindex! =- 1);
}

This way you don't have to do a strcmp each time, and don't declare any variables. In case you didn't know, getactor returns an invalid actor (with a name of "" and a cloneindex of -1). Also I notice you haven't been uploading Linux versions as much anymore...
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby jimmynewguy » Fri Sep 16, 2011 4:55 pm

skydereign wrote:Just as an optimization to your check function, you can do this instead.

*Slaps forehead*
Thanks sky, I'm not so sure how well this works anymore though. It doesn't like to flow both directions anymore... Ah oh well!
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby jimmynewguy » Mon Sep 19, 2011 12:35 am

Optimized it a little more, here's bigger sprites acting as lava. 100 actors, little bit of lag while being created is all. With linux this time! (Sorry sky for the first time)
Attachments
untitled.PNG
Careful, hot!
Linux_lava.zip
Linux
(741.46 KiB) Downloaded 81 times
Lava.zip
Windows
(785.33 KiB) Downloaded 99 times
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby Jagmaster » Mon Sep 19, 2011 1:07 am

Pretty nice effect! change the color to green and you have slime!
I think my cpu would go kaput if I implemented it in a game. But maybe mix with tiled animation and you would have a less realistic but cool effect!
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby jimmynewguy » Mon Sep 19, 2011 1:24 am

Thanks! I like it a little, but it's really not practical. It's just fun to mess with and see what comes of it, tried messing with objects to float in the water, but it ended up bobbing a bunch.

All the lava one does is use a for loop and checks the distance between one particle and all the others (excluding itself) and moves away if they're to close. (and sticks together a tiny bit)

EDIT: I should wait before I post, I tweaked it a little and made it better and faster. Oh well, I'm not sure if I should share the source code, it all really messy and sloppy.. Plus it's still not too practical! :)

WARING! What you are about to see is bad. Check only checks for the ground in this one so don't use the original check function.
Code: Select all
int i;

if(!off)
{
for(i=0;i<nwater;i++)
{
if(i != cloneindex)
{
Actor * col = getclone2("water", i);
if(abs(x-col->x)+abs(y-col->y) < 12)
{
angle = direction(x,y,col->x,col->y)+180;
directional_velocity = 2;
break;
}
}
}
}

if(check(x,y))
{
yvelocity = 0;
angle += 180;
directional_velocity *= 0.8;
off = 1;
}

yvelocity = max(yvelocity + 1, 6);
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby SuperSonic » Tue Sep 20, 2011 2:26 pm

Wow, this is amazing and I don't get any lag! +1 for that dood :wink:
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby Game A Gogo » Thu Sep 22, 2011 12:49 pm

I'm curious, how did you make your water physic in your first post? I've tried doing one but I kept failing horribly!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby jimmynewguy » Thu Sep 22, 2011 4:04 pm

Lots of if's! :D you can see it in here, made the water longer since when they moved towards each other the went through sometimes...
Attachments
Water.zip
(4.86 KiB) Downloaded 102 times
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: Water Physics (attempt) and faster collision free

Postby JamesLeonardo32 » Sun Sep 25, 2011 10:26 am

Nice physics!

I made some experiments with it. (Updated with better water effect)
Attachments
themindd.png
theWaterCaves(U).zip
Updated!
(111.37 KiB) Downloaded 104 times
theWaterCaves.zip
Old version
(110.75 KiB) Downloaded 103 times
JamesLeonardo32
 
Posts: 320
Joined: Wed Oct 13, 2010 4:57 pm
Score: 36 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest