update: all

This commit is contained in:
Павел Терехов 2025-05-16 12:27:48 +03:00
parent 5e0376b4cf
commit 8b84cfc541

446
main.py
View File

@ -2,37 +2,12 @@ import arcade
import json import json
import math import math
import random import random
import pyglet
from pyglet.display.base import Screen, ScreenMode
from fill_level import filler from fill_level import filler
SCREEN_WIDTH = 800 SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 600 SCREEN_HEIGHT = 720
# class food():
# def __init__(self, x, y, healf = 1):
# self.x = x
# self.y = y
# self.healf = healf
# class body():
# def __init__(self, x, y, rotate, type):
# self.x = x
# self.y = y
# self.rotate = rotate
# self.type = type
# class SNAKE():
# def __init__(self, star_point_x, star_point_y, start_rotate = 0):
# self.tail_rot = 0
# self.body = [
# body(star_point_x, star_point_y, start_rotate, "head"),
# body(star_point_x - 1, star_point_y, start_rotate, "tail")
# ]
# def check_contact(self,x,y):
# cont = 0
# for body in self.body:
# if body.x == x and body.y == y:
# cont = 1
# return cont
# def calculate_coeff(self, degr): # def calculate_coeff(self, degr):
# return math.cos(math.radians(degr)) + math.sin(math.radians(degr)) # return math.cos(math.radians(degr)) + math.sin(math.radians(degr))
@ -50,79 +25,39 @@ SCREEN_HEIGHT = 600
# if (deg0 == 0 and deg1 == 180) or (deg0 == 270 and deg1 == 0): # if (deg0 == 0 and deg1 == 180) or (deg0 == 270 and deg1 == 0):
# return 270 # return 270
# return 0 # return 0
# def convert_rot_to_tail(self, deg0, deg2):
class Level_data(): class food():
def __init__(self, level_data_json = []): def __init__(self, x, y, healf = 1):
if level_data_json: self.x = x
self.fill_grid(level_data_json) self.y = y
self.healf = healf
def fill_grid(self, level_data_json): class body():
self.name = level_data_json["name"] def __init__(self, x, y, rotate, type, health = 3):
self.floor = level_data_json["floor"] self.x = x
self.size = level_data_json["size"] self.y = y
self.enemy_types = level_data_json["enemy_types"] self.rotate = rotate
self.enemy_spawns = level_data_json["enemy_spawns"] self.type = type
self.start_point = level_data_json["start_point"] self.health = health
class MYGAME(arcade.Window): class SNAKE():
def __init__(self, star_point_x, star_point_y, start_rotate = 0):
self.tail_rot = 0
self.body = [
body(star_point_x, star_point_y, start_rotate, "head"),
body(star_point_x - 1, star_point_y, start_rotate, "tail")
]
def check_contact(self,x,y):
cont = 0
for body in self.body:
if body.x == x and body.y == y:
cont = 1
return cont
def __init__(self, width, height): def get_damage(self, index):
super().__init__(width, height) self.body[index].health -= 1
arcade.set_background_color(arcade.color.AMAZON) if self.body[index].health == 0:
del self.body[index:len(self.body)]
def setup(self, level_name):
print(f"Upload level: {level_name}")
with open(f'./DATA/Levels/{level_name}/data.json', 'r') as file:
self.Lvl_data = Level_data(json.load(file))
if self.Lvl_data.name :
print(f"{self.Lvl_data.name} loaded")
else:
print("Error to load level")
self.player_body_list = arcade.SpriteList()
self.floor_list = arcade.SpriteList()
self.enemies_list = arcade.SpriteList()
self.enemy_spawn = arcade.SpriteList()
self.tecnical_list = arcade.SpriteList()
grid = fill_empty_grid()
self.floor_grid = self.arr2grid(self.Lvl_data.floor, grid)
self.print_grid(self.floor_grid)
# food
self.food_list = arcade.SpriteList()
self.food_sleep = 200
self.delay = 200
self.food = []
# Счет
self.score = 0
self.scale_ = 1.4
screen_center = [SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2]
self.level_start = [screen_center[0] - self.Lvl_data.size[0] * 16 * self.scale_, screen_center[1] - self.Lvl_data.size[1] * 16 * self.scale_]
# Загрузка змеи
self.player_body_list.append(arcade.Sprite(f"./DATA/Sprites/Snake/head.png", self.scale_, self.Lvl_data.start_point["x"], self.Lvl_data.start_point["y"], 0))
self.player_body_list.append(arcade.Sprite(f"./DATA/Sprites/Snake/tail.png", self.scale_, self.Lvl_data.start_point["x"]-1, self.Lvl_data.start_point["y"], 0))
self.player_body_list[0].type = "head"
self.player_body_list[1].type = "tail"
for body in self.player_body_list:
body.healf = 3
body.center_x = self.level_start[0] - 16 + ( body.center_x ) * 32 * self.scale_
body.center_y = self.level_start[1] - 16 + ( body.center_y ) * 32 * self.scale_
# Загрузка пола
for floor in self.Lvl_data.floor:
floor_sprite = arcade.Sprite(floor["sprite"], self.scale_)
floor_sprite.center_x = self.level_start[0] - 16 + ( floor["x"] ) * 32 * self.scale_
floor_sprite.center_y = self.level_start[1] - 16 + ( floor["y"] ) * 32 * self.scale_
self.floor_list.append(floor_sprite)
def calculate_rot(self, degr1, degr2): def calculate_rot(self, degr1, degr2):
@ -140,73 +75,201 @@ class MYGAME(arcade.Window):
return 270 return 270
return 90 return 90
def calc_tail_rotate(self): def calc_tail_rotate(self):
tail = self.player_body_list[len(self.player_body_list)-1] tail = self.body[len(self.body)-1]
pre_last = self.player_body_list[len(self.player_body_list)-2] pre_last = self.body[len(self.body)-2]
grad = 0 grad = 0
pos_x = tail.center_x pos_x = tail.x
pos_y = tail.center_y pos_y = tail.y
while not((pre_last.center_x == pos_x) and (pre_last.center_y == pos_y)): while not((pre_last.x == pos_x) and (pre_last.y == pos_y)):
pos_x = tail.center_x + int(math.cos(math.radians(grad))) * 32 * self.scale_ pos_x = tail.x + int(math.cos(math.radians(grad)))
pos_y = tail.center_y + int(math.sin(math.radians(grad))) * 32 * self.scale_ pos_y = tail.y + int(math.sin(math.radians(grad)))
grad += 90 grad += 90
return grad - 90 return grad - 90
def update_sprite(self, type):
return f"./DATA/Sprites/Snake/{type}.png"
def player_move(self, vector): def player_move(self, vector):
i = len(self.player_body_list)-1 i = len(self.body)-1
self.tail_rot = self.player_body_list[i].angle self.tail_rot = self.body[i].rotate
while i > 0: while i > 0:
self.player_body_list[i].center_x = self.player_body_list[i-1].center_x self.body[i].x = self.body[i-1].x
self.player_body_list[i].center_y = self.player_body_list[i-1].center_y self.body[i].y = self.body[i-1].y
self.player_body_list[i].angle = self.player_body_list[i-1].angle self.body[i].rotate = self.body[i-1].rotate
self.player_body_list[i].type = self.player_body_list[i-1].type self.body[i].type = self.body[i-1].type
self.player_body_list[i].texture = self.player_body_list[i-1].texture
i -= 1 i -= 1
self.player_body_list[0].angle = vector * 90 self.body[0].rotate = vector * 90
self.player_body_list[0].center_x = int(math.cos(math.radians(self.player_body_list[0].angle))) * 32 * self.scale_ + self.player_body_list[0].center_x self.body[0].x = int(math.cos(math.radians(self.body[0].rotate))) + self.body[0].x
self.player_body_list[0].center_y = int(math.sin(math.radians(self.player_body_list[0].angle))) * 32 * self.scale_ + self.player_body_list[0].center_y self.body[0].y = int(math.sin(math.radians(self.body[0].rotate))) + self.body[0].y
self.player_body_list[0].angle = 360 - self.player_body_list[0].angle self.body[0].rotate = 360 - self.body[0].rotate
if self.player_body_list[0].angle != self.player_body_list[1].angle:
self.player_body_list[1].type = "body-rotate" if self.body[0].rotate != self.body[1].rotate:
self.player_body_list[1].angle = 360 - self.calculate_rot(360 - self.player_body_list[0].angle, 360 - self.player_body_list[1].angle) self.body[1].type = "body-rotate"
self.body[1].rotate = 360 - self.calculate_rot(360 - self.body[0].rotate, 360 - self.body[1].rotate)
else: else:
self.player_body_list[1].type = "body" self.body[1].type = "body"
self.player_body_list[1].texture = arcade.load_texture(self.update_sprite(self.player_body_list[1].type)) self.body[ len(self.body) - 1 ].type = "tail"
self.body[ len(self.body) - 1 ].rotate = 360 - self.calc_tail_rotate()
self.player_body_list[ len(self.player_body_list) - 1 ].type = "tail"
self.player_body_list[ len(self.player_body_list) - 1 ].texture = arcade.load_texture(self.update_sprite( self.player_body_list[ len(self.player_body_list) - 1 ].type ))
self.player_body_list[ len(self.player_body_list) - 1 ].angle = 360 - self.calc_tail_rotate()
def add_body(self): def add_body(self):
last_body = self.player_body_list[len(self.player_body_list)-1] last_body = self.body[len(self.body)-1]
new_body = arcade.Sprite(self.update_sprite( "tail" ), self.scale_,last_body.center_x, last_body.center_y, self.tail_rot) new_body = body(last_body.x, last_body.y, self.tail_rot, "tail")
v_x = int(math.cos(math.radians(360 - self.tail_rot))) * 32 * self.scale_ v_x = int(math.cos(math.radians(360 - self.tail_rot)))
v_y = int(math.sin(math.radians(360 - self.tail_rot))) * 32 * self.scale_ v_y = int(math.sin(math.radians(360 - self.tail_rot)))
new_body.center_x = last_body.center_x - v_x new_body.x = last_body.x - v_x
new_body.center_y = last_body.center_y - v_y new_body.y = last_body.y - v_y
l = len(self.player_body_list) - 1 l = len(self.body) - 1
if 360 - self.player_body_list[l].angle != 360 - self.tail_rot: if 360 - self.body[l].rotate != 360 - self.tail_rot:
self.player_body_list[l].type = "body-rotate" self.body[l].type = "body-rotate"
self.player_body_list[l].angle = 360 - self.calculate_rot(360 - self.player_body_list[l].angle, 360 - self.tail_rot) self.body[l].rotate = 360 - self.calculate_rot(360 - self.body[l].rotate, 360 - self.tail_rot)
else: else:
self.player_body_list[l].type = "body" self.body[l].type = "body"
self.player_body_list[l].texture = arcade.load_texture(self.update_sprite(self.player_body_list[l].type)) self.body.append(new_body)
self.player_body_list.append(new_body)
class Level_data():
def __init__(self, level_data_json = []):
if level_data_json:
self.fill_grid(level_data_json)
def fill_grid(self, level_data_json):
self.name = level_data_json["name"]
self.floor = level_data_json["floor"]
self.size = level_data_json["size"]
self.enemy_types = level_data_json["enemy_types"]
self.enemy_spawns = level_data_json["enemy_spawns"]
self.start_point = level_data_json["start_point"]
class MYGAME(arcade.Window):
def __init__(
self,
width: int = 1280,
height: int = 720,
title: str | None = "Snake",
fullscreen: bool = False,
resizable: bool = False,
update_rate: float = 1 / 60,
antialiasing: bool = True,
gl_version: tuple[int, int] = (3, 3),
screen: Screen | None = None,
style: str | None = pyglet.window.Window.WINDOW_STYLE_DEFAULT,
visible: bool = True,
vsync: bool = False,
gc_mode: str = "context_gc",
center_window: bool = True,
samples: int = 4,
enable_polling: bool = True,
gl_api: str = "gl",
draw_rate: float = 1 / 60,
fixed_rate: float = 1.0 / 60.0,
fixed_frame_cap: int | None = None,
):
super().__init__(width, height)
arcade.set_background_color(arcade.color.AMAZON)
def setup(self, level_name):
print(f"Upload level: {level_name}")
with open(f'./DATA/Levels/{level_name}/data.json', 'r') as file:
self.Lvl_data = Level_data(json.load(file))
if self.Lvl_data.name :
print(f"{self.Lvl_data.name} loaded")
else:
print("Error to load level")
self.enemies_list = arcade.SpriteList()
self.enemy_spawn = arcade.SpriteList()
self.tecnical_list = arcade.SpriteList()
# Сетка уровня
self.floor_list = arcade.SpriteList()
grid = fill_empty_grid()
self.floor_grid = self.arr2grid(self.Lvl_data.floor, grid)
self.print_grid(self.floor_grid)
# Загрузка текстур
self.texture_list = {
"snake":
{
"head": arcade.load_texture( "./DATA/Sprites/Snake/head.png" ),
"body": arcade.load_texture( "./DATA/Sprites/Snake/body.png" ),
"body-rotate": arcade.load_texture( "./DATA/Sprites/Snake/body-rotate.png" ),
"tail": arcade.load_texture( "./DATA/Sprites/Snake/tail.png" )
},
"food":
{
"healthy-food": arcade.load_texture( "./DATA/Sprites/Enemies/Tier 0/healthy_food.png" )
},
"floor":
{
"floor-gray": arcade.load_texture( "./DATA/Sprites/Floor/floor_grey.png" )
}
}
# food
self.food_list = arcade.SpriteList()
self.food_sleep = 200
self.delay = 200
self.food = []
# Счет
self.score = 0
self.scale_ = 1.4
screen_center = [SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2]
self.level_start = [screen_center[0] - self.Lvl_data.size[0] * 16 * self.scale_, screen_center[1] - self.Lvl_data.size[1] * 16 * self.scale_]
# Загрузка змеи
self.snake_sprite_list = arcade.SpriteList()
self.snake = SNAKE(self.Lvl_data.start_point["x"], self.Lvl_data.start_point["y"])
# Загрузка пола
for floor in self.Lvl_data.floor:
floor_sprite = arcade.Sprite(self.texture_list["floor"]["floor-gray"], self.scale_)
floor_sprite.center_x = self.level_start[0] - 16 + ( floor["x"] ) * 32 * self.scale_
floor_sprite.center_y = self.level_start[1] - 16 + ( floor["y"] ) * 32 * self.scale_
self.floor_list.append(floor_sprite)
def update_snake_sprites(self):
# Обновляем положениям спрайтов
if (len(self.snake.body) == len(self.snake_sprite_list)):
for i, body_part in enumerate(self.snake.body):
self.snake_sprite_list[i].texture = self.texture_list[ "snake" ][ body_part.type ]
self.snake_sprite_list[i].angle = body_part.rotate
self.snake_sprite_list[i].center_x = self.level_start[0] - 16 + ( body_part.x ) * 32 * self.scale_
self.snake_sprite_list[i].center_y = self.level_start[1] - 16 + ( body_part.y ) * 32 * self.scale_
elif (len(self.snake.body) - len(self.snake_sprite_list) > 0):
# Обновляем список спрайтов
delta = len(self.snake.body) - len(self.snake_sprite_list)
i = len(self.snake.body) - delta
while i <= len(self.snake.body) - 1:
snake_new_sprite = arcade.Sprite(self.texture_list[ "snake" ][ self.snake.body[i].type ], self.scale_)
snake_new_sprite.angle = self.snake.body[i].rotate
snake_new_sprite.center_x = self.level_start[0] - 16 + ( self.snake.body[i].x ) * 32 * self.scale_
snake_new_sprite.center_y = self.level_start[1] - 16 + ( self.snake.body[i].y ) * 32 * self.scale_
self.snake_sprite_list.append( snake_new_sprite )
i += 1
else:
# Обновляем список спрайтов
delta = len(self.snake_sprite_list) - len(self.snake.body)
i = len(self.snake.body) - delta + 1
while i <= len(self.snake_sprite_list) - 1:
self.snake_sprite_list[i].kill()
i += 1
def spawn_food(self): def spawn_food(self):
spawn = False spawn = False
@ -214,10 +277,10 @@ class MYGAME(arcade.Window):
x = random.randint(0, 14) x = random.randint(0, 14)
y = random.randint(0, 14) y = random.randint(0, 14)
if self.floor_grid[y][x] == 1: if self.floor_grid[y][x] == 1:
food_sprite = arcade.Sprite(f"./DATA/Sprites/Enemies/Tier 0/healthy_food.png", self.scale_) food_sprite = arcade.Sprite(self.texture_list[ "food" ][ "healthy-food" ], self.scale_)
food_sprite.center_x = self.level_start[0] - 16 + ( x ) * 32 * self.scale_ food_sprite.center_x = self.level_start[0] - 16 + ( x ) * 32 * self.scale_
food_sprite.center_y = self.level_start[1] - 16 + ( y ) * 32 * self.scale_ food_sprite.center_y = self.level_start[1] - 16 + ( y ) * 32 * self.scale_
if arcade.check_for_collision_with_list(food_sprite, self.floor_list) != [] and arcade.check_for_collision_with_list(food_sprite, self.player_body_list) == []: if arcade.check_for_collision_with_list(food_sprite, self.floor_list) != [] and arcade.check_for_collision_with_list(food_sprite, self.snake_sprite_list) == []:
self.food_list.append(food_sprite) self.food_list.append(food_sprite)
spawn = True spawn = True
else: else:
@ -237,45 +300,55 @@ class MYGAME(arcade.Window):
if self.check_floor(360 - enemy.angle, enemy): if self.check_floor(360 - enemy.angle, enemy):
enemy.center_x = int(math.cos(math.radians(360 - enemy.angle))) * 32 * self.scale_ + enemy.center_x enemy.center_x = int(math.cos(math.radians(360 - enemy.angle))) * 32 * self.scale_ + enemy.center_x
enemy.center_y = int(math.sin(math.radians(360 - enemy.angle))) * 32 * self.scale_ + enemy.center_y enemy.center_y = int(math.sin(math.radians(360 - enemy.angle))) * 32 * self.scale_ + enemy.center_y
def check_detect(self, enemy): def check_detect(self, enemy):
pass pass
def update(self):
def on_update(self, delta_time: float):
self.update_snake_sprites()
# Food # Food
self.food_sleep -= 1 self.food_sleep -= 1
if self.food_sleep <= 0: if self.food_sleep <= 0:
self.spawn_food() self.spawn_food()
self.food_sleep = self.delay self.food_sleep = self.delay
list = arcade.check_for_collision_with_list(self.player_body_list[0], self.food_list) list = arcade.check_for_collision_with_list(self.snake_sprite_list[0], self.food_list)
if list != []: if list != []:
self.food_list.remove(list[0]) self.food_list.remove(list[0])
self.score += 1 self.score += 1
for body_part in self.snake.body:
body_part.health = 3
self.snake.body
self.snake.add_body()
self.spawn_food() self.spawn_food()
self.add_body()
# Enemy # Enemy
for enemy in self.enemies_list: # for enemy in self.enemies_list:
enemy.sleep -= 1 # enemy.sleep -= 1
self.check_detect(enemy) # self.check_detect(enemy)
if (enemy.sleep == enemy.delay / 2 ): # if (enemy.sleep == enemy.delay / 2 ):
self.find_way(enemy) # self.find_way(enemy)
elif (enemy.sleep == 0 ): # elif (enemy.sleep == 0 ):
self.enemy_move(enemy) # self.enemy_move(enemy)
enemy.sleep = enemy.delay # enemy.sleep = enemy.delay
# Enemy_spawn # Enemy_spawn
for spawn in self.Lvl_data.enemy_spawns[0]: # for spawn in self.Lvl_data.enemy_spawns[0]:
spawn["sleep"] -= 1 # spawn["sleep"] -= 1
if spawn["sleep"] <= 0: # if spawn["sleep"] <= 0:
spawn["sleep"] = spawn["delay"] # spawn["sleep"] = spawn["delay"]
self.spawn_enemy(spawn["y"], spawn["x"], spawn["tier"]) # self.spawn_enemy(spawn["y"], spawn["x"], spawn["tier"])
def spawn_enemy(self, y, x, tier): def spawn_enemy(self, y, x, tier):
type = random.randint(0, len(self.Lvl_data.enemy_types[tier-1])) type = random.randint(0, len(self.Lvl_data.enemy_types[tier-1]))
if (type == 0): if (type == 0):
enemy_sprite = arcade.Sprite("./DATA/Sprites/Enemies/Tier 1/little-spider.png", self.scale_) enemy_sprite = arcade.Sprite("./DATA/Sprites/Enemies/Tier 1/little-spider.png", self.scale_)
posible = arcade.check_for_collision_with_list(enemy_sprite, self.player_body_list) == [] posible = arcade.check_for_collision_with_list(enemy_sprite, self.snake_sprite_list) == []
posible = posible and arcade.check_for_collision_with_list(enemy_sprite, self.enemies_list) == [] posible = posible and arcade.check_for_collision_with_list(enemy_sprite, self.enemies_list) == []
if posible: if posible:
enemy_sprite.damage = 1 enemy_sprite.damage = 1
@ -314,17 +387,20 @@ class MYGAME(arcade.Window):
return grid return grid
# Обработка нажатий # Обработка нажатий
MOVEMENT_SPEED = 1
def check_floor(self, vector, sprite): def check_floor(self, vector, sprite):
rotate = 90 * vector rotate = 90 * vector
v_x = int(math.cos(math.radians(rotate))) * 32 * self.scale_ v_x = int(math.cos(math.radians(rotate))) * 32 * self.scale_
v_y = int(math.sin(math.radians(rotate))) * 32 * self.scale_ v_y = int(math.sin(math.radians(rotate))) * 32 * self.scale_
new_pos = arcade.Sprite( "./DATA/Sprites/Floor/move_ghost.png", self.scale_, sprite.center_x + v_x, sprite.center_y + v_y ) new_pos = arcade.Sprite( self.texture_list["floor"]["floor-gray"], self.scale_, sprite.center_x + v_x, sprite.center_y + v_y )
posible = arcade.check_for_collision_with_list(new_pos, self.floor_list) != [] posible = arcade.check_for_collision_with_list(new_pos, self.floor_list) != []
posible = posible and arcade.check_for_collision_with_list(new_pos, self.player_body_list) == [] body_part = arcade.check_for_collision_with_list(new_pos, self.snake_sprite_list)
posible = posible and arcade.check_for_collision_with_list(new_pos, self.enemies_list) == [] if ( body_part != [] and body_part[0] != self.snake_sprite_list[0]):
self.snake.get_damage(self.snake_sprite_list.index(body_part[0]))
posible = False
# posible = posible and arcade.check_for_collision_with_list(new_pos, self.enemies_list) == []
new_pos.kill() new_pos.kill()
return posible return posible
@ -332,43 +408,43 @@ class MYGAME(arcade.Window):
def on_key_press(self, key, modifiers): def on_key_press(self, key, modifiers):
"""Вызывается при нажатии пользователем клавиши""" """Вызывается при нажатии пользователем клавиши"""
# Get the first sprite (head) from the player list # Get the first sprite (head) from the player list
if len(self.player_body_list) == 0: if len(self.snake_sprite_list) == 0:
return return
if key in (arcade.key.UP, arcade.key.W): if key in (arcade.key.UP, arcade.key.W):
if self.check_floor(1, self.player_body_list[0]) and self.player_body_list[0].angle != 90: if self.snake_sprite_list[0].angle != 90:
self.player_move(1) if self.check_floor(1, self.snake_sprite_list[0]):
self.snake.player_move(1)
self.update_snake_sprites()
elif key in (arcade.key.DOWN, arcade.key.S): elif key in (arcade.key.DOWN, arcade.key.S):
if self.check_floor(3, self.player_body_list[0]) and self.player_body_list[0].angle != 270: if self.snake_sprite_list[0].angle != 270:
self.player_move(3) if self.check_floor(3, self.snake_sprite_list[0]):
self.snake.player_move(3)
self.update_snake_sprites()
elif key in (arcade.key.LEFT, arcade.key.A): elif key in (arcade.key.LEFT, arcade.key.A):
if self.check_floor(2, self.player_body_list[0]) and (self.player_body_list[0].angle != 360 and self.player_body_list[0].angle != 0): if (self.snake_sprite_list[0].angle != 360 and self.snake_sprite_list[0].angle != 0):
self.player_move(2) if self.check_floor(2, self.snake_sprite_list[0]):
self.snake.player_move(2)
self.update_snake_sprites()
elif key in (arcade.key.RIGHT, arcade.key.D): elif key in (arcade.key.RIGHT, arcade.key.D):
if self.check_floor(0, self.player_body_list[0]) and self.player_body_list[0].angle != 180: if self.snake_sprite_list[0].angle != 180:
self.player_move(0) if self.check_floor(0, self.snake_sprite_list[0]):
self.snake.player_move(0)
self.update_snake_sprites()
# def on_key_release(self, key, modifiers):
# if len(self.player_body_list) > 0:
# self.player_sprite = self.player_body_list[0]
# if key in (arcade.key.UP, arcade.key.DOWN, arcade.key.W, arcade.key.S):
# self.player_sprite.change_y = 0
# elif key in (arcade.key.LEFT, arcade.key.RIGHT, arcade.key.A, arcade.key.D):
# self.player_sprite.change_x = 0
def on_draw(self): def on_draw(self):
self.update()
# Очищаем экран перед каждой отрисовкой # Очищаем экран перед каждой отрисовкой
self.clear() self.clear()
# Отрисовываем все спрайты # Отрисовываем все спрайты
self.floor_list.draw() self.floor_list.draw()
self.tecnical_list.draw() # self.tecnical_list.draw()
self.food_list.draw() self.food_list.draw()
self.enemies_list.draw() # self.enemies_list.draw()
self.player_body_list.draw() self.snake_sprite_list.draw()
arcade.draw_text(f"Score: {self.score}", self.level_start[0], self.level_start[1], arcade.color.BLACK, 24)
def print_spawn(who, x, y): def print_spawn(who, x, y):