-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
29 changed files
with
822 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
umask 0011 | ||
$1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.