We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
import pygame import sys import random
pygame.init()
WIDTH, HEIGHT = 800, 400 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("لعبة بسيطة مثل ماريو")
WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) BLUE = (0, 0, 255)
player_size = 50 player_x = 50 player_y = HEIGHT - player_size - 50 player_speed = 5 player_velocity_y = 0 gravity = 0.8 is_jumping = False
obstacle_width, obstacle_height = 50, 50 obstacle_x = WIDTH obstacle_y = HEIGHT - obstacle_height - 50 obstacle_speed = 7
coin_size = 30 coin_x = random.randint(200, WIDTH) coin_y = HEIGHT - coin_size - 50
score = 0
font = pygame.font.Font(None, 36)
clock = pygame.time.Clock()
running = True while running: screen.fill(WHITE)
# الأحداث for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # التحكم في اللاعب keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player_x -= player_speed if keys[pygame.K_RIGHT]: player_x += player_speed if keys[pygame.K_SPACE] and not is_jumping: is_jumping = True player_velocity_y = -15 # الجاذبية if is_jumping: player_velocity_y += gravity player_y += player_velocity_y if player_y >= HEIGHT - player_size - 50: player_y = HEIGHT - player_size - 50 is_jumping = False # حركة العقبات obstacle_x -= obstacle_speed if obstacle_x < -obstacle_width: obstacle_x = WIDTH obstacle_y = HEIGHT - obstacle_height - 50 # حركة النقاط coin_x -= obstacle_speed if coin_x < -coin_size: coin_x = random.randint(200, WIDTH) coin_y = HEIGHT - coin_size - 50 # التصادم مع العقبات if ( player_x < obstacle_x + obstacle_width and player_x + player_size > obstacle_x and player_y < obstacle_y + obstacle_height and player_y + player_size > obstacle_y ): print("Game Over!") running = False # جمع النقاط if ( player_x < coin_x + coin_size and player_x + player_size > coin_x and player_y < coin_y + coin_size and player_y + player_size > coin_y ): score += 1 coin_x = random.randint(200, WIDTH) # رسم العناصر pygame.draw.rect(screen, BLUE, (player_x, player_y, player_size, player_size)) pygame.draw.rect(screen, RED, (obstacle_x, obstacle_y, obstacle_width, obstacle_height)) pygame.draw.ellipse(screen, (255, 215, 0), (coin_x, coin_y, coin_size, coin_size)) # عرض النقاط score_text = font.render(f"Score: {score}", True, BLACK) screen.blit(score_text, (10, 10)) # تحديث الشاشة pygame.display.flip() # ضبط الإطار clock.tick(30)
pygame.quit() sys.exit()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
import pygame
import sys
import random
تهيئة pygame
pygame.init()
إعدادات الشاشة
WIDTH, HEIGHT = 800, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("لعبة بسيطة مثل ماريو")
الألوان
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
إعداد الشخصية
player_size = 50
player_x = 50
player_y = HEIGHT - player_size - 50
player_speed = 5
player_velocity_y = 0
gravity = 0.8
is_jumping = False
إعداد العقبات والنقاط
obstacle_width, obstacle_height = 50, 50
obstacle_x = WIDTH
obstacle_y = HEIGHT - obstacle_height - 50
obstacle_speed = 7
coin_size = 30
coin_x = random.randint(200, WIDTH)
coin_y = HEIGHT - coin_size - 50
نقاط اللاعب
score = 0
الخط
font = pygame.font.Font(None, 36)
الزمن
clock = pygame.time.Clock()
اللعبة
running = True
while running:
screen.fill(WHITE)
إنهاء اللعبة
pygame.quit()
sys.exit()
The text was updated successfully, but these errors were encountered: