WinterLicht / Chaos-Projectile

Run ‘n’ Gun meets RPG
60 stars 17 forks source link

Tuple index out of range #5

Closed Algorithmus closed 8 years ago

Algorithmus commented 8 years ago

I tried to run the game, but it doesn't start up. I get

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "game.py", line 66, in <module> systemMngr = systemmanager.SystemManager(evManager, game) File "systemmanager.py", line 33, in __init__ self.systems.append(rendersystem.RenderSystem(event_manager, gameWorld)) File "rendersystem.py", line 37, in __init__ clamp_camera=False) File "build/bdist.macosx-10.3-fat/egg/pyscroll/orthographic.py", line 71, in __init__ File "build/bdist.macosx-10.3-fat/egg/pyscroll/orthographic.py", line 360, in reload_animations File "build/bdist.macosx-10.3-fat/egg/pyscroll/animation.py", line 13, in __init__ IndexError: tuple index out of range (Tried this on a Linux computer as well. Same result.) Apparently, pyscroll fails to find the animation frames in the level map data. I'm not sure if this is a problem with the game or with pyscroll.

Funatiker commented 8 years ago

Hi @Algorithmus, thank you for your report. From which directory have you tried to start the game?

Edit: I've clarified the instructions (see #6 ). You are supposed to run the game from the src directory. Does that fix the issue on MacOS?

Algorithmus commented 8 years ago

No, it still doesn't work. I tried it from the root directory, and then in src. If I run it in the root directory, then it says it doesn't find data/level.tmx. I think it finds the tmx file when I run it from the src directory, since the tuple error occurs after the gameworld variable gets created.

Funatiker commented 8 years ago

Just to make that sure: The "tuple index out of range"-error occurs both on Linux and on MacOS when running from the src directory?

Which version of Pyscroll are you using? Run import pyscroll and then pyscroll.__version__ in a Python console. I'm successfully running 2.14.3 on a Debian-like system. My pyscroll directory does not contain orthographic.py and animation.py and none of the existing files contains reload_animations.

Algorithmus commented 8 years ago

Well, it gets past that error now if I tell pip to downgrade to 2.14. I think what happened was that they added these new features in 2.16.2, which is probably where animation.py and orthographic.py come from. But I have a problem with the joystick axis:

Traceback (most recent call last): File "game.py", line 76, in <module> spinner.run() File "game.py", line 42, in run self.event_manager.post(event) File "/home/user/Workspace/Chaos-Projectile/src/events.py", line 408, in post listener.notify(event) File "/home/user/Workspace/Chaos-Projectile/src/controller.py", line 69, in notify horiz_axis_pos = self.joystick.get_axis(3) pygame.error: Invalid joystick axis

Am I required to have some sort of gamepad plugged in?

Funatiker commented 8 years ago

Normally, the joystick-code should only be executed if pygame.joystick.get_count() is greater than zero (see beginning of controller.py). We assume your joystick to be a PlayStation/Xbox360-Controller. That's why we use axes 2 and 3.

The call of pygame.joystick.get_count() should be reliable, provided that joystick has been initialized which is supposed to be already done by pygame.init() in game.py.

Algorithmus commented 8 years ago

Okay, I figured it out. Apparently, I had some other USB device plugged in. According to the pygame docs, it can recognize other things connected to the USB, including keyboards and tablets. Apparently, you can check if it has the appropriate axes by using get_numaxes(). The device I had only has 2, so get_axis(3) doesn't exist. I added an additional check in controller.py:

if self.joystick and self.joystick.get_numaxes() > 3: (about line 69)

Now it works. Thanks.

Related issue for reference: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=710162

Funatiker commented 8 years ago

Thank you for this suggestion. Since we access both get_axis(3) and get_axis(2), we should check whether there are at least 4 axes, shouldn't we?

Algorithmus commented 8 years ago

Ja, just realized my mistake. Fixed. But the idea is the same.

Funatiker commented 8 years ago

Great! Thanks. One more question. What's the easiest way to enforce the right version of pyscroll? I'd say

pip install 'pyscroll<2.16.2' --force-reinstall

Algorithmus commented 8 years ago

I did pip install 'pyscroll<2.14.3', which appears to work, but I can't get it anywhere higher than that without using 2.16.2. But if it works with 2.15.2, then I guess it's fine to use that for the docs.

Funatiker commented 8 years ago

Let's just hope it works.

Funatiker commented 8 years ago

@Algorithmus the updated README has been pulled now. The pseudo-joystick-patch is on its way.

Besides that, I want to thank you for your active contribution in this issue. We'd really like to see more contribution by you. Feel free to stay active.

Algorithmus commented 8 years ago

Admittedly, I was looking into this game for "research" into my own platform game that I am making. It is similar in some ways, and not so similar in others (eg, my game is closer to Castlevania than Contra or Super Metroid, and my characters are vampires avoiding sunlight, and not a sun goddess looking for sun shards. Haha.) I'm not sure if I will have time to contribute otherwise beyond maybe just testing and building. This was also unfortunately the only way to contact you about this project, but I just wanted to say I am impressed and pleasantly surprised to find there is someone else who is also using Krita to make game assets and I wish you luck on further progress with your game.

Funatiker commented 8 years ago

I think the biggest lesson to learn when reading the code here is that quadratic runtime is already heavy when done in every frame: The projectiles check collisions with any other object. This means, if there are 50 projectiles on the screen, we have to consider 2500 possible collisions in every frame.

Feel free to keep us updated about your progress in letting your characters avoiding the sunlight.

Algorithmus commented 8 years ago

On^2, lovely. I want to avoid that when possible or minimize using it if possible.

What would be the best way to contact you? I don't imagine using a Github issue would be adequate.

Funatiker commented 8 years ago

Got Jabber?

On the ^2-problem: Maintain several sets of objects. If projectiles can't crash into projectiles, don't consider them when checking for collisions. Think about dividing the world into sections. If two objects are far apart, it isn't necessary to check whether they collide.

Algorithmus commented 8 years ago

Ja, that's a common strategy. Don't do the check if they're outside of the player's view. Another option is to limit the size of your levels and if you need a bigger level, split them into separate smaller levels. Works for games like Zelda and Castlevania. (Oh, you sort of mentioned that)

I think I am on Jabber. I have a jit.si account.

Funatiker commented 8 years ago

@Algorithmus Add me on Jabber then :)

bitcraft commented 8 years ago

WinterLicht had opened an issue for pyscroll to fix this "tuple error" and i implemented a fix in version 2.16.5. That should clear up that particular error. I've tested the game on my windows system with the current pyscroll and it seems to work just fine and also added a test case to make sure the error doesn't come up again. Thanks!

With the animated tile support, you can animate the lamps in the background now. :smile:

MCMic commented 8 years ago

The readme should be updated accordingly, as the game seems to run fine with 2.16.6