Author Topic: Slappa!  (Read 9104 times)

congusbongus (OP)

  • Posts: 80
    • congusbongusgames
Slappa!
« on: October 24, 2014, 03:09:14 pm »

Downloads: https://github.com/cxong/Slappa/releases/tag/1.0.1
opk: https://github.com/cxong/Slappa/releases/download/1.0.1/slappa.opk
GitHub: https://github.com/cxong/Slappa


This is a little game I made recently and ported to GCW-Zero. It's an arcade kungfu minigame with high scores, good for quick games.
This was originally a submission for pyweek recently: https://pyweek.org/e/Slappa/
But having recently received a GCW-Zero, I decided to port it. Right now there's an opk and Windows download, or if you have Python you can run the game directly (open source, MIT license, various open licenses for the content).

Incidentally, does anyone else have experience using pygame with GCW-Zero? Being quite new to both, I ran into a number of issues. Most are related to pygame, but there doesn't seem to be much in the way of guidelines online, so I thought I might share some tips I found here. Basically, Python and pygame are both pretty slow so in the end I couldn't maintain a smooth 60fps as soon as more than 4 sprites were on screen, so I had to opt for 30fps instead. I think it has something to do with the relatively large sprite sizes - I was working with 256x256 sprite sheets, perhaps that's too big considering the CPU's tiny caches. Next time I might try an OpenGL ES-based framework.

Anyway, here are some tips:
- Always use convert(), or convert_alpha() if you have to. This converts the surfaces to the same pixel format as the screen's, otherwise every blit will require a conversion.
- Use tick_busy_loop; tick is very imprecise.
- Perform as much processing ahead of time as possible - scaling, font rendering, rotations etc.
- Try to pre-render fonts; failing this, try not to use anti-aliasing, it's very slow. A few font renders is ok but rendering a screen full of text will kill your frame rate.
- Color key transparency is faster than surfaces with partial alpha
- Make the sprites as small as possible
- If there is audio crackling, try increasing the mixer buffer size, but not too much as it will increase latency
- Hide the mouse (unless your game needs it)
« Last Edit: October 25, 2014, 12:46:43 pm by congusbongus »

congusbongus (OP)

  • Posts: 80
    • congusbongusgames
Re: Slappa!
« Reply #1 on: October 24, 2014, 03:15:47 pm »
Here's a quick gameplay video:
<a href="https://web.archive.org/web/20201201053107/https://www.youtube.com/watch?v=KrL03milBMA" target="_blank">https://www.youtube.com/watch?v=KrL03milBMA</a>
I haven't tried this but if you have USB OTG I think you can play with two players. The video was recorded on PC.

zear

  • * Moderator
  • Posts: 2381
Re: Slappa!
« Reply #2 on: October 24, 2014, 03:28:48 pm »
This game is absolutely rad, I am having a lot of fun playing it. Good job! :)
Would you be interested to have your game placed in the official GCW Zero repository: repo.gcw-zero.com?

Just two things I noticed:
* Is there a way to erase a typed letter in the hi-score entering dialog? Turns out I had to press B to erase a letter :P
* What is the keymapping on the right side of this picture? Is that for a device different than GCW Zero? It's quite confusing.


About USB OTG - that feature is not yet ready and is disabled in public firmware releases. But it's nice to know the game supports it.

As for your python questions/notes - the majority of software ported to GCW Zero was written using C/C++ & SDL backend, so we don't have much experience with pygame and your notes are valuable to us. Would you like to join our IRC channel (connection details) so we can help you debug/improve the game performance?

congusbongus (OP)

  • Posts: 80
    • congusbongusgames
Re: Slappa!
« Reply #3 on: October 25, 2014, 12:46:09 pm »
Would you be interested to have your game placed in the official GCW Zero repository: repo.gcw-zero.com?
Yes please!

* What is the keymapping on the right side of this picture? Is that for a device different than GCW Zero? It's quite confusing.
I've removed those for GCW-Zero, but it should appear if a joystick is detected. Those controls are for the second player, which uses the first joystick device (2nd for GCW-Zero since the first is used by the analog stick).

pcercuei

  • Posts: 1689
    • My devblog
Re: Slappa!
« Reply #4 on: October 27, 2014, 12:20:05 pm »
Your game may be slow but it's too easy to say that the GCW Zero is not powerful enough.
You should first work on optimizing your code; things like this will definitely be slow: https://github.com/cxong/Slappa/blob/master/animation.py#L30

Also, from what I can see you render at 640x480 then downscale to 320x240 in software. Don't do that! Instead, use 640x480 as the screen size, and add X-OD-NeedsDownscaling=true to your .desktop file.

Nebuleon

  • Guest
Re: Slappa!
« Reply #5 on: October 27, 2014, 09:08:39 pm »
Your game may be slow but it's too easy to say that the GCW Zero is not powerful enough.
You should first work on optimizing your code; things like this will definitely be slow: https://github.com/cxong/Slappa/blob/d3a4a5b/animation.py#L30-L32
Yes. Because code like this:
Code: [Select]
while self.sub_counter >= self.duration:
 self.sub_counter -= self.duration
 self.counter += 1
can be replaced with
Code: [Select]
quot_rem = divmod(self.sub_counter, self.duration)
self.counter += quot_rem[0]  # the quotient
self.sub_counter = quot_rem[1]  # the remainder replaces the old value
This runs in constant time.

Under one circumstance, the while loop will be faster, and that's when 'self.sub_counter < self.duration' for a majority of the time, and you don't expect the iteration count to ever exceed one, and integer division is expensive on the architecture running the code. In all other circumstances, prefer the division-and-remainder code.

congusbongus (OP)

  • Posts: 80
    • congusbongusgames
Re: Slappa!
« Reply #6 on: October 27, 2014, 10:53:52 pm »
Your game may be slow but it's too easy to say that the GCW Zero is not powerful enough.
I've profiled the code and the two most expensive tasks are fill() and blit(). If I disable sprite drawing and leave everything else, frame rate is very high. Based on this I conclude that either GCW Zero blitting, for large surfaces, is slow, or python/pygame. Given what I've seen from games written in C/SDL, I'd say it's a bit of both.

You should first work on optimizing your code; things like this will definitely be slow: https://github.com/cxong/Slappa/blob/master/animation.py#L30
That loop will usually run 0 or 1 times, making the difference immaterial. Actually I'm surprised you'd say that would be slow; even if I were writing optimised C I wouldn't worry about code like that, as it's just integer arithmetic, constant time stuff.

Also, from what I can see you render at 640x480 then downscale to 320x240 in software. Don't do that! Instead, use 640x480 as the screen size, and add X-OD-NeedsDownscaling=true to your .desktop file.
That's actually misleading; the game "world" behaves as if it's in a 640x480 space but I pre-scale everything. To demonstrate, you should find no pygame.transform.scale calls in the game loop at all.

Kloppix

  • Posts: 36
Re: Slappa!
« Reply #7 on: October 28, 2014, 01:33:17 am »
Your game is great, dude. Are you planning to continue it ?

pcercuei

  • Posts: 1689
    • My devblog
Re: Slappa!
« Reply #8 on: October 28, 2014, 09:37:32 am »
Maybe you could try with SDL2 bindings? Then it would be GPU-accelerated.

congusbongus (OP)

  • Posts: 80
    • congusbongusgames
Re: Slappa!
« Reply #9 on: October 28, 2014, 09:45:24 pm »
Your game is great, dude. Are you planning to continue it ?
Thanks! Although I have many ideas about it, I don't think I'll continue unless people want more work done on it. If you have any suggestions feel free to raise them here: https://github.com/cxong/Slappa/issues No promises though!

Kouen Hasuki

  • Posts: 155
Re: Slappa!
« Reply #10 on: October 29, 2014, 03:34:58 pm »
Checking this out now!

zear

  • * Moderator
  • Posts: 2381
Re: Slappa!
« Reply #11 on: October 31, 2014, 03:45:10 pm »
@congusbongus
Slappa! is now officially part of the GCW Zero repository: http://repo.gcw-zero.com/
Thanks!

PS. If you want any changes (upload a new build, change the screenshot, description, etc.) feel free to contact me.

DPA09

  • Posts: 101
Re: Slappa!
« Reply #12 on: November 15, 2014, 07:28:23 pm »
Awesome.  I really appreciate having a high score table - a small touch but too many people don't bother with it. 

Thanks!

Senor Quack

  • Posts: 225
Re: Slappa!
« Reply #13 on: November 16, 2014, 04:19:55 am »
Really fun & cute game :)

 

Post a new topic
Post a new topic