A new UI, Performance improvements and Web support
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, collision 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:
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:
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 project 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 do 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.
What now?
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.
Files
Get Asteroid Explorer
Asteroid Explorer
Simple physics-based spaceship game
Status | In development |
Author | ycakegames |
Genre | Action |
Tags | LÖVE, Physics, rougelike, Space |
More posts
- Update 0.5Dec 01, 2024
Leave a comment
Log in with itch.io to leave a comment.