Hatena::ブログ(Diary)

万年素人からGeekへの道 このページをアンテナに追加 RSSフィード Twitter

□僕のAndroidアプリ □NGUI翻訳 □僕の翻訳した本 □僕のChrome拡張 □たばこ税増税の署名 〜募集中〜

2012-04-10 Tuesday このエントリーを含むブックマーク このエントリーのブックマークコメント

Pygame Subset for Android

・これでPygameAndroidできるかも?

http://pygame.renpy.org/

・「PGS4A」のダウンロード

http://pygame.renpy.org/dl/

※PGS4Aは>PyGame Subset for(4) Androidってことか。

私はWindows使ったのでzip版をDLして解凍

cd pgs4a-0.9.4

JDKは入っている前提。

以下のコマンドを何も考えずに実行!

android.py installsdk

↓これはyesと答えた

Do you accept the Android SDK Terms and Conditions?
yes/no> yes

↓これはyesと答えた

Do you want to create a key?
yes/no> yes

↓これはyesと答えた

Will you make a backup of android.keystore, and keep it in a safe
place?
yes/no> yes

↓これは名前を答えた

Please enter your name or the name of your organization.
> shinriyo

「pgs4a-0.9.4」ディレクトリ内にに"mygame"ディレクトリ作成し、

その中に以下を突っ込む

・main.py

import pygame

# Import the android module. If we can't import it, set it to None - this
# lets us test it, and check to see if we want android-specific behavior.
try:
    import android
except ImportError:
    android = None

# Event constant.
TIMEREVENT = pygame.USEREVENT

# The FPS the game runs at.
FPS = 30

# Color constants.
RED = (255, 0, 0, 255)
GREEN = (0, 255, 0, 255)

def main():
    pygame.init()

    # Set the screen size.
    screen = pygame.display.set_mode((480, 800))

    # Map the back button to the escape key.
    if android:
        android.init()
        android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

    # Use a timer to control FPS.
    pygame.time.set_timer(TIMEREVENT, 1000 / FPS)

    # The color of the screen.
    color = RED

    while True:

        ev = pygame.event.wait()

        # Android-specific:
        if android:
            if android.check_pause():
                android.wait_for_resume()

        # Draw the screen based on the timer.
        if ev.type == TIMEREVENT:
            screen.fill(color)
            pygame.display.flip()

        # When the touchscreen is pressed, change the color to green.
        elif ev.type == pygame.MOUSEBUTTONDOWN:
            color = GREEN

        # When it's released, change the color to RED.
        elif ev.type == pygame.MOUSEBUTTONUP:
            color = RED

        # When the user hits back, ESCAPE is sent. Handle it and end
        # the game.
        elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
            break

# This isn't run on Android.
if __name__ == "__main__":
    main()

http://pygame.renpy.org/android-packaging.htmlから引用

そのあとで、mygameフォルダに入り、main.pyを実行

cd mygame
C:\Python27\python.exe main.py

※なぜかvirtualenv上でpythonコマンドpygameインポートがきかなかったので、

「C:\Python27\python.exe」にしないと動かなかった。

・次のこのコマンド

android.py configure mygame

以下のように答えた まちがってるかも??


What is the full name of your application? This name will appear in
the list of installed applications.
> mygame

What is the short name of your application? This name will be used in
the launcher, and for application shortcuts.
[mygame]> mg

What is the name of the package?

This is usually of the form com.domain.program or
com.domain.email.program. It must only contain ASCII letters and dots.
> com.shinriyo.mygame

What is the application's version?

This should be the human-readable version that you would present to a
person.
> 0

What is the version code?

This should be an integer number, and the value should increase
between versions.
[0]>

How would you like your application to be displayed?
1) In landscape mode.
2) In portrait mode.

1-2> 2

How is your application laid out?
1) A single directory, that will be placed on device internal storage.
2) A single directory, that will be placed on device external storage.
3) Multiple directories that correspond to internal, external, and
asset storage.

1-3> 1

What permissions should your application have? Possible permissions
are:

INTERNET (network access), VIBRATE (vibration control).      Please
enter a space-separated list of permissions.
[INTERNET VIBRATE]>

Do you want to include SQLite3 with your application?
yes/no [no]>

Do you want to include the Python Imaging Library (PIL) with your
application?
yes/no [no]>

android.py build」コマンドは少なくとも2つの引数らしい

から以下のコマンドでは成功した。しかしapkファイルはどこかにできてる?

android.py build mygame release

・ちなみにこれはデバイスを繋いだ時におこなうみたい

android.py build mygame release install

Pygame Subset for iPhoneは無い・・・