Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
6e3aeca232 | |||
59943dc54d | |||
792fec50d6 | |||
ec40c35fda | |||
ce7df429b9 | |||
557dc54acc | |||
bb0b2caa80 | |||
0d530b9ad6 | |||
041307a28c | |||
21d334ddb9 | |||
5008db05e1 | |||
9513e5d5bc | |||
c1771906e4 | |||
e31eec876a | |||
ed319f0a2e | |||
|
bd926a629d | ||
d9b25436e9 | |||
b5000a668d | |||
8a60d943fd | |||
0708cfb319 | |||
df30c40deb | |||
7e016819dc | |||
|
3db0ceaab3 | ||
437f336e5a |
232
.gitignore
vendored
Normal file
|
@ -0,0 +1,232 @@
|
|||
### C++ ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
### PlatformIO ###
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
||||
.pio
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
### Python Patch ###
|
||||
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
||||
poetry.toml
|
||||
|
||||
# ruff
|
||||
.ruff_cache/
|
||||
|
||||
# LSP config files
|
||||
pyrightconfig.json
|
||||
|
||||
### Vim ###
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
Sessionx.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
|
@ -1 +1,25 @@
|
|||
# JacoVirt
|
||||
|
||||
## How run the project ?
|
||||
|
||||
|
||||
Clone the project :
|
||||
~~~
|
||||
git clone https://git.afpy.org/MDL29/JacoBot.git
|
||||
~~~
|
||||
Go in the folder of project then in the virtual pad folder
|
||||
~~~
|
||||
cd Jacobot/jacovirt
|
||||
~~~
|
||||
Downloads dependencies and create a virtual environement
|
||||
~~~
|
||||
poetry install
|
||||
~~~
|
||||
Run the virtual pad with :
|
||||
~~~
|
||||
poetry run jacovirt pad
|
||||
~~~
|
||||
Run the virtual bot with :
|
||||
~~~
|
||||
poetry run jacovirt bot
|
||||
~~~
|
||||
|
|
Before Width: | Height: | Size: 455 KiB After Width: | Height: | Size: 455 KiB |
Before Width: | Height: | Size: 412 KiB After Width: | Height: | Size: 412 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/B.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/G.png
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/P.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/R.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/Y.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/boat.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/castle.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/city.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/mountain.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/start.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/tile_1.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/tile_2.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/tile_3.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/tile_4.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/tile_5.png
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/tile_6.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/tree.png
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
jacovirt/jacovirt/Img/bot/wooden/wave.png
Normal file
After Width: | Height: | Size: 34 KiB |
56
jacovirt/jacovirt/args.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
import argparse
|
||||
import logging
|
||||
|
||||
import jacovirt.logger
|
||||
|
||||
log_level = {
|
||||
"CRITICAL": logging.CRITICAL,
|
||||
"ERROR": logging.ERROR,
|
||||
"WARN": logging.WARNING,
|
||||
"INFO": logging.INFO,
|
||||
"DEBUG": logging.DEBUG,
|
||||
}
|
||||
|
||||
def main():
|
||||
|
||||
# General parser
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
|
||||
# Subparser
|
||||
sub = parser.add_subparsers(dest="sub")
|
||||
|
||||
parser.add_argument(
|
||||
"-l",
|
||||
"--log",
|
||||
choices=log_level.keys(),
|
||||
default="WARN",
|
||||
help=("Set level log"),
|
||||
dest="log",
|
||||
)
|
||||
|
||||
|
||||
# Parser for JacoVirt Pad
|
||||
pad = sub.add_parser("pad", help="Run JacoVirt Pad")
|
||||
|
||||
# Parser for JacoVirt Bot
|
||||
bot = sub.add_parser("bot", help="Run JacoVirt Bot")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.sub is None:
|
||||
parser.print_help()
|
||||
exit(1)
|
||||
|
||||
logging.getLogger().setLevel(args.log)
|
||||
|
||||
match args.sub:
|
||||
case "pad":
|
||||
logging.info("Lunch JacoVirt Pad")
|
||||
from jacovirt.pad import window
|
||||
window.main()
|
||||
case "bot":
|
||||
logging.info("Lunch JacoVirt Bot")
|
||||
from jacovirt.bot import window
|
||||
window.main()
|
||||
case _:
|
||||
SystemExit
|
51
jacovirt/jacovirt/bot/bot.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import arcade
|
||||
import logging
|
||||
|
||||
|
||||
class Bot(arcade.Sprite):
|
||||
"""
|
||||
Bot sprite
|
||||
"""
|
||||
def __init__(self, start, grid, scale=0.75):
|
||||
self.sprite = ":resources:images/space_shooter/playerShip1_green.png"
|
||||
|
||||
self.grid = grid
|
||||
self.pos = list(start)
|
||||
|
||||
super().__init__(self.sprite, scale, hit_box_algorithm="None")
|
||||
self.set_pos()
|
||||
self.angle = 270
|
||||
|
||||
def set_pos(self):
|
||||
for tile in self.grid.tiles:
|
||||
if tile.pos == tuple(self.pos):
|
||||
self.position = tile.position
|
||||
logging.debug(f"Move bot to {self.pos} - {self.position}")
|
||||
break
|
||||
|
||||
def left(self):
|
||||
self.angle += 90
|
||||
if self.angle >= 360:
|
||||
self.angle -=360
|
||||
|
||||
def right(self):
|
||||
self.angle -= 90
|
||||
if self.angle < 0:
|
||||
self.angle += 360
|
||||
|
||||
def forward(self):
|
||||
match self.angle:
|
||||
case 0:
|
||||
if self.pos[1] < self.grid.column - 1:
|
||||
self.pos[1] += 1
|
||||
case 90:
|
||||
if self.pos[0] > 0:
|
||||
self.pos[0] -= 1
|
||||
case 180:
|
||||
if self.pos[1] > 0:
|
||||
self.pos[1] -= 1
|
||||
case 270:
|
||||
if self.pos[0] < self.grid.row - 1:
|
||||
self.pos[0] += 1
|
||||
|
||||
self.set_pos()
|
61
jacovirt/jacovirt/bot/grid.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
import arcade
|
||||
|
||||
from importlib import resources
|
||||
|
||||
from jacovirt.bot.level import level
|
||||
|
||||
|
||||
class Tile(arcade.Sprite):
|
||||
"""
|
||||
Tile sprite
|
||||
"""
|
||||
def __init__(self, x, y, start_x, start_y, size=100, spacing=10, scale=0.5):
|
||||
self.pos = (x, y)
|
||||
|
||||
self.theme = level.get("theme")
|
||||
self.sprite = level.get(self.pos)
|
||||
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
self.image_file_name = f"{img_folder}/bot/{self.theme}/{self.sprite}.png"
|
||||
|
||||
self.size = size
|
||||
self.spacing = spacing
|
||||
|
||||
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
|
||||
self.position = (
|
||||
start_x + x * (self.size + self.spacing) + self.size / 2,
|
||||
start_y + y * (self.size + self.spacing) + self.size / 2
|
||||
)
|
||||
|
||||
def debug(self, size=10):
|
||||
arcade.draw_text(
|
||||
self.pos,
|
||||
self.left + self.spacing,
|
||||
self.bottom + self.spacing,
|
||||
arcade.color.BLACK,
|
||||
size,
|
||||
)
|
||||
|
||||
|
||||
class Grid():
|
||||
"""
|
||||
Grid object
|
||||
"""
|
||||
def __init__(self, x, y, row=6, column=6, size=100, spacing=10):
|
||||
self.row = row
|
||||
self.column = column
|
||||
self.pos = (x, y)
|
||||
self.tiles = arcade.SpriteList()
|
||||
|
||||
for r in range(row):
|
||||
for c in range(column):
|
||||
self.tiles.append(
|
||||
Tile(
|
||||
x=r,
|
||||
y=c,
|
||||
start_x=x,
|
||||
start_y=y,
|
||||
size=size,
|
||||
spacing=spacing
|
||||
)
|
||||
)
|
39
jacovirt/jacovirt/bot/level.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
level = {
|
||||
"theme": "wooden",
|
||||
(0,0): "wave",
|
||||
(0,1): "castle",
|
||||
(0,2): "wave",
|
||||
(0,3): "tile_1",
|
||||
(0,4): "R",
|
||||
(0,5): "start",
|
||||
(1,0): "city",
|
||||
(1,1): "tile_6",
|
||||
(1,2): "tile_3",
|
||||
(1,3): "tile_2",
|
||||
(1,4): "tree",
|
||||
(1,5): "tile_1",
|
||||
(2,0): "wave",
|
||||
(2,1): "wave",
|
||||
(2,2): "mountain",
|
||||
(2,3): "tile_4",
|
||||
(2,4): "wave",
|
||||
(2,5): "G",
|
||||
(3,0): "B",
|
||||
(3,1): "tile_2",
|
||||
(3,2): "tile_4",
|
||||
(3,3): "Y",
|
||||
(3,4): "wave",
|
||||
(3,5): "tile_2",
|
||||
(4,0): "wave",
|
||||
(4,1): "P",
|
||||
(4,2): "tile_3",
|
||||
(4,3): "tile_1",
|
||||
(4,4): "tile_2",
|
||||
(4,5): "tile_5",
|
||||
(5,0): "wave",
|
||||
(5,1): "tile_1",
|
||||
(5,2): "wave",
|
||||
(5,3): "boat",
|
||||
(5,4): "tile_1",
|
||||
(5,5): "tile_4",
|
||||
}
|
79
jacovirt/jacovirt/bot/window.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
import arcade
|
||||
import jacovirt.logger
|
||||
import logging
|
||||
|
||||
from jacovirt.bot.grid import Grid
|
||||
from jacovirt.bot.bot import Bot
|
||||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "JacoVirt Bot"
|
||||
SCREEN_WIDTH = int(1000)
|
||||
SCREEN_HEIGHT = int(1000)
|
||||
|
||||
# Window color
|
||||
BACKGROUND_COLOR = arcade.color.CATALINA_BLUE
|
||||
|
||||
COLUMN = 6
|
||||
ROW = 6
|
||||
SIZE_TILE = 100
|
||||
SPACING = 10
|
||||
X_START = (SCREEN_HEIGHT - (SIZE_TILE + SPACING) * ROW) / 2
|
||||
Y_START = (SCREEN_WIDTH - (SIZE_TILE + SPACING) * COLUMN) / 2
|
||||
|
||||
|
||||
class Window(arcade.Window):
|
||||
"""Main application class"""
|
||||
|
||||
def __init__(self):
|
||||
# Init parent class
|
||||
super().__init__(int(SCREEN_WIDTH), int(SCREEN_HEIGHT), SCREEN_TITLE)
|
||||
# Set background color
|
||||
arcade.set_background_color(BACKGROUND_COLOR)
|
||||
|
||||
self.grid = None
|
||||
self.bot = None
|
||||
|
||||
def setup(self):
|
||||
"""Set up the pad"""
|
||||
logging.info("Set up the bot.")
|
||||
|
||||
self.grid = Grid(X_START, Y_START, ROW, COLUMN, SIZE_TILE, SPACING)
|
||||
self.bot = Bot((0,5), self.grid)
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
|
||||
# Clear the screen
|
||||
self.clear()
|
||||
|
||||
# Draw tiles
|
||||
self.grid.tiles.draw()
|
||||
|
||||
# If debug log level, draw info for tiles
|
||||
if logging.root.level <= logging.DEBUG:
|
||||
for tile in self.grid.tiles:
|
||||
tile.debug()
|
||||
|
||||
self.bot.draw()
|
||||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
if symbol == arcade.key.R:
|
||||
logging.info("Restart !")
|
||||
self.setup()
|
||||
|
||||
if symbol == arcade.key.Q:
|
||||
arcade.exit()
|
||||
|
||||
if symbol == arcade.key.LEFT:
|
||||
self.bot.left()
|
||||
if symbol == arcade.key.RIGHT:
|
||||
self.bot.right()
|
||||
if symbol == arcade.key.UP:
|
||||
self.bot.forward()
|
||||
|
||||
def main():
|
||||
"""Main method"""
|
||||
window = Window()
|
||||
window.setup()
|
||||
arcade.run()
|
9
jacovirt/jacovirt/instruction.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from datetime import datetime
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Instruction(BaseModel):
|
||||
move: Literal["FORWARD", "LEFT", "RIGHT"]
|
||||
timestamp: datetime
|
||||
source: str
|
|
@ -1,160 +0,0 @@
|
|||
import turtle
|
||||
from importlib import resources
|
||||
import math
|
||||
from time import sleep
|
||||
import redis
|
||||
|
||||
r = redis.Redis(host="localhost")
|
||||
|
||||
mobile = r.pubsub()
|
||||
|
||||
mobile.subscribe('jacobot-instructions')
|
||||
|
||||
poscubettox = 0
|
||||
poscubettoy = 0
|
||||
|
||||
xstart = 0
|
||||
ystart = 0
|
||||
|
||||
xmax = 5
|
||||
ymax = 5
|
||||
|
||||
distance = 0
|
||||
angle = 0
|
||||
|
||||
theme = 0
|
||||
|
||||
def main():
|
||||
|
||||
def dark_theme():
|
||||
global posxstart, posystart, distance, theme
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
turtle.bgpic(str(img_folder/ "Background_dark.png"))
|
||||
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_droite_dark.gif"))
|
||||
turtle.shapesize(3,3,6)
|
||||
|
||||
distance = 84
|
||||
|
||||
posxstart = -211
|
||||
posystart = 200
|
||||
|
||||
theme = 1
|
||||
|
||||
def light_theme():
|
||||
global posxstart, posystart, distance, theme
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
turtle.bgpic(str(img_folder/ "Background_light.png"))
|
||||
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_droite_light.gif"))
|
||||
turtle.shapesize(10,10,6)
|
||||
|
||||
distance = 90
|
||||
|
||||
posxstart = -226
|
||||
posystart = 225
|
||||
|
||||
theme = 2
|
||||
|
||||
def cubetto_init():
|
||||
global posxstart, posystart, distance
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_haut_dark.gif"))
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_bas_dark.gif"))
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_gauche_dark.gif"))
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_droite_dark.gif"))
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_haut_light.gif"))
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_bas_light.gif"))
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_gauche_light.gif"))
|
||||
turtle.register_shape(str(img_folder/ "Cubetto_forme_droite_light.gif"))
|
||||
|
||||
dark_theme()
|
||||
|
||||
turtle.penup()
|
||||
turtle.goto(posxstart, posystart)
|
||||
|
||||
def cubetto_forme_init():
|
||||
global angle, theme
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
if angle == 360 or angle == -360:
|
||||
angle=0
|
||||
if angle == 0:
|
||||
if theme == 1:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_droite_dark.gif"))
|
||||
elif theme == 2:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_droite_light.gif"))
|
||||
if angle == 90 or angle == -270:
|
||||
if theme == 1:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_haut_dark.gif"))
|
||||
elif theme == 2:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_haut_light.gif"))
|
||||
if angle == 180 or angle == -180:
|
||||
if theme == 1:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_gauche_dark.gif"))
|
||||
elif theme == 2:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_gauche_light.gif"))
|
||||
if angle == 270 or angle == -90:
|
||||
if theme == 1:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_bas_dark.gif"))
|
||||
elif theme == 2:
|
||||
turtle.shape(str(img_folder/ "Cubetto_forme_bas_light.gif"))
|
||||
|
||||
def cubetto_forward():
|
||||
global xmax, ymax, xstart, ystart, distance, poscubettox, poscubettoy
|
||||
|
||||
FuturXRight = (poscubettox+1)
|
||||
FuturXLeft = (poscubettox-1)
|
||||
FuturYTop = (poscubettoy-1)
|
||||
FuturYBottom = (poscubettoy+1)
|
||||
|
||||
turtle.forward(distance)
|
||||
|
||||
if angle == 0 and FuturXRight <= xmax:
|
||||
poscubettox += 1
|
||||
|
||||
elif (angle == 90 or angle == -270) and FuturYTop >= ystart:
|
||||
poscubettoy -= 1
|
||||
|
||||
elif (angle == 180 or angle == -180) and FuturXLeft >= xstart:
|
||||
poscubettox -= 1
|
||||
|
||||
elif (angle == 270 or angle == -90) and FuturYBottom <= ymax:
|
||||
poscubettoy += 1
|
||||
|
||||
else:
|
||||
print("You are out of the carpet !")
|
||||
exit()
|
||||
|
||||
def cubetto_left():
|
||||
global angle
|
||||
turtle.left(90)
|
||||
angle += 90
|
||||
cubetto_forme_init()
|
||||
|
||||
def cubetto_right():
|
||||
global angle
|
||||
turtle.right(90)
|
||||
angle -= 90
|
||||
cubetto_forme_init()
|
||||
|
||||
cubetto_init()
|
||||
|
||||
while True:
|
||||
for m_recu in mobile.listen():
|
||||
|
||||
if m_recu:
|
||||
m_data = m_recu["data"]
|
||||
|
||||
if m_data == b"FORWARD":
|
||||
cubetto_forward()
|
||||
elif m_data == b"LEFT":
|
||||
cubetto_left()
|
||||
elif m_data == b"RIGHT":
|
||||
cubetto_right()
|
||||
elif m_data == b"INIT":
|
||||
cubetto_init()
|
||||
elif m_data == b"EXIT":
|
||||
exit()
|
||||
sleep(0.3)
|
||||
|
||||
main()
|
8
jacovirt/jacovirt/logger.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import logging
|
||||
from rich.logging import RichHandler
|
||||
|
||||
# Set level INFO log for Arcade library
|
||||
logging.getLogger("arcade").setLevel(logging.INFO)
|
||||
|
||||
# Logger config
|
||||
logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s", datefmt="%m/%d/%Y %H:%M:%S", handlers=[RichHandler()])
|
|
@ -1,340 +0,0 @@
|
|||
import arcade
|
||||
import os.path
|
||||
from importlib import resources
|
||||
import redis
|
||||
|
||||
|
||||
# Redis setting
|
||||
host = "localhost"
|
||||
channel = "jacobot-instructions"
|
||||
|
||||
SCREEN_MULTILPLIER = 1.5
|
||||
SCREEN_MULTILPLIER /= 4
|
||||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "Jaco Pad"
|
||||
SCREEN_WIDTH = int(2000* SCREEN_MULTILPLIER)
|
||||
SCREEN_HEIGHT = int(2000* SCREEN_MULTILPLIER)
|
||||
|
||||
#Token row
|
||||
TOKEN_ROW = 8
|
||||
|
||||
# Token size
|
||||
TOKEN_HEIGHT = int(160 * SCREEN_MULTILPLIER)
|
||||
TOKEN_WIDTH = int(160 * SCREEN_MULTILPLIER)
|
||||
|
||||
# Token scale
|
||||
HELD_TOKEN_SCALE_MULTILPLIER = 1.4
|
||||
|
||||
# Space between tokens
|
||||
X_SPACING_TOKEN = int(45*SCREEN_MULTILPLIER + TOKEN_WIDTH)
|
||||
Y_SPACING_TOKEN = int(45*SCREEN_MULTILPLIER + TOKEN_HEIGHT)
|
||||
|
||||
# Token start
|
||||
X_TOKEN_START = int(108*SCREEN_MULTILPLIER + TOKEN_WIDTH / 2)
|
||||
Y_TOKEN_START = int(1618*SCREEN_MULTILPLIER + TOKEN_HEIGHT / 2)
|
||||
|
||||
# List of token types
|
||||
TOKEN_TYPES = ["up", "left", "right", "function"]
|
||||
|
||||
#Mat start
|
||||
X_MAT_START = int(1072 * SCREEN_MULTILPLIER)
|
||||
Y_MAT_START = int(1648 * SCREEN_MULTILPLIER)
|
||||
X_MAT_FUNCTION_START = X_MAT_START
|
||||
Y_MAT_FUNCTION_START = int(510 * SCREEN_MULTILPLIER)
|
||||
|
||||
# Mat size
|
||||
MAT_HEIGHT = int(200 * SCREEN_MULTILPLIER)
|
||||
MAT_WIDTH = int(200 * SCREEN_MULTILPLIER)
|
||||
|
||||
# Number of column & row mat
|
||||
MAT_COLUMN = 4
|
||||
MAT_ROW = 4
|
||||
MAT_FUNCTION_ROW = 2
|
||||
|
||||
# Space between mats
|
||||
X_SPACING_MAT = int(MAT_WIDTH + 30 * SCREEN_MULTILPLIER)
|
||||
Y_SPACING_MAT = int(MAT_WIDTH + 30 * SCREEN_MULTILPLIER)
|
||||
|
||||
# Image
|
||||
X_START_MAIN_MAT_IMAGE = 1415 * SCREEN_MULTILPLIER
|
||||
Y_START_MAIN_MAT_IMAGE = 1304 * SCREEN_MULTILPLIER
|
||||
X_START_FUNCTION_MAT_IMAGE = X_START_MAIN_MAT_IMAGE
|
||||
Y_START_FUNCTION_MAT_IMAGE = 393 * SCREEN_MULTILPLIER
|
||||
|
||||
# Couleur
|
||||
BACKGROUND_COLOR = (133, 100, 100)
|
||||
|
||||
|
||||
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
class Start_mat(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMBER):
|
||||
super().__init__(width, height, color)
|
||||
|
||||
class Mat(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMBER):
|
||||
super().__init__(width, height, color)
|
||||
|
||||
class Mat_function(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMBER):
|
||||
super().__init__(width, height, color)
|
||||
|
||||
class Token_sprite(arcade.Sprite):
|
||||
""" Token sprite """
|
||||
|
||||
def __init__(self, token_type, scale=1):
|
||||
# Attributes for token type
|
||||
self.token_type = token_type
|
||||
scale *= SCREEN_MULTILPLIER
|
||||
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
self.image_file_name = fr"{img_folder}/pad/token/{self.token_type}.png"
|
||||
|
||||
# Call the parent
|
||||
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
|
||||
|
||||
class Image(arcade.Sprite):
|
||||
def __init__(self, file_name, scale=1):
|
||||
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
self.image_file_name = f"{img_folder}/pad/{file_name}"
|
||||
|
||||
scale *= SCREEN_MULTILPLIER
|
||||
# Call the parent
|
||||
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
|
||||
|
||||
|
||||
|
||||
class Cubito(arcade.Window):
|
||||
"""Main application class"""
|
||||
|
||||
def __init__(self):
|
||||
# Init parent class
|
||||
super().__init__(int(SCREEN_WIDTH), int(SCREEN_HEIGHT), SCREEN_TITLE)
|
||||
# Set background color
|
||||
arcade.set_background_color(BACKGROUND_COLOR)
|
||||
|
||||
# Connection to Redis
|
||||
self.r = redis.Redis(host=host)
|
||||
|
||||
|
||||
# List of tokens
|
||||
self.token_list = None
|
||||
|
||||
# Hold token
|
||||
self.held_token = None
|
||||
|
||||
# Origin pos for hold token
|
||||
self.held_token_original_position = None
|
||||
|
||||
#List of start mats
|
||||
self.start_mat_list = None
|
||||
|
||||
# List of mats
|
||||
self.mat_list = None
|
||||
|
||||
# List of mats function
|
||||
self.mat_function_list = None
|
||||
|
||||
# List of mats
|
||||
self.image_list = None
|
||||
|
||||
def setup(self):
|
||||
"""Set up the game"""
|
||||
|
||||
# Token we are dragging with the mouse
|
||||
self.held_token = None
|
||||
|
||||
# Original location of token we are dragging with the mouse in case
|
||||
# they have to go back.
|
||||
self.held_token_original_position = None
|
||||
|
||||
self.token_list = arcade.SpriteList()
|
||||
self.mat_list = arcade.SpriteList()
|
||||
self.start_mat_list = arcade.SpriteList()
|
||||
self.mat_function_list = arcade.SpriteList()
|
||||
self.image_list = arcade.SpriteList()
|
||||
|
||||
for y in range(TOKEN_ROW):
|
||||
x = X_TOKEN_START
|
||||
for token_type in TOKEN_TYPES:
|
||||
#placer les tokens
|
||||
token = Token_sprite(token_type)
|
||||
token.position = x, Y_TOKEN_START - Y_SPACING_TOKEN * y
|
||||
x += X_SPACING_TOKEN
|
||||
self.token_list.append(token)
|
||||
token.token_type
|
||||
|
||||
#placer des cases sous les tokens
|
||||
start_mat = Start_mat(MAT_HEIGHT, MAT_WIDTH, color=arcade.color.BEIGE)
|
||||
start_mat.position = x - X_SPACING_TOKEN, Y_TOKEN_START - Y_SPACING_TOKEN * y
|
||||
self.start_mat_list.append(start_mat)
|
||||
|
||||
# Placer les cases principales
|
||||
for y in range(MAT_ROW):
|
||||
for x in range(MAT_COLUMN):
|
||||
mat = Mat(MAT_HEIGHT, MAT_WIDTH)
|
||||
mat.position = X_MAT_START + X_SPACING_MAT * x, Y_MAT_START - Y_SPACING_MAT * y
|
||||
self.mat_list.append(mat)
|
||||
|
||||
# Placer les cases fonctions
|
||||
for y in range(MAT_FUNCTION_ROW):
|
||||
for x in range(MAT_COLUMN):
|
||||
mat = Mat_function(MAT_HEIGHT, MAT_WIDTH, arcade.color.BABY_BLUE)
|
||||
mat.position = X_MAT_FUNCTION_START + X_SPACING_MAT * x, Y_MAT_FUNCTION_START - Y_SPACING_MAT * y
|
||||
self.mat_function_list.append(mat)
|
||||
|
||||
# Placer les images
|
||||
image = Image(file_name="case/Principal.png", scale=1)
|
||||
image.position = X_START_MAIN_MAT_IMAGE, Y_START_MAIN_MAT_IMAGE
|
||||
self.image_list.append(image)
|
||||
|
||||
image = Image(file_name="case/Fonction.png", scale=1)
|
||||
image.position = X_START_FUNCTION_MAT_IMAGE, Y_START_FUNCTION_MAT_IMAGE
|
||||
self.image_list.append(image)
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
# Clear the screen
|
||||
self.clear()
|
||||
|
||||
#Draw the images
|
||||
self.image_list.draw()
|
||||
|
||||
#Draw the mat
|
||||
# self.mat_list.draw()
|
||||
# self.start_mat_list.draw()
|
||||
# self.mat_function_list.draw()
|
||||
|
||||
# Draw the token
|
||||
self.token_list.draw()
|
||||
|
||||
|
||||
def pull_to_top(self, token: arcade.Sprite):
|
||||
""" Pull token to top of rendering order (last to render, looks on-top) """
|
||||
|
||||
# Remove, and append to the end
|
||||
self.token_list.remove(token)
|
||||
self.token_list.append(token)
|
||||
|
||||
def on_mouse_press(self, x, y, button, key_modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
|
||||
# Get list of tokens we've clicked on
|
||||
tokens = arcade.get_sprites_at_point((x, y), self.token_list)
|
||||
|
||||
|
||||
# Have we clicked on a token?
|
||||
if len(tokens) > 0:
|
||||
|
||||
# Might be a stack of tokens, get the top one
|
||||
primary_token = tokens[-1]
|
||||
|
||||
# All other cases, grab the token we are clicking on
|
||||
self.held_token = primary_token
|
||||
# Save the position
|
||||
self.held_token_original_position = self.held_token.position
|
||||
|
||||
# Expand the size of token
|
||||
self.held_token.scale *= HELD_TOKEN_SCALE_MULTILPLIER
|
||||
|
||||
# Put on top in drawing order
|
||||
self.pull_to_top(self.held_token)
|
||||
|
||||
|
||||
def on_mouse_release(self, x, y, button, modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
def collision(reset_position, list_mat):
|
||||
# Find the closest mat, in case we are in contact with more than one
|
||||
mat, distance = arcade.get_closest_sprite(self.held_token, list_mat)
|
||||
|
||||
# See if we are in contact with the closest mat
|
||||
if arcade.check_for_collision(self.held_token, mat):
|
||||
# Reduce the size of token
|
||||
self.held_token.scale /= HELD_TOKEN_SCALE_MULTILPLIER
|
||||
|
||||
# Center the token
|
||||
self.held_token.position = mat.center_x, mat.center_y
|
||||
|
||||
# Success, don't reset position of tokens
|
||||
reset_position = False
|
||||
|
||||
return reset_position
|
||||
|
||||
|
||||
# If we don't have any tokens, who cares
|
||||
if self.held_token == None:
|
||||
return
|
||||
|
||||
reset_position = True
|
||||
reset_position = collision(reset_position, self.mat_list)
|
||||
reset_position = collision(reset_position, self.start_mat_list)
|
||||
reset_position = collision(reset_position, self.mat_function_list)
|
||||
|
||||
if reset_position:
|
||||
# Where-ever we were dropped, it wasn't valid. Reset the each token's position
|
||||
# to its original spot.
|
||||
self.held_token.position = self.held_token_original_position
|
||||
|
||||
# Reduce the size of token
|
||||
self.held_token.scale /= HELD_TOKEN_SCALE_MULTILPLIER
|
||||
|
||||
|
||||
# We are no longer holding tokens
|
||||
self.held_token = None
|
||||
|
||||
|
||||
def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
|
||||
"""Called when the user moves the mouse"""
|
||||
|
||||
# If we are holding token, move it with the mouse
|
||||
if self.held_token != None:
|
||||
self.held_token.center_x += dx
|
||||
self.held_token.center_y += dy
|
||||
|
||||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
if symbol == arcade.key.R:
|
||||
self.setup()
|
||||
print("Restart !")
|
||||
|
||||
if symbol == arcade.key.Q:
|
||||
arcade.exit()
|
||||
|
||||
if symbol == arcade.key.S:
|
||||
self.cubito()
|
||||
|
||||
|
||||
def cubito(self, function=False):
|
||||
"""Move cubito !"""
|
||||
|
||||
if function:
|
||||
list = self.mat_function_list
|
||||
else:
|
||||
list = self.mat_list
|
||||
|
||||
for mat in list:
|
||||
token, distance = arcade.get_closest_sprite(mat, self.token_list)
|
||||
if arcade.check_for_collision(token, mat):
|
||||
token_type = str(token.token_type)
|
||||
if token_type == "up":
|
||||
self.r.publish(channel, "FORWARD")
|
||||
if token_type == "left":
|
||||
self.r.publish(channel, "LEFT")
|
||||
if token_type == "right":
|
||||
self.r.publish(channel, "RIGHT")
|
||||
if token_type == "function":
|
||||
if function:
|
||||
return
|
||||
else:
|
||||
self.cubito(function=True)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
"""Main method"""
|
||||
window = Cubito()
|
||||
window.setup()
|
||||
arcade.run()
|
49
jacovirt/jacovirt/pad/token.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import arcade
|
||||
from importlib import resources
|
||||
|
||||
|
||||
class Token(arcade.Sprite):
|
||||
""" Token sprite """
|
||||
|
||||
def __init__(self, token_type, scale=1):
|
||||
# Attributes for token type
|
||||
self.token_type = token_type
|
||||
|
||||
with resources.path("jacovirt", 'Img') as img_folder :
|
||||
self.image_file_name = f"{img_folder}/pad/token/{self.token_type}.png"
|
||||
|
||||
# Call the parent
|
||||
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
|
||||
|
||||
|
||||
class Token_generator(arcade.Sprite):
|
||||
""" Token generator sprite """
|
||||
|
||||
def __init__(self, token_type, scale=1):
|
||||
# Attributes for token type
|
||||
self.type = token_type
|
||||
|
||||
self.image_file_name = ":resources:images/tiles/boxCrate_double.png"
|
||||
|
||||
self.tokens = arcade.SpriteList()
|
||||
|
||||
# Call the parent
|
||||
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
|
||||
|
||||
def create_token(self, x, y):
|
||||
# Create a token
|
||||
token = Token(self.type)
|
||||
token.position = x, y
|
||||
self.tokens.append(token)
|
||||
return token
|
||||
|
||||
def draw_tokens(self):
|
||||
self.tokens.draw()
|
||||
|
||||
|
||||
class Token_trash(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMERICAN_ROSE):
|
||||
super().__init__(width, height, color)
|
||||
|
||||
def remove_token(self, held_token):
|
||||
held_token.remove_from_sprite_lists()
|
188
jacovirt/jacovirt/pad/window.py
Normal file
|
@ -0,0 +1,188 @@
|
|||
import arcade
|
||||
import jacovirt.logger
|
||||
import logging
|
||||
from jacovirt.pad.token import Token, Token_generator, Token_trash
|
||||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "Jaco Pad"
|
||||
SCREEN_WIDTH = int(1000)
|
||||
SCREEN_HEIGHT = int(1000)
|
||||
|
||||
# Window color
|
||||
BACKGROUND_COLOR = (133, 100, 100)
|
||||
|
||||
|
||||
class Window(arcade.Window):
|
||||
"""Main application class"""
|
||||
|
||||
def __init__(self):
|
||||
# Init parent class
|
||||
super().__init__(int(SCREEN_WIDTH), int(SCREEN_HEIGHT), SCREEN_TITLE)
|
||||
# Set background color
|
||||
arcade.set_background_color(BACKGROUND_COLOR)
|
||||
|
||||
# List of token generator
|
||||
self.tokens_generator = arcade.SpriteList()
|
||||
|
||||
# List of trash
|
||||
self.tokens_trash = arcade.SpriteList()
|
||||
|
||||
# The held token
|
||||
self.held_token = None
|
||||
|
||||
# List of tokens
|
||||
self.tokens = arcade.SpriteList()
|
||||
|
||||
def setup(self):
|
||||
"""Set up the pad"""
|
||||
logging.debug("Set up the pad.")
|
||||
|
||||
# Create a token
|
||||
token = Token("up", 1)
|
||||
token.position = 500, 500
|
||||
self.tokens.append(token)
|
||||
|
||||
# Create a token generator
|
||||
token_generator = Token_generator("up", 1)
|
||||
token_generator.position = 200, 500
|
||||
self.tokens_generator.append(token_generator)
|
||||
|
||||
# Create a other token generator
|
||||
token_generator = Token_generator("right", 1)
|
||||
token_generator.position = 800, 500
|
||||
self.tokens_generator.append(token_generator)
|
||||
|
||||
# Create a trash for token
|
||||
trash = Token_trash(200, 200)
|
||||
trash.position = 500, 800
|
||||
self.tokens_trash.append(trash)
|
||||
|
||||
# Create a camera
|
||||
self.camera = arcade.Camera()
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
|
||||
self.camera.use()
|
||||
|
||||
# Clear the screen
|
||||
self.clear()
|
||||
|
||||
# Draw the token generator
|
||||
self.tokens_generator.draw()
|
||||
|
||||
# Draw the trash
|
||||
self.tokens_trash.draw()
|
||||
|
||||
# Draw the tokens
|
||||
self.tokens.draw()
|
||||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
logging.debug(f"User press {symbol}, {modifiers}")
|
||||
|
||||
if symbol == arcade.key.R:
|
||||
self.setup()
|
||||
print("Restart !")
|
||||
|
||||
if symbol == arcade.key.Q:
|
||||
arcade.exit()
|
||||
|
||||
if symbol == arcade.key.F:
|
||||
# When the user hits f. Flip between full and not full screen.
|
||||
if self.fullscreen:
|
||||
# If in fullscreen, switch to windowed mode
|
||||
self.set_fullscreen(False)
|
||||
|
||||
# Resize the camera to match the window size
|
||||
width, height = self.get_size()
|
||||
self.camera.resize(width, height)
|
||||
|
||||
# Reset camera position
|
||||
self.camera.move((0, 0))
|
||||
|
||||
else:
|
||||
# If not in fullscreen, switch to fullscreen mode
|
||||
|
||||
# Remember the previous window size
|
||||
last_width, last_height = self.get_size()
|
||||
|
||||
# Switch to fullscreen
|
||||
self.set_fullscreen(True)
|
||||
|
||||
# Adjust camera and window size for fullscreen
|
||||
width, height = self.get_size()
|
||||
self.camera.resize(width, height)
|
||||
|
||||
# Calculate the difference in center position between last window size and new fullscreen size
|
||||
self.x_fullscreen_diff = (last_width - width) / 2
|
||||
self.y_fullscreen_diff = (last_height - height) / 2
|
||||
|
||||
# Move camera to keep the same center point in the game
|
||||
self.camera.move((self.x_fullscreen_diff, self.y_fullscreen_diff))
|
||||
|
||||
|
||||
def on_mouse_press(self, x, y, button, key_modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
logging.debug(f"Mouse pressed at {x},{y}")
|
||||
|
||||
# If the game is in fullscreen mode, adjust mouse coordinates
|
||||
if self.fullscreen:
|
||||
x = x + self.x_fullscreen_diff
|
||||
y = y + self.y_fullscreen_diff
|
||||
logging.debug(f"Mouse pressed at {x}, {y} in the game window in full screen")
|
||||
|
||||
# Get list of tokens we've clicked on
|
||||
tokens = arcade.get_sprites_at_point((x, y), self.tokens)
|
||||
|
||||
# Have we clicked on a token?
|
||||
if len(tokens) > 0:
|
||||
# Might be a stack of tokens, get the top one
|
||||
primary_token = tokens[-1]
|
||||
|
||||
# All other cases, grab the token we are clicking on
|
||||
self.held_token = primary_token
|
||||
|
||||
return
|
||||
|
||||
# Get the list of generator we've clicked on
|
||||
generators = arcade.get_sprites_at_point((x, y), self.tokens_generator)
|
||||
|
||||
# Have we clicked on a generator ?
|
||||
if len(generators) > 0:
|
||||
generator = generators[-1]
|
||||
logging.debug(f"Cliced on the generator of {generator.type}")
|
||||
|
||||
# Create a token and take it
|
||||
self.held_token = generator.create_token(x, y)
|
||||
self.tokens.append(self.held_token)
|
||||
|
||||
def on_mouse_release(self, x, y, button, modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
logging.debug(f"Mouse relase at {x},{y}")
|
||||
|
||||
if self.held_token is not None:
|
||||
# Find the closest trash
|
||||
trash, distance = arcade.get_closest_sprite(self.held_token, self.tokens_trash)
|
||||
|
||||
# See if we are in contact with the closest trash, if yes delete the held token
|
||||
if arcade.check_for_collision(self.held_token, trash):
|
||||
trash.remove_token(self.held_token)
|
||||
|
||||
# Remove the token from the hand
|
||||
self.held_token = None
|
||||
|
||||
def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
|
||||
"""Called when the user moves the mouse"""
|
||||
|
||||
# If we are holding token, move it with the mouse
|
||||
if self.held_token != None:
|
||||
self.held_token.center_x += dx
|
||||
self.held_token.center_y += dy
|
||||
|
||||
|
||||
def main():
|
||||
"""Main method"""
|
||||
window = Window()
|
||||
window.setup()
|
||||
arcade.run()
|
|
@ -9,15 +9,19 @@ readme = "README.md"
|
|||
python = "^3.11"
|
||||
arcade = "^2.6.17"
|
||||
redis = "^5.0.3"
|
||||
pydantic = "^2.7.1"
|
||||
rich = "^13.7.1"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
flake8 = "^7.0.0"
|
||||
pdbr = "^0.8.8"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
jacovirt-bot = "jacovirt.jacobot:main"
|
||||
jacovirt-pad = "jacovirt.pad.jacopad:main"
|
||||
jacovirt = "jacovirt.args:main"
|
||||
|
||||
[[tool.poetry.include]]
|
||||
path = "jacovirt/jacovirt/Img/*"
|
||||
|
|