Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
Signed-off-by: GuillaumeFalourd <[email protected]>
  • Loading branch information
GuillaumeFalourd committed Mar 8, 2021
2 parents 095af30 + 082efae commit 95ee3b2
Show file tree
Hide file tree
Showing 29 changed files with 822 additions and 129 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This repository contains Ritchie formulas which can be executed by [ritchie-cli]
- [Send Email](https://github.com/GuillaumeFalourd/formulas-python/tree/master/send/email): `rit send email`
- [Snake Game](https://github.com/GuillaumeFalourd/formulas-python/tree/master/game/snake): `rit game snake`
- [Flappy Bird Game](https://github.com/GuillaumeFalourd/formulas-python/tree/master/game/flappy-bird): `rit game flappy-bird`
- [Alien Invasion Game](https://github.com/GuillaumeFalourd/formulas-python/tree/master/game/alien-invasion): `rit game alien-invasion`

### Doing

Expand Down
Binary file added docs/img/rit-game-alien-invasion-formula.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/rit-game-alien-invasion-play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions face/recognition/src/formula/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def run(sample_picture, image_path, face_name):

# Create arrays of known face encodings and their names
known_face_encodings = [profile_face_encoding, reeves_face_encoding]
known_face_names = [face_name, "Keanu Reeves"]
known_face_names = [face_name, "K. Reeves"]
else:
# Create arrays of Keanu Reeves face encoding and his name
known_face_encodings = [reeves_face_encoding]
known_face_names = ["Keanu Reeves"]
known_face_names = ["K. Reeves"]

# Initialize some variables
face_locations = []
Expand Down
13 changes: 13 additions & 0 deletions game/alien-invasion/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ritclizup/rit-python3-runner

USER root

RUN mkdir /rit
COPY . /rit
RUN sed -i 's/\r//g' /rit/set_umask.sh
RUN sed -i 's/\r//g' /rit/run.sh
RUN chmod +x /rit/set_umask.sh

WORKDIR /app
ENTRYPOINT ["/rit/set_umask.sh"]
CMD ["/rit/run.sh"]
28 changes: 28 additions & 0 deletions game/alien-invasion/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The Makefile file will be deprecated in March 2021. It will be replaced by the current build.sh file
# SH
BINARY_NAME=run.sh
BINARY_NAME_WINDOWS=run.bat
BIN_FOLDER=bin
BIN_CONFIG_VENV=config_env.sh

build: python-build sh_unix bat_windows docker

python-build:
mkdir -p $(BIN_FOLDER)
cp -r src/* $(BIN_FOLDER)
pip3 install -r $(BIN_FOLDER)/requirements.txt --user --disable-pip-version-check

sh_unix:
echo '#!/bin/bash' > $(BIN_FOLDER)/$(BINARY_NAME)
echo 'if [ -f /.dockerenv ] ; then' >> $(BIN_FOLDER)/$(BINARY_NAME)
echo 'pip3 install -r "$$(dirname "$$0")"/requirements.txt --user --disable-pip-version-check >> /dev/null' >> $(BIN_FOLDER)/$(BINARY_NAME)
echo 'fi' >> $(BIN_FOLDER)/$(BINARY_NAME)
echo 'python3 "$$(dirname "$$0")"/main.py' >> $(BIN_FOLDER)/$(BINARY_NAME)
chmod +x $(BIN_FOLDER)/$(BINARY_NAME)

bat_windows:
echo '@ECHO OFF' > $(BIN_FOLDER)/$(BINARY_NAME_WINDOWS)
echo 'python main.py' >> $(BIN_FOLDER)/$(BINARY_NAME_WINDOWS)

docker:
cp Dockerfile set_umask.sh $(BIN_FOLDER)
17 changes: 17 additions & 0 deletions game/alien-invasion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ritchie Formula

## Command

```bash
rit game alien-invasion
```

## Description

Formula para jogar Alien Invasion usando o Ritchie.

## Demo

![Execution](/docs/img/rit-game-alien-invasion-formula.png)

![Game](/docs/img/rit-game-alien-invasion-play.png)
34 changes: 34 additions & 0 deletions game/alien-invasion/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:: Python parameters
echo off
SETLOCAL
SET BIN_FOLDER=bin
SET BAT_FILE=%BIN_FOLDER%\run.bat
SET SH_FILE=%BIN_FOLDER%\run.sh
:build
mkdir %BIN_FOLDER%
xcopy /E /I src %BIN_FOLDER%
CALL :BAT_WINDOWS
CALL :SH_LINUX
CALL :CP_DOCKER
pip3 install -r %BIN_FOLDER%/requirements.txt
GOTO DONE

:BAT_WINDOWS
echo @ECHO OFF > %BAT_FILE%
echo SET mypath=%%~dp0 >> %BAT_FILE%
echo start /B /D "%%mypath%%" /WAIT python main.py >> %BAT_FILE%

:SH_LINUX
echo #!/bin/bash > %SH_FILE%
echo if [ -f /.dockerenv ] ; then >> %SH_FILE%
echo pip3 install -r "$(dirname "$0")"/requirements.txt ^>^> /dev/null >> %SH_FILE%
echo fi >> %SH_FILE%
echo python3 "$(dirname "$0")"/main.py >> %SH_FILE%
GOTO DONE

:CP_DOCKER
copy Dockerfile %BIN_FOLDER%
copy set_umask.sh %BIN_FOLDER%
GOTO DONE

:DONE
29 changes: 29 additions & 0 deletions game/alien-invasion/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

BINARY_NAME=run.sh
BINARY_NAME_WINDOWS=run.bat
BIN_FOLDER=bin

#python-build:
mkdir -p $BIN_FOLDER
cp -r src/* $BIN_FOLDER
pip3 install -r $BIN_FOLDER/requirements.txt --user --disable-pip-version-check

#sh_unix:
{
echo "#!/bin/bash"
echo "if [ -f /.dockerenv ] ; then"
echo "pip3 install -r \$(dirname \"\$0\")/requirements.txt --user --disable-pip-version-check >> /dev/null"
echo "fi"
echo "python3 \$(dirname \"\$0\")/main.py"
} >> $BIN_FOLDER/$BINARY_NAME
chmod +x $BIN_FOLDER/$BINARY_NAME

#bat_windows:
{
echo "@ECHO OFF"
echo "python main.py"
} >> $BIN_FOLDER/$BINARY_NAME_WINDOWS

#docker:
cp Dockerfile set_umask.sh $BIN_FOLDER
15 changes: 15 additions & 0 deletions game/alien-invasion/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"dockerImageBuilder": "ritclizup/rit-python3-builder",
"inputs": [
{
"label": "Mode:",
"name": "rit_mode",
"type": "text",
"items": [
"EASY",
"MEDIUM",
"HARD"
]
}
]
}
17 changes: 17 additions & 0 deletions game/alien-invasion/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"execution": [
"local",
"docker"
],
"os": {
"deps": [],
"support": [
"windows",
"mac",
"linux"
]
},
"tags": [
"game", "alien-invasion"
]
}
3 changes: 3 additions & 0 deletions game/alien-invasion/set_umask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
umask 0011
$1
39 changes: 39 additions & 0 deletions game/alien-invasion/src/classes/alien.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pygame
from pygame.sprite import Sprite

class Alien(Sprite):
"""A class to represent a single alien in the fleet."""

def __init__(self, ai_settings, screen):
"""Initialize the alien and set its starting position."""
super(Alien, self).__init__()
self.screen = screen
self.ai_settings = ai_settings

# Load the alien image and set its rect attribute
self.image = pygame.image.load('images/alien.bmp')
self.rect = self.image.get_rect()

# Start each new alien near the top left of the screen.
self.rect.x = self.rect.width
self.rect.y = self.rect.height

# Store the alien's exact position.
self.x = float(self.rect.x)

def blitme(self):
"""Draw the alien at its current location."""
self.screen.blit(self.image, self.rect)

def check_edges(self):
"""Return True if alien is at the edge of screen."""
screen_rect = self.screen.get_rect()
if self.rect.right >= screen_rect.right:
return True
elif self.rect.left < 0:
return True

def update(self):
"""Move the alien right or left."""
self.x += (self.ai_settings.alien_speed_factor*self.ai_settings.fleet_direction)
self.rect.x = self.x
33 changes: 33 additions & 0 deletions game/alien-invasion/src/classes/bullet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pygame
from pygame.sprite import Sprite

class Bullet(Sprite):
"""A class to manage bullets fired from the ship."""

def __init__(self, ai_settings, screen, ship):
"""Create a bullet object at the ship's current position."""
super(Bullet, self).__init__()
#super().__init__()
self.screen = screen

# Create a bullet rect at (0, 0) and then set correct position.
self.rect = pygame.Rect(0, 0, ai_settings.bullet_width, ai_settings.bullet_height)
self.rect.centerx = ship.rect.centerx
self.rect.top = ship.rect.top

# Store the bullet's position as a decimal value
self.y = float(self.rect.y)

self.color = ai_settings.bullet_color
self.speed_factor = ai_settings.bullet_speed_factor

def update(self):
"""Move the bullet up the screen."""
# Update the decimal position of the bullet.
self.y -= self.speed_factor
# Update the rect position
self.rect.y = self.y

def draw_bullet(self):
"""Draw the bullet to the screen."""
pygame.draw.rect(self.screen, self.color, self.rect)
33 changes: 33 additions & 0 deletions game/alien-invasion/src/classes/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pygame.font

class Button():
"""Filled rectangle with a label."""

def __init__(self, ai_settings, screen, msg):
"""Initialize button attributes."""
self.screen = screen
self.screen_rect = screen.get_rect()

# Set dimensions and properties of the button.
self.width, self.height = 200, 50
self.button_color = (0, 255, 0)
self.text_color = (255, 255, 255)
self.font = pygame.font.SysFont(None, 48)

# Build the button's rect object and center it
self.rect = pygame.Rect(0, 0, self.width, self.height)
self.rect.center = self.screen_rect.center

# The button message needs to be prepped only once.
self.prep_msg(msg)

def prep_msg(self, msg):
"""Turn msg into a rendered image and center it on the button."""
self.msg_image = self.font.render(msg, True, self.text_color, self.button_color)
self.msg_image_rect = self.msg_image.get_rect()
self.msg_image_rect.center = self.rect.center

def draw_button(self):
"""Draw blank button and then draw message on it."""
self.screen.fill(self.button_color, self.rect)
self.screen.blit(self.msg_image, self.msg_image_rect)
Loading

0 comments on commit 95ee3b2

Please sign in to comment.