forked from MDL29/JacoBot
parent
9513e5d5bc
commit
f5c1e2d59a
|
@ -38,4 +38,9 @@ class Token_generator(arcade.Sprite):
|
|||
return token
|
||||
|
||||
def draw_tokens(self):
|
||||
self.tokens.draw()
|
||||
self.tokens.draw()
|
||||
|
||||
|
||||
class Token_garbage_can(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMERICAN_ROSE):
|
||||
super().__init__(width, height, color)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import arcade
|
||||
import jacovirt.logger
|
||||
import logging
|
||||
from jacovirt.pad.token import Token, Token_generator
|
||||
from jacovirt.pad.token import Token, Token_generator, Token_garbage_can
|
||||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "Jaco Pad"
|
||||
|
@ -25,6 +25,9 @@ class Pad(arcade.Window):
|
|||
# List of token generator
|
||||
self.tokens_generator = arcade.SpriteList()
|
||||
|
||||
# List of garbage can
|
||||
self.tokens_garbage_can = arcade.SpriteList()
|
||||
|
||||
# The held token
|
||||
self.held_token = None
|
||||
|
||||
|
@ -49,6 +52,11 @@ class Pad(arcade.Window):
|
|||
token_generator.position = 800, 500
|
||||
self.tokens_generator.append(token_generator)
|
||||
|
||||
# Create a garbage can for token
|
||||
garbage_can = Token_garbage_can(200, 200)
|
||||
garbage_can.position = 500, 800
|
||||
self.tokens_garbage_can.append(garbage_can)
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
|
||||
|
@ -58,9 +66,13 @@ class Pad(arcade.Window):
|
|||
# Draw the token generator
|
||||
self.tokens_generator.draw()
|
||||
|
||||
# Draw the garbage can
|
||||
self.tokens_garbage_can.draw()
|
||||
|
||||
# Draw the tokens
|
||||
self.tokens.draw()
|
||||
|
||||
|
||||
def on_key_press(self, symbol, modifiers):
|
||||
"""Called when the user presses key"""
|
||||
if symbol == arcade.key.R:
|
||||
|
@ -80,7 +92,6 @@ class Pad(arcade.Window):
|
|||
|
||||
# Have we clicked on a token?
|
||||
if len(tokens) > 0:
|
||||
|
||||
# Might be a stack of tokens, get the top one
|
||||
primary_token = tokens[-1]
|
||||
|
||||
|
@ -106,7 +117,16 @@ class Pad(arcade.Window):
|
|||
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 garbage can we've release on
|
||||
tokens_garbage_can = arcade.get_sprites_at_point((x, y), self.tokens_garbage_can)
|
||||
|
||||
# If we are on a grabage can
|
||||
if len(tokens_garbage_can) > 0:
|
||||
# Delete the held token
|
||||
self.tokens.remove(self.held_token)
|
||||
|
||||
# remove token from hand
|
||||
if self.held_token != None:
|
||||
self.held_token = None
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user