Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from several developers (GitHub usernames):

* Lucas Almeida (lalmeida32)
* Gustavo Sampaio (GusSampaio)







Binary file added assets/sounds/collect-power-ups.mp3
Binary file not shown.
Binary file added assets/sounds/death.mp3
Binary file not shown.
Binary file added assets/sounds/eat-apple.wav
Binary file not shown.
Binary file added assets/sounds/game-start.mp3
Binary file not shown.
Binary file added assets/sounds/gamemusic.mp3
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/sounds/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
All audio used is free license and obtained from the
websites https://pixabay.com/pt/sound-effects/
and https://freesound.org/
26 changes: 25 additions & 1 deletion sucury.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import pygame
import random
import sys
from pygame import mixer

##
## Game customization.
Expand Down Expand Up @@ -66,6 +67,14 @@

arena = pygame.display.set_mode((WIDTH, HEIGHT))

# Initializes music and sound effects
mixer.music.load("assets/sounds/gamemusic.mp3")
eat_apple_sound = mixer.Sound("assets/sounds/eat-apple.wav")
game_start_sound = mixer.Sound("assets/sounds/game-start.mp3")
death_sound = mixer.Sound("assets/sounds/death.mp3")
mixer.music.play(loops=-1)


BIG_FONT = pygame.font.Font("assets/font/Ramasuri.ttf", int(WIDTH/8))
SMALL_FONT = pygame.font.Font("assets/font/Ramasuri.ttf", int(WIDTH/20))

Expand Down Expand Up @@ -186,11 +195,15 @@ def update(self):

# Check for border crash.
if self.head.x not in range(0, WIDTH) or self.head.y not in range(0, HEIGHT):
mixer.music.stop() # Stop the music when dying
mixer.Sound.play(death_sound) # Play the sound of death
self.alive = False

# Check for self-bite.
for square in self.tail:
if self.head.x == square.x and self.head.y == square.y:
mixer.music.stop() # Stop the music when dying
mixer.Sound.play(death_sound) # Play the sound of death
self.alive = False

# Set the last_velocity, to remove 180° turns.
Expand All @@ -207,7 +220,7 @@ def update(self):

# Respan the head
self.x, self.y = grid_size, grid_size
self.head = pygame.Rect(self.x, self.y, grid_size, grid_size)
self.head = pygame.Rect(self.x, self.y, grid_size, grid_size)

# Respan the initial tail
self.tail = []
Expand All @@ -220,6 +233,9 @@ def update(self):
self.alive = True
self.should_grow = False

# When reborn, the music starts again
mixer.music.play(loops=-1)

# Drop and apple
apple = Apple()

Expand Down Expand Up @@ -287,6 +303,9 @@ def draw_grid():
snake = Snake() # The snake
apple = Apple() # An apple

# Play the start sound
mixer.Sound.play(game_start_sound)

##
## Main loop
##
Expand Down Expand Up @@ -315,6 +334,10 @@ def draw_grid():
sys.exit()
elif event.key == pygame.K_p: # S : pause game
game_on = not game_on
if game_on:
mixer.music.unpause()
else:
mixer.music.pause()

## Update the game

Expand All @@ -340,6 +363,7 @@ def draw_grid():

# If the head pass over an apple, lengthen the snake and drop another apple
if snake.head.x == apple.x and snake.head.y == apple.y:
mixer.Sound.play(eat_apple_sound)
snake.grow()
apple = Apple()

Expand Down