diff --git a/game_icon.png b/game_icon.png new file mode 100644 index 0000000..956950c Binary files /dev/null and b/game_icon.png differ diff --git a/main.py b/main.py index 0a5e600..a4e1cfc 100644 --- a/main.py +++ b/main.py @@ -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 @@ -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 @@ -94,7 +94,6 @@ def draw(self): def increase_length(self): #increase length of the snake - // class PLAY: def __init__(self): @@ -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): @@ -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') @@ -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()