1
0
forked from MDL29/LPH-cubito

avancement tablette

This commit is contained in:
mart1 2024-02-24 14:30:14 +01:00
parent 82e02bbe9f
commit 9010c8dae4

View File

@ -3,6 +3,7 @@ Cubito
"""
import arcade
import random
# import cubito
# Screen title and size
@ -26,6 +27,17 @@ Y_SPACING_TOKEN = TOKEN_HEIGHT + TOKEN_HEIGHT * VERTICAL_MARGIN_PERCENT
# List of token types
TOKEN_TYPES = ["FORDWARD", "RIGHT", "LEFT", "PAUSE", "FUNCTION"]
RAINBOW_COLORS = [
arcade.color.ELECTRIC_CRIMSON,
arcade.color.FLUORESCENT_ORANGE,
arcade.color.ELECTRIC_YELLOW,
arcade.color.ELECTRIC_GREEN,
arcade.color.ELECTRIC_CYAN,
arcade.color.MEDIUM_ELECTRIC_BLUE,
arcade.color.ELECTRIC_INDIGO,
arcade.color.ELECTRIC_PURPLE,
]
# Mat size
MAT_PERCENT_OVERSIZE = 1.25
MAT_HEIGHT = int(TOKEN_HEIGHT * MAT_PERCENT_OVERSIZE)
@ -49,6 +61,26 @@ BOTTOM_Y = MAT_HEIGHT / 2 + MAT_HEIGHT * VERTICAL_MARGIN_PERCENT
# Start from left side
START_X = MAT_WIDTH / 2 + MAT_WIDTH * HORIZONTAL_MARGIN_PERCENT
class Token(arcade.Sprite):
""" Card sprite """
def __init__(self, scale=1):
""" Card constructor """
# Image to use for the sprite when face up
self.image_file_name = ":resources:onscreen_controls/shaded_dark/up.png"
# Call the parent
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
class Mat(arcade.SpriteSolidColor):
""" Token sprite """
def __init__(self, height, width, color = arcade.color.AMARANTH):
""" Token constructor """
# Call the parent
super().__init__(width, height, color)
class Cubito(arcade.Window):
"""Main application class"""
@ -73,35 +105,81 @@ class Cubito(arcade.Window):
# List of mats function
self.mat_function_list = None
# List of cards we are dragging with the mouse
self.held_tokens = None
# Original location of cards we are dragging with the mouse in case
# they have to go back.
self.held_tokens_original_position = None
def setup(self):
"""Set up the game"""
...
self.token_list = arcade.SpriteList()
for i in range(3):
token = Token()
token.position = START_X, BOTTOM_Y
self.token_list.append(token)
# List of cards we are dragging with the mouse
self.held_tokens = []
self.mat_list = arcade.SpriteList()
for i in range(3):
for j in range(3):
mat = Mat(MAT_HEIGHT, MAT_WIDTH, RAINBOW_COLORS[random.randint(0, 7)])
mat.position = START_X + 50*i, TOP_Y - 50*j
self.mat_list.append(mat)
# Original location of cards we are dragging with the mouse in case
# they have to go back.
self.held_tokens_original_position = []
def on_draw(self):
"""Render the screen"""
# Clear the screen
arcade.start_render()
self.mat_list.draw()
self.token_list.draw()
def on_mouse_press(self, x, y, button, key_modifiers):
"""Called when the user presses a mouse button"""
...
# Get list of cards we've clicked on
tokens = arcade.get_sprites_at_point((x, y), self.token_list)
# Have we clicked on a card?
if len(tokens) > 0:
# Might be a stack of cards, get the top one
primary_token = tokens[-1]
# All other cases, grab the face-up card we are clicking on
self.held_tokens = [primary_token]
# Save the position
self.held_tokens_original_position = [self.held_tokens[0].position]
def on_mouse_release(self, x, y, button, modifiers):
"""Called when the user presses a mouse button"""
...
# If we don't have any cards, who cares
if len(self.held_tokens) == 0:
return
# We are no longer holding cards
self.held_tokens = []
def on_mouse_motion(self, x, y, dx, dy):
"""Called when the user moves the mouse"""
...
# If we are holding cards, move them with the mouse
for token in self.held_tokens:
token.center_x += dx
token.center_y += dy
def on_key_press(self, symbol, modifiers):
"""Called when the user presses key"""
...
def cubito(self, function=False):
"""Move cubito !"""
...
def main():
"""Main method"""