forked from MDL29/JacoBot
parent
8a60d943fd
commit
b5000a668d
|
@ -14,3 +14,28 @@ class Token(arcade.Sprite):
|
|||
|
||||
# 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)
|
||||
|
||||
def draw_tokens(self):
|
||||
self.tokens.draw()
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import arcade
|
||||
import jacovirt.logger
|
||||
import logging
|
||||
from jacovirt.pad.token import Token
|
||||
from jacovirt.pad.token import Token, Token_generator
|
||||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "Jaco Pad"
|
||||
|
@ -22,14 +22,23 @@ class Pad(arcade.Window):
|
|||
# Set background color
|
||||
arcade.set_background_color(BACKGROUND_COLOR)
|
||||
|
||||
# List of token generator
|
||||
self.tokens_generator = arcade.SpriteList()
|
||||
|
||||
|
||||
def setup(self):
|
||||
"""Set up the pad"""
|
||||
logging.info("Set up the pad.")
|
||||
|
||||
# Create the token
|
||||
# Create a token
|
||||
self.token = Token("up", 1*SCREEN_MULTILPLIER)
|
||||
self.token.position = 500, 500
|
||||
|
||||
# Create a token generator
|
||||
token_generator = Token_generator("up", 1*SCREEN_MULTILPLIER)
|
||||
token_generator.position = 200, 500
|
||||
self.tokens_generator.append(token_generator)
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
|
||||
|
@ -39,6 +48,12 @@ class Pad(arcade.Window):
|
|||
# Draw the token
|
||||
self.token.draw()
|
||||
|
||||
# Draw the token generator
|
||||
self.tokens_generator.draw()
|
||||
|
||||
for generator in self.tokens_generator:
|
||||
generator.draw_tokens()
|
||||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
if symbol == arcade.key.R:
|
||||
|
@ -47,7 +62,21 @@ class Pad(arcade.Window):
|
|||
|
||||
if symbol == arcade.key.Q:
|
||||
arcade.exit()
|
||||
|
||||
|
||||
def on_mouse_press(self, x, y, button, key_modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
logging.info(f"Mouse pressed at {x},{y}")
|
||||
|
||||
# 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.info(f"Cliced on the generator of {generator.type}")
|
||||
|
||||
# Create a token
|
||||
generator.create_token(x, y)
|
||||
|
||||
def main():
|
||||
"""Main method"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user