forked from MDL29/JacoBot
Creates a garbage zone for the virtual pad #34
This commit is contained in:
parent
041307a28c
commit
33a99d9f43
|
@ -25,6 +25,8 @@ class Token_generator(arcade.Sprite):
|
|||
|
||||
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")
|
||||
|
||||
|
@ -32,9 +34,16 @@ class Token_generator(arcade.Sprite):
|
|||
# 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()
|
||||
|
|
|
@ -72,10 +72,6 @@ class Pad(arcade.Window):
|
|||
# Draw the tokens
|
||||
self.tokens.draw()
|
||||
|
||||
# Draw the held tokens
|
||||
if self.held_token is not None:
|
||||
self.held_token.draw()
|
||||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
if symbol == arcade.key.R:
|
||||
|
@ -97,7 +93,6 @@ class Pad(arcade.Window):
|
|||
if len(tokens) > 0:
|
||||
# Might be a stack of tokens, get the top one
|
||||
primary_token = tokens[-1]
|
||||
self.tokens.remove(primary_token)
|
||||
|
||||
# All other cases, grab the token we are clicking on
|
||||
self.held_token = primary_token
|
||||
|
@ -114,22 +109,21 @@ class Pad(arcade.Window):
|
|||
|
||||
# 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.info(f"Mouse relase at {x},{y}")
|
||||
|
||||
# Get list of tokens_trash we've release on
|
||||
tokens_trash = arcade.get_sprites_at_point((x, y), self.tokens_trash)
|
||||
if self.held_token is not None:
|
||||
# Find the closest trash
|
||||
trash, distance = arcade.get_closest_sprite(self.held_token, self.tokens_trash)
|
||||
|
||||
# If we are on a tokens_trash
|
||||
if len(tokens_trash) > 0:
|
||||
# Delete the held token
|
||||
self.held_token = None
|
||||
|
||||
# remove token from hand
|
||||
if self.held_token != None:
|
||||
self.tokens.append(self.held_token)
|
||||
# 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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user