اذهب إلى المحتوى

Tariq Qaid

الأعضاء
  • المساهمات

    1
  • تاريخ الانضمام

  • تاريخ آخر زيارة

كل منشورات العضو Tariq Qaid

  1. import pygame import sys # تهيئة مكتبة Pygame pygame.init() # إعداد الشاشة WIDTH, HEIGHT = 800, 600 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) # تحميل الخطوط font = pygame.font.SysFont("Arial", 30) # الشخصيات class Player: def __init__(self, x, y, color): self.x = x self.y = y self.width = 50 self.height = 50 self.color = color self.speed = 5 self.health = 100 def draw(self): pygame.draw.rect(screen, self.color, (self.x, self.y, self.width, self.height)) # شريط الصحة pygame.draw.rect(screen, RED, (self.x, self.y - 10, self.health, 5)) def move(self, keys, left, right, up, down): if keys[left]: self.x -= self.speed if keys[right]: self.x += self.speed if keys[up]: self.y -= self.speed if keys[down]: self.y += self.speed # الأعداء class Enemy: def __init__(self, x, y): self.x = x self.y = y self.width = 50 self.height = 50 self.color = BLUE self.health = 50 def draw(self): pygame.draw.rect(screen, self.color, (self.x, self.y, self.width, self.height)) # شريط الصحة pygame.draw.rect(screen, RED, (self.x, self.y - 10, self.health, 5)) # شاشة المقدمة def show_intro(): screen.fill(WHITE) title = font.render("مرحبا بك في لعبة القتال الممتعة", True, BLACK) start = font.render("اضغط على أي مفتاح للبدء", True, BLACK) screen.blit(title, (WIDTH // 2 - title.get_width() // 2, HEIGHT // 3)) screen.blit(start, (WIDTH // 2 - start.get_width() // 2, HEIGHT // 2)) pygame.display.update() wait_for_key() def wait_for_key(): while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: return # الوظيفة الرئيسية def main(): player = Player(100, 300, BLACK) enemy = Enemy(600, 300) clock = pygame.time.Clock() run = True while run: clock.tick(60) screen.fill(WHITE) # التحقق من الأحداث for event in pygame.event.get(): if event.type == pygame.QUIT: run = False # حركة اللاعب keys = pygame.key.get_pressed() player.move(keys, pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN) # تحديث الشاشة player.draw() enemy.draw() # منطق اللعبة (إصابة العدو) if ( player.x < enemy.x + enemy.width and player.x + player.width > enemy.x and player.y < enemy.y + enemy.height and player.y + player.height > enemy.y 😞 enemy.health -= 1 # انتهاء اللعبة if enemy.health <= 0: win_text = font.render("لقد فزت!", True, BLACK) screen.blit(win_text, (WIDTH // 2 - win_text.get_width() // 2, HEIGHT // 2)) pygame.display.update() pygame.time.delay(2000) run = False pygame.display.update() pygame.quit() # تشغيل اللعبة show_intro() main()
×
×
  • أضف...