Commit f858eab8 authored by Julian Rudolf's avatar Julian Rudolf
Browse files

Merge remote-tracking branch 'origin/dev'

# Conflicts:
#	Shield/graph_from_map.py
parents fb4a3002 a25135e6
Game/data/SnakeHeadBot_30x30.png

1.1 KB | W: | H:

Game/data/SnakeHeadBot_30x30.png

10.8 KB | W: | H:

Game/data/SnakeHeadBot_30x30.png
Game/data/SnakeHeadBot_30x30.png
Game/data/SnakeHeadBot_30x30.png
Game/data/SnakeHeadBot_30x30.png
  • 2-up
  • Swipe
  • Onion skin
Game/data/SnakeHeadRed_30x30.png

1.01 KB | W: | H:

Game/data/SnakeHeadRed_30x30.png

6.9 KB | W: | H:

Game/data/SnakeHeadRed_30x30.png
Game/data/SnakeHeadRed_30x30.png
Game/data/SnakeHeadRed_30x30.png
Game/data/SnakeHeadRed_30x30.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -6,6 +6,8 @@ import multiprocessing as mp
sys.path.append("../Shield")
from shield import ShieldSnake, get_shield, find_node, init_shield
from graph_from_map import generate_graph
# -------------------------------------------------------------------
# main.py
......@@ -21,6 +23,8 @@ from shield import ShieldSnake, get_shield, find_node, init_shield
white = (255, 255, 255)
black = (0, 0, 0)
grey = (60, 60, 60)
very_light_grey = (190, 190, 190)
light_grey = (112, 128, 144)
red = (200, 0, 0)
light_red = (255, 0, 0)
green = (0, 155, 0)
......@@ -29,6 +33,7 @@ dark_green = (0, 80, 0)
purple = (214, 32, 211)
blue = (0, 0, 255)
light_blue = (61, 178, 253)
very_light_blue = (175, 238, 238)
yellow = (200, 200, 0)
light_yellow = (255, 255, 0)
......@@ -72,6 +77,9 @@ p1_icon = pygame.image.load('data/snake_images/p1_icon.png')
p2_icon = pygame.image.load('data/snake_images/p2_icon.png')
p3_icon = pygame.image.load('data/snake_images/p3_icon.png')
p4_icon = pygame.image.load('data/snake_images/p4_icon.png')
map3_icon = pygame.image.load('data/map3_icon.png')
map5_icon = pygame.image.load('data/map5_icon.png')
map6_icon = pygame.image.load('data/map6_icon.png')
p1_snake = green_head, green, green_start, green_win, green_win_end, green_lost, green_lost_end
p2_snake = purple_head, purple, purple_start, purple_win, purple_win_end, purple_lost, purple_lost_end
......@@ -99,11 +107,13 @@ clock = pygame.time.Clock()
# probabilities for coloring
crash_prob_treshold = [0.0, 0.7]
# map filename (from grapf_from_map)
# map filename (from graph_from_map)
map_filename = '../Shield/maps/map6.pickle'
# map and start position
startsnake1, startsnake2 = maps.start6
map = maps.map6
snake_length = 15
tmp_snake_length = 15
apples = [(set([]), green_apple), (set([]), purple_apple)]
bombs = [(set([]), bomb_img)]
......@@ -128,7 +138,7 @@ class Snake:
# direction : direction of the snake at the crossing
# shield_snake : the player snake in shield logic
# enemy_snake : the enemy snake in shield logic
def __init__(self, pos, vel, angle, id, img=green_head, color=green, apple_img=green_apple, act_shield=False):
def __init__(self, pos, vel, angle, id, img=green_head, color=green, apple_img=green_apple, act_shield=False, length=snake_length):
self.pos = [pos[0][1] * block_size, pos[0][0] * block_size]
self.vel = [vel[0][0] * block_size, vel[0][1] * block_size]
self.poslist = []
......@@ -139,7 +149,7 @@ class Snake:
self.angle = angle
self.img = img
self.shield = act_shield
self.length = 30
self.length = length
assert self.length == len(pos) and self.length == len(vel), 'length of snake != pos, vel amount (maps.py)'
self.head = self.img
self.color = color
......@@ -153,10 +163,14 @@ class Snake:
self.id = id
self.process = None
self.crash_prob_queue = mp.Queue()
self.enemy_norm_snake = None
def set_enemy_snake(self, snake):
self.enemy_snake = snake
def set_enemy_norm_snake(self, snake):
self.enemy_norm_snake = snake
def score_display(self, pos):
score(self.score, pos, self.color)
......@@ -396,8 +410,7 @@ class Snake:
es = self.enemy_snake.copy()
self.process = mp.Process(target=get_shield, args=(self.crash_prob_queue, ps, es))
self.process.start()
#print("normal_print ps: nodes " + str(self.shield_snake.nodes) + " edges " + str(self.shield_snake.edges) + ' dist ' + str(self.shield_snake.dist) +'\n' + 'es: nodes ' + str(self.enemy_snake.nodes) + " edges " + str(self.enemy_snake.edges) + 'dist ' + str(self.enemy_snake.dist) + '\n' + 'process ' + str(self.process.pid) + " started snake: " + str(self.id))
# print("normal_print ps: nodes " + str(self.shield_snake.nodes) + " edges " + str(self.shield_snake.edges) + ' dist ' + str(self.shield_snake.dist) +'\n' + 'es: nodes ' + str(self.enemy_snake.nodes) + " edges " + str(self.enemy_snake.edges) + 'dist ' + str(self.enemy_snake.dist) + '\n' + 'process ' + str(self.process.pid) + " started snake: " + str(self.id))
self.wrap_around()
......@@ -415,27 +428,25 @@ class Snake:
if self.shield and self.process is not None and self.process.exitcode is not None:
self.crash_prob = self.crash_prob_queue.get()
#print("done early id " + str(self.id) + ' ' + str(self.crash_prob) + ' ' + 'pid: ' + str(self.process.pid))
# print("done early id " + str(self.id) + ' ' + str(self.crash_prob) + ' ' + 'pid: ' + str(self.process.pid))
self.process.close()
self.process = None
self.color_prob(self.crash_prob)
# if set to False, no recalc
shield_recalc = False
for p in self.crash_prob.items():
if p[1] == 0.0:
shield_recalc = False
if shield_recalc:
print("Shield has to recalculate")
test = True
if self.shield and self.process is None and self.shield_snake.shield_calc_dist() and test:
print("Starting recalc")
ps = self.shield_snake.copy()
es = self.enemy_snake.copy()
self.process = mp.Process(target=get_shield, args=(self.crash_prob_queue, ps, es))
self.process.start()
print("ps: nodes " + str(self.shield_snake.nodes) + " edges " + str(self.shield_snake.edges) + ' dist ' + str(self.shield_snake.dist) +'\n' + 'es: nodes ' + str(self.enemy_snake.nodes) + " edges " + str(self.enemy_snake.edges) + 'dist ' + str(self.enemy_snake.dist) + '\n' + 'process ' + str(self.process.pid) + " started snake: " + str(self.id))
# shield recalc nur wenn gegnerische Schlange 1 nach crossing
# wenn eigene schlange bei crossing -> process töten(?)
if check_if_after_crossing(self.enemy_norm_snake.pos[1] / block_size,
self.enemy_norm_snake.pos[0] / block_size, self.enemy_norm_snake.direction):
if self.shield and self.process is None and self.shield_snake.shield_calc_dist():
print("Starting recalc")
ps = self.shield_snake.copy()
es = self.enemy_snake.copy()
self.process = mp.Process(target=get_shield, args=(self.crash_prob_queue, ps, es))
self.process.start()
print("ps: nodes " + str(self.shield_snake.nodes) + " edges " + str(self.shield_snake.edges) + ' dist ' + str(
self.shield_snake.dist) + '\n' + 'es: nodes ' + str(self.enemy_snake.nodes) + " edges " + str(
self.enemy_snake.edges) + 'dist ' + str(self.enemy_snake.dist) + '\n' + 'process ' + str(
self.process.pid) + " started snake: " + str(self.id))
self.draw_snake()
self.count += 1
......@@ -466,6 +477,49 @@ class Snake:
self.crash_prob_draw.append((red, [pos[0], pos[1], block_size, block_size]))
# checks if coordinates are one after crossing
def check_if_after_crossing(y, x, angle):
ret = False
if angle == 'up':
ret = check_if_crossing(x, y+1)
elif angle == 'down':
ret = check_if_crossing(x, y-1)
elif angle == 'right':
ret = check_if_crossing(x-1, y)
elif angle == 'left':
ret = check_if_crossing(x+1, y)
if ret and False:
print("after crossing with angle: " + angle + " and pos [" + str(x) + "|" + str(y) +"]")
return ret
# checks if there is a crossing at the given coordinates
def check_if_crossing(y, x):
x = int(x)
y = int(y)
path_num = 0
if x < 1 or x > 28 or y < 1 or y > 28:
return False
if map[x][y] == 1:
assert False, 'position not path'
if map[x][y+1] == 0:
path_num += 1
if map[x+1][y] == 0:
path_num += 1
if map[x][y-1] == 0:
path_num += 1
if map[x-1][y] == 0:
path_num += 1
if path_num > 2:
return True
else:
return False
# determines if snakes have crashed
# parameters:
# snakes: list of all snakes
......@@ -555,15 +609,70 @@ def gen_rand_apple(image):
def button(text, pos, color1, color2, action, text_color=black):
cur = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
speed_select = ((int(res_x / 2 - 200), res_y - 415, 100, 30), (int(res_x / 2 - 320), res_y - 415, 100, 30), (int(res_x / 2 - 440), res_y - 415, 100, 30))
length_select = ((int(res_x / 2 + 340), res_y - 415, 100, 30), (int(res_x / 2 + 220), res_y - 415, 100, 30), (int(res_x / 2 + 100), res_y - 415, 100, 30))
if pos[0] + pos[2] > cur[0] > pos[0] and pos[1] + pos[3] > cur[1] > pos[1]:
pygame.draw.rect(Display, color2, pos)
if click[0] == 1:
if action == "switch":
return False
elif action == "select":
elif action == "length10":
pygame.draw.rect(Display, white, length_select[0], 8)
pygame.draw.rect(Display, white, length_select[1], 8)
pygame.draw.rect(Display, black, length_select[2], 8)
clock.tick(6)
set_snake_length(10)
clock.tick(6)
elif action == "length15":
pygame.draw.rect(Display, white, length_select[0], 8)
pygame.draw.rect(Display, black, length_select[1], 8)
pygame.draw.rect(Display, white, length_select[2], 8)
clock.tick(6)
set_snake_length(15)
clock.tick(6)
elif action == "length20":
pygame.draw.rect(Display, black, length_select[0], 8)
pygame.draw.rect(Display, white, length_select[1], 8)
pygame.draw.rect(Display, white, length_select[2], 8)
clock.tick(6)
set_snake_length(20)
clock.tick(6)
elif action == "speed25":
pygame.draw.rect(Display, white, speed_select[0], 8)
pygame.draw.rect(Display, white, speed_select[1], 8)
pygame.draw.rect(Display, black, speed_select[2], 8)
clock.tick(6)
set_game_speed(25)
clock.tick(6)
elif action == "speed45":
pygame.draw.rect(Display, white, speed_select[0], 8)
pygame.draw.rect(Display, black, speed_select[1], 8)
pygame.draw.rect(Display, white, speed_select[2], 8)
clock.tick(6)
set_game_speed(45)
clock.tick(6)
elif action == "speed65":
pygame.draw.rect(Display, black, speed_select[0], 8)
pygame.draw.rect(Display, white, speed_select[1], 8)
pygame.draw.rect(Display, white, speed_select[2], 8)
clock.tick(6)
set_game_speed(65)
clock.tick(6)
elif action == "select_snake":
clock.tick(6)
select_snake()
clock.tick(6)
return False
elif action == "select_map":
clock.tick(6)
select_map()
clock.tick(6)
return False
elif action == "loading":
clock.tick(6)
loading_screen()
clock.tick(6)
return False
elif action == "controls":
clock.tick(6)
......@@ -623,18 +732,22 @@ def select_snake():
global p1_snake
global p2_snake
select = True
pos1 = (-150, -150)
pos2 = (-150, 150)
pos3 = (150, -150)
pos4 = (150, 150)
pos1 = (-180, -150)
pos2 = (-180, 180)
pos3 = (180, -150)
pos4 = (180, 180)
p1_pos = pos1
p2_pos = pos3
p1 = selection_rect(green, 200, 200, p1_pos)
p2 = selection_rect(red, 200, 200, p2_pos)
Display.fill(light_blue)
message_screen("Select your Snake!", blue, -350, "large")
message_screen("Player 1: Green", green, -300, "small", -150)
message_screen("Player 2: Red", red, -300, "small", 150)
Display.fill(white)
message_screen("Select your Snake!", black, -350, "large")
message_screen("Player 1: Green", green, -300, "small", -180)
message_screen("Player 2: Red", red, -300, "small", 180)
message_screen("Sarah", green, -30, "medium", -180)
message_screen("Chizi", purple, -30, "medium", 180)
message_screen("Aurelia", grey, 300, "medium", -180)
message_screen("Zoey", red, 300, "medium", 180)
image_screen(p1_icon, pos1)
image_screen(p2_icon, pos2)
......@@ -648,37 +761,37 @@ def select_snake():
if event.key == pygame.K_ESCAPE:
exit_game()
elif event.key == pygame.K_LEFT and not p1_pos == pos1 and not p1_pos == pos2:
pygame.draw.rect(Display, light_blue, p1, 5)
p1_pos = (p1_pos[0] - 300, p1_pos[1])
p1.move_ip(-300, 0)
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0] - 360, p1_pos[1])
p1.move_ip(-360, 0)
elif event.key == pygame.K_RIGHT and not p1_pos == pos3 and not p1_pos == pos4:
pygame.draw.rect(Display, light_blue, p1, 5)
p1_pos = (p1_pos[0] + 300, p1_pos[1])
p1.move_ip(300, 0)
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0] + 360, p1_pos[1])
p1.move_ip(360, 0)
elif event.key == pygame.K_UP and not p1_pos == pos1 and not p1_pos == pos3:
pygame.draw.rect(Display, light_blue, p1, 5)
p1_pos = (p1_pos[0], p1_pos[1] - 300)
p1.move_ip(0, -300)
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0], p1_pos[1] - 330)
p1.move_ip(0, -330)
elif event.key == pygame.K_DOWN and not p1_pos == pos2 and not p1_pos == pos4:
pygame.draw.rect(Display, light_blue, p1, 5)
p1_pos = (p1_pos[0], p1_pos[1] + 300)
p1.move_ip(0, +300)
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0], p1_pos[1] + 330)
p1.move_ip(0, +330)
elif event.key == pygame.K_a and not p2_pos == pos1 and not p2_pos == pos2:
pygame.draw.rect(Display, light_blue, p2, 5)
p2_pos = (p2_pos[0] - 300, p2_pos[1])
p2.move_ip(-300, 0)
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0] - 360, p2_pos[1])
p2.move_ip(-360, 0)
elif event.key == pygame.K_d and not p2_pos == pos3 and not p2_pos == pos4:
pygame.draw.rect(Display, light_blue, p2, 5)
p2_pos = (p2_pos[0] + 300, p2_pos[1])
p2.move_ip(300, 0)
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0] + 360, p2_pos[1])
p2.move_ip(360, 0)
elif event.key == pygame.K_w and not p2_pos == pos1 and not p2_pos == pos3:
pygame.draw.rect(Display, light_blue, p2, 5)
p2_pos = (p2_pos[0], p2_pos[1] - 300)
p2.move_ip(0, -300)
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0], p2_pos[1] - 330)
p2.move_ip(0, -330)
elif event.key == pygame.K_s and not p2_pos == pos2 and not p2_pos == pos4:
pygame.draw.rect(Display, light_blue, p2, 5)
p2_pos = (p2_pos[0], p2_pos[1] + 300)
p2.move_ip(0, +300)
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0], p2_pos[1] + 330)
p2.move_ip(0, +330)
if p1_pos == p2_pos:
pygame.draw.rect(Display, black, p1, 5)
......@@ -689,7 +802,7 @@ def select_snake():
if p1_pos == pos1:
p1_snake = green_head, green, green_start, green_win, green_win_end, green_lost, green_lost_end
elif p1_pos == pos2:
p1_snake = bot_head, black, bot_start, bot_win, bot_win_end, bot_lost, bot_lost_end
p1_snake = bot_head, very_light_grey, bot_start, bot_win, bot_win_end, bot_lost, bot_lost_end
elif p1_pos == pos3:
p1_snake = purple_head, purple, purple_start, purple_win, purple_win_end, purple_lost, purple_lost_end
elif p1_pos == pos4:
......@@ -698,45 +811,219 @@ def select_snake():
if p2_pos == pos1:
p2_snake = green_head, green, green_start, green_win, green_win_end, green_lost, green_lost_end
elif p2_pos == pos2:
p2_snake = bot_head, black, bot_start, bot_win, bot_win_end, bot_lost, bot_lost_end
p2_snake = bot_head, very_light_grey, bot_start, bot_win, bot_win_end, bot_lost, bot_lost_end
elif p2_pos == pos3:
p2_snake = purple_head, purple, purple_start, purple_win, purple_win_end, purple_lost, purple_lost_end
elif p2_pos == pos4:
p2_snake = red_head, red, red_start, red_win, red_win_end, red_lost, red_lost_end
select = button("Got my Snake", (int(res_x / 2 - 60), res_y - 475, 120, 50), green, light_green, action="switch")
select = button("Got my Snake", (int(res_x / 2 - 60), res_y - 450, 120, 50), green, light_green, action="select_map")
clock.tick(30)
pygame.display.update()
def select_map():
map_select = True
global map
global map_filename
global startsnake1, startsnake2
global snake_length
Display.fill(white)
pos1 = (-300, -100)
pos2 = (0, -100)
pos3 = (300, -100)
pos4 = (-300, 200)
pos5 = (0, 200)
pos6 = (300, 200)
p1_pos = pos1
p2_pos = pos3
p1 = selection_rect(green, 200, 200, p1_pos)
p2 = selection_rect(red, 200, 200, p2_pos)
message_screen("Select the Map!", black, -350, "large")
message_screen("If different maps are selected, its random choice", grey, -300, "small")
message_screen("Map1", black, pos1[1], "small", pos1[0])
message_screen("Map2", black, pos2[1], "small", pos2[0])
image_screen(map3_icon, pos3)
message_screen("Map4", black, pos4[1], "small", pos4[0])
image_screen(map5_icon, pos5)
image_screen(map6_icon, pos6)
pygame.draw.rect(Display, black, (int(res_x / 2 + 220), res_y - 415, 100, 30), 8)
pygame.draw.rect(Display, black, (int(res_x / 2 - 320), res_y - 415, 100, 30), 8)
while map_select:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit_game()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
exit_game()
elif event.key == pygame.K_0:
map = maps.map8
map_filename = '../Shield/maps/map8.pickle'
startsnake1, startsnake2 = maps.start8
snake_length = 4
return
elif event.key == pygame.K_LEFT and not p1_pos == pos1 and not p1_pos == pos4:
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0] - 300, p1_pos[1])
p1.move_ip(-300, 0)
elif event.key == pygame.K_RIGHT and not p1_pos == pos3 and not p1_pos == pos6:
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0] + 300, p1_pos[1])
p1.move_ip(300, 0)
elif event.key == pygame.K_UP and not p1_pos == pos1 and not p1_pos == pos2 and not p1_pos == pos3:
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0], p1_pos[1] - 300)
p1.move_ip(0, -300)
elif event.key == pygame.K_DOWN and not p1_pos == pos4 and not p1_pos == pos5 and not p1_pos == pos6:
pygame.draw.rect(Display, white, p1, 5)
p1_pos = (p1_pos[0], p1_pos[1] + 300)
p1.move_ip(0, 300)
elif event.key == pygame.K_a and not p2_pos == pos1 and not p2_pos == pos4:
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0] - 300, p2_pos[1])
p2.move_ip(-300, 0)
elif event.key == pygame.K_d and not p2_pos == pos3 and not p2_pos == pos6:
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0] + 300, p2_pos[1])
p2.move_ip(300, 0)
elif event.key == pygame.K_w and not p2_pos == pos1 and not p2_pos == pos2 and not p2_pos == pos3:
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0], p2_pos[1] - 300)
p2.move_ip(0, -300)
elif event.key == pygame.K_s and not p2_pos == pos4 and not p2_pos == pos5 and not p2_pos == pos6:
pygame.draw.rect(Display, white, p2, 5)
p2_pos = (p2_pos[0], p2_pos[1] + 300)
p2.move_ip(0, 300)
if p1_pos == p2_pos:
pygame.draw.rect(Display, black, p1, 5)
else:
pygame.draw.rect(Display, p1_snake[1], p1, 5)
pygame.draw.rect(Display, p2_snake[1], p2, 5)
p1_map = maps.map3
p2_map = maps.map3
p1_map_filename = '../Shield/maps/map3.pickle'
p2_map_filename = '../Shield/maps/map3.pickle'
p1_start = maps.start3
p2_start = maps.start3
p1_length = snake_length
p2_length = snake_length
if p1_pos == pos3:
p1_map = maps.map3
p1_map_filename = '../Shield/maps/map3.pickle'
p1_start = maps.start3
p1_length = 20
elif p1_pos == pos5:
p1_map = maps.map5
p1_map_filename = '../Shield/maps/map5.pickle'
p1_start = maps.start5
p1_length = 20
elif p1_pos == pos6:
p1_map = maps.map6
p1_map_filename = '../Shield/maps/map6.pickle'
p1_start = maps.start6
p1_length = 20
if p2_pos == pos3:
p2_map = maps.map3
p2_map_filename = '../Shield/maps/map3.pickle'
p2_start = maps.start3
p2_length = 15
elif p2_pos == pos5:
p2_map = maps.map5
p2_map_filename = '../Shield/maps/map5.pickle'
p2_start = maps.start5
p2_length = 15
elif p2_pos == pos6:
p2_map = maps.map6
p2_map_filename = '../Shield/maps/map6.pickle'
p2_start = maps.start6
p2_length = 30
if p1_pos == p2_pos:
map = p1_map
map_filename = p1_map_filename
startsnake1, startsnake2 = p1_start
snake_length = p1_length
else:
rand = random.randint(0, 1)
if rand:
map = p1_map
map_filename = p1_map_filename
startsnake1, startsnake2 = p1_start
snake_length = p1_length
else:
map = p2_map
map_filename = p2_map_filename
startsnake1, startsnake2 = p2_start
snake_length = p2_length
button("Fast", (int(res_x / 2 - 200), res_y - 415, 100, 30), red, light_red, action="speed65")
button("Medium", (int(res_x / 2 - 320), res_y - 415, 100, 30), yellow, light_yellow, action="speed45")
button("Slow", (int(res_x / 2 - 440), res_y - 415, 100, 30), green, light_green, action="speed25")
button("Long", (int(res_x / 2 + 340), res_y - 415, 100, 30), red, light_red, action="length20")
button("Medium", (int(res_x / 2 + 220), res_y - 415, 100, 30), yellow, light_yellow, action="length15")
button("Short", (int(res_x / 2 + 100), res_y - 415, 100, 30), green, light_green, action="length10")
map_select = button("Got the Map", (int(res_x / 2 - 60), res_y - 425, 120, 50), light_blue, very_light_blue, action="loading")
clock.tick(30)
pygame.display.update()
def set_game_speed(speed):
global FPS
FPS = speed
def set_snake_length(length):
global tmp_snake_length
tmp_snake_length = length
# print("set_snake_length to " + str(tmp_snake_length))
def modify_start_pos():
global snake_length
snake_length = tmp_snake_length
if snake_length == 20:
return
j = 20 - snake_length
for i in range(j):
startsnake1["pos"].pop()
startsnake1["vel"].pop()
startsnake2["pos"].pop()
startsnake2["vel"].pop()
def loading_screen():
loading = True
i = 1
j = 0
Display.fill(light_blue)
Display.fill(white)
message_screen("Loading ...", black, -350, 'large')
message_screen("V", p1_snake[1], 0, 'large', -30)
message_screen("S", p2_snake[1], 0, 'large', 30)
image_screen(p1_snake[2], (-250, 0))
image_screen(p2_snake[2], (250, 0))
pygame.display.update()
modify_start_pos()
generate_graph(snake_length, map, map_filename)
Display.fill(white)
while loading:
if i == 1:
message_screen("Loading .", black, -350, 'medium')
i += 1
elif i == 2:
message_screen("Loading ..", black, -350, 'medium')
i += 1
elif i == 3:
message_screen("Loading ...", black, -350, 'medium')