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

لعبة باستخدام بايثون، عند الاصطدام بالوحش تنقص عدد الأرواح

Jgkjfj Khguuy

السؤال

انا قمت ببرمجة لعبة واريد  الشخصية تتجنب الوحش واذا اصطدم بالوحش تنقص lives

انا قمت ببرمجة كل شئ لاكن لم اعرف كيف اجعل حياة الشخصية  تنقص فلو سمحتو اذا حد يعرف يفيدني

((اريد البرمجة بلغة بايثون))

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

عليك التحقق من إحداثيات اللاعب (x,y) ثم التحقق من إحداثيات الوحش (monster_x, monster_y) ثم إن حصل تطابق تقوم بإنقاص قيمة الحياة عن طريق: 

lives  = lives - 1 

أو

lives -= 1 

عند القسم الذي يتطلب إنقاص قمة الرّوح، فيصبح لديك:

If player_x == monster_x and player_y == monster_y:
lives = lives - 1

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0
بتاريخ On 3/11/2021 at 02:36 قال محمد أيت لعرايك:

المرجو تقديم مثال للكود اللذي كتبت لكي نفهم جيدا ماذا تريد و نساعدك على إضافة منطق جديد للعبة الخاصة بك

 

from processing import *
lives = 5
score = 0
width = 300
height = 300
monster_x = 40
monster_y = 60
monster_width = 50
monster_height = 50
speed_x = 5
speed_y = 3
move_x = 4
move_y = 6
player_x = 100
player_y = 100
game_over = False

def setup():
    global monster
    global player
    size(width, height)
    monster = loadImage("monster.png")
    player = loadImage("player.png")
    textSize(20)
    
def draw():
    global monster_x
    global monster_y
    global monster2_x
    global monster2_x
    global move_x
    global move_y
    global speed_x
    global speed_y
    global game_over
    background(20,10,50)
    image(player, player_x, player_y)
    if lives <= 0:
        game_over = True
    if not game_over:
        text("Score: {}".format(score), 10, 25)
        text("Lives: {}".format(lives), 10, 45)
        monster_x = monster_x + speed_x
        monster_y = monster_y + speed_y
        if monster_x < 0 or monster_x + monster_width > width:
            speed_x = -speed_x
        if monster_y < 0 or monster_y + monster_height > height:
            speed_y = -speed_y
        image(monster, monster_x, monster_y)
    else:
        textSize(40)
        text("Game Over!", 40, 160)
    
        
    

def sprite_clicked(x, y):
    in_x = monster_x <= x <= monster_x + monster_width
    in_y = monster_y <= y <= monster_y + monster_height
    if in_x and in_y:
        return True
    else:
        return False
def keyPressed():
    global player_x
    global player_y
    old_x = player_x
    old_y = player_y
    if keyboard.keyCode == RIGHT:
        player_x = player_x + 5    
    if keyboard.keyCode == LEFT:
        player_x = player_x - 5
    if keyboard.keyCode == DOWN:
        player_y = player_y + 5
    if keyboard.keyCode == UP:
        player_y = player_y - 5
        
        player_y = player_y + 5
    if player_x < 0 or player_x + 60 > width:
        player_x = old_x
    if player_y < 0 or player_y + 60 > height:
        player_y = old_y
    
def check_collision_with_walls():
    global player_x
    global player_y
    global lives
    global apple_eaten
    global cheese_eaten
    top_left = check_colour_at_point(player_x, player_y)
    top_right = check_colour_at_point(player_x + 40, player_y)
    bottom_left = check_colour_at_point(player_x, player_y + 40)
    bottom_right = check_colour_at_point(player_x + 40, player_y + 40)
    points = [top_left, top_right, bottom_left, bottom_right]
    if (0, 0, 0) in points:
        player_x = 52
   player_y = 52    
        lives = lives - 1
        
    
def mouseClicked():
    global score
    global lives
    if sprite_clicked(mouse.x, mouse.y):
        score = score + 10
    else:
        lives = lives - 1        

run()

هذه هي البرمجة وشكرا تعبتك معي

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...