diff --git a/images/tree.png b/images/tree.png new file mode 100644 index 0000000..f6d808e Binary files /dev/null and b/images/tree.png differ diff --git a/import pgzrun.py b/import pgzrun.py deleted file mode 100644 index 6173a86..0000000 --- a/import pgzrun.py +++ /dev/null @@ -1,57 +0,0 @@ -import pgzrun -import random - -WIDTH = 800 -HEIGHT = 600 - -background = Actor('grass') - -player = Actor('p3_front') -player.x = 400 -player.y = 300 - -coin = Actor('coingold') -coin.x = random.randint(0, 800) -coin.y = random.randint(0, 600) - -score = 0 -timer = 35 - -def update(): - global score - global timer - - if timer <= 0: - return - - timer -= 1 / 60 - - if keyboard.up: - player.y -= 5 - if keyboard.down: - player.y += 5 - if keyboard.left: - player.x -= 5 - if keyboard.right: - player.x += 5 - - if player.colliderect(coin): - coin.x = random.randint(0, 800) - coin.y = random.randint(0, 600) - score += 1 - sounds.sfx_coin_single1.play() - - -def draw(): - if timer <= 0: - screen.clear() - screen.draw.text('Game Over', (350,270), color=(255,255,255), fontsize=30) - screen.draw.text('Score: ' + str(score), (350,330), color=(255,255,255), fontsize=30) - else: - background.draw() - player.draw() - coin.draw() - screen.draw.text('Score: ' + str(score), (15,10), color=(255,255,255), fontsize=30) - screen.draw.text('Time: ' + str(round(timer, 2)), (330,10), color=(255,255,255), fontsize=30) - -pgzrun.go() # Must be last line \ No newline at end of file diff --git a/main.py b/main.py index 83e4272..0b67f46 100644 --- a/main.py +++ b/main.py @@ -1,50 +1,105 @@ -""" -renny -""" import pgzrun import random WIDTH = 800 HEIGHT = 600 -ship = Actor('playership1_blue') -ship.x = 370 -ship.y = 550 +background = Actor('grass') -gem = Actor('gemgreen') -gem.x = random.randint(20, 780) -gem.y = 0 + +player = Actor('p3_front') +player.x = 400 +player.y = 300 + + +coin = Actor('coingold') +coin.x = random.randint(50, WIDTH - 50) +coin.y = random.randint(50, HEIGHT - 50) + + +trees = [] + +tree_count = 2 +for _ in range(tree_count): + new_tree = Actor('tree') + + new_tree.x = random.randint(80, WIDTH - 80) + new_tree.y = random.randint(80, HEIGHT - 80) + + while new_tree.colliderect(player): + new_tree.x = random.randint(80, WIDTH - 80) + new_tree.y = random.randint(80, HEIGHT - 80) + trees.append(new_tree) score = 0 -game_over = False +timer = 35 -def on_mouse_move(pos, rel, buttons): - ship.x = pos[0] + +def check_tree_collision(new_x, new_y): + temp_player = Actor('p3_front', pos=(new_x, new_y)) + for tree in trees: + if temp_player.colliderect(tree): + return False + return True def update(): - global score, game_over + global score + global timer + if timer <= 0: + return + + timer -= 1 / 60 + + move_speed = 5 + + if keyboard.up: + new_y = player.y - move_speed + if check_tree_collision(player.x, new_y): + player.y = new_y + if keyboard.down: + new_y = player.y + move_speed + if check_tree_collision(player.x, new_y): + player.y = new_y if keyboard.left: - ship.x = ship.x - 5 + new_x = player.x - move_speed + if check_tree_collision(new_x, player.y): + player.x = new_x if keyboard.right: - ship.x = ship.x + 5 + new_x = player.x + move_speed + if check_tree_collision(new_x, player.y): + player.x = new_x + + + if player.colliderect(coin): + + while True: + coin.x = random.randint(50, WIDTH - 50) + coin.y = random.randint(50, HEIGHT - 50) + overlap_tree = False + for t in trees: + if coin.colliderect(t): + overlap_tree = True + break + if not overlap_tree: + break + score += 1 + sounds.sfx_coin_single1.play() - gem.y = gem.y + 4 + score / 5 - if gem.y > 600: - game_over = True - if gem.colliderect(ship): - gem.x = random.randint(20, 780) - gem.y = 0 - score = score + 1 def draw(): - screen.fill((80,0,70)) - if game_over: - screen.draw.text('Game Over', (360, 300), color=(255,255,255), fontsize=60) - screen.draw.text('Score: ' + str(score), (360, 350), color=(255,255,255), fontsize=60) + if timer <= 0: + screen.fill((30, 30, 30)) + screen.draw.text('Game Over', (330, 270), color=(255,255,255), fontsize=36) + screen.draw.text('Final Score: ' + str(score), (330, 330), color=(255,255,255), fontsize=30) else: - gem.draw() - ship.draw() + background.draw() + + for tree in trees: + tree.draw() + player.draw() + coin.draw() screen.draw.text('Score: ' + str(score), (15,10), color=(255,255,255), fontsize=30) + screen.draw.text('Time: ' + str(round(timer, 2)), (330,10), color=(255,255,255), fontsize=30) pgzrun.go() # Must be last line \ No newline at end of file