Product
new game
Project URL Https/ ismail.com Category Python Project Title Https/ ismail.com Project Description Https/ ismail.com Highlights import pygame import random import sys 1. Setup pygame.init() info = pygame.display.Info() WI…
Product
Project URL Https/ ismail.com Category Python Project Title Https/ ismail.com Project Description Https/ ismail.com Highlights import pygame import random import sys 1. Setup pygame.init() info = pygame.display.Info() WI…
Project URL Https/ ismail.com Category Python Project Title Https/ ismail.com Project Description Https/ ismail.com Highlights import pygame import random import sys 1. Setup pygame.init() info = pygame.display.Info() WIDTH = info.currentw HEIGHT = info.currenth screen = pygame.display.setmode((WIDTH, HEIGHT)) Rang (Colors) WOODBROWN = (150, 75, 0) SKYBLUE = (15, 15, 30) BALLCOLORS = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0)] WHITE = (255, 255, 255) Fonts font = pygame.font.SysFont("Arial", 60, bold=True) smallfont = pygame.font.SysFont("Arial", 45) Game Variables --- paddlew, paddleh = 250, 45 Yahan change kiya hai: HEIGHT - 300 takki paddle screen ke upar dikhe paddley = HEIGHT - 300 def createball(): return { 'x': random.randint(50, WIDTH - 50), 'y': random.randint(-600, -100), 'speed': random.randint(7, 12), 'color': random.choice(BALLCOLORS), 'radius': 25 } def resetgame(): return { 'paddlex': WIDTH // 2 - (paddlew // 2), 'balls': [createball() for in range(4)], 'score': 0, 'lives': 5, 'gameover': False } g = resetgame() clock = pygame.time.Clock() Main Loop --- while True: screen.fill(SKYBLUE) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() Finger touch/drag control if event.type == pygame.MOUSEMOTION and not g['gameover']: g['paddlex'] = event.pos[0] - (paddlew // 2) Restart logic if event.type == pygame.MOUSEBUTTONDOWN and g['gameover']: g = resetgame() if not g['gameover']: 1. Paddle (Lakdi) ka Rect paddlerect = pygame.Rect(g['paddlex'], paddley, paddlew, paddleh) 2. Balls Logic for ball in g['balls']: ball['y'] += ball['speed'] ballrect = pygame.Rect(ball['x'] - ball['radius'], ball['y'] - ball['radius'], ball['radius']2, ball['radius']2) Collision: Jab ball lakdi se takraye if paddlerect.colliderect(ballrect): ball['y'] = -50 ball['x'] = random.randint(50, WIDTH - 50) g['score'] += 1 ball['speed'] += 0.3 Miss: Jab ball niche nikal jaye if ball['y'] > HEIGHT: g['lives'] -= 1 ball['y'] = -100 ball['x'] = random.randint(50, WIDTH - 50) if g['lives'] <= 0: g['gameover'] = True Drawing --- 1. Lakdi (Paddle) - Iska position fix kiya hai pygame.draw.rect(screen, WOODBROWN, (g['paddlex'], paddley, paddlew, paddleh), borderradius=8) Lakdi ki design lines pygame.draw.line(screen, (80, 40, 0), (g['paddlex'], paddley + 15), (g['paddlex'] + paddlew, paddley + 15), 4) 2. Balls for ball in g['balls']: pygame.draw.circle(screen, ball['color'], (ball['x'], int(ball['y'])), ball['radius']) 3. UI scoretxt = smallfont.render(f"Score: {g['score']}", True, WHITE) livestxt = smallfont.render(f"Lives: {g['lives']}", True, (255, 50, 50)) screen.blit(scoretxt, (50, 70)) screen.blit(livestxt, (WIDTH - 250, 70)) else: Game Over Screen msg = font.render("GAME OVER", True, (255, 0, 0)) sc = smallfont.render(f"Score: {g['score']}", True, WHITE) retry = smallfont.render("Tap to Restart", True, WOODBROWN) screen.blit(msg, (WIDTH // 2 - 180, HEIGHT // 2 - 100)) screen.blit(sc, (WIDTH // 2 - 100, HEIGHT // 2)) screen.blit(retry, (WIDTH // 2 - 140, HEIGHT // 2 + 100)) pygame.display.update() clock.tick(60) Https/ ismail.com Example Code markdown import pygame import random import sys 1. Setup pygame.init() info = pygame.display.Info() WIDTH = info.currentw HEIGHT = info.currenth screen = pygame.display.setmode((WIDTH, HEIGHT)) Rang (Colors) WOODBROWN = (150, 75, 0) SKYBLUE = (15, 15, 30) BALLCOLORS = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0)] WHITE = (255, 255, 255) Fonts font = pygame.font.SysFont("Arial", 60, bold=True) smallfont = pygame.font.SysFont("Arial", 45) Game Variables --- paddlew, paddleh = 250, 45 Yahan change kiya hai: HEIGHT - 300 takki paddle screen ke upar dikhe paddley = HEIGHT - 300 def createball(): return { 'x': random.randint(50, WIDTH - 50), 'y': random.randint(-600, -100), 'speed': random.randint(7, 12), 'color': random.choice(BALLCOLORS), 'radius': 25 } def resetgame(): return { 'paddlex': WIDTH // 2 - (paddlew // 2), 'balls': [createball() for in range(4)], 'score': 0, 'lives': 5, 'gameover': False } g = resetgame() clock = pygame.time.Clock() Main Loop --- while True: screen.fill(SKYBLUE) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() Finger touch/drag control if event.type == pygame.MOUSEMOTION and not g['gameover']: g['paddlex'] = event.pos[0] - (paddlew // 2) Restart logic if event.type == pygame.MOUSEBUTTONDOWN and g['gameover']: g = resetgame() if not g['gameover']: 1. Paddle (Lakdi) ka Rect paddlerect = pygame.Rect(g['paddlex'], paddley, paddlew, paddleh) 2. Balls Logic for ball in g['balls']: ball['y'] += ball['speed'] ballrect = pygame.Rect(ball['x'] - ball['radius'], ball['y'] - ball['radius'], ball['radius']2, ball['radius']2) Collision: Jab ball lakdi se takraye if paddlerect.colliderect(ballrect): ball['y'] = -50 ball['x'] = random.randint(50, WIDTH - 50) g['score'] += 1 ball['speed'] += 0.3 Miss: Jab ball niche nikal jaye if ball['y'] > HEIGHT: g['lives'] -= 1 ball['y'] = -100 ball['x'] = random.randint(50, WIDTH - 50) if g['lives'] <= 0: g['gameover'] = True Drawing --- 1. Lakdi (Paddle) - Iska position fix kiya hai pygame.draw.rect(screen, WOODBROWN, (g['paddlex'], paddley, paddlew, paddleh), borderradius=8) Lakdi ki design lines pygame.draw.line(screen, (80, 40, 0), (g['paddlex'], paddley + 15), (g['paddlex'] + paddlew, paddley + 15), 4) 2. Balls for ball in g['balls']: pygame.draw.circle(screen, ball['color'], (ball['x'], int(ball['y'])), ball['radius']) 3. UI scoretxt = smallfont.render(f"Score: {g['score']}", True, WHITE) livestxt = smallfont.render(f"Lives: {g['lives']}", True, (255, 50, 50)) screen.blit(scoretxt, (50, 70)) screen.blit(livestxt, (WIDTH - 250, 70)) else: Game Over Screen msg = font.render("GAME OVER", True, (255, 0, 0)) sc = smallfont.render(f"Score: {g['score']}", True, WHITE) retry = smallfont.render("Tap to Restart", True, WOODBROWN) screen.blit(msg, (WIDTH // 2 - 180, HEIGHT // 2 - 100)) screen.blit(sc, (WIDTH // 2 - 100, HEIGHT // 2)) screen.blit(retry, (WIDTH // 2 - 140, HEIGHT // 2 + 100)) pygame.display.update() clock.tick(60) Https/ ismail.com Screenshots or Demo Videos No response
Discuss this product