Asteroid Explorer (Custom physics using verlet integration and SAT)

Show off your games, demos and other (playable) creations.
whateverest
Prole
Posts: 12
Joined: Fri Sep 29, 2023 6:46 pm

Re: Asteroid Explorer (Custom physics using verlet integration and SAT)

Post by whateverest »

I have released Version 0.4. its a rather big update.
The most notable changes are:

Interesting levels!
I finally got around to implementing a cellular-based map generation. The results are really good I think.

"Proper" graphics
I created a tilemap for the terrain and replaced the third-party art. Well... it looks okay-ish, but its still "programmer art" :).

FPS independend physics
Took me a very long time to notice, but the physics were behaving subtly different when the game was running with different fps. I thought I was handling different delta times correclty, turns out I was wrong. Using the linked code worked wonderfully.

Itch-io Release (Linux/Windows/Macos)
Feel free to check it out here: https://ycakegames.itch.io/asteroid-explorer.
I tried to follow the instructions in the wiki for creating executables. I only have linux machines to try the game on though, so I'd be really thankful for playtesters on Windows/macos.

Items
Only fuel pickups for now. Pickups only have a chance to spawn inside "crevices". As the game progresses the levels get longer and the fuel pickups fewer.

Implemented reverse thrusters (Arrow down)
Very weak and you can only use them if you upgrade them at least once for now.
This does not feel super useful as is. Maybe I will change it so using them does not apply reverse thrust but cancels movement in any direction instead.

I am really happy with the state of the game, the basic mechanics are implemented and the core gameplay loop works.
I had lots of fun implementing it so far. Learning about verlet integration, sat, procedural generation and creating and using spritesheets "from scratch" was really cool.

Things I would like to add sometime in the future would be:
  • Sound. I think this is missing before I could actually call it a "proper game".
  • Web and Android Version. I have tried (and failed) to get the game running with love.js. Android I haven't tried yet but i think the game could be played on Android devices, I might have to tweak the speed and zoom the game further in for that though.
  • More interesting objectives and danger.
  • UI improvements. That's always a thing I could and should to. The UI is still really basic. But working on new cool features beats polishing the UI most of the time :)
whateverest
Prole
Posts: 12
Joined: Fri Sep 29, 2023 6:46 pm

Re: Asteroid Explorer (Custom physics using verlet integration and SAT)

Post by whateverest »

I have released Version 0.5, this will probably be the last update for a while.
The main features in this release are:

Controller Support
I have tested it with a PS5 Controller, analog inputs via stick/trigger are supported.

Better Visual Effects
I added an explosion effect for the spaceship by following this tutorial https://gamedev.net/tutorials/_/creativ ... ect-r2701/. Also I improved the rocket exhaust smoke effect

Basic sounds
I implemented sound effects for the rocket engine and for the spaceship explosion.

Also I finally "fixed" an annoying bug with my collision response code (you may have noticed wreck parts completely freaking out sometimes).
whateverest
Prole
Posts: 12
Joined: Fri Sep 29, 2023 6:46 pm

Re: Asteroid Explorer (Custom physics using verlet integration and SAT)

Post by whateverest »

I wanted 0.5 to be the last update for a while... But game development is too much fun, so here is Version 0.6!

Considering that I have put quite a lot of work and code into this release, there is not that much new stuff in the game.
Still, there are a few interesting things to write about:

MASSIVE Performance improvements
Until now the (collidable) static tiles of the level geometry were normal verlet physics objects like the player.
Every frame, all tiles did position updates, collission checks etc.,.
Small levels ran well, but FPS started to drop for me for levels around 20x20 in size.
Pretty bad considering currently only 1-2 moving objects exist in any given level.

I came up with a fairly simple solution, which improved performance dramatically:
Static objects are always added to the end of the table of objects in the world. So the table looks like this:

verlet.objects = {player,tile1,tile2,tile3....tile100}

Now when looping through the objects for collission detection or updates i simply do this:

Code: Select all

         
         for i = 1, #verlet.objects do
                local obj1 = verlet.objects[i]
                if obj1.static then
                    -- imobile objects are always at the end of the table. We dont need to check the rest
                    return
                end
                for j = i + 1, #verlet.objects do
                    local obj2 = verlet.objects[j]
                    verlet.solve_collision(dt, obj1, obj2)
                end
            end
            
Now levels can easily have sizes of 70x70 or more while still running at 144 FPS (on my machine:)).
This also made it possible to run the game with love.js, see the next chapter.

I still keep the default level size small but it is nice to know that I could make the levels much larger and add more interesting stuff in general.

Web support
The biggest hurdle with getting the game to run with love.js, besides the complicated build process, was the abysmal performance.
I was getting 0 - 3 FPS even for small levels.
With the performance fix discussed above I am getting 144 FPS with the web version too.

Before I got the game to run I stumbled onto a small incompatibility between love on desktop and love.js.
love 11.5 on desktop is using luajit 2.1 which has builtin support for bitwise operations. Lua 5.1., which is currently used for building love.js, does not.

The following worked with love on desktop but not with love.js:

Code: Select all

    
    require("bit")
    x = bit.bxor(1,2)
I currently use bitwise "xor"-operations for choosing the correct sprite for the tiles at the start of the level.
I tried to fix this by including the bitop-extension for LUA 5.1/5.2 and it worked! !
I managed to build a version of love.js that supports the "bit"-module and the itch page features a web version as well now.

There are two small problems left with the web version
  • It seems like random values and seeds do not work like they to in the desktop version. So the web version currently isn't as random as the desktop one :). Probably related to this issue.
  • Analog Input with joystick/Controllers does not seem to work
I'd like to fix the first one sometimes, the second is not a priority for me.

GUI
Staying true to my pointless...ahem...noble goal of "write almost everything yourself", I started implementing a GUI library for the game "from scratch".
The features of the library so far are:
  • Text fields, Buttons, Labels and Panels(Containers)
  • Basic automatic layouting. Relative horizontal and vertical layout, inspired by Androids "LinearLayout"
  • Mouse support and navigable by keyboard and controller
All Interactive screens in the game use this new UI now. It is still not pretty, but better I think.
Also while using a controller you now never have to use the keyboard while playing (for buying upgrades etc.).

I gotta say, writing a GUI toolkit is a lot of work. Even in this primitive state It is almost the second largest part of my game, in terms of lines of code.




As usual the .love file can be downloaded right here in the forum post. The web and compiled Versions are available on https://ycakegames.itch.io/asteroid-explorer.


The game has come quite far, considering it started as a quick proof of concept for my own physics library made in a single day.
Not sure how long I want to continue working on the game.
Sure, I could endlessly add new mechanics and stuff but maybe I'll use the tools I wrote and use them in another project.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests