tout marche

This commit is contained in:
Bertrand_DUCON 2024-03-16 17:34:53 +01:00
parent c5a580f104
commit 3564095cb5
8 changed files with 85 additions and 10 deletions

BIN
Cubetto_forme_bas.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
Cubetto_forme_droite.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
Cubetto_forme_gauche.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
Cubetto_forme_haut.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 412 KiB

View File

@ -15,21 +15,36 @@ def cubetto_init():
penup()
goto(-210,194)
x_c = 0
y_c = 0
sh = "d"
def cubetto_forme_init():
global angle
global angle, sh
sh = "d"
if angle == 360 or angle == -360:
angle=0
sh = "d"
if angle == 0:
shape("Cubetto_forme_droite.gif")
sh = "d"
if angle == 90 or angle == -270:
shape("Cubetto_forme_haut.gif")
sh = "h"
if angle == 180 or angle == -180:
shape("Cubetto_forme_gauche.gif")
sh = "g"
if angle == 270 or angle == -90:
shape("Cubetto_forme_bas.gif")
sh = "b"
def cubetto_forward():
global sh, x_c, y_c
forward(84)
print(sh, x_c)
if sh == "d" and x_c<=336 and x_c>=0:
x_c+=84
if sh == "h" and y_c<=(4*84) and y_c>=0:
y_c-=84
def cubetto_left():
global angle
@ -48,6 +63,7 @@ def cubetto_backward():
forward(84)
right(180)
cubetto_init()

BIN
fond.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 KiB

View File

@ -3,6 +3,7 @@ Cubito
"""
from itertools import count
from time import sleep
from cubito import cubetto_forward, cubetto_left, cubetto_right, cubetto_backward
import arcade
# import cubito
@ -10,7 +11,7 @@ import arcade
# Screen title and size
SCREEN_TITLE = "Cubito"
SCREEN_WIDTH = 500
SCREEN_HEIGHT = 500
SCREEN_HEIGHT = 430
# Margin between mat & screen side
VERTICAL_MARGIN_PERCENT = 0.10
@ -60,10 +61,10 @@ class Token(arcade.Sprite):
sprite = {
"FORDWARD": "up",
"RIGHT": "right",
"LEFT": "left",
"FUNCTION": "hamburger",
"PAUSE": "pause_square"
"RIGHT": "r",
"LEFT": "l",
"FUNCTION": "star_round",
"PAUSE": "cancel"
}
def __init__(self, token_type, scale=1):
@ -86,13 +87,25 @@ class Mat(arcade.SpriteSolidColor):
# Count instance mat classes
ids = count(0)
def __init__(self, wigth, height, color=arcade.csscolor.DARK_OLIVE_GREEN):
def __init__(self, wigth, height, color=arcade.color.BLEU_DE_FRANCE):
# Get id from number of instance classes
self.id = next(self.ids)
# Init parent class
super().__init__(wigth, height, color)
class Mat_function(arcade.SpriteSolidColor):
"""Mat sprite"""
# Count instance mat classes
ids = count(0)
def __init__(self, wigth, height, color=arcade.color.BLEU_DE_FRANCE):
# Get id from number of instance classes
self.id = next(self.ids)
# Init parent class
super().__init__(wigth, height, color)
class Cubito(arcade.Window):
"""Main application class"""
@ -101,7 +114,7 @@ class Cubito(arcade.Window):
# Init parent class
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
# Set background color
arcade.set_background_color(arcade.color.AMAZON)
arcade.set_background_color(arcade.color.AIR_SUPERIORITY_BLUE)
# List of tokens
self.token_list = None
@ -127,18 +140,28 @@ class Cubito(arcade.Window):
self.mat_list = arcade.SpriteList()
self.mat_function_list = arcade.SpriteList()
for y in range(MAT_ROW):
# Create the top "play" piles
for x in range(MAT_COLUMN):
mat = Mat(MAT_WIDTH, MAT_HEIGHT)
mat.position = (
X_MAT_POS + X_SPACING_MAT * x,
Y_MAT_POS - Y_SPACING_MAT * y,
Y_MAT_POS - Y_SPACING_MAT * y - 60
)
self.mat_list.append(mat)
self.mat_function_list = arcade.SpriteList()
for x in range(MAT_COLUMN):
mat = Mat_function(MAT_WIDTH, MAT_HEIGHT)
mat.position = (
X_MAT_POS + X_SPACING_MAT * x,
Y_MAT_POS - Y_SPACING_MAT * y - 150
)
self.mat_function_list.append(mat)
# Sprite list with all the cards, no matter what pile they are in.
self.token_list = arcade.SpriteList()
@ -188,6 +211,7 @@ class Cubito(arcade.Window):
# Find the closest pile, in case we are in contact with more than one
mat, distance = arcade.get_closest_sprite(self.held_token, self.mat_list)
mat_function, distance = arcade.get_closest_sprite(self.held_token, self.mat_function_list)
reset_position = True
# See if we are in contact with the closest mat
@ -197,6 +221,16 @@ class Cubito(arcade.Window):
# Success, don't reset position of cards
reset_position = False
if arcade.check_for_collision(self.held_token, mat_function):
token, distance = arcade.get_closest_sprite(self.held_token, self.token_list)
if token.type != "FUNCTION":
self.held_token.position = mat_function.center_x, mat_function.center_y
else:
self.held_token.position = self.held_token_original_position
# Success, don't reset position of cards
reset_position = False
# Release on top play pile? And only one card held?
if reset_position:
@ -219,6 +253,31 @@ class Cubito(arcade.Window):
def on_key_press(self, symbol, modifiers):
"""Called when the user presses key"""
if symbol == arcade.key.L:
token_type_list = []
for i in self.mat_list:
token, distance = arcade.get_closest_sprite(i, self.token_list)
if arcade.check_for_collision(i, token):
token_type_list.append(token.type)
for t in token_type_list:
if t == "FORDWARD":
cubetto_forward()
elif t == "LEFT":
cubetto_left()
elif t == "RIGHT":
cubetto_right()
elif t == "FUNCTION":
for i in self.mat_function_list:
token, distance = arcade.get_closest_sprite(i, self.token_list)
if arcade.check_for_collision(i, token):
token_type_list.append(token.type)
elif t == "PAUSE":
sleep(1)
# Press « R » key
if symbol == arcade.key.R:
print("Restart !")