clockworkpi

[Repost with Snapshot] Install and Run Pygame on GameShell with Miniconda

Install and Run Pygame on GameShell with Miniconda

Step1: Connect to GameShell via ssh

>> ssh cpi@192.168.1.112
cpi@192.168.1.112's password: [type “cpi”]
Linux clockworkpi …
cpi@clockworkpi:~$ pwd 
/home/cpi

You can find the address to “ssh" to by navigating to “tiny cloud” in the GameShell. The default username and password are both “cpi”.

Create a folder “downloads” in “/home/cpi/“, where we will place the Miniconda install script later.

>> mkdir downloads
>> ls 
apps  downloads games  launcher  launchergo  music  skins

Step2: Download Miniconda for Linux and Move to GameShell

I already download the miniconda install script (https://repo.anaconda.com/miniconda/Miniconda-3.16.0-Linux-armv7l.sh, which is renamed miniconda-install.sh) on the computer and thus I just “scp” it to the GameShell. Alternatively, you can of course download the Anaconda install script directly to the GameShell after “ssh” to it.

~ >> cd ~/Downloads 
~/Downloads >> scp miniconda-install.sh cpi@192.168.1.112:/home/cpi/downloads

Wait until the transferring/downloading process done.

Step3: Install Miniconda on GameShell

Login to GameShell and install Miniconda.

>> ssh cpi@192.168.1.112
cpi@192.168.1.112's password: [type “cpi”]
Linux clockworkpi …
cpi@clockworkpi:~$ bash downloads/miniconda-install.sh
…

Read the terms and follow the promotions to install Miniconda. Then create the environment, say “first”, install “SDL” ([2]) and “pygame".

cpi@clockworkpi:~$ conda create -n first python=2.7
…

Step4: Install SDL ([2])

cpi@clockworkpi:~$ cd downloads
cpi@clockworkpi:~/downloads$ wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz
cpi@clockworkpi:~/downloads$ tar -xzvf SDL-1.2.14.tar.gz
cpi@clockworkpi:~/downloads$ cd SDL-1.2.14
cpi@clockworkpi:~/downloads$ ./configure --prefix=$HOME
cpi@clockworkpi:~/downloads$ make
cpi@clockworkpi:~/downloads$ make install

Step5: Install Pygame ([2])

cpi@clockworkpi:~$ source activate first
(first) cpi@clockworkpi:~$ cd downloads
(first) cpi@clockworkpi:~/downloads$ wget https://www.pygame.org/ftp/pygame-1.9.1release.tar.gz
(first) cpi@clockworkpi:~/downloads$ tar -xzvf pygame-1.9.1release.tar.gz
(first) cpi@clockworkpi:~/downloads$ cd pygame-1.9.1release

Comment out the line starting with “_camera” in “Setup”, and then install the “pygame” by running:

(first) cpi@clockworkpi:~/downloads$python setup.py install

Now you can import “pygame”.

(first) cpi@clockworkpi:~/downloads$python
Python 2.7.10 …
>>> import pygame

Step6: Create a Game and Start in GameShell

Connect to GameShell and navigate into the games. Create a repository “first_game” for the new game.

(first) cpi@clockworkpi:~$ cd games
(first) cpi@clockworkpi:~/games$ mkdir first_game

Create the pygame script “first.py” in “~/games/first_game".

import os, sys, random, time, datetime, math
import pygame
from pygame.locals import *
from pygame.color import *

GS_KEY_MENU = 27
GS_KEY_X = 117
GS_KEY_Y = 105
GS_KEY_A = 106
GS_KEY_B = 107
GS_KEY_UP = 273
GS_KEY_DOWN = 274
GS_KEY_RIGHT = 275
GS_KEY_LEFT = 276
GS_KEY_SELECT = 32
GS_KEY_START = 13

class First :
    def __init__(self) :
        self.width = 320
        self.height = 240
        self.delta = 0.2
        self.event = None

    def draw(self, screen) :
        pygame.display.flip()
        screen.fill(THECOLORS["white"])
        screen.blit(pygame.font.Font(None, 24).render("Hello world!", 1, THECOLORS["black"]), (10, 10))
        screen.blit(pygame.font.Font(None, 24).render("You pressed: %s" % self.event, 1, THECOLORS["black"]), (10, 50))
        pygame.display.flip()

    def run(self) :
        pygame.init()
        screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        screen.fill(THECOLORS["white"])
        clock = pygame.time.Clock()

        running = True
        while running :
            for event in pygame.event.get():
                if event.type == QUIT:
                    running = False
                elif event.type == KEYDOWN :
                    self.event = event.key
                    if event.key == GS_KEY_MENU :
                        running = False
            self.draw(screen)
            pygame.event.pump()
            clock.tick(1 / self.delta)

if __name__ == "__main__" :
    game = First()
    game.run()

Then create an entrance shell “11_First.sh” in the launcher of GameShell.

(first) cpi@clockworkpi:~$ cd launcher/Menu/GameShell
(first) cpi@clockworkpi:~$ vi 11_First.sh

The content of “11_First.sh” should be like this.

#! /bin/bash

source activate first
python ~/games/first_game/first.py

You can also make an icon for the new game, say a png picture “First.png”, and put it into “~/launcher/skin/default/Menu/GameShell”.

Reload the UI, and now you should see a new app named “First” in the launcher. Enter it, you will see “Hello world!” followed by a promotion to tell you the code of the last pressed key. If you followed exactly what are given in “first.py”, then you can exit the first game and back to the launcher by pressing the button “MENU” on the GameShell.

That’s all. Happy coding!

References
As there are limits on the number of links, you have to manually replace the slash after “https” to “://”

[1] https/docs.anaconda.com/anaconda/install/linux/
[2] https/community.webfaction.com/questions/315/how-do-i-install-pygame
[3] https/github.com/pvcraven/gameshell_template

屏幕快照 2020-07-11 下午9.32.02

2 Likes