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

ui changes

parent 4fb8de32
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
......@@ -23,6 +23,8 @@ from graph_from_map import generate_graph
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)
......@@ -31,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)
......@@ -109,8 +112,8 @@ map_filename = '../Shield/maps/map6.pickle'
# map and start position
startsnake1, startsnake2 = maps.start6
map = maps.map6
snake_length = 20
tmp_snake_length = 20
snake_length = 15
tmp_snake_length = 15
apples = [(set([]), green_apple), (set([]), purple_apple)]
bombs = [(set([]), bomb_img)]
......@@ -606,6 +609,8 @@ 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)
......@@ -613,26 +618,44 @@ def button(text, pos, color1, color2, action, text_color=black):
if action == "switch":
return False
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)
......@@ -779,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:
......@@ -788,7 +811,7 @@ 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:
......@@ -824,6 +847,8 @@ def select_map():
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():
......@@ -939,10 +964,10 @@ def select_map():
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 + 100), res_y - 415, 100, 30), red, light_red, action="length20")
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 + 340), 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), blue, light_blue, action="loading")
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()
......@@ -955,7 +980,7 @@ def set_game_speed(speed):
def set_snake_length(length):
global tmp_snake_length
tmp_snake_length = length
print("set_snake_length to " + str(tmp_snake_length))
# print("set_snake_length to " + str(tmp_snake_length))
def modify_start_pos():
......@@ -982,7 +1007,6 @@ def loading_screen():
pygame.display.update()
modify_start_pos()
generate_graph(snake_length, map, map_filename)
pygame.time.delay(1000)
Display.fill(white)
while loading:
for event in pygame.event.get():
......@@ -997,7 +1021,7 @@ def loading_screen():
message_screen("S", p2_snake[1], 0, 'large', 30)
image_screen(p1_snake[2], (-250, 0))
image_screen(p2_snake[2], (250, 0))
loading = button("Play", (int(res_x / 2 - 60), res_y - 600, 120, 50), blue, light_blue, action="switch")
loading = button("Play", (int(res_x / 2 - 60), res_y - 600, 120, 50), light_blue, very_light_blue, action="switch")
clock.tick(30)
pygame.display.update()
......@@ -1020,6 +1044,7 @@ def game_intro():
message_screen("Snake Game", green, -120, "large")
message_screen("Collect " + str(apple_win_count) + " apples faster than your enemy,", black, -30, "small")
message_screen("without crashing!", black, 10, "small")
message_screen("First player to win 3 rounds, wins the game!", black, 70, "small")
button("Controls", (int(res_x / 2 - 60), res_y - 150, 120, 50), yellow, light_yellow, action="controls")
button("Quit", (int(res_x / 2 + 120), res_y - 150, 100, 50), red, light_red, action="quit")
intro = button("Play", (int(res_x / 2 - 220), res_y - 150, 100, 50), green, light_green, action="select_snake")
......@@ -1062,24 +1087,46 @@ def game_loop():
s = pygame.Surface((res_x, res_y), pygame.SRCALPHA)
s.fill((255, 255, 255, 180))
Display.blit(s, (0, 0))
game_over = False
if playerwin == 1 or (playerwin == 3 and snake1.getscore() > snake2.getscore()):
overall_score[0] += 1
message_screen("Player 1 wins this round !", p1_snake[1], -50, "large")
image_screen(p1_snake[3], (0, -250))
if overall_score[0] == 3:
overall_score[0] = 0
overall_score[1] = 0
message_screen("Player 1 wins the game !", p1_snake[1], -50, "large")
image_screen(p1_snake[4], (-200, -250))
image_screen(p2_snake[6], (200, -250))
game_over = True
else:
message_screen("Player 1 wins this round !", p1_snake[1], -50, "large")
image_screen(p1_snake[3], (-200, -250))
image_screen(p2_snake[5], (200, -250))
if playerwin == 2 or (playerwin == 3 and snake2.getscore() > snake1.getscore()):
overall_score[1] += 1
message_screen("Player 2 wins this round !", p2_snake[1], -50, "large")
image_screen(p2_snake[3], (0, -250))
if overall_score[1] == 3:
overall_score[0] = 0
overall_score[1] = 0
message_screen("Player 2 wins the game!", p2_snake[1], -50, "large")
image_screen(p2_snake[4], (-200, -250))
image_screen(p1_snake[6], (200, -250))
game_over = True
else:
message_screen("Player 2 wins this round !", p2_snake[1], -50, "large")
image_screen(p2_snake[3], (-200, -250))
image_screen(p1_snake[5], (200, -250))
if playerwin == 3 and snake1.getscore() == snake2.getscore():
message_screen("Tied!", black, -50, "large")
message_screen(str(overall_score[0]), green, 30, "large", -60)
message_screen(":", black, 30, "large")
message_screen(str(overall_score[1]), purple, 30, "large", 60)
message_screen("Press Space to restart or Esc to quit.", black, 80)
game_over = True
if not game_over:
message_screen(str(overall_score[0]), green, 30, "large", -60)
message_screen(":", black, 30, "large")
message_screen(str(overall_score[1]), purple, 30, "large", 60)
message_screen("Press Space to start next game or Esc to quit.", black, 80)
else:
message_screen("Press Space to start next round or Esc to quit.", black, 80)
round_over = True
pygame.display.update()
while game_over:
while round_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit_game()
......
No preview for this file type
No preview for this file type
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment