Pygame用户面板,旋转,边界

2024-06-23 18:45:15 发布

您现在位置:Python中文网/ 问答频道 /正文

首先我需要一个用户面板。从那里用户将输入3个输入。例1)你的k是什么?A) [用户İ输入]2)你的M是什么?B) [用户输入]3)您的a是什么?C) [用户输入]每当用户应用这些答案时,pygame窗口将打开。最后一个答案是右边系统的下平台和x方向之间的角度。其他两个答案将转到arduino串行通信。终于有了界限。圆圈不能越过上下障碍物。从系统左侧通过。我的代码在下面。提前感谢您的回答:)

import pygame,sys
    pygame.init()


    win=pygame.display.set_mode((1030,650))
    pygame.display.set_caption("Seri Manipulator Kontrolü")

    x = 700
    y = 300
    width = 5
    height = 0
    vel = 5
    oxu= 870
    oyu= 420
    owu= 160
    ohu= 10
    oxd= 870
    oyd= 220
    owd= 160
    ohd= 10
    centeredobx=870
    centeredoby=230
    centeredboy=190
    centereden=10
    cubukx= 880
    cubuky= 320
    cubuken= 140
    cubukboy= 10


    def yazdir():
                    win.fill((0,0,0))
                    pygame.draw.circle(win, (0, 127, 255), (x, y), width, 0)
                    pygame.draw.rect(win, (255, 0, 0), (oxu, oyu, owu, ohu))
                    pygame.draw.rect(win, (255, 0, 0), (oxd, oyd, owd, ohd))
                    pygame.draw.rect(win, (255, 255, 0), (centeredobx, centeredoby, centereden, centeredboy))
                    pygame.draw.rect(win, (128, 128, 128), (cubukx, cubuky, cubuken, cubukboy))
                    pygame.draw.rect(win, (255, 0, 0), (1020, 220, 10, 200))
                    pygame.display.update()



    run = True
    while run:
        pygame.time.delay(100)
        for event in pygame.event.get():
            print(event)
            if event.type == pygame.QUIT:
                run = False
                pygame.quit()


        keys = pygame.key.get_pressed()

    if pygame.key.get_pressed() and x in range(865,1025) and y in range(225,235) or pygame.key.get_pressed() and x in range(865,1025) and y in range(415,425):
        return

    else:
            if keys[pygame.K_RIGHT] and 1010 > x > 860 and 235 <= y <= 415 and centeredobx <= 1005:
                centeredobx += vel
                cubukx += vel
                cubuken -= vel
                yazdir()

            if keys[pygame.K_LEFT] and 1010 > x > 860 and 235 <= y <= 415 and centeredobx >= 875:
                centeredobx -= vel
                cubukx -= vel
                cubuken += vel
                yazdir()


            if keys[pygame.K_LEFT] and x > 5:
                x -= vel
                yazdir()

            if keys[pygame.K_RIGHT] and x < 1005: 
                x += vel
                yazdir()

            if keys[pygame.K_UP] and y > 5 :
                y -= vel
                yazdir()

            if keys[pygame.K_DOWN] and y < 645:
                y += vel
                yazdir()




    pygame.quit()

Tags: and用户inrecteventifkeyspygame

热门问题