Sand Simulator / 2D Fun

The Partridge Family were neither partridges nor a family. Discuss.
FirepathAgain
Posts: 30
Joined: March 20th, 2021, 3:01 am

Sand Simulator / 2D Fun

Post by FirepathAgain » May 21st, 2021, 11:51 pm

Hey again everyone

I've been working on a sand simulator / game and want to show what it does so far.

https://www.youtube.com/watch?v=ycENPoeEUG4

I'll be back with more info later, I need to go to a meeting.


Basically a lot more is needed, but it's on the list lol. At the moment it has a basic sound, that used to work pretty well, but with the latest changes for efficiency is a bit more janky.

I've been working on making it more efficient by separating different zones of material. Basically there are dynamic particles that update every frame, a dynamic body, and a static body.

The bodies have an edge and a bulk.

The edges are used with dynamic particles for collisions.

The static bulk does nothing.

The dynamic bulk next to its edge may transition to being an edge each frame.

The dynamic edge may transition to a dynamic particle each frame.


Actually that's about it lol. Video shows various debug colours and pausing, stepping through, and zooming, scrolling, changing brush size.

FirepathAgain
Posts: 30
Joined: March 20th, 2021, 3:01 am

Re: Sand Simulator / 2D Fun

Post by FirepathAgain » May 23rd, 2021, 5:59 am

I updated to use vector gravity physics. I still need to advance it to make the vectors work in directions other than down, but this is a big step towards that. It wasn't hard either, a couple of hours, mostly debugging silly mistakes. I must have designed it pretty well lol.

Looks better now, the sand falls through the air more realistically and just looks better.

EDIT: Also now the magenta debug border section is a lot more sparkly and magical looking. Not sure why it changed, obviously to do with particles falling faster now and not hitting the edge all at once or something like that.

https://youtu.be/9hv6zD6CW58

FirepathAgain
Posts: 30
Joined: March 20th, 2021, 3:01 am

Re: Sand Simulator / 2D Fun

Post by FirepathAgain » May 30th, 2021, 2:37 am

A third installment in the ever-exciting world of sand simulation.

I tackled the last (I think) remaining spot not being calculated as vector simulation and made it vector / physics based. This is the piling / collision deflection section where it was doing a simple logic of if blocked down try left or right, and if blocked, try the other side, and if blocked, blocked.

It now deflects based on the particle's trajectory. It attempts to go to one side or the other. It has less of a chance of trying the second side if the first side fails too, which improves / resolves some edge case behaviour.

I also added two more different modes to the brush. It now pours (as normal), slings, and hoses. All three modes are pouring but allow giving each particle an initial velocity in different ways.


https://youtu.be/YXC_TQeV98g

FirepathAgain
Posts: 30
Joined: March 20th, 2021, 3:01 am

Re: Sand Simulator / 2D Fun

Post by FirepathAgain » August 8th, 2021, 4:54 am

I made another video on this thing.

Progress has been slow. Mostly I half-rewrote it to be able to multi-thread it. Weeks of work and the threading took about 1.5 hours after that.

Made the material colours able to vary.

Added another material to test interaction with existing material. At the moment this is just testing two solid materials that behave the same way. I did adjust density to check how that worked and no problems but reverted to the same as the sand as that's what it should be anyway, roughly.

I want to work on improving the viewport for smoother zooming and scrolling.

Lots of stuff I want to do but it's starting to get to the stage of expansion and adding fun stuff.

https://youtu.be/HGHvWSwwXdU

albinopapa
Posts: 4370
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Sand Simulator / 2D Fun

Post by albinopapa » August 12th, 2021, 9:22 pm

Interesting stuff.

Have you determined how many particles you're creating and rendering? Seems to be quite a few and still pretty smooth.

Are you planning on releasing the source code? or as a library? or just for personal use?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

FirepathAgain
Posts: 30
Joined: March 20th, 2021, 3:01 am

Re: Sand Simulator / 2D Fun

Post by FirepathAgain » October 16th, 2021, 9:51 pm

Sorry papa haven't been on in a while.

How many particles? Ahh I haven't counted really but heeeeeaps. It will handle tens of thousands of dynamic particles. Millions of static ones. I have further improvements I want to make to physics logic and utilise a shader for part of it too, we'll see, lots of ideas to work on.


I did these changes like a month ago and haven't touched it since. It's probably the coolest looking update, so I want to share. Copy / paste my video description below:

I added lighting to my simulation. I played around with the materials and lighting model for a long while to achieve the effect I was after.

Base ambient lighting consists of an ambient light level and a directional light from above to give the materials some texture.

The mouse light is a point light with a quadratic falloff as normal for the diffuse component but also a separate quadratic falloff for the specular component. This allows me to create materials that are very shiny and reflective and reflect light even when there seems to be very little light on it like how reflective tape behaves.

The three materials in the example are:

Gravel: Reflects more ambient light than diffuse and no specular light. You can see some texture to it as the light moves around.

Sand: Reflects more ambient than diffuse but a lot of both and some specular. The ambient and diffuse are high enough that they combine and over-expose it and lead to it looking very bright where the light is close. The specular component gives it a slight glittery glass look.

Gold: Relflects more ambient than diffuse but only at moderate levels, and reflects a lot of specular light. It also has a much longer falloff for the specular light to make it glitter in the dark a little.


The other main change is that I've added more than one world Block and made them work together seamlessly. This took little work, telling me that the design was already good for them.


I have a lot more ideas I'd like to work on like more focused simulation calculation to prevent overloading the CPU and GPU.

I'd like to move some of the physics calculations to the GPU using another shader now that I have some practice with HLSL shaders.

I'm working on liquids at the moment which work OK but need improvement.

The physics logic needs some changes to make it work more efficiently. It could possibly also stand to be simplified.

I'd like to add little random gems of solid colours that also emit a small radius of their own coloured light.

The sound needs work to change what is going on. Instead of each material having a sound I want to move the sound back to the material type (solid, liquid, gas) which have their own character but all particles of that type contribute to the single sound.


https://youtu.be/Pt9Pj07Wj2U

FirepathAgain
Posts: 30
Joined: March 20th, 2021, 3:01 am

Re: Sand Simulator / 2D Fun

Post by FirepathAgain » January 26th, 2022, 6:00 am

I've lost my job of 11 years, a bit painful to say the least but I was killing myself working there.

Anyway, I've added a ship into my sand simulator thing. I had some ideas on how it could become a game.

It has the light attached to it now which I want to use as part of the gameplay mechanics.

I added a looping hum sound for the ship which changes based on its velocity. It is also positional in relation to the screen.

Next I want to add blaster shots - sprites and sounds. I already have those sounds tested with a random frequency variation to give each shot a slightly different sound. It's going to be neat.

There is also a feature I added to allow the player to lock the ship direction to assist with battling enemies and not turning around when you want to back off, like one of those vertical space shooter things whatever.

Enjoy.


https://youtu.be/5DLwX-dfb04

albinopapa
Posts: 4370
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Sand Simulator / 2D Fun

Post by albinopapa » January 26th, 2022, 5:49 pm

Pretty cool, sorry to hear about the job loss. Looking forward to see where you go with this.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

FirepathAgain
Posts: 30
Joined: March 20th, 2021, 3:01 am

Re: Sand Simulator / 2D Fun

Post by FirepathAgain » January 28th, 2022, 10:17 pm

I didn't mean this to be so long but it is good to talk. I talk about the game stuff halfway down lol.


Thanks papa I appreciate your concern. It's been a bit of a hard thing losing the job. The work and product was not aligning with me but the people were basically good friends. I burned myself out pushing myself not thinking I was doing enough. We still play D&D and Red Dead Online through discord so it's good to stay in touch but yeh.

I've started looking at new jobs, still kind of down about it. I want to be positive. I find it hard to be confident about being able to do something until I've tried it so applying for jobs I haven't done (even if similar to stuff I have been doing) is still daunting. Less so now as I'm more in control of my life financially (at least somewhat) and know what I need out of work and am more looking to do what suits me versus taking whichever job is offered up.

I found a job in the city for lead game programmer with requirements that I can confidently say I match. But an hour travel each way and into the city which stresses me out is a negative. Even if it's two days a week working from home.

There is another that is back in the small city I want to move back to in a few years. Working with C++ and Unity for scientific purposes. It's a startup but the money is great, but moving for a job especially a startup that might fall over after a year or whatever, risky.

I've been trying to really think about my values and I've been trying to work and save money / pay off my home to make my life easier. Now I'm at a stage where I don't need great money, I feel I want to go back to the things I really value. The slower life of a smaller town, family, friends, enjoying where I am. I grew up poor, poorer than I realised at the time, and was happy. I am currently using my time off to get rid of excess stuff that I have that I haven't touched for a few years or that I don't need. I'm thinking hard about some bigger changes / sacrifices getting rid of my dream motorcycle that I've had for 15 years now, and selling up out of a hobby that is fun but a little costly and burdens me in terms of being able to move and change.

I need to start to realise that the things I want (living in that small city, more peace) are not going to happen before I retired if they don't happen soon. Well, I'm halfway from starting my working life to being retirement age so that's not exactly like I haven't had a good go at living in the bigger city and trying to make money.

Anyway I guess the point of all that was I was trying to say that maybe I don't want a programmer / software developer job any more and I want to be OK with that. I don't need my job to define me. I've spent 11 years doing it, so I can say I did that. It wasn't just for a few months or 6 months or a year or two. Doing something else would hopefully be less stressful and keep my mind clear to work on my own game things in my own time without my enthusiasm for it being drained away by having done basically the same thing all day when I get home or all week when I get to the weekend.

And I'm learning some things like:

Be kind to your self.
You're allowed to enjoy the things you like.
Think positively (not delusionally). There is more truth in the positive thoughts than the negative most of the time).
It's OK if all you did today was survive. I really like this, having read it only a few days ago. We weren't born to work. We were born to exist.
Put in 80% instead of 110%. You'll find that everyone else is doing this and no-one will think you're slacking or not doing enough.

So if anyone else is having a hard time try to think of those things. I've spent most of my life thinking I'm not good enough, I'm not doing enough, even though I know how intelligent and capable I am.




With the ship in this game yesterday I separated out the weapon from it. So I made the image separate and needed to make some changes so the ship could draw itself.

I think I need to redo how I'm building the image up in a couple of ways but that is a reinvention that can wait.

I then split the ship down into some base classes - in-game-asset (location, facing left / right data), with drawable-asset (canvas data, drawing functionality) and drivable-asset (data and functionality for accelerating and adjusting location) derived from that.

Then I derived ship from all three of those. Ship now being abstract that can be used for player ship and (later) enemy ships. Ship also contains the ship sounds, which I will later make a base class so specific varieties of sounds can be given to it to give each ship its own sound (deeper, louder, etc). Player ship (and enemy ships) define the movement acceleration / deceleration rates and image used for drawing.


Then I put in functionality for the weapon and to be able to attach and detach it from the ship. The weapon can also draw itself, and is also derived from the drawable-asset and in-game-asset so gets all that data and functionality (location, drawing) without doing extra work.

So I have a test now where the weapon is in the game world and pressing a button attaches and detaches it from the ship, which opens up gameplay ideas.

So from this point it is going to be relatively easy to make various enemy ship types and they will have the same abilities (like being able to pick up different weapons).


I want to work on the weapon projectiles next. They will basically be to weapon like weapon is to ship. The weapon will manage them in a collection and remove them when they are done (their sound is finished and they've existed for their pre-determined lifetime or they hit something). So when the ship draws the weapon the weapon will draw each of the projectiles.

So each weapon could have an interchangeable projectile type. So one weapon could have one projectile and another a different one, but maybe you get a power up and the projectile type changes on that weapon.


I was also thinking about having little health bars hovering above each ship. They would just be another collection like projectiles but attached to the ship instead of the weapon.

albinopapa
Posts: 4370
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Sand Simulator / 2D Fun

Post by albinopapa » January 29th, 2022, 11:04 am

Life has been a real piece of work for a lot of people the past couple of years. I for one went through a divorce which was finalized in Jan 2021. The marriage was emotionally draining and I have thoughts of self loathing and inadequacies all too often. I spent so long in the marriage living off her success as a way of getting retribution for the torment she put me through I now have no direction. Even now, my son and I are living off my SSDI and his child support while I figure out what I'm going to do in two years when he turns 18.

I agree, you do need to slow things down and do what makes you happy, at least you seem to have a few goals in mind. Focus on you and your mental and physical health for awhile.

Anyway, something that might help with organization with the game entities is to create a World class. Any time your ship fires a projectile, you spawn it and add it to a vector in the World class. The reason I suggest this is it separates the weapon from the ammo. For instance, if you do get a power up to change the weapon or change the projectile, having it separate from the weapon allows for those already on screen to exist as well as the new upgraded/downgraded projectiles. It sounds like such a small thing, but when I was making a shooter like this, I really liked the outcome.

Cheers.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply