parent
7d7166047f
commit
ef40fc1bca
61
jacovirt/jacovirt/bot/grid.py
Normal file
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
|
||||
)
|
||||
)
|
|
@ -2,16 +2,25 @@ import arcade
|
|||
import jacovirt.logger
|
||||
import logging
|
||||
|
||||
from jacovirt.bot.grid import Grid
|
||||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "JacoVirt Bot"
|
||||
SCREEN_MULTILPLIER = 1
|
||||
SCREEN_WIDTH = int(1000 * SCREEN_MULTILPLIER)
|
||||
SCREEN_HEIGHT = int(1000 * SCREEN_MULTILPLIER)
|
||||
SCREEN_WIDTH = int(1000)
|
||||
SCREEN_HEIGHT = int(1000)
|
||||
|
||||
# Window color
|
||||
BACKGROUND_COLOR = arcade.color.CATALINA_BLUE
|
||||
|
||||
class Bot(arcade.Window):
|
||||
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):
|
||||
|
@ -20,27 +29,39 @@ class Bot(arcade.Window):
|
|||
# Set background color
|
||||
arcade.set_background_color(BACKGROUND_COLOR)
|
||||
|
||||
self.grid = 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)
|
||||
|
||||
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()
|
||||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
if symbol == arcade.key.R:
|
||||
logging.info("Restart !")
|
||||
self.setup()
|
||||
print("Restart !")
|
||||
|
||||
if symbol == arcade.key.Q:
|
||||
arcade.exit()
|
||||
|
||||
def main():
|
||||
"""Main method"""
|
||||
window = Bot()
|
||||
window = Window()
|
||||
window.setup()
|
||||
arcade.run()
|
||||
arcade.run()
|
||||
|
|
Loading…
Reference in New Issue
Block a user