Pygame на Android

Pygame Subset for Android отличная штука которая позволяет с минимальным количеством изменением кода портировать на Android,то что было написано для PC на библиотеке pygame. Помню что я как-то написал бинарные часы и сейчас меня приспичило их портировать, чтобы протестировать работоспособность.

1. Подключаем устройство по USB для режима отладки (Можно использовать виртуальную, но они достаточно сильно глючат)

После подключения к компьютеру, включите режим отладки на телефоне(планшете) Настройки --> Для разработчиков -->Отладка по USB

2. Скачиваем и распаковываем последнюю версию.

3. Тестирование на недостающие компоненты

$./android.py test

4. Установка AndroidSDK

$./android.py installsdk

5. Создаём каталог

mkdir binaryclock

6. Создаём в папке  файл 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


'''
************************************************************************
*Binary clock *
*Copyright (C) 2010 Komarov Alexander *
* *
*This program is free software: you can redistribute it and/or modify *
*it under the terms of the GNU General Public License as published by *
*the Free Software Foundation, either version 3 of the License, or *
*(at your option) any later version. *
* *
*This program is distributed in the hope that it will be useful, *
*but WITHOUT ANY WARRANTY; without even the implied warranty of *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See t *
*GNU General Public License for more details. *
*
*You should have received a copy of the GNU General Public License *
*along with this program. If not, see <http://www.gnu.org/licenses/>. *
************************************************************************'''

import sys
import time
class Clock:
     screen=pygame.display.set_mode((640,480))
     def __init__(self):
          pygame.init()
          pygame.display.set_caption('Binary Clock')

     def main(self):
         
         while True:
             for e in pygame.event.get():
                 if e.type == pygame.QUIT:
                     exit(0)
                 elif e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                     exit(0)
             self.capture()
             self.logic()
             pygame.display.flip()
             time.sleep(0.5)

     def capture(self):

         #Hour
         #Row1
         pygame.draw.circle(self.screen, (255, 255, 255), (70, 400), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (70, 300), 30 )
         #Row2
         pygame.draw.circle(self.screen, (255, 255, 255), (170, 400), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (170, 300), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (170, 200), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (170, 100), 30 )
         #Min
         #Row1
         pygame.draw.circle(self.screen, (255, 255, 255), (270, 400), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (270, 300), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (270, 200), 30 )
         #Row2
         pygame.draw.circle(self.screen, (255, 255, 255), (370, 400), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (370, 300), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (370, 200), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (370, 100), 30 )
         #Sec
         #Row1
         pygame.draw.circle(self.screen, (255, 255, 255), (470, 400), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (470, 300), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (470, 200), 30 )
         #Row2
         pygame.draw.circle(self.screen, (255, 255, 255), (570, 400), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (570, 300), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (570, 200), 30 )
         pygame.draw.circle(self.screen, (255, 255, 255), (570, 100), 30 )
     def logic(self):
         #Hour
         if int(time.asctime( time.localtime(time.time()) )[11])==1:
             pygame.draw.circle(self.screen, (255, 0, 0), (70, 400), 30 )
         if int(time.asctime( time.localtime(time.time()) )[11])==2:
             pygame.draw.circle(self.screen, (255, 0, 0), (70, 300), 30 )

         if int(time.asctime( time.localtime(time.time()) )[12])==1:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==2:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==3:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==4:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==5:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==6:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==7:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 300), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==8:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 100), 30 )
         if int(time.asctime( time.localtime(time.time()) )[12])==9:
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (170, 100), 30 )
         #Min
         if int(time.asctime( time.localtime(time.time()) )[14])==1:
            pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
         if int(time.asctime( time.localtime(time.time()) )[14])==2:
            pygame.draw.circle(self.screen, (255, 0, 0), (270, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[14])==3:
            pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (270, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[14])==4:
            pygame.draw.circle(self.screen, (255, 0, 0), (270, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[14])==5:
            pygame.draw.circle(self.screen, (255, 0, 0), (270, 200), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (270, 400), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==1:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==2:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==3:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==4:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==5:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==6:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==7:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 300), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==8:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 100), 30 )
         if int(time.asctime( time.localtime(time.time()) )[15])==9:
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (370, 100), 30 )
        #Sec
         if int(time.asctime( time.localtime(time.time()) )[17])==1:
            pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
         if int(time.asctime( time.localtime(time.time()) )[17])==2:
            pygame.draw.circle(self.screen, (255, 0, 0), (470, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[17])==3:
            pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (470, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[17])==4:
            pygame.draw.circle(self.screen, (255, 0, 0), (470, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[17])==5:
            pygame.draw.circle(self.screen, (255, 0, 0), (470, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (470, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==1:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==2:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==3:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==4:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==5:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==6:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==7:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 300), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 200), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==8:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 100), 30 )
         if int(time.asctime( time.localtime(time.time()) )[18])==9:
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 400), 30 )
            pygame.draw.circle(self.screen, (255, 0, 0), (570, 100), 30 )
     
     
start=Clock()
start.main()

 

Вы можите убедиться, что изминения с оригиналом минимальны. Сравнить.

7.Конфигурирование проекта (нужно ответить на вопросы)

./android.py configure binaryclock

8. Сборка пакета и установка пакета на устройство

./android.py build binaryclock release install

Возможная ошибка error: insufficient permissions for device Устройство не определено, чтобы оно корректно определилось, нужно сделать некоторые действия:

#usb-devices

T:  Bus=02 Lev=02 Prnt=02 Port=01 Cnt=01 Dev#= 15 Spd=480 MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=18d1 ProdID=0003 Rev=02.30
S:  Manufacturer=USB Developer
S:  Product=Android
S:  SerialNumber=20080411
C:  #Ifs= 2 Cfg#= 1 Atr=c0 MxPwr=500mA
I:  If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
I:  If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=42 Prot=01 Driver=usbfs

В вашем случае может быть немного не такие параметры, из всего списка нам нужен Vendor=18d1

Добавляем строки: #nano /etc/udev/rules.d/51-android.rules

SUBSYSTEM=="usb", SYSFS{idVendor}=="18d1", <---Vendor

SYMLINK+="android_adb", MODE="0666"

Применяем права:
# chmod a+r /etc/udev/rules.d/51-android.rules
Пробуем заново скомпилить проект.

 

9.Отладка

./android.py logcat

Ссылки:

http://pygame.renpy.org

Теги: , ,

Дата: 11 апреля 2012

Автор: ignusius

Комментарии: 374

Комментарии: 374

  1. remedio cialis 5mg [url=https://omgcialis.com/]cialis super active plus[/url] cialis caserta

  2. cialis niet eten [url=https://omgcialis.com/]cialis prices[/url] cialis livraison discrete

  3. does cialis enlarge [url=https://omgcialis.com/]best cialis pill[/url] using cialis for bodybuilding

  4. cialis n3 [url=https://omgcialis.com/]buy cialis online pharmacy[/url] cialis pump bodybuilding

  5. cialis charakterystyka [url=https://omgcialis.com/]daily cialis[/url] max dosis cialis

  6. cialis painful ejaculation [url=https://omgcialis.com/]canadian pharmacy cialis[/url] cialis penicillin

  7. review cialis vs viagra [url=https://omgcialis.com/]generic tadalafil 5mg price[/url] cialis generyczny najtaniej

  8. hydrochloroquin https://plaquenilx.com/# hydroxychloroquine medication

  9. [url=https://hqd.wiki/]почему hqd светится синим[/url]

    савеловский рынок электронные сигареты

  10. Xem đá Bóng Trực Tuyến Trực Tiếp đá Bóng Ngonhtv7 trực tuyếnCũng chủ yếu vì nguyên nhân này mà kênh Banthang TV luôn bị die link hay sập Server từng Khi có các trận đấu lớn, điều này khiến mang đến các người yêu thương thích soccer cực kỳ khó khăn chịu vì trận đấu bị loại gián đoạn thân chừng.

  11. Giày Bóng Rổ Chi Phí Rẻ Bền đẹp Nhất, Chi Phí Sốc, Nên Mua Ở Đâuxem k+pm onlineLần thứ nhất ra mắt thì giầy Jordan 1 có màu đỏ, trắng và đen phối với nhau. Với upper mỏng dính nhẹ nhõm và đế bền hơn cùng cỗ đệm lấy trực tiếp từ Crazylight Boost năm 2016, tạm thời Rose 8 cũng vô cùng đáng để test.

  12. По моему мнению Вы не правы. Могу это доказать. Пишите мне в PM, пообщаемся.
    нубы против зомби играть онлайн бесплатно

Оставить комментарий

*

Комментарий:

Ваш e-mail не будет опубликован.
Обязательные поля помечены *

Разрешенные HTML теги:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>