forked from MDL29/JacoBot
parent
9513e5d5bc
commit
5008db05e1
|
@ -25,8 +25,6 @@ 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")
|
||||
|
||||
|
@ -34,8 +32,9 @@ 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)
|
||||
|
|
|
@ -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_trash
|
||||
|
||||
# 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 trash
|
||||
self.tokens_trash = 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 trash for token
|
||||
trash = Token_trash(200, 200)
|
||||
trash.position = 500, 800
|
||||
self.tokens_trash.append(trash)
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
|
||||
|
@ -58,9 +66,16 @@ class Pad(arcade.Window):
|
|||
# Draw the token generator
|
||||
self.tokens_generator.draw()
|
||||
|
||||
# Draw the trash
|
||||
self.tokens_trash.draw()
|
||||
|
||||
# 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:
|
||||
|
@ -80,14 +95,12 @@ 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]
|
||||
self.tokens.remove(primary_token)
|
||||
|
||||
# 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
|
||||
|
||||
return
|
||||
|
||||
|
@ -101,13 +114,22 @@ 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 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)
|
||||
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