def run_game(): # Initialize the game configuration pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Snake_game") sn = Snake(ai_settings, screen) fr = Fruit(ai_settings, screen) stats = GameStats(ai_settings) sb = Score(ai_settings, screen, stats) while True: gf.check_event(sn) sn.update() gf.update_fruit(ai_settings, sn, fr, stats, sb) gf.update_screen(ai_settings, screen, sn, fr, sb)
def run_game(): pygame.init() width = 800 height = 600 screen = pygame.display.set_mode((width, height)) pygame.display.set_caption("Powerup") score = Score(screen, width, height) while True: screen.fill((255, 255, 255)) score.update() pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: score.add_score(100) if event.key == pygame.K_UP: score.add_coins(1)
# Importing the required modules from turtle import Screen from snake import Snake from food import Food from scoreboard import Score import time # Creating a screen to display our snake game screen = Screen() screen.setup(width=600, height=600) screen.bgcolor('black') screen.title('Snake Game') screen.tracer(0) # Creating score, snake, and food objects from the respective Classes score = Score() snake = Snake() food = Food() # Event listeners to tract the button clicks screen.listen() screen.onkey(fun=snake.up, key='Up') screen.onkey(fun=snake.down, key='Down') screen.onkey(fun=snake.left, key='Left') screen.onkey(fun=snake.right, key='Right') is_game_on = True # Loop to keep the game on while is_game_on: screen.update()
from turtle import Screen import time from food import Food from snake import Snake from scoreboard import Score screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("Snake Game") screen.tracer(0) snake = Snake() food = Food() score = Score() screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.left, "Left") screen.onkey(snake.right, "Right") game_is_on = True while game_is_on: screen.update() time.sleep(0.1) snake.move() # detect collision with food
from turtle import Screen import time from snake import Snake from food import Food from scoreboard import Score screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("Nadir's Snake Game") screen.tracer(0) score_board = 0 snake = Snake() food = Food() score = Score() screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.right, "Right") screen.onkey(snake.left, "Left") is_game_on = True while is_game_on: screen.update() time.sleep(0.1) snake.move() # collision of food if snake.head.distance(food) < 15: food.refresh() score.add_score()
import time from snake import Snake from food import Food from scoreboard import Score screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("Snake Game") #this sets the updating of the screen off screen.tracer(0) snake = Snake() food = Food() score = Score() screen.listen() screen.onkey(fun=snake.up, key="Up") screen.onkey(fun=snake.right, key="Right") screen.onkey(fun=snake.left, key="Left") screen.onkey(fun=snake.down, key="Down") x = 0 game_is_on = True user_score = 0 while game_is_on: #This makes us update our screen and display the user all the changes that have been made screen.update() snake.move()
screen.bgcolor((119, 221, 119)) screen.tracer(0) snake = Snake() snake.create_snake() screen.listen() screen.onkey(key="Up", fun=snake.up) screen.onkey(key="Down", fun=snake.down) screen.onkey(key="Right", fun=snake.right) screen.onkey(key="Left", fun=snake.left) food = Food() score = Score() is_continue = True while is_continue: time.sleep(0.09) screen.update() snake.move() if snake.head.distance(food) < 10: food.refresh() snake.extend() score.increase_score() if snake.head.xcor() > 490 or snake.head.xcor() < -490 or snake.head.ycor( ) > 390 or snake.head.ycor() < -390: is_continue = False score.game_over()
from turtle import Screen from paddle import Paddle from ball import Ball import time from scoreboard import Score score = Score() screen = Screen() screen.setup(800, 600) screen.bgcolor("black") screen.title("Pong") screen.tracer(0) r_paddle = Paddle((360, 0)) l_paddle = Paddle((-360, 0)) ball = Ball() screen.listen() screen.onkey(r_paddle.right_go_up, "Up") screen.onkey(r_paddle.right_go_down, "Down") screen.onkey(l_paddle.left_go_up, "w") screen.onkey(l_paddle.left_go_down, "s") game_is_on = True while game_is_on: time.sleep(ball.move_speed) screen.update() ball.move() # Detect Collision with the Upper and Lower Walls: if ball.ycor() > 280 or ball.ycor() < -280:
from turtle import Screen from paddle import Paddle from scoreboard import Score from ball import Ball import time #Setting up screen properties screen = Screen() screen.screensize(canvheight=400, canvwidth=600, bg="black") screen.title("Python Pong Game") #Turning screen animation off screen.tracer(0) #Setting up Scoreboard and field scoreboard = Score() line = Score() line.draw_game_field() #Setting up the paddles initial_position_l = [-300, 40] initial_position_r = [300, 40] l_paddle = Paddle() r_paddle = Paddle() l_paddle.create_paddle(initial_position_l) r_paddle.create_paddle(initial_position_r) #Setting up the ball. ball = Ball() #Initializing the game while loop.
from ball import Ball from paddle import Paddle from scoreboard import Score screen = Screen() screen.setup(width=800, height=600) screen.bgcolor("black") screen.title("Pong") screen.tracer(0) paddle_right = Paddle((350, 0)) paddle_left = Paddle((-350, 0)) score1 = Score((-200, 250)) score2 = Score((200, 250)) ball = Ball() screen.listen() screen.onkeypress(paddle_right.go_up, "Up") screen.onkeypress(paddle_right.go_down, "Down") screen.onkeypress(paddle_left.go_up, "w") screen.onkeypress(paddle_left.go_down, "s") game_is_on = True score1.sum_score1() score2.sum_score2() while game_is_on:
from turtle import Screen from snakeproperties import Snake from food import Food from scoreboard import Score import time screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("snake game") screen.tracer() snake = Snake() foodie = Food() score1 = Score() screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.left, "Left") screen.onkey(snake.right, "Right") is_game_on = True while is_game_on: screen.update() time.sleep(1) snake.move() # detect collision with food
from turtle import Screen from car_manager import CarManager from player import Player from scoreboard import Score import time screen = Screen() screen.screensize(600, 600) screen.bgcolor("white") screen.title(" TURTLE CROSSING") screen.tracer(0) player = Player() score = Score() car_manager = CarManager() screen.listen() screen.onkey(fun=player.cross_the_road, key="Up") game_on = True while game_on: time.sleep(0.1) screen.update() # Creating a car: car_manager.create_car() car_manager.drive() # DETECT collision with a car: for car in car_manager.all_cars: if player.distance(car) < 20:
from turtle import Turtle, Screen import time from snake import Snake from food import Food from scoreboard import Score screen = Screen() screen.setup(height=600, width=600) screen.title("The Python Snake Game") screen.bgcolor("black") screen.tracer(0) screen.listen() snake = Snake() food = Food() score = Score() food.refresh() game_on = True while game_on: score.starting_score() screen.update() time.sleep(0.1) snake.move() # Key Commands screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.right, "Right") screen.onkey(snake.left, "Left")
from turtle import Screen from snake import Snake from food import Food from scoreboard import Score import time screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("My Snake Game") screen.tracer(0) snake = Snake() food = Food() score = Score() score.write(score.score) screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.left, "Left") screen.onkey(snake.right, "Right") game_is_on = True while game_is_on: screen.update() time.sleep(0.1) snake.move() #collision with food if snake.head.distance(food) < 15:
from turtle import Screen from players import Player from cars import CarManager from scoreboard import Score import time screen = Screen() screen.screensize(600, 600) screen.tracer(0) player = Player() cars = CarManager() score = Score() screen.listen() screen.onkey(player.move_up, "Up") screen.onkey(player.move_down, "Down") game_on = True while game_on: screen.update() time.sleep(0.1) cars.create_car() cars.move_car() if player.level_up(): player.go_to_start() cars.speed_up() score.points() for car in cars.all_cars:
from turtle import Screen, time from snake import Snake from food import Food from scoreboard import Score screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("Welcome to Snake Game") screen.tracer(0) snake = Snake() food = Food() scoreboard = Score() screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.left, "Left") screen.onkey(snake.right, "Right") game_is_on = True while game_is_on: screen.update() time.sleep(0.1) snake.move() '''Detect collision with food''' if snake.head.distance(food) < 15: food.refresh()
import time from turtle import Screen from player import Player from car_manager import CarManager from scoreboard import Score screen = Screen() screen.setup(width=600, height=600) screen.tracer(0) player = Player() car_manager = CarManager() score = Score() screen.listen() screen.onkey(player.move, "Up") game_is_on = True while game_is_on: time.sleep(0.1) screen.update() car_manager.create_car() car_manager.move() for car in car_manager.car_list: if car.distance(player) < 20: score.reset() car_manager.reset() player.reset_posotion() time.sleep(5) if player.is_at_finish():
from snake import Snake from food import Food from scoreboard import Score import time # Screen Setup: screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("Snake Game") screen.tracer(0) # Creating a Snake with square turtles: snake = Snake() food = Food() score = Score() # Controlling snake on screen: screen.listen() screen.onkey(snake.up, "Up") screen.onkey(snake.down, "Down") screen.onkey(snake.left, "Left") screen.onkey(snake.right, "Right") game_is_on = True while game_is_on: screen.update() time.sleep(0.1) snake.move() # Detect Collision with food: if snake.all_snake_parts[0].distance(food) < 15: food.refresh()
from paddle import Paddle from ball import Ball from scoreboard import Score screen = Screen() screen.bgcolor("black") screen.setup(width=800, height = 600) screen.title("Welcome to the Pong game") screen.tracer(0) r_paddle = Paddle((350, 0)) l_paddle = Paddle((-350, 0)) ball = Ball() scoreboard = Score() screen.listen() screen.onkey(r_paddle.go_up, "o") screen.onkey(r_paddle.go_down, "l") screen.onkey(l_paddle.go_up, "w") screen.onkey(l_paddle.go_down, "s") ''' In game, 'o' is "UP" and 'l' is "Down" for right paddle player. Similiarly, 'w' is "UP" and 's' is "DOWN" for left paddle player''' game_is_on = True while game_is_on: time.sleep(ball.move_speed) screen.update()
from turtle import Turtle, Screen from paddle import Paddle from ball import Ball import time from scoreboard import Score screen = Screen() screen.setup(width=800, height=600) screen.bgcolor("black") screen.title("Classic Pong Game") screen.tracer(0) r_paddle = Paddle((350, 0)) l_paddle = Paddle((-350, 0)) ball = Ball() score = Score() screen.listen() screen.onkey(r_paddle.go_up, "Up") screen.onkey(r_paddle.go_down, "Down") screen.onkey(l_paddle.go_up, "w") screen.onkey(l_paddle.go_down, "s") game_on = True while game_on: screen.update() time.sleep(ball.ball_speed) ball.move() # Detect Collision with wall: if ball.ycor() > 280 or ball.ycor() < -280: # Screen size 600
from config import screen_setup from constants import UP, DOWN, RIGHT, LEFT from food import Food from scoreboard import Score from snake import Snake # ########### ########### ########## screen = screen_setup() screen.listen() # ########### ########### ########## snake = Snake() food = Food() score = Score() # ########### ########### ########## screen.onkey(key=UP, fun=snake.to_up) screen.onkey(key=DOWN, fun=snake.to_down) screen.onkey(key=RIGHT, fun=snake.to_right) screen.onkey(key=LEFT, fun=snake.to_left) ###################################### def play(): is_game_on = True while is_game_on:
import time from turtle import Screen from food import Food from scoreboard import Score from snake import Snake screen = Screen() screen.setup(600, 600) screen.bgcolor("black") screen.title("Snake Game") screen.tracer(0) snake = Snake() food = Food() score = Score() screen.listen() screen.onkeypress(snake.up, "Up") screen.onkeypress(snake.down, "Down") screen.onkeypress(snake.left, "Left") screen.onkeypress(snake.right, "Right") <<<<<<< HEAD ======= >>>>>>> 0530d7b... Initial commit game_is_on = True while game_is_on: screen.update()
from turtle import Screen from paddle import paddle from ball import Ball from scoreboard import Score import time screen = Screen() screen.bgcolor("black") screen.setup(width=800, height=600) screen.title("ping-pong") screen.tracer(0) lpad = paddle(350, 0) rpad = paddle(-350, 0) ball = Ball() score = Score() screen.listen() screen.onkey(key="Up", fun=rpad.up) screen.onkey(key="Down", fun=rpad.down) screen.onkey(key="w", fun=lpad.up) screen.onkey(key="s", fun=lpad.down) score.__init__() game = True x = 0.1 while game: screen.update() ball.ball_move() time.sleep(x) if ball.ycor() > 280 or ball.ycor() < -280: ball.ycollide() if ball.distance(rpad) < 50 or ball.xcor() > 380 or ball.distance(
def run_game(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("PacMan Portal") spritesheet1 = SpriteSheet('PacManNGhost.png', screen) spritesheet2 = SpriteSheet('MoreStuff.png', screen) spritesheet3 = SpriteSheet('Ghost.png', screen) title = Title(ai_settings, screen) ghostpoints = GhostPoints(screen, spritesheet1, spritesheet3) play_button = Button(ai_settings, screen, "Play", ai_settings.screen_width / 2, ai_settings.screen_height * 2 / 3) score_button = Button(ai_settings, screen, "High Scores", ai_settings.screen_width / 2, ai_settings.screen_height * 2 / 3 + 100) score = Score(ai_settings, screen, spritesheet1) pacman = Pacman(ai_settings, screen, spritesheet1) red_ghost = RedGhost(ai_settings, screen, spritesheet1) green_ghost = GreenGhost(ai_settings, screen, spritesheet3) orange_ghost = OrangeGhost(ai_settings, screen, spritesheet3) pink_ghost = PinkGhost(ai_settings, screen, spritesheet3) red_portal = Portal(ai_settings, screen, spritesheet2) blue_portal = Portal(ai_settings, screen, spritesheet2) left_hitbox = LeftHitbox(ai_settings, pacman) right_hitbox = RightHitbox(ai_settings, pacman) up_hitbox = UpHitbox(ai_settings, pacman) down_hitbox = DownHitbox(ai_settings, pacman) blocks = Group() g_blocks = Group() dots = Group() power_dots = Group() bullets = Group() side_portals = SidePortals(ai_settings, screen) fruit = Fruit(ai_settings, screen, spritesheet1) time = 1 maze = Maze(ai_settings, screen, spritesheet2, blocks, g_blocks, dots, power_dots) while True: timer = pygame.time.Clock() timer.tick(60) time += 1 if time == 61: time = 1 gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) gf.check_events(ai_settings, screen, spritesheet2, play_button, score_button, pacman, bullets) if ai_settings.game_on: pygame.mouse.set_visible(False) maze.reset_maze(spritesheet2, dots, power_dots) pacman.reset_pacman() red_ghost.reset_ghost() green_ghost.reset_ghost() orange_ghost.reset_ghost() pink_ghost.reset_ghost() fruit.reset_fruit() fruit.fruit_count = 0 bullets.empty() red_portal.reset_portal(pacman) blue_portal.reset_portal(pacman) score.reset_score() score.prep_lives() score.prep_score() score.prep_high_score() score.prep_level() gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) maze.pre_game_draw() sleep(5) while ai_settings.game_on: timer.tick(60) time += 1 if time == 61: time = 1 pacman.cooldown() red_ghost.cooldown() green_ghost.cooldown() orange_ghost.cooldown() pink_ghost.cooldown() gf.check_events(ai_settings, screen, spritesheet2, play_button, score_button, pacman, bullets) if pacman.active: gf.check_collisions(ai_settings, score, pacman, blocks, g_blocks, dots, power_dots, left_hitbox, right_hitbox, up_hitbox, down_hitbox, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, green_ghost, orange_ghost, pink_ghost) score.extra_life() if not pacman.active and score.lives > 0: score.lives -= 1 score.prep_lives() pacman.reset_pacman() red_ghost.reset_ghost() green_ghost.reset_ghost() orange_ghost.reset_ghost() pink_ghost.reset_ghost() fruit.reset_fruit() fruit.fruit_count = 0 bullets.empty() red_portal.reset_portal(pacman) blue_portal.reset_portal(pacman) sleep(3) gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) maze.pre_game_draw() sleep(5) elif not pacman.active and score.lives == 0: sleep(3) ai_settings.game_on = False pygame.mouse.set_visible(True) for x in range(0, len(score.high_score_list)): if score.points > score.high_score_list[x]: score.high_score_list.insert(x, score.points) score.high_score_list.pop() break high_score_file = open("High_Scores.txt", "w") for x in range(0, len(score.high_score_list) - 1): high_score_file.write( str(score.high_score_list[x]) + "\n") high_score_file.write(str(score.high_score_list[8])) high_score_file.close() print(list(map(str, score.high_score_list))) pacman.update_pacman() red_ghost.update_ghost(pacman) green_ghost.update_ghost(pacman) orange_ghost.update_ghost(pacman) pink_ghost.update_ghost(pacman) for bullet in bullets: bullet.update_bullet() left_hitbox.update_hitbox(pacman) right_hitbox.update_hitbox(pacman) up_hitbox.update_hitbox(pacman) down_hitbox.update_hitbox(pacman) red_portal.expire_portal(pacman) blue_portal.expire_portal(pacman) fruit.update_fruit() gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) if len(dots) == 0 and len(power_dots) == 0: gf.end_level(ai_settings, screen, time, spritesheet2, score, title, play_button, score_button, pacman, maze, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost) elif ai_settings.score_on: while ai_settings.score_on: gf.check_events(ai_settings, screen, spritesheet2, play_button, score_button, pacman, bullets) gf.update_screen(ai_settings, screen, time, score, title, play_button, score_button, pacman, blocks, g_blocks, dots, power_dots, bullets, red_portal, blue_portal, fruit, side_portals, red_ghost, ghostpoints, green_ghost, orange_ghost, pink_ghost)
import time from turtle import Screen from food import Food from scoreboard import Score from snake import Snake screen = Screen() screen.title("Snake Game") screen.setup(width=600, height=600) screen.bgcolor("black") screen.tracer(0) snake = Snake() food = Food() score = Score() screen.listen() screen.onkey(snake.up, "w") screen.onkey(snake.down, "s") screen.onkey(snake.left, "a") screen.onkey(snake.right, "d") game_is_on = True while game_is_on: snake.move() screen.update() time.sleep(0.1) if snake.head.distance(food) < 16: food.refresh()
from turtle import Screen, Turtle import time from snake import Snake from food import Food from scoreboard import Score border = Turtle() score = Score() screen = Screen() screen.listen() screen.onkey(screen.resetscreen, "r") snake = Snake() food = Food() screen.title("Snake") screen.screensize(600, 600, "black") border.penup() border.goto(-300, -300) border.pencolor("white") border.pendown() border.forward(600) border.left(90) border.forward(600) border.left(90) border.forward(600) border.left(90) border.forward(600)
def __init__(self): #initialising score window self.scoreDialog = QtWidgets.QMainWindow() self.score_screen = Score() self.score_screen.setupUi(self.scoreDialog)
from turtle import Turtle, Screen import time from bat import Bat from ball import Ball from scoreboard import Score import random screen = Screen() screen.setup(width=1200, height=800) screen.bgcolor("black") screen.title("My Snake Game") screen.tracer(0) game_is_on = True bat1 = Bat(0) bat2 = Bat(1) ball = Ball() score_right = Score("right") score_left = Score("left") screen.listen() screen.onkeypress(bat1.up, "w") screen.onkeypress(bat1.down, "s") screen.onkeypress(bat2.up, "Up") screen.onkeypress(bat2.down, "Down") rally = 0 goal_right = 0 goal_left = 0 while game_is_on: goal = False screen.update() time.sleep(0.02) ball.move()
screen = Screen() screen.listen() screen.title("Snake-Arena") screen.setup(width=640, height=640) screen.bgcolor("black") screen.tracer(0) mySnake = Snake() screen.onkey(mySnake.up, "Up") screen.onkey(mySnake.down, "Down") screen.onkey(mySnake.left, "Left") screen.onkey(mySnake.right, "Right") f = Food() screen.update() score = 0 b_score = Score(score) run = True while run: if mySnake.check_food(f.n_pos): score += 1 b_score.update_score(score) f.respawn() else: screen.update() time.sleep(0.2) mySnake.move() if mySnake.check_wall(): run = False b_score.game_over() head = mySnake.tur[0] for t in mySnake.tur[1:]:
from pong_screen import PongScreen from scoreboard import Score import random import time scr = PongScreen() user_input = scr.screen.textinput(prompt="Enter the number corresponding to one of the following options" + "\n0 - Zero players\n1 - One players\n2 - Two players", title="Number of Players") right_paddle = Paddle((450, 0)) if user_input == "1": right_paddle.color("#f88f01") left_paddle = Paddle((-450, 0)) ball = Ball() left_score = Score((100, 250)) right_score = Score((-100, 250)) scr.screen.update() scr.screen.listen() game_over = False while not game_over: # Move ball ball.move() # if ball touches ceiling, floor or paddles, it will bounce ball.bounce(right_paddle, left_paddle) # if ball gets away from the paddles if ball.xcor() > 530: right_score.score += 1