Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving Issue 1 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Binary file added game_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 21 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def wait_for_key(self):
class Apple:
def __init__(self, parent_screen):
self.parent_screen = parent_screen
self.image = oss.image.load("resources/apple.jpg.png").convert()
self.image = oss.image.load("./apple.jpg.png").convert()
self.x = 120
self.y = 120

Expand All @@ -50,7 +50,7 @@ def move(self):
class Snake:
def __init__(self, parent_screen):
self.parent_screen = parent_screen
self.image = oss.image.load("resources/block.jpg.png").convert()
self.image = oss.image.load("./block.jpg.png").convert()
self.direction = 'down'

self.length = 1
Expand Down Expand Up @@ -94,7 +94,6 @@ def draw(self):

def increase_length(self):
#increase length of the snake
//

class PLAY:
def __init__(self):
Expand All @@ -111,35 +110,42 @@ def __init__(self):
self.speed=0.25

def play_background_music(self):
oss.mixer.music.load("resources/enigma-dream-170618.mp3")
oss.mixer.music.load("./enigma-dream-170618.mp3")
oss.mixer.music.play(-1, 0)

def play_sound(self, sound_name):
if sound_name == 'beep':
sound = oss.mixer.Sound("resources/beep.mp3.mp3")
sound = oss.mixer.Sound("./beep.mp3.mp3")
elif sound_name == 'beep':
sound = oss.mixer.Sound("resources/beep.mp3.mp3")
sound = oss.mixer.Sound("./beep.mp3.mp3")

oss.mixer.Sound.play(sound)

def reset(self):
self.snake = Snake(self.surface)
self.apple = Apple(self.surface)
self.speed = 0.25

def increase_speed(self):
if self.snake.length == 5:
self.speed = 0.1
elif self.snake.length == 10:
self.speed = 0.05
elif self.snake.length == 15:
self.speed = 0.01

def is_collision(self, x1, y1, x2, y2):
#add collision of snake on boundary

def is_out_of_bounds(self):
if(
self.snake.x[0]<0
if (self.snake.x[0]<0
or self.snake.x[0]>=1000
or self.snake.y[0]<0
or self.snake.y[0]>=800
):
or self.snake.y[0]>=800):
return True
return False
def render_background(self):
bg = oss.image.load("resources/background.jpg.jpg")
bg = oss.image.load("./background.jpg.jpg")
self.surface.blit(bg, (0,0))

def play(self):
Expand All @@ -153,6 +159,8 @@ def play(self):
self.play_sound("beep")
self.snake.increase_length()
self.apple.move()
if self.snake.length%5==0:
self.increase_speed()

if self.is_out_of_bounds():
self.play_sound('beep')
Expand Down Expand Up @@ -227,6 +235,8 @@ def run(self):
if __name__ == '__main__':
oss.init()
surface = oss.display.set_mode((1000, 800))
oss.display.set_caption('Snake Game')
oss.display.set_icon(oss.image.load(r"./game_icon.png"))
welcome = WelcomeScreen(surface)
welcome.show_welcome()
welcome.wait_for_key()
Expand Down