Motive Game programming is built in as Python Games by default on Raspberry Pi, but I wondered if it could be done on Mac as well. All the games on the Raspberry Pi are made by myself, so it seemed that I couldn't get them completely, but I will introduce them because there was a similar library. It is "Free Python Games", a library created in 2012 for school education purposes. It seems that it is usually used in middle and high schools in the United States.
Method
python3 -m venv venv_game
source ./venv_game/bin/activate
pip install freegames
python3 -m freegames list
ant
bagels
bounce
cannon
connect
crypto
fidget
flappy
guess
life
maze
memory
minesweeper
pacman
paint
pong
simonsays
snake
tictactoe
tiles
tron
There are 21 types.
python3 -m freegames.pacman
You can play Pac-Man.
(From Free Python Games --Main page)
It's a common -m
option, but it seems to run insidemain ()
in the module.
Guess from the code on the Free Python Games Main page or Github To do. There are some games that are difficult to operate at first glance because there is no instruction manual if there is no hint.
An example is pong
(a table tennis game released by Atari. The world's first home video game).
pong.py
#Line:86-89
onkey(lambda: move(1, 20), 'w')
onkey(lambda: move(1, -20), 's')
onkey(lambda: move(2, 20), 'i')
onkey(lambda: move(2, -20), 'k')
player1 can operate the paddle up and down with w`` s
key and player2 with ʻi`` k`.
Learn The comments in the code at pacman contain exercises.
python
"""Pacman, classic arcade game.
Exercises
1. Change the board. (Let's change the board)
2. Change the number of ghosts. (Let's change the number of enemy characters)
3. Change where pacman starts. (Let's change the starting position of Pac-Man)
4. Make the ghosts faster/slower. (Let's change the speed of the enemy character)
5. Make the ghosts smarter. (Let's make the enemy character smarter)
"""
It seems that 1 to 4 are good, but the final problem requires full-scale thinking such as using machine learning or deep learning.
python3 -m freegames copy pacman
python3 pacman.py
If you simply change the color of the enemy character from red to green, it will be as follows.
pacman.py
#Line:126-142
#Maybe I'm moving an enemy character here
for point, course in ghosts:
if valid(point + course):
point.move(course)
else:
options = [
vector(5, 0),
vector(-5, 0),
vector(0, 5),
vector(0, -5),
]
plan = choice(options)
course.x = plan.x
course.y = plan.y
up()
goto(point.x + 10, point.y + 10)
dot(20, 'green') #dot(20, 'red')
Future
I introduced a Demo game that runs on python.
Since games like Pong
introduced above are also made simply, there is no CPU, so if you want to play alone, you will have to make your own CPU.
It's an old NES, but how did you implement the movement of enemy characters?: Sweat_smile:
Reference
Recommended Posts