More effects and tweaks
This commit is contained in:
BIN
music/QonsVivaEveryone.mp3
Executable file
BIN
music/QonsVivaEveryone.mp3
Executable file
Binary file not shown.
86
snake.py
86
snake.py
@@ -21,6 +21,7 @@ class Game:
|
|||||||
self.snake_speed = 7
|
self.snake_speed = 7
|
||||||
self.enable_effects = True
|
self.enable_effects = True
|
||||||
self.enable_music = False
|
self.enable_music = False
|
||||||
|
self.music_started_once = False
|
||||||
|
|
||||||
# Snake and food characters
|
# Snake and food characters
|
||||||
# ASCII Table: https://theasciicode.com.ar/
|
# ASCII Table: https://theasciicode.com.ar/
|
||||||
@@ -80,7 +81,12 @@ class Game:
|
|||||||
|
|
||||||
# Start music
|
# Start music
|
||||||
if self.enable_music:
|
if self.enable_music:
|
||||||
self.queue.put('music.start')
|
if self.music_started_once:
|
||||||
|
self.music_unpause()
|
||||||
|
else:
|
||||||
|
self.music_start()
|
||||||
|
else:
|
||||||
|
self.music_pause()
|
||||||
|
|
||||||
# Start game!!!
|
# Start game!!!
|
||||||
self.start_game()
|
self.start_game()
|
||||||
@@ -95,27 +101,10 @@ class Game:
|
|||||||
|
|
||||||
# Calculate snake speed
|
# Calculate snake speed
|
||||||
wait_for_input_ms = {
|
wait_for_input_ms = {
|
||||||
1: 250,
|
1: 250, 2: 225, 3: 200,
|
||||||
2: 225,
|
4: 175, 5: 150, 6: 125,
|
||||||
3: 200,
|
7: 100, 8: 75, 9: 50, 10: 25
|
||||||
4: 175,
|
|
||||||
5: 150,
|
|
||||||
6: 125,
|
|
||||||
7: 100,
|
|
||||||
8: 75,
|
|
||||||
9: 50,
|
|
||||||
10: 25
|
|
||||||
}
|
}
|
||||||
# if self.snake_speed == 1: wait_for_input_ms = 250
|
|
||||||
# if self.snake_speed == 2: wait_for_input_ms = 225
|
|
||||||
# if self.snake_speed == 3: wait_for_input_ms = 200
|
|
||||||
# if self.snake_speed == 4: wait_for_input_ms = 175
|
|
||||||
# if self.snake_speed == 5: wait_for_input_ms = 150
|
|
||||||
# if self.snake_speed == 6: wait_for_input_ms = 125
|
|
||||||
# if self.snake_speed == 7: wait_for_input_ms = 100
|
|
||||||
# if self.snake_speed == 8: wait_for_input_ms = 75
|
|
||||||
# if self.snake_speed == 9: wait_for_input_ms = 50
|
|
||||||
# if self.snake_speed == 10: wait_for_input_ms = 25
|
|
||||||
self.stdscr.timeout(wait_for_input_ms[self.snake_speed])
|
self.stdscr.timeout(wait_for_input_ms[self.snake_speed])
|
||||||
|
|
||||||
# Ensure window is large enough
|
# Ensure window is large enough
|
||||||
@@ -157,23 +146,36 @@ class Game:
|
|||||||
# RIGHT
|
# RIGHT
|
||||||
elif next_key == curses.KEY_RIGHT and key != curses.KEY_LEFT:
|
elif next_key == curses.KEY_RIGHT and key != curses.KEY_LEFT:
|
||||||
key = next_key
|
key = next_key
|
||||||
# (P)ause
|
# ESCAPE Menu
|
||||||
elif next_key == ord('p'):
|
elif next_key == 27:
|
||||||
previous_key = key
|
previous_key = key
|
||||||
self.print_center("Game Paused. Press P to Resume.")
|
if self.enable_music: self.music_pause()
|
||||||
|
self.print_center(f"GAME PAUSED...", 0, self.colors['red'])
|
||||||
|
self.print_center(f"ESC Resume, (R)estart, (Q)uit, (M)enu", 2, self.colors['green'])
|
||||||
while True:
|
while True:
|
||||||
key = self.stdscr.getch()
|
key = self.stdscr.getch()
|
||||||
if key == ord('p'):
|
if key == 27:
|
||||||
break
|
break
|
||||||
|
elif key == ord('r'):
|
||||||
|
if self.enable_music: self.music_unpause()
|
||||||
|
self.start_game()
|
||||||
|
return
|
||||||
|
elif key == ord('q'):
|
||||||
|
self.exit_game()
|
||||||
|
elif key == ord('m'):
|
||||||
|
self.load()
|
||||||
|
return
|
||||||
|
# Resume
|
||||||
key = previous_key
|
key = previous_key
|
||||||
|
if self.enable_music: self.music_unpause()
|
||||||
continue
|
continue
|
||||||
# (R)estart
|
# (R)estart
|
||||||
elif next_key == ord('r'):
|
elif next_key == ord('r'):
|
||||||
self.start_game()
|
self.start_game()
|
||||||
return
|
return
|
||||||
# (Q)uit
|
# # (Q)uit
|
||||||
elif next_key == ord('q'):
|
# elif next_key == ord('q'):
|
||||||
break
|
# break
|
||||||
|
|
||||||
# Calculate new head
|
# Calculate new head
|
||||||
head = snake[0]
|
head = snake[0]
|
||||||
@@ -237,16 +239,21 @@ class Game:
|
|||||||
# Game Over screen
|
# Game Over screen
|
||||||
self.effect('over')
|
self.effect('over')
|
||||||
self.print_center(f"GAME OVER! SCORE: {score}", 0, self.colors['red'])
|
self.print_center(f"GAME OVER! SCORE: {score}", 0, self.colors['red'])
|
||||||
self.print_center(f"(R)estart, or (Q)uit", 2, self.colors['green'])
|
self.print_center(f"(R)estart, (Q)uit, (M)enu", 2, self.colors['green'])
|
||||||
self.stdscr.nodelay(0)
|
self.stdscr.nodelay(0)
|
||||||
|
#if self.enable_music: self.music_pause()
|
||||||
while True:
|
while True:
|
||||||
key = self.stdscr.getch()
|
key = self.stdscr.getch()
|
||||||
if key == ord('r'):
|
if key == ord('r'):
|
||||||
|
#if self.enable_music: self.music_unpause()
|
||||||
self.start_game()
|
self.start_game()
|
||||||
return
|
return
|
||||||
elif key == ord('q'):
|
elif key == ord('q'):
|
||||||
# Game over, exit app!
|
# Game over, exit app!
|
||||||
self.exit_game()
|
self.exit_game()
|
||||||
|
elif key == ord('m'):
|
||||||
|
self.load()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def print_center(self, value, y_offset = 0, color = 3):
|
def print_center(self, value, y_offset = 0, color = 3):
|
||||||
@@ -346,6 +353,19 @@ class Game:
|
|||||||
if self.enable_effects:
|
if self.enable_effects:
|
||||||
self.queue.put(effect)
|
self.queue.put(effect)
|
||||||
|
|
||||||
|
def music_start(self):
|
||||||
|
self.music_started_once = True
|
||||||
|
self.queue.put('music.start')
|
||||||
|
|
||||||
|
def music_stop(self):
|
||||||
|
self.queue.put('music.stop')
|
||||||
|
|
||||||
|
def music_pause(self):
|
||||||
|
self.queue.put('music.pause')
|
||||||
|
|
||||||
|
def music_unpause(self):
|
||||||
|
self.queue.put('music.unpause')
|
||||||
|
|
||||||
|
|
||||||
def main(stdscr, queue):
|
def main(stdscr, queue):
|
||||||
game = Game(stdscr, queue)
|
game = Game(stdscr, queue)
|
||||||
@@ -367,8 +387,8 @@ def sound_process(sound_queue):
|
|||||||
# Load sounds/music (adjust file paths as needed)
|
# Load sounds/music (adjust file paths as needed)
|
||||||
# Use .wav or .ogg for better compatibility
|
# Use .wav or .ogg for better compatibility
|
||||||
#effect = pygame.mixer.Sound('effects/bing.mp3')
|
#effect = pygame.mixer.Sound('effects/bing.mp3')
|
||||||
#music_file = 'music/Guitar_Sound.mp3'
|
music_file = 'music/QonsVivaEveryone.mp3'
|
||||||
music_file = 'music/s.mp3'
|
#music_file = 'music/s.mp3'
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if not sound_queue.empty():
|
if not sound_queue.empty():
|
||||||
@@ -386,6 +406,10 @@ def sound_process(sound_queue):
|
|||||||
pygame.mixer.music.play(-1) # Play music indefinitely
|
pygame.mixer.music.play(-1) # Play music indefinitely
|
||||||
elif command == 'music.stop':
|
elif command == 'music.stop':
|
||||||
pygame.mixer.music.stop()
|
pygame.mixer.music.stop()
|
||||||
|
elif command == 'music.pause':
|
||||||
|
pygame.mixer.music.pause();
|
||||||
|
elif command == 'music.unpause':
|
||||||
|
pygame.mixer.music.unpause();
|
||||||
|
|
||||||
# Quit came
|
# Quit came
|
||||||
elif command == 'quit':
|
elif command == 'quit':
|
||||||
|
|||||||
Reference in New Issue
Block a user