#4:j'ai ajouté la gestion de la matrice
This commit is contained in:
parent
f1638d8be2
commit
db4d5d6e2f
|
@ -36,3 +36,11 @@ def right():
|
|||
Turn right fonction
|
||||
"""
|
||||
turtle.right(90)
|
||||
|
||||
def mouvement(value):
|
||||
if value == "FORWORD":
|
||||
fordward()
|
||||
if value == "LEFT":
|
||||
left()
|
||||
if value == "RIGHT":
|
||||
right()
|
||||
|
|
|
@ -4,7 +4,7 @@ ressources : https://api.arcade.academy/en/latest/resources.html
|
|||
"""
|
||||
|
||||
import arcade
|
||||
# import cubito
|
||||
import cubito
|
||||
|
||||
# Screen title and size
|
||||
SCREEN_TITLE = "Cubito"
|
||||
|
@ -65,12 +65,19 @@ START_X = MAT_WIDTH / 2 + MAT_WIDTH * HORIZONTAL_MARGIN_PERCENT
|
|||
|
||||
|
||||
|
||||
class Start_mat(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMBER):
|
||||
super().__init__(width, height, color)
|
||||
|
||||
|
||||
class Mat(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMBER):
|
||||
super().__init__(width, height, color)
|
||||
|
||||
class Mat_function(arcade.SpriteSolidColor):
|
||||
def __init__(self, height, width, color=arcade.color.AMBER):
|
||||
super().__init__(width, height, color)
|
||||
|
||||
|
||||
class Token_sprite(arcade.Sprite):
|
||||
""" Card sprite """
|
||||
|
@ -106,6 +113,9 @@ class Cubito(arcade.Window):
|
|||
# Origin pos for hold token
|
||||
self.held_token_original_position = None
|
||||
|
||||
#List of start mats
|
||||
self.start_mat_list = None
|
||||
|
||||
# List of mats
|
||||
self.mat_list = None
|
||||
|
||||
|
@ -124,9 +134,9 @@ class Cubito(arcade.Window):
|
|||
self.held_token_original_position = []
|
||||
|
||||
self.token_list = arcade.SpriteList()
|
||||
|
||||
self.mat_list = arcade.SpriteList()
|
||||
|
||||
self.start_mat_list = arcade.SpriteList()
|
||||
self.mat_function_list = arcade.SpriteList()
|
||||
|
||||
for y in range(TOKEN_ROW):
|
||||
x = X_TOKEN_START
|
||||
|
@ -136,19 +146,31 @@ class Cubito(arcade.Window):
|
|||
token.position = x, Y_TOKEN_START - Y_SPACING_TOKEN * y
|
||||
x+=X_SPACING_TOKEN
|
||||
self.token_list.append(token)
|
||||
token.token_type
|
||||
|
||||
#placer des cases sous les tokens
|
||||
mat = Mat(MAT_HEIGHT, MAT_WIDTH, color=arcade.color.AMAZON)
|
||||
mat.position = x - X_SPACING_TOKEN, Y_TOKEN_START - Y_SPACING_TOKEN * y
|
||||
self.mat_list.append(mat)
|
||||
start_mat = Start_mat(MAT_HEIGHT, MAT_WIDTH, color=arcade.color.AMAZON)
|
||||
start_mat.position = x - X_SPACING_TOKEN, Y_TOKEN_START - Y_SPACING_TOKEN * y
|
||||
self.start_mat_list.append(start_mat)
|
||||
|
||||
|
||||
#placer les cases principals
|
||||
for y in range(MAT_ROW):
|
||||
for x in range(MAT_COLUMN):
|
||||
mat = Mat(MAT_HEIGHT, MAT_WIDTH)
|
||||
mat.position = X_MAT_START + X_SPACING_MAT * x, Y_MAT_START - Y_SPACING_MAT * y
|
||||
self.mat_list.append(mat)
|
||||
|
||||
#placer les cases fonctions
|
||||
Y_MAT_FUNCTION_START = Y_MAT_START
|
||||
print(Y_MAT_FUNCTION_START)
|
||||
|
||||
for y in range(MAT_FUNCTION_ROW):
|
||||
for x in range(MAT_COLUMN):
|
||||
mat = Mat_function(MAT_HEIGHT, MAT_WIDTH, arcade.color.BABY_BLUE)
|
||||
mat.position = X_MAT_START + X_SPACING_MAT * x, Y_MAT_FUNCTION_START - Y_SPACING_MAT * y
|
||||
self.mat_function_list.append(mat)
|
||||
|
||||
|
||||
|
||||
def on_draw(self):
|
||||
"""Render the screen"""
|
||||
|
@ -159,6 +181,14 @@ class Cubito(arcade.Window):
|
|||
for mat in self.mat_list:
|
||||
mat.draw()
|
||||
|
||||
#Draw the start mat
|
||||
for start_mat in self.start_mat_list:
|
||||
start_mat.draw()
|
||||
|
||||
#Draw the mat function
|
||||
for mat_function in self.mat_function_list:
|
||||
mat_function.draw()
|
||||
|
||||
# Draw the token
|
||||
for token in self.token_list:
|
||||
token.draw()
|
||||
|
@ -199,29 +229,36 @@ class Cubito(arcade.Window):
|
|||
|
||||
def on_mouse_release(self, x, y, button, modifiers):
|
||||
"""Called when the user presses a mouse button"""
|
||||
def collition(reset_position, list_mat):
|
||||
# Find the closest mat, in case we are in contact with more than one
|
||||
mat, distance = arcade.get_closest_sprite(self.held_tokens[0], list_mat)
|
||||
|
||||
# See if we are in contact with the closest mat
|
||||
if arcade.check_for_collision(self.held_tokens[0], mat):
|
||||
|
||||
# For each held token, move it to the mat 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 tokens
|
||||
reset_position = False
|
||||
|
||||
return reset_position
|
||||
|
||||
|
||||
# If we don't have any tokens, who cares
|
||||
if len(self.held_tokens) == 0:
|
||||
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
|
||||
reset_position = collition(reset_position, self.mat_list)
|
||||
reset_position = collition(reset_position, self.start_mat_list)
|
||||
|
||||
# See if we are in contact with the closest mat
|
||||
if arcade.check_for_collision(self.held_tokens[0], mat):
|
||||
|
||||
# For each held token, move it to the mat 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
|
||||
# Where-ever we were dropped, it wasn't valid. Reset the each token's position
|
||||
# to its original spot.
|
||||
for mat_index, token in enumerate(self.held_tokens):
|
||||
token.position = self.held_token_original_position[mat_index]
|
||||
|
@ -229,7 +266,6 @@ class Cubito(arcade.Window):
|
|||
# We are no longer holding tokens
|
||||
self.held_tokens = []
|
||||
|
||||
|
||||
def on_mouse_motion(self, x, y, dx, dy):
|
||||
"""Called when the user moves the mouse"""
|
||||
...
|
||||
|
@ -248,10 +284,26 @@ class Cubito(arcade.Window):
|
|||
self.setup()
|
||||
print("Restart !")
|
||||
|
||||
if symbol == arcade.key.S:
|
||||
for mat in self.mat_list:
|
||||
token, distance = arcade.get_closest_sprite(mat, self.token_list)
|
||||
|
||||
if arcade.check_for_collision(token, mat):
|
||||
instruction = str(token.token_type).upper()
|
||||
if instruction == "UP":
|
||||
instruction = "FORWORD"
|
||||
cubito.mouvement(instruction)
|
||||
print(instruction)
|
||||
|
||||
|
||||
|
||||
|
||||
def cubito(self, function=False):
|
||||
"""Move cubito !"""
|
||||
...
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
"""Main method"""
|
||||
window = Cubito()
|
||||
|
|
Reference in New Issue
Block a user