Christian2147 / Laser-Fighter

This is the main repository for Laser Fighter - A graphical 2D laser shooting game set in outer space.
GNU General Public License v3.0
5 stars 2 forks source link

Support for computers running Linux #4

Open yosoyducc opened 1 month ago

yosoyducc commented 1 month ago

I can see in the README that there are plans to port the game to Linux. That's awesome! I'm opening this issue to highlight the things that need to be done to port the game.

Laser Fighter currently makes some system calls to the Windows API. The head culprit is ScreenSetup.py which manages screen initialization. This file imports win32api and win32con to achieve this. While this approach works on Windows, it means other operating systems cannot run this game natively. This is the main reason the game will not run outside of a Windows environment. A possible solution is to use a more OS-agnostic approach to these windowing functions, like getting the monitor dimensions. I'm not aware of anything of this nature for Python at the moment, I'd have to look more into this.

Another thing to notice is this game also imports the font "Courier" from the system, which is not commonly found on OSes other than Windows. This can result in fallback to some really awful-looking default system font. We can see this in effect when running the game in WINE on Linux, which does not have the Courier font installed by default. A solution is to just include the font file with the game, but it's possible that the Courier font has a proprietary license, causing trouble with redistribution.

Aside from these two points, there shouldn't be much else that needs to be changed to port the game. I'd be interested in opening a pull request to work on this.

Christian2147 commented 1 month ago

Thanks for your feedback! Yes I do plan on making this game Linux compatible in the future. Before that can be done, however, I need to make some major changes to the code once again so that the game is not using the poorly optimized turtle library. I would have done that this summer, but felt that working on code organization was more important. Once this change is made, I can begin working towards Linux compatibility.

yosoyducc commented 1 month ago

I'd like to follow up. @Christian2147 and I have done some work on getting this to run on Linux. I've managed to get it to run on my machine, but only when deviating from the instructions a bit. I'll outline this below.

As of this commit e328eac, Linux instructions for setting up the env are accurate and work. However, some instructions are unclear, particularly around removing win32 dependencies. It tells us to use xrandr instead. There's no way to import xrandr into python that I am aware of.

Here are the instructions for what I did:

source/setup/WindowSetup.py

Note: The reason why we're assigning 1920x1080 to these is because in this version the game does not appear to scale well with any other resolution.

source/utils/PreventSleep.py

source/textures/lasers/Player_laser.gif

source/textures/interface/Icons/

monitor properties

From here, running python3 main.py from within the source/ directory launched the game just fine. On my system, it seems to use an entire CPU core at 100%, whereas the Windows build from releases when run under Wine does not.

Christian2147 commented 1 month ago

@yosoyducc Thanks for the follow up! I have added most of these to the instructions page. The rest of these procedures I plan on implementing in the games code through a Hotfix update coming up later in the week! All of these commands not working have to do with improper naming or Linux incompatibility.

I am not sure why the scaling is working incorrectly. Try implementing the solution that I gave and see if it scales correctly when on fullscreen mode. Windowed mode scaling has not been implemented yet.

Christian2147 commented 1 month ago

@yosoyducc I have just released a new update which addresses some of the requirements for porting the game to Linux. Linux compatibility is possible if you follow the instructions on the instructions page. In the future, I plan on making this a fully automated process. Thank you for your help!