小编Hab*_*ail的帖子

我怎样才能让我的子弹看起来像是从我的枪尖中出来?

在此处输入图片说明在此处输入图片说明我有在我的子弹不看问题喜欢他们来了我的枪出来,他们看起来像他们来的球员身体出视频,你可以在视频中看到它拍摄别的地方或者它的枪了同样的事情左侧它向上射击很好,但向下射击很糟糕VIDEO

在此处输入图片说明

我试着把我的枪调到 120,但结果是一切都对右侧有效,而不对左侧VIDEO 有效,因为你可以看到它只是小故障

我的弹丸课

class projectile(object):
   def __init__(self, x, y, dirx, diry, color):
       self.x = x
       self.y = y
       self.dirx = dirx
       self.diry = diry
       self.slash = pygame.image.load("round.png")
       self.slash = pygame.transform.scale(self.slash,(self.slash.get_width()//2,self.slash.get_height()//2))
       self.rect  = self.slash.get_rect()
       self.rect.topleft = ( self.x, self.y )
       self.speed = 18
       self.color = color
       self.hitbox = (self.x + -18, self.y, 46,60)



Run Code Online (Sandbox Code Playgroud)

我的射弹是如何附加的


        if event.type == pygame.MOUSEBUTTONDOWN:           
                    
                    # this is for the bullets
            if len(bullets) < 3:
                if box1.health > 25:
                    mousex, mousey …
Run Code Online (Sandbox Code Playgroud)

python pygame

8
推荐指数
1
解决办法
256
查看次数

Pygame 井字游戏逻辑?我该怎么做

我正在尝试用 pygame 制作一个井字游戏,我想知道我将如何处理这里的逻辑,这是我目前所拥有的。视频 < 我只有当我点击中间按钮时它才会在屏幕上显示播放器 2 x 然后悬停在我鼠标上的图像将变成 O 以让播放器 1 转但我的问题是我将如何做这样的逻辑,如果玩家 1 连续得到 3 或玩家 2 连续得到 3我真的很困惑,我需要有人陪我扔它

我现在的井字游戏代码

import pygame,random
pygame.init()

# draw our window
window = pygame.display.set_mode((500,540),pygame.NOFRAME)
pygame.display.set_caption("Tic Tac TOE")



MANUAL_CURSOR = pygame.image.load('nw.png').convert_alpha()


MANUAL_CURSOR2 = pygame.image.load('nOW.png').convert_alpha()



bg = pygame.image.load("ticO.png")
fps = 40

clock = pygame.time.Clock()

class button():
    def __init__(self, color, x,y,width,height, text=''):
        self.color = color
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.text = text
        self.over = False

    def draw(self,window,outline=None): …
Run Code Online (Sandbox Code Playgroud)

python pygame tic-tac-toe

8
推荐指数
1
解决办法
303
查看次数

我如何在 Pygame 中制作基本的汽车物理?

在此处输入图片说明

我想知道如何使用箭头键制作一辆可以移动和旋转的汽车。我正在尝试制作一个汽车物理游戏,玩家可以在其中控制汽车并四处行驶和停车,但是我在如何开始实施控制方面遇到了麻烦。我怎样才能让我的车用箭头键沿着它旋转的方向移动?

例如,如果我按下后退箭头键,汽车应该倒车,如果汽车在倒车的同时也在转弯,它应该按照汽车转弯的方式移动。

这是我现在的代码。现在真的没有任何事情发生。

import pygame
pygame.init()

window = pygame.display.set_mode((800,800))
pygame.display.set_caption("car game")

class car:
    def __init__(self,x,y,height,width,color):
        self.x = x
        self.y = y
        self.height = height
        self.width = width
        self.color = color
        self.carimage = pygame.image.load("1.png")
        self.rect = pygame.Rect(x,y,height,width)
    def draw(self):
        self.rect.topleft = (self.x,self.y)
        window.blit(self.carimage,self.rect)

white = (255,255,2555)
car1 = car(300,300,20,20,white)

def ReDrawWindow():
    car1.draw()

# main loop
runninggame = True
while runninggame:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            runninggame = False
    ReDrawWindow()
    pygame.display.update()

pygame.quit()   
Run Code Online (Sandbox Code Playgroud)

python pygame

6
推荐指数
2
解决办法
723
查看次数

Pygame 基本计算器

我正在尝试制作一个基本的计算器,但我遇到的问题是如何输出文本?我如何做到这一点,当我点击加它允许我添加或者如果我点击分割它允许我划分并在我的屏幕上的黄色部分显示输出

在此处输入图片说明

这就是我现在所拥有的。你可以运行它;没有什么特别的。我的问题是我怎样才能让计算器做到这样,当我点击加号然后去添加数字时,它允许我添加或当我点击除法时,它允许我划分我的数字并在屏幕上显示输出?

import pygame,math
pygame.init()

window_height = 500
window_width = 500
window  = pygame.display.set_mode((window_height,window_width))

    # the buttons for the shop MENU
class button():
    def __init__(self, color, x,y,width,height, text=''):
        self.color = color
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.text = text
        self.over = False

    def draw(self,window,outline=None):
                #Call this method to draw the button on the screen
        if outline:
            pygame.draw.rect(window, outline, (self.x-2,self.y-2,self.width+4,self.height+4),0)
                    
        pygame.draw.rect(window, self.color, (self.x,self.y,self.width,self.height),0)
                
        if self.text != '':
            font = pygame.font.SysFont('comicsans', 60)
            text = …
Run Code Online (Sandbox Code Playgroud)

python pygame

6
推荐指数
1
解决办法
1045
查看次数

在 Pygame 中正确旋转 Cannon 的问题仍然存在

在此处输入图片说明以前很少有人帮助我解决这个问题,但轮换仍然很混乱我的大炮不会向玩家旋转,很好,它们都不合适我真的需要帮助解决这个问题,这是我第一次尝试让某些东西向玩家旋转我我试图让我的大炮口向玩家旋转,但旋转混乱了我不知道如何修复它。

    class enemyshoot:
        def __init__(self,x,y,height,width,color):
        # [...............]
             self.look_at_pos = (x,y)

     def draw(self):
          # [............]
            self.rect = self.shootsright.get_rect(topleft = (self.x, self.y))

            dx = self.look_at_pos[0] - self.rect.centerx
            dy = self.look_at_pos[1] - self.rect.centery 
            angle = (180/math.pi) * math.atan2(-dx, dy)
            (window.blit(self.image, self.rect))
            self.image = pygame.transform.rotate(self.shootsright, angle)
            self.rect  = self.image.get_rect(center = self.rect.center)

        def lookAt( self, coordinate ):
            self.look_at_pos = coordinate
Run Code Online (Sandbox Code Playgroud)

我的完整敌人射击课

    shotsright = pygame.image.load("canss.png")
    class enemyshoot:
        def __init__(self,x,y,height,width,color):
            self.x = x
            self.y =y
            self.height = height
            self.width = width
            self.color = color
            self.health …
Run Code Online (Sandbox Code Playgroud)

python pygame

4
推荐指数
1
解决办法
187
查看次数

标签 统计

pygame ×5

python ×5

tic-tac-toe ×1