Permalink
Browse files

Write pygame_sdl2/RAPT example game.

  • Loading branch information...
renpytom committed Jul 22, 2015
0 parents commit dcc43e790d8fef0fcc1d1d81887bf1c68e7bdb24
Showing with 298 additions and 0 deletions.
  1. +1 −0 .android.json
  2. +1 −0 .gitignore
  3. BIN DejaVuSans.ttf
  4. +99 −0 DejaVuSans.txt
  5. +91 −0 README.rst
  6. +106 −0 main.py
  7. BIN pygame-icon.png
@@ -0,0 +1 @@
{"orientation": "sensorLandscape", "include_pil": false, "icon_name": "Android Test", "google_play_key": null, "layout": "internal", "source": false, "version": "1.0", "store": "none", "numeric_version": "100", "target_version": 14, "google_play_salt": null, "expansion": false, "include_sqlite": false, "permissions": ["VIBRATE"], "name": "Android Test", "package": "org.renpy.android_test"}
@@ -0,0 +1 @@
main.pyo
BIN +608 KB DejaVuSans.ttf
Binary file not shown.
@@ -0,0 +1,99 @@
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
Bitstream Vera Fonts Copyright
------------------------------
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:
The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".
This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.
The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.
Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.
Arev Fonts Copyright
------------------------------
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of the fonts accompanying this license ("Fonts") and
associated documentation files (the "Font Software"), to reproduce
and distribute the modifications to the Bitstream Vera Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to
the following conditions:
The above copyright and trademark notices and this permission notice
shall be included in all copies of one or more of the Font Software
typefaces.
The Font Software may be modified, altered, or added to, and in
particular the designs of glyphs or characters in the Fonts may be
modified and additional glyphs or characters may be added to the
Fonts, only if the fonts are renamed to names not containing either
the words "Tavmjong Bah" or the word "Arev".
This License becomes null and void to the extent applicable to Fonts
or Font Software that has been modified and is distributed under the
"Tavmjong Bah Arev" names.
The Font Software may be sold as part of a larger software package but
no copy of one or more of the Font Software typefaces may be sold by
itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the name of Tavmjong Bah shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Font Software without prior written authorization
from Tavmjong Bah. For further information, contact: tavmjong @ free
. fr.
$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $
@@ -0,0 +1,91 @@
RAPT Pygame Example
===================
This serves as an example of how to get a simple Pygame game working on
Android.
Step 0: Ready the game.
-----------------------
Please ensure that the main file of your game is named main.py.
Please ensure that your game will run with pygame_sdl2. Generally, this
consists of adding the lines::
try:
import pygame_sdl2
pygame_sdl2.import_as_pygame()
except ImportError:
pass
to the top of your main.py file, before the first import of pygame. (However,
note that pygame_sdl2 does not yet implement all of pygame.)
For now, RAPT supports only python2.7.
This repository serves as a simple pygame_sdl2-ready game.
Step 1: Install dependencies.
-----------------------------
RAPT depends on your computer having a JDK in the path, and Python 2.7 installed.
On Windows, you'll need a 32-bit JDK if you're using a 32-bit Python 2.7.
You may also need to install device drivers and permissions to ensure that
the Android SDK will talk to your device.
Step 2: Download and unzip RAPT.
--------------------------------
Download the latest nightly build of RAPT from
http://nightly.renpy.org/current/ . The file you want will end in -rapt.zip.
Unzip the file. All further commands should be run from inside the rapt
directory.
Step 3: Install the Android SDK.
--------------------------------
This can be done by running::
python android.py installsdk
RAPT will prompt you to accept various license, and create a signing key.
This has to be done only once per RAPT install.
Step 4: Configure the game.
---------------------------
Configure the game::
python android.py configure /path/to/rapt-pygame-example
The correct answers vary depending on the game. For our example, we used:
* Full Name: Android Test
* Short Name: Android Test
* Package Name: org.renpy.android_test
* Human-readable Version: 1.0
* Version Code: 100
* Orientation: 1) Landscape
* Expansion APK: 1) No
* Android Version: 3) Android 4.0
* Application Layout: 1) Single directory, device internal storage.
* Include Source Code: no
* Permissions: VIBRATE
* SQlite3: no (may not work)
* PIL: no (may not work)
This must be done once per game.
Step 5: Build, Install, and Run the game.
-----------------------------------------
This can be done with the command::
python android.py --launch build /path/to/rapt-pygame-example release install
This must be done each time the game changes, to ensure the latest version is
on the device.
106 main.py
@@ -0,0 +1,106 @@
# Allow pygame_sdl2 to be imported as pygame.
import pygame_sdl2
pygame_sdl2.import_as_pygame()
import pygame
import os
def save_state(x, y):
"""
Saves the game state.
"""
with open("state.txt", "w") as f:
f.write("{} {}".format(x, y))
def load_state():
try:
with open("state.txt", "r") as f:
x, y = f.read().split()
x = int(x)
y = int(y)
return x, y
except:
return None, None
def delete_state():
if os.path.exists("state.txt"):
os.unlink("state.txt")
def main():
pygame.init()
screen = pygame.display.set_mode((1280, 720))
screen_w, screen_h = screen.get_size()
icon = pygame.image.load("pygame-icon.png")
icon = icon.convert_alpha()
icon_w, icon_h = icon.get_size()
font = pygame.font.Font("DejaVuSans.ttf", 24)
text = font.render("Touch the screen.", True, (255, 255, 255, 255))
text_w, text_h = text.get_size()
sleeping = False
# On startup, load state saved by APP_WILLENTERBACKGROUND, and the delete
# that state.
x, y = load_state()
delete_state()
while True:
# If not sleeping, draw the screen.
if not sleeping:
screen.fill((0, 0, 0, 255))
screen.blit(text, (screen_w / 2 - text_w / 2, screen_h / 2 - text_h / 2))
if x is not None:
screen.blit(icon, (x - icon_w / 2, y - icon_h / 2))
pygame.display.flip()
ev = pygame.event.wait()
# Pygame quit.
if ev.type == pygame.QUIT:
break
# Android back key.
elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_AC_BACK:
break
elif ev.type == pygame.MOUSEBUTTONDOWN:
x, y = ev.pos
elif ev.type == pygame.APP_WILLENTERBACKGROUND:
# The app is about to go to sleep. It should save state, cancel
# any timers, and stop drawing the screen until an APP_DIDENTERFOREGROUND
# event shows up.
save_state(x, y)
sleeping = True
elif ev.type == pygame.APP_DIDENTERFOREGROUND:
# The app woke back up. Delete the saved state (we don't need it),
# restore any times, and start drawing the screen again.
delete_state()
sleeping = False
# For now, we have to re-open the window when entering the
# foreground.
screen = pygame.display.set_mode((1280, 720))
if __name__ == "__main__":
main()
BIN +24.9 KB pygame-icon.png
Binary file not shown.

0 comments on commit dcc43e7

Please sign in to comment.