Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added Road cross turtle game in pygame scripts folder #990

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

Closed
AJgthb2002 wants to merge 2 commits into prathimacode-hub:main from AJgthb2002:main
Closed
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
21 changes: 21 additions & 0 deletions PyGamesScripts/Turtle Road Cross game/README.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## The Cross Boss!
#### An interactive single-player game where the player must help the turtle reach the other side of the road, by successfully dodging the cars.

- The turtle can only move forward.
- Cars appear on the screen at random intervals and move along the road from right to left.
- If the turtle reaches the other side successfully, the player is promoted to the next game level.
- The difficulty level increases progressively with the increase in the speed of cars on the road.
- The game is over when a car touches the turtle.
- Built using the turtle module in python.

<table>
<tr>
<td>
<img src="https://user-images.githubusercontent.com/73184612/128293281-5492671c-211a-4970-b8a9-b3c34b7e61c4.png"> </img>
</td>
<td>
<img src="https://user-images.githubusercontent.com/73184612/128293303-330929fb-1e87-4836-aae9-2849122eeb58.png"> </img>
</td>
</tr>
</table>

Binary file added PyGamesScripts/Turtle Road Cross game/bg.png
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
30 changes: 30 additions & 0 deletions PyGamesScripts/Turtle Road Cross game/car_manager.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from turtle import Turtle
import random
COLORS = ["firebrick", "orange", "yellow", "white", "blue", "purple", "cornflower blue", "deep pink"]
STARTING_MOVE_DISTANCE = 5
MOVE_INCREMENT = 5


class CarManager():
def __init__(self):
self.allcars=[]
self.carspeed = STARTING_MOVE_DISTANCE

def create_car(self):
random_chance= random.randint(1,6)
if random_chance ==1:
newcar= Turtle()
newcar.shape("square")
newcar.shapesize(1,2)
newcar.penup()
newcar.color(random.choice(COLORS))
random_y = random.randint(-215, 215)
newcar.goto(300, random_y)
self.allcars.append(newcar)

def move_cars(self):
for car in self.allcars:
car.backward(self.carspeed)

def level_up(self):
self.carspeed += MOVE_INCREMENT
41 changes: 41 additions & 0 deletions PyGamesScripts/Turtle Road Cross game/main.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard


screen = Screen()
screen.setup(width=600, height=600)
screen.bgpic("bg.png")
screen.title("Cross the road!")
screen.tracer(0)
playert= Player()
car= CarManager()
scoreboard= Scoreboard()
screen.listen()
screen.onkeypress(playert.moveup,"Up")


game_is_on = True
while game_is_on:
time.sleep(0.1)
screen.update()

car.create_car()
car.move_cars()

#detect collision with car
for c in car.allcars:
if c.distance(playert) < 25:
game_is_on= False
scoreboard.game_over()
#detect successful reach to end line
if playert.ycor() >= 260:
playert.start_pos()
car.level_up()
scoreboard.increase_level()



screen.exitonclick()
23 changes: 23 additions & 0 deletions PyGamesScripts/Turtle Road Cross game/player.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from turtle import Turtle

STARTING_POSITION = (-60, -270)
MOVE_DISTANCE = 10
FINISH_LINE_Y = 280


class Player(Turtle):
def __init__(self):
super().__init__()
self.shape("turtle")
self.color("black")
self.penup()
self.start_pos()

def start_pos(self):
self.goto(STARTING_POSITION)
self.setheading(90)

def moveup(self):
newy= self.ycor()+ MOVE_DISTANCE
self.goto(self.xcor(), newy)

26 changes: 26 additions & 0 deletions PyGamesScripts/Turtle Road Cross game/scoreboard.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from turtle import Turtle
FONT = ("Courier", 24, "normal")


class Scoreboard(Turtle):
def __init__(self):
super().__init__()
self.hideturtle()
self.penup()
self.level =1
self.goto(-290, 230)
self.update_scoreboard()


def increase_level(self) :
self.level+=1
self.update_scoreboard()

def update_scoreboard(self):
self.clear()
self.color("black")
self.write(f"Level: {self.level}", align="left", font=FONT)

def game_over(self):
self.goto(0,0)
self.write("GAME OVER", align="center", font= FONT)

AltStyle によって変換されたページ (->オリジナル) /