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

Ujjwal singh 20/issue #473 #506

Merged
merged 2 commits into from
Oct 12, 2024
Merged
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
20 changes: 20 additions & 0 deletions Game_Development/Turtle Collection Game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Turtle Collection Game

🎯 Goal The goal of this project is to create a turtle game.

🧾 Description
The Turtle Collection Game is a simple arcade-style game built using the Python turtle module. The player controls a turtle that navigates the screen, collecting points while avoiding obstacles. The objective is to increase the score by moving the player turtle toward randomly placed point items on the screen. The game ends if the player collides with any obstacles.

🧮 What I had done!


Developed a simple arcade-style game using Python's turtle module. The player controls a turtle that collects points while avoiding randomly placed obstacles. The player moves the turtle using the arrow keys, and the score increases when the turtle touches a randomly appearing "point" object. The game ends if the player collides with any obstacles. The game includes basic mechanics for movement, scoring, and game-over conditions, with potential for further improvements and additional features.

📚 Libraries Needed

turtle: For creating graphics, handling movement, and player interactions.
random: To generate random positions for the point and obstacles on the screen.

📢 Conclusion

In conclusion, the Turtle Collection Game is a fun and interactive project built using Python's turtle and random modules. It allows the player to control a turtle to collect points while avoiding obstacles, incorporating basic game mechanics like movement, collision detection, and scoring. The project is functional, and its simplicity makes it ideal for further enhancements, such as adding difficulty levels, sound effects, or more complex game dynamics. It's a great starting point for those looking to explore game development using Python.
105 changes: 105 additions & 0 deletions Game_Development/Turtle Collection Game/Turtle Collection Game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import turtle
import random

# Setup the screen
screen = turtle.Screen()
screen.title("Turtle Collection Game")
screen.setup(width=800, height=600)
screen.bgcolor("lightblue")

# Create player turtle
player = turtle.Turtle()
player.shape("turtle")
player.color("green")
player.penup()
player.speed(10) # Slow animation speed to see the movement

# Create point turtle
point = turtle.Turtle()
point.shape("square")
point.color("gold")
point.penup()
point.speed(0)
point.hideturtle() # Hide the point turtle initially

# Create obstacle turtles
obstacles = []
num_obstacles = 10
for _ in range(num_obstacles):
obstacle = turtle.Turtle()
obstacle.shape("square")
obstacle.color("red")
obstacle.penup()
obstacle.speed(0)
obstacle.goto(random.randint(-350, 350), random.randint(-250, 250))
obstacles.append(obstacle)

# Score
score = 0

# Functions
def move_up():
player.setheading(90) # Move up

def move_down():
player.setheading(270) # Move down

def move_left():
player.setheading(180) # Move left

def move_right():
player.setheading(0) # Move right

def check_collision(t1, t2):
return t1.distance(t2) < 20

def update_score():
global score
score += 10
score_display.clear()
score_display.write(f"Score: {score}", align="center", font=("Arial", 24, "normal"))

# Keyboard bindings
screen.listen()
screen.onkey(move_up, "Up")
screen.onkey(move_down, "Down")
screen.onkey(move_left, "Left")
screen.onkey(move_right, "Right")

# Display score
score_display = turtle.Turtle()
score_display.hideturtle()
score_display.penup()
score_display.goto(0, 260)
score_display.write(f"Score: {score}", align="center", font=("Arial", 24, "normal"))

# Place the point randomly
def place_point():
x = random.randint(-350, 350)
y = random.randint(-250, 250)
point.goto(x, y)
point.showturtle()

place_point()

# Game loop
while True:
player.forward(1) # Move the player turtle forward

# Check collision with point
if check_collision(player, point):
update_score()
place_point()

# Check collision with obstacles
for obstacle in obstacles:
if check_collision(player, obstacle):
score_display.clear()
score_display.goto(0, 0)
score_display.write("Game Over!", align="center", font=("Arial", 36, "bold"))
turtle.done()
break

screen.update() # Update the screen

screen.mainloop()