forked from MDL29/LPH-cubito
modification de cubito
This commit is contained in:
parent
9010c8dae4
commit
92bcc3b468
11
cubito.py
11
cubito.py
|
@ -19,20 +19,25 @@ turtle.goto(-225,225)
|
||||||
turtle.pendown()
|
turtle.pendown()
|
||||||
|
|
||||||
|
|
||||||
def fordward():
|
def FORDWARD():
|
||||||
"""
|
"""
|
||||||
Forward fonction
|
Forward fonction
|
||||||
"""
|
"""
|
||||||
turtle.forward(distance)
|
turtle.forward(distance)
|
||||||
|
|
||||||
def left():
|
def LEFT():
|
||||||
"""
|
"""
|
||||||
Turn left fonction
|
Turn left fonction
|
||||||
"""
|
"""
|
||||||
turtle.left(90)
|
turtle.left(90)
|
||||||
|
|
||||||
def right():
|
def RIGHT():
|
||||||
"""
|
"""
|
||||||
Turn right fonction
|
Turn right fonction
|
||||||
"""
|
"""
|
||||||
turtle.right(90)
|
turtle.right(90)
|
||||||
|
|
||||||
|
def PAUSE() :
|
||||||
|
"""
|
||||||
|
Pause fonction
|
||||||
|
"""
|
|
@ -4,7 +4,7 @@ Cubito
|
||||||
|
|
||||||
import arcade
|
import arcade
|
||||||
import random
|
import random
|
||||||
# import cubito
|
import cubito
|
||||||
|
|
||||||
# Screen title and size
|
# Screen title and size
|
||||||
SCREEN_TITLE = "Cubito"
|
SCREEN_TITLE = "Cubito"
|
||||||
|
@ -27,16 +27,7 @@ Y_SPACING_TOKEN = TOKEN_HEIGHT + TOKEN_HEIGHT * VERTICAL_MARGIN_PERCENT
|
||||||
# List of token types
|
# List of token types
|
||||||
TOKEN_TYPES = ["FORDWARD", "RIGHT", "LEFT", "PAUSE", "FUNCTION"]
|
TOKEN_TYPES = ["FORDWARD", "RIGHT", "LEFT", "PAUSE", "FUNCTION"]
|
||||||
|
|
||||||
RAINBOW_COLORS = [
|
COLOR_MAT = arcade.color.AO
|
||||||
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 size
|
||||||
MAT_PERCENT_OVERSIZE = 1.25
|
MAT_PERCENT_OVERSIZE = 1.25
|
||||||
|
@ -61,15 +52,23 @@ BOTTOM_Y = MAT_HEIGHT / 2 + MAT_HEIGHT * VERTICAL_MARGIN_PERCENT
|
||||||
# Start from left side
|
# Start from left side
|
||||||
START_X = MAT_WIDTH / 2 + MAT_WIDTH * HORIZONTAL_MARGIN_PERCENT
|
START_X = MAT_WIDTH / 2 + MAT_WIDTH * HORIZONTAL_MARGIN_PERCENT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Token(arcade.Sprite):
|
class Token(arcade.Sprite):
|
||||||
""" Card sprite """
|
""" Card sprite """
|
||||||
|
|
||||||
def __init__(self, scale=1):
|
token_image = {"FORDWARD" : ":resources:onscreen_controls/shaded_dark/up.png",
|
||||||
|
"RIGHT" : ":resources:onscreen_controls/shaded_dark/right.png",
|
||||||
|
"LEFT" : ":resources:onscreen_controls/shaded_dark/left.png",
|
||||||
|
"PAUSE" : ":resources:onscreen_controls/shaded_dark/pause_square.png",
|
||||||
|
"FUNCTION" : ":resources:onscreen_controls/shaded_dark/hamburger.png",
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, type_token,scale=0.5):
|
||||||
""" Card constructor """
|
""" Card constructor """
|
||||||
|
|
||||||
# Image to use for the sprite when face up
|
self.type_token = type_token
|
||||||
self.image_file_name = ":resources:onscreen_controls/shaded_dark/up.png"
|
self.image_file_name = Token.token_image[type_token]
|
||||||
|
|
||||||
# Call the parent
|
# Call the parent
|
||||||
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
|
super().__init__(self.image_file_name, scale, hit_box_algorithm="None")
|
||||||
|
|
||||||
|
@ -117,19 +116,26 @@ class Cubito(arcade.Window):
|
||||||
"""Set up the game"""
|
"""Set up the game"""
|
||||||
|
|
||||||
self.token_list = arcade.SpriteList()
|
self.token_list = arcade.SpriteList()
|
||||||
for i in range(3):
|
for i in range(9):
|
||||||
token = Token()
|
token = Token(type_token=TOKEN_TYPES[i%5])
|
||||||
token.position = START_X, BOTTOM_Y
|
token.position = START_X, BOTTOM_Y
|
||||||
self.token_list.append(token)
|
self.token_list.append(token)
|
||||||
# List of cards we are dragging with the mouse
|
# List of cards we are dragging with the mouse
|
||||||
self.held_tokens = []
|
self.held_tokens = []
|
||||||
|
|
||||||
self.mat_list = arcade.SpriteList()
|
self.mat_list = arcade.SpriteList()
|
||||||
for i in range(3):
|
for j in range(4):
|
||||||
for j in range(3):
|
for i in range(4):
|
||||||
mat = Mat(MAT_HEIGHT, MAT_WIDTH, RAINBOW_COLORS[random.randint(0, 7)])
|
mat = Mat(MAT_HEIGHT, MAT_WIDTH, COLOR_MAT)
|
||||||
mat.position = START_X + 50*i, TOP_Y - 50*j
|
mat.position = START_X + 50*i, TOP_Y - 50*j
|
||||||
self.mat_list.append(mat)
|
self.mat_list.append(mat)
|
||||||
|
|
||||||
|
self.mat_function_list = arcade.SpriteList()
|
||||||
|
for j in range(4) :
|
||||||
|
for i in range(2) :
|
||||||
|
mat_function = Mat(MAT_HEIGHT, MAT_WIDTH, COLOR_MAT)
|
||||||
|
mat_function.position = START_X + 50*i, TOP_Y - 50*j
|
||||||
|
self.mat_function_list.append(mat_function)
|
||||||
|
|
||||||
# Original location of cards we are dragging with the mouse in case
|
# Original location of cards we are dragging with the mouse in case
|
||||||
# they have to go back.
|
# they have to go back.
|
||||||
|
@ -141,6 +147,7 @@ class Cubito(arcade.Window):
|
||||||
arcade.start_render()
|
arcade.start_render()
|
||||||
self.mat_list.draw()
|
self.mat_list.draw()
|
||||||
self.token_list.draw()
|
self.token_list.draw()
|
||||||
|
self.mat_function_list()
|
||||||
|
|
||||||
def on_mouse_press(self, x, y, button, key_modifiers):
|
def on_mouse_press(self, x, y, button, key_modifiers):
|
||||||
"""Called when the user presses a mouse button"""
|
"""Called when the user presses a mouse button"""
|
||||||
|
@ -158,11 +165,33 @@ class Cubito(arcade.Window):
|
||||||
# Save the position
|
# Save the position
|
||||||
self.held_tokens_original_position = [self.held_tokens[0].position]
|
self.held_tokens_original_position = [self.held_tokens[0].position]
|
||||||
|
|
||||||
def on_mouse_release(self, x, y, button, modifiers):
|
def on_mouse_release(self, x : float, y : float , button : int, modifiers : int):
|
||||||
"""Called when the user presses a mouse button"""
|
"""Called when the user presses a mouse button"""
|
||||||
# If we don't have any cards, who cares
|
# If we don't have any cards, who cares
|
||||||
if len(self.held_tokens) == 0:
|
if len(self.held_tokens) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Find the closest pile, in case we are in contact with more than one
|
||||||
|
mat, distance = arcade.get_closest_sprite(self.held_tokens[0], self.mat_list)
|
||||||
|
reset_position = True
|
||||||
|
|
||||||
|
# See if we are in contact with the closest pile
|
||||||
|
if arcade.check_for_collision(self.held_tokens[0], mat):
|
||||||
|
|
||||||
|
# For each held card, move it to the pile we dropped on
|
||||||
|
for i, dropped_token in enumerate(self.held_tokens):
|
||||||
|
# Move cards to proper position
|
||||||
|
dropped_token.position = mat.center_x, mat.center_y
|
||||||
|
|
||||||
|
# Success, don't reset position of cards
|
||||||
|
reset_position = False
|
||||||
|
|
||||||
|
# Release on top play pile? And only one card held?
|
||||||
|
if reset_position:
|
||||||
|
# Where-ever we were dropped, it wasn't valid. Reset the each card's position
|
||||||
|
# to its original spot.
|
||||||
|
for mat_index, token in enumerate(self.held_tokens):
|
||||||
|
token.position = self.held_tokens_original_position[mat_index]
|
||||||
|
|
||||||
# We are no longer holding cards
|
# We are no longer holding cards
|
||||||
self.held_tokens = []
|
self.held_tokens = []
|
||||||
|
@ -177,6 +206,19 @@ class Cubito(arcade.Window):
|
||||||
|
|
||||||
def on_key_press(self, symbol, modifiers):
|
def on_key_press(self, symbol, modifiers):
|
||||||
"""Called when the user presses key"""
|
"""Called when the user presses key"""
|
||||||
|
if symbol == arcade.key.L :
|
||||||
|
for mat in self.mat_list :
|
||||||
|
token, distance = arcade.get_closest_sprite(mat ,self.token_list)
|
||||||
|
if arcade.check_for_collision(token, mat) :
|
||||||
|
print(token.type_token)
|
||||||
|
if token.type_token == "FORDWARD" :
|
||||||
|
cubito.FORDWARD()
|
||||||
|
if token.type_token == "LEFT" :
|
||||||
|
cubito.LEFT()
|
||||||
|
if token.type_token == "RIGHT" :
|
||||||
|
cubito.RIGHT()
|
||||||
|
if token.type_token == "PAUSE" :
|
||||||
|
cubito.PAUSE()
|
||||||
|
|
||||||
def cubito(self, function=False):
|
def cubito(self, function=False):
|
||||||
"""Move cubito !"""
|
"""Move cubito !"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user