Python 问题是我的子弹没有射中球员

Python 问题是我的子弹没有射中球员,python,pygame,Python,Pygame,正如你所看到的,子弹没有附加在我的玩家桨x上,或者为什么我不确定问题出在哪里,我的代码允许我向玩家x和y射击 for shootss in shootsright: shootss.x += shootss.xspeed shootss.y += shootss.yspeed if shootss.x > 700 or shootss.x < 0 or shootss.y > 500 or

正如你所看到的,子弹没有附加在我的玩家桨x上,或者为什么我不确定问题出在哪里,我的代码允许我向玩家x和y射击

        for shootss in shootsright:
            shootss.x += shootss.xspeed
            shootss.y += shootss.yspeed
            if shootss.x > 700 or shootss.x < 0 or shootss.y > 500 or shootss.y < 0:
                    
                shootsright.pop(shootsright.index(shootss))
        if len(shootsright) < 1:
            for enemyshoot in enemyshooting:
                BULLET_SPEED = 10
                start_x = round(enemyshoot.x+enemyshoot.width+-35)
                start_y = round(enemyshoot.y + enemyshoot.height+-25)
                target_x = player1.x+player1.width//2
                target_y = player1.y+player1.width//2
                delta_x, delta_y = target_x - start_x, target_y - start_y
                distance = math.sqrt(delta_x ** 2 + delta_y ** 2)
                dir_x = BULLET_SPEED * delta_x / distance
                dir_y = BULLET_SPEED * delta_y / distance
                distance = math.sqrt(dir_x**2 + dir_y**2)
                if distance > 0:
                    shootsright.append(enemyboolss(start_x,start_y,(0,0,0),dir_x, dir_y))


我的球员班

class Player:
        def __init__(self,x,y,height,width,color):
            self.x = x
            self.y = y
            self.height = height
            self.width = width
            self.color = color
            self.speed = Speed(0,5)
            self.rect = pygame.Rect(x,y,height,width)
            self.hits = (self.x + 20, self.y, 28,60)
            self.health = 10
                # the hitbox our projectiles will be colliding with
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)



我的完整代码

import pygame
import random
import math 

WIDTH, HEIGHT = 600, 500
pygame.init()

window = pygame.display.set_mode((WIDTH,HEIGHT))

# title
pygame.display.set_caption("pong")



def quitlol():
    pygame.quit()
    quit()
    #---------------------------------------------------

def button(msg,x,y,w,h,ic,ac,action=None):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

    if x+w > mouse[0] > x and y+h > mouse[1] > y:
        pygame.draw.rect(window, ac,(x,y,w,h))
        if click[0] == 1 and action != None:
            action()         
    else:
        pygame.draw.rect(window, ic,(x,y,w,h))
        smallText = pygame.font.SysFont("lolfont.ttf",60)
        textSurf, textRect = text_objects(msg, smallText)
        textRect.center = ( (x+(w/2)), (y+(h/2)) )
        window.blit(textSurf, textRect)
        
    #------------------------------------------------------


def text_objects(text, font):
    black = (0,0,0)
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()


def options_menu():
    red = (200,0,0)
    green = (0,200,0)
    bright_red = (255,0,0)
    bright_green = (0,255,0)
    option = True
    while option:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                option = False
                
        window.fill((0,0,0))
        button("Mute Music",220,270,190,40,green,bright_green,)
        button("Collisions Mute",220,340,190,40,green,bright_green)
        button("Disable Snow",220,200,190,40,green,bright_green)



def game_intro():

                
    snow_list=[]
    no_of_circles=100;
    clock = pygame.time.Clock()
    FPS = 60
    clock.tick(FPS)
    for i in range(no_of_circles):
        x = random.randrange(0, 600)
        y = random.randrange(0, 500)
        snow_list.append([x,y])
    red = (200,0,0)
    green = (0,200,0)
    bright_red = (255,0,0)
    bright_green = (0,255,0)
    fps = 460
    clock = pygame.time.Clock()
    intro = True
    while intro:
        clock.tick(fps)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                intro = False
                pygame.quit()



        window.fill((0,0,0))




        for point in snow_list:
            point[1]+=1
            pygame.draw.circle(window, (255,255,255), point, 2)

            if(point[1] >= 600):
                point[0] = random.randrange(0, 600)
                point[1] = random.randrange(-10, -5)

        clock.tick(FPS)



        font = pygame.font.Font("Candarali.ttf", 60)
        loltext = font.render("CrimSon Syndrome", True,(255,255,255))
        lolrect = loltext.get_rect()
        lolrect.center = ((300,100))
        window.blit(loltext,lolrect)

        font = pygame.font.Font("lolfont.ttf", 40)
        loltext = font.render("Classic Pong Game", True,(255,255,255))
        lolrect = loltext.get_rect()
        lolrect.center = ((300,160))
        window.blit(loltext,lolrect)

        font = pygame.font.Font("lolfont.ttf", 40)
        loltext = font.render("By:Habib I.", True,(255,255,255))
        lolrect = loltext.get_rect()
        lolrect.center = ((300,460))
        window.blit(loltext,lolrect)

                    
        button("Quit Game",220,270,190,40,green,bright_green,quitlol)
        button("Options",220,340,190,40,green,bright_green,options_menu)
        button("2 Players",220,200,190,40,green,bright_green,game_loop)


    # ---------------------------------------------------------------------





      

        pygame.display.update()


def game_loop():

    class Speed:
        def __init__(self,x,y):
            self.x = x
            self.y = y

      #-------------------------------- enemy shoots left and right

    class Player:
        def __init__(self,x,y,height,width,color):
            self.x = x
            self.y = y
            self.height = height
            self.width = width
            self.color = color
            self.speed = Speed(0,5)
            self.rect = pygame.Rect(x,y,height,width)
            self.hits = (self.x + 20, self.y, 28,60)
            self.health = 10
                # the hitbox our projectiles will be colliding with
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)



        def pad_top(self):
            return pygame.Rect(self.rect.x,self.rect.y,
                               self.rect.width,self.rect.height//4)

        def pad_middle(self):
            return pygame.Rect(self.rect.x,self.rect.y+rect.height//4,
                               self.rect.width,self.rect.height//2)

        def pad_bottom(self):
            return pygame.Rect(self.rect.x,self.rect.y+3*self.rect.height//4,
                               self.rect.width,self.rect.height//4)

        def up(self):
            if self.rect.y < self.speed.y:
                return
            self.rect.move_ip(0, -self.speed.y)

        def down(self):
            if self.rect.y + self.speed.y > WIDTH:
                return
            self.rect.move_ip(0, self.speed.y)

        def draw(self):
            pygame.draw.rect(window,self.color,self.rect)


    class Ball:
        def __init__(self,x,y,height,width,color):
            self.color = color
            self.speed = Speed(5,5)
            self.x = x
            self.y = y
            self.height = height
            self.width = width
            self.rect = pygame.Rect(x,y,height,width)

        def draw(self):
            pygame.draw.circle(window, self.color, self.rect.center,10)



        def move(self):
            nextx = self.rect.x + self.speed.x
            nexty = self.rect.y + self.speed.y
            if nextx <= 0 or nextx >= WIDTH: self.speed.x *= -1
            if nexty <= 0 or nexty >= HEIGHT: self.speed.y *= -1
            self.rect.move_ip(self.speed.x,self.speed.y)






    white = (255,255,255)
    player1 = Player(30,150,10,120,white)
    player2 = Player(570,150,10,120,white)

    ball1 = Ball(290,200,20,20,white)

    FPS = 60

       # enemys bullets
    class enemyboolss(object):
        def __init__(self, x, y,color, xspeed, yspeed):
            self.x = x
            self.y = y
            self.xspeed = xspeed
            self.yspeed = yspeed
            self.ksud = pygame.image.load("BOM.png")
            self.hitbox  = self.ksud.get_rect()
            self.rect  = self.ksud.get_rect()
            self.rect.topleft = (self.x,self.y)
            self.ksud = pygame.transform.scale(self.ksud,(self.ksud.get_width()//25,self.ksud.get_height()//25))
            self.color = color
            self.hitbox = (self.x + 57, self.y + 33, 29, 52) # NEW
        def draw(self, window):
            self.rect.topleft = (self.x,self.y)
            player_rect = self.ksud.get_rect(center = self.rect.center) 
            player_rect.centerx += 0 # 10 is just an example
            player_rect.centery += 0 # 15 is just an example
            self.hitbox = (self.x + 10, self.y + 10, 15, 15) # NEW
            window.blit(self.ksud,self.rect)

    







    # the rect in the middile 
    class tinyrect:
        def __init__(self,x,y,height,width,color):
            self.x = x
            self.y = y
            self.height = height
            self.width = width
            self.color = color
            self.rect = pygame.Rect(x,y,height,width)
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)

    tiny1 = tinyrect(300,0,1,500,white)

    #------------------------------------



    # collision things

    # fps class
    clock = pygame.time.Clock()
    pygame.event.get()

    # ReDraw The WIndow

    # -----------------------------------------------------------------------------------------------
            
    # score 1 for player 1
    font = pygame.font.Font("lolfont.ttf", 49)
    score = 0
    loltext = font.render("Score: "+str(score), True,(255,255,255))
    lolrect = loltext.get_rect()
    lolrect.center = ((200,100))



    # score for player 2
    font = pygame.font.Font("Candarai.ttf", 49)
    player2score = 0
    text = font.render("Score: "+str(player2score), True,(255,255,255))
    rects = text.get_rect()
    rects.center = ((400,100))

      #-------------------------------- enemy shoots left and right
    class health:
        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 = 10
            self.rect = pygame.Rect(x,y,height,width)
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
            self.hitbox = (self.x + 20, self.y, 18,10)

        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)


            self.hitbox = (self.x +-60 , self.y + 5, 38,10)
            pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 150, 15)) # NEW
            pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 150 - (5 * (10 - self.health)), 15))


    enemy1 = health(200,100,0,0,white)
    enemy2 = health(390,100,0,0,white)
    healthing = [enemy1,enemy2]

    # this part is the enemyshooting at the player
    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 = 10
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
           #-------------------------------------------------------
            # Make a Reference Copy of the bitmap for later rotation

 

            self.hitbox = (self.x + 20, self.y, 18,10)
            self.isLookingAtPlayer = False
            self.look_at_pos = (x,y)
            self.rect = pygame.Rect(x,y,height,width)
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)



            self.hitbox = (self.x +-60 , self.y + 5, 38,10)
            pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 100, 10)) # NEW
            pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 100 - (5 * (10 - self.health)), 10))

    enemyshoot1 = enemyshoot(300,300,10,10,white)
    enemyshooting = [enemyshoot1]

    

      #-------------------------------- enemy shoots left and right
    class collisions:
        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 = 10
            self.rect = pygame.Rect(x,y,height,width)
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
            self.hitbox = (self.x + 20, self.y, 18,10)

        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)



    collision1 = collisions(3,0,5,1225,white)
    collision2 = collisions(599,0,5,1225,white)
    collisionss = [collision1,collision2]

    

  #-------------------------------- enemy shoots left and right
    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 = 10
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
           #-------------------------------------------------------
            # Make a Reference Copy of the bitmap for later rotation


            self.hitbox = (self.x + 20, self.y, 18,10)
            self.isLookingAtPlayer = False
            self.look_at_pos = (x,y)
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)

            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)
            self.image = pygame.transform.rotate(self.shootsright, angle)
            self.rect  = self.image.get_rect(center = self.rect.center)

            window.blit(self.image, self.rect)
            self.hitbox = (self.x +-60 , self.y + 5, 38,10)
            pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 100, 10)) # NEW
            pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 100 - (5 * (10 - self.health)), 10))

    enemyshoot1 = enemyshoot(300,300,10,10,white)
    # -----------------------------------------------------------------------------------------------
    def ReDrawWindow():
        for collisions in collisionss:
            collisions.draw()
        window.fill((0,0,0))
        player2.draw()
        player1.draw()
        ball1.draw()


        tiny1.draw()
        window.blit(loltext,lolrect)
        window.blit(text,rects)
        for bull in bulls:
            bull.draw(window)
        for health in healthing:
            health.draw()
        for shootss in shootsright:
            shootss.draw(window)
        for enemyshoot in enemyshooting:
            enemyshoot.draw()



    snow_list=[]
    no_of_circles=100;
    clock.tick(FPS)
    for i in range(no_of_circles):
        x = random.randrange(0, 600)
        y = random.randrange(0, 500)
        snow_list.append([x,y])

    clock = pygame.time.Clock()

    #Initialize values for color (RGB format)
    WHITE=(255,255,255)
    RED=(255,0,0)
    GREEN=(0,255,0)
    BLUE=(0,0,255)
    BLACK=(0,0,0)
    # score lol


    bulls = []
    shootsright = []
    playing = True
    while playing:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                playing = False
                break;
    


        for shootss in shootsright:
            shootss.x += shootss.xspeed
            shootss.y += shootss.yspeed
            if shootss.x > 700 or shootss.x < 0 or shootss.y > 500 or shootss.y < 0:
                    
                shootsright.pop(shootsright.index(shootss))
        if len(shootsright) < 1:
            for enemyshoot in enemyshooting:
                BULLET_SPEED = 10
                start_x = round(enemyshoot.x+enemyshoot.width+-35)
                start_y = round(enemyshoot.y + enemyshoot.height+-25)
                target_x = player1.x+player1.width//2
                target_y = player1.y+player1.width//2
                delta_x, delta_y = target_x - start_x, target_y - start_y
                distance = math.sqrt(delta_x ** 2 + delta_y ** 2)
                dir_x = BULLET_SPEED * delta_x / distance
                dir_y = BULLET_SPEED * delta_y / distance
                distance = math.sqrt(dir_x**2 + dir_y**2)
                if distance > 0:
                    shootsright.append(enemyboolss(start_x,start_y,(0,0,0),dir_x, dir_y))




        for point in snow_list:
            point[1]+=1
            pygame.draw.circle(window, (255,255,255), point, 2)

            if(point[1] >= 600):
                point[0] = random.randrange(0, 600)
                point[1] = random.randrange(-10, -5)

        pygame.display.flip()
        clock.tick(FPS)



        ball1.move()


        if ball1.rect.colliderect(collision1.rect):
            if enemy1.health > -22:
                enemy1.health -= 5
                ball1.speed.y += 5
                ball1 = Ball(290,200,20,20,white)
                player2score += 1
                text = font.render("Score:" + str(player2score), True, (255,255,255))
                rects.center = ((400,100))
                font1 = pygame.font.SysFont('comicsans', 50)
                detexto = font1.render('~Player One Has Scored!!!~', 1, (255,0,0))
                window.blit(detexto, (290 - (detexto.get_width()/2),200))
                pygame.display.update()
                i = 0
                while i < 300:
                    pygame.time.delay(10)
                    i += 1
                    for event in pygame.event.get():
                        if event.type == pygame.QUIT:
                            i = 301
                            pygame.quit()
         
                
            


        if ball1.rect.colliderect(collision2.rect):
            if enemy2.health > -22:
                enemy2.health -= 5
                ball1.speed.y += 5
                ball1 = Ball(290,200,20,20,white)
                player2score += 1
                loltext = font.render("Score:" + str(player2score), True, (255,255,255))
                lolrect.center = ((200,100))
                font1 = pygame.font.SysFont('comicsans', 50)
                detexto = font1.render('~Player Two Has Scored!!!~', 1, (255,0,0))
                window.blit(detexto, (290 - (detexto.get_width()/2),200))
                pygame.display.update()
                i = 0
                while i < 300:
                    pygame.time.delay(10)
                    i += 1
                    for event in pygame.event.get():
                        if event.type == pygame.QUIT:
                            i = 301
                            pygame.quit()

        # ball hit paddle
        for player in [player1, player2]:
            if ball1.rect.colliderect(player.rect):
                ball1.speed.x *= -1
                ball1.speed.x += 0.2 * abs(ball1.speed.x) / ball1.speed.x
                # Ball collide upper part of paddle
                if ball1.rect.colliderect(player.pad_top()):
                    # Ball go up
                    ball1.speed.y = -abs(ball1.speed.y)
                # Ball collide lower part of paddle
                elif ball1.rect.colliderect(player.pad_bottom()):
                    # Ball fo down
                    ball1.speed.y = abs(ball1.speed.y)

        # key event
        keys = pygame.key.get_pressed()

        if keys[pygame.K_UP]:   player2.up()
        if keys[pygame.K_DOWN]: player2.down()
        if keys[pygame.K_w]:    player1.up()
        if keys[pygame.K_s]:    player1.down()



        ReDrawWindow()

        pygame.display.update()

    pygame.quit()
game_intro()
game_loop()


导入pygame
随机输入
输入数学
宽度,高度=600500
pygame.init()
window=pygame.display.set_模式((宽度、高度))
#头衔
pygame.display.set_标题(“pong”)
def quitlol():
pygame.quit()
退出
#---------------------------------------------------
def按钮(消息、x、y、w、h、ic、ac、操作=无):
mouse=pygame.mouse.get_pos()
click=pygame.mouse.get_pressed()
如果x+w>鼠标[0]>x和y+h>鼠标[1]>y:
pygame.draw.rect(窗口,ac,(x,y,w,h))
如果单击[0]==1并执行操作!=无:
行动()
其他:
pygame.draw.rect(窗口,ic,(x,y,w,h))
smallText=pygame.font.SysFont(“lolfont.ttf”,60)
textSurf,textRect=text\u对象(msg,smallText)
textRect.center=((x+(w/2)),(y+(h/2)))
blit(textSurf,textRect)
#------------------------------------------------------
def text_对象(文本、字体):
黑色=(0,0,0)
textSurface=font.render(文本,真,黑色)
返回textSurface,textSurface.get_rect()
def选项菜单()
红色=(200,0,0)
绿色=(0200,0)
鲜红色=(255,0,0)
亮绿色=(0255,0)
选项=真
而选项:
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
选项=False
窗口填充((0,0,0))
按钮(“静音音乐”,220270190,40,绿色,亮绿色,)
按钮(“碰撞静音”,220340190,40,绿色,亮绿色)
按钮(“禁用雪”,220200190,40,绿色,亮绿色)
def game_intro():
雪景列表=[]
_圈的数量=100;
clock=pygame.time.clock()
FPS=60
时钟滴答声(FPS)
对于范围内的i(没有圆圈):
x=random.randrange(0600)
y=random.randrange(0500)
snow\u list.append([x,y])
红色=(200,0,0)
绿色=(0200,0)
鲜红色=(255,0,0)
亮绿色=(0255,0)
fps=460
clock=pygame.time.clock()
简介=正确
而简介:
时钟滴答声(fps)
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
简介=错误
pygame.quit()
窗口填充((0,0,0))
对于snow_列表中的点:
点[1]+=1
pygame.draw.circle(窗口,(255255),点,2)
如果(点[1]>=600):
点[0]=random.randrange(0600)
点[1]=random.randrange(-10,-5)
时钟滴答声(FPS)
font=pygame.font.font(“Candarali.ttf”,60)
loltext=font.render(“深红综合症”,真,(255255))
lolrect=loltext.get_rect()
lolrect.center=((300100))
blit(loltext,lolrect)
font=pygame.font.font(“lolfont.ttf”,40)
loltext=font.render(“经典乒乓球游戏”,真,(255255))
lolrect=loltext.get_rect()
lolrect.center=((300160))
blit(loltext,lolrect)
font=pygame.font.font(“lolfont.ttf”,40)
loltext=font.render(“By:Habib I.”,True,(255255))
lolrect=loltext.get_rect()
lolrect.center=((300460))
blit(loltext,lolrect)
按钮(“退出游戏”,220270190,40,绿色,亮绿色,退出)
按钮(“选项”,220340190,40,绿色,亮绿色,选项菜单)
按钮(“2名玩家”,220200190,40,绿色,亮绿色,游戏循环)
# ---------------------------------------------------------------------
pygame.display.update()
def game_loop():
班速:
定义初始化(self,x,y):
self.x=x
self.y=y
#--------------------------------敌人左右射击
职业球员:
定义初始值(自、x、y、高度、宽度、颜色):
self.x=x
self.y=y
自我高度=高度
self.width=宽度
self.color=颜色
自身速度=速度(0,5)
self.rect=pygame.rect(x,y,高度,宽度)
self.hits=(self.x+20,self.y,28,60)
自我健康=10
#我们的射弹将要撞上的撞机匣
def牵引(自):
self.rect.topleft=(self.x,self.y)
pygame.draw.rect(窗口,self.color,self.rect)
def垫_顶部(自):
返回pygame.Rect(self.Rect.x,self.Rect.y,
self.rect.width、self.rect.height//4)
def垫_中间(自):
返回pygame.Rect(self.Rect.x,self.Rect.y+Rect.height//4,
self.rect.width、self.rect.height//2)
def垫_底部(自):
返回pygame.Rect(self.Rect.x,self.Rect.y+3*self.Rect.height//4,
self.rect.width、self.rect.height//4)
def up(自我):
如果self.rect.y宽度:
返回
自校正移动ip(0,自校正速度y)
def牵引(自):
pygame.draw.rect(窗口,self.color,self.rect)
班级舞会:
定义初始值(自、x、y、高度、宽度、颜色):
self.color=颜色
自速度=速度(5,5)
self.x=x
self.y=y
自我高度=高度
self.width=宽度
self.rect=pygame.rect(x,y,高度,宽度)
def牵引(自):
pygame.draw.circle(窗口,self.color,self.rect.center,10)
def移动(自我):
nextx=self.rect.x+self.speed.x
nexty=self.rect.y+self.speed.y
如果nextx=WIDTH:self.speed.x*=-1
如果nexty=HE
import pygame
import random
import math 

WIDTH, HEIGHT = 600, 500
pygame.init()

window = pygame.display.set_mode((WIDTH,HEIGHT))

# title
pygame.display.set_caption("pong")



def quitlol():
    pygame.quit()
    quit()
    #---------------------------------------------------

def button(msg,x,y,w,h,ic,ac,action=None):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

    if x+w > mouse[0] > x and y+h > mouse[1] > y:
        pygame.draw.rect(window, ac,(x,y,w,h))
        if click[0] == 1 and action != None:
            action()         
    else:
        pygame.draw.rect(window, ic,(x,y,w,h))
        smallText = pygame.font.SysFont("lolfont.ttf",60)
        textSurf, textRect = text_objects(msg, smallText)
        textRect.center = ( (x+(w/2)), (y+(h/2)) )
        window.blit(textSurf, textRect)
        
    #------------------------------------------------------


def text_objects(text, font):
    black = (0,0,0)
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()


def options_menu():
    red = (200,0,0)
    green = (0,200,0)
    bright_red = (255,0,0)
    bright_green = (0,255,0)
    option = True
    while option:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                option = False
                
        window.fill((0,0,0))
        button("Mute Music",220,270,190,40,green,bright_green,)
        button("Collisions Mute",220,340,190,40,green,bright_green)
        button("Disable Snow",220,200,190,40,green,bright_green)



def game_intro():

                
    snow_list=[]
    no_of_circles=100;
    clock = pygame.time.Clock()
    FPS = 60
    clock.tick(FPS)
    for i in range(no_of_circles):
        x = random.randrange(0, 600)
        y = random.randrange(0, 500)
        snow_list.append([x,y])
    red = (200,0,0)
    green = (0,200,0)
    bright_red = (255,0,0)
    bright_green = (0,255,0)
    fps = 460
    clock = pygame.time.Clock()
    intro = True
    while intro:
        clock.tick(fps)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                intro = False
                pygame.quit()



        window.fill((0,0,0))




        for point in snow_list:
            point[1]+=1
            pygame.draw.circle(window, (255,255,255), point, 2)

            if(point[1] >= 600):
                point[0] = random.randrange(0, 600)
                point[1] = random.randrange(-10, -5)

        clock.tick(FPS)



        font = pygame.font.Font("Candarali.ttf", 60)
        loltext = font.render("CrimSon Syndrome", True,(255,255,255))
        lolrect = loltext.get_rect()
        lolrect.center = ((300,100))
        window.blit(loltext,lolrect)

        font = pygame.font.Font("lolfont.ttf", 40)
        loltext = font.render("Classic Pong Game", True,(255,255,255))
        lolrect = loltext.get_rect()
        lolrect.center = ((300,160))
        window.blit(loltext,lolrect)

        font = pygame.font.Font("lolfont.ttf", 40)
        loltext = font.render("By:Habib I.", True,(255,255,255))
        lolrect = loltext.get_rect()
        lolrect.center = ((300,460))
        window.blit(loltext,lolrect)

                    
        button("Quit Game",220,270,190,40,green,bright_green,quitlol)
        button("Options",220,340,190,40,green,bright_green,options_menu)
        button("2 Players",220,200,190,40,green,bright_green,game_loop)


    # ---------------------------------------------------------------------





      

        pygame.display.update()


def game_loop():

    class Speed:
        def __init__(self,x,y):
            self.x = x
            self.y = y

      #-------------------------------- enemy shoots left and right

    class Player:
        def __init__(self,x,y,height,width,color):
            self.x = x
            self.y = y
            self.height = height
            self.width = width
            self.color = color
            self.speed = Speed(0,5)
            self.rect = pygame.Rect(x,y,height,width)
            self.hits = (self.x + 20, self.y, 28,60)
            self.health = 10
                # the hitbox our projectiles will be colliding with
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)



        def pad_top(self):
            return pygame.Rect(self.rect.x,self.rect.y,
                               self.rect.width,self.rect.height//4)

        def pad_middle(self):
            return pygame.Rect(self.rect.x,self.rect.y+rect.height//4,
                               self.rect.width,self.rect.height//2)

        def pad_bottom(self):
            return pygame.Rect(self.rect.x,self.rect.y+3*self.rect.height//4,
                               self.rect.width,self.rect.height//4)

        def up(self):
            if self.rect.y < self.speed.y:
                return
            self.rect.move_ip(0, -self.speed.y)

        def down(self):
            if self.rect.y + self.speed.y > WIDTH:
                return
            self.rect.move_ip(0, self.speed.y)

        def draw(self):
            pygame.draw.rect(window,self.color,self.rect)


    class Ball:
        def __init__(self,x,y,height,width,color):
            self.color = color
            self.speed = Speed(5,5)
            self.x = x
            self.y = y
            self.height = height
            self.width = width
            self.rect = pygame.Rect(x,y,height,width)

        def draw(self):
            pygame.draw.circle(window, self.color, self.rect.center,10)



        def move(self):
            nextx = self.rect.x + self.speed.x
            nexty = self.rect.y + self.speed.y
            if nextx <= 0 or nextx >= WIDTH: self.speed.x *= -1
            if nexty <= 0 or nexty >= HEIGHT: self.speed.y *= -1
            self.rect.move_ip(self.speed.x,self.speed.y)






    white = (255,255,255)
    player1 = Player(30,150,10,120,white)
    player2 = Player(570,150,10,120,white)

    ball1 = Ball(290,200,20,20,white)

    FPS = 60

       # enemys bullets
    class enemyboolss(object):
        def __init__(self, x, y,color, xspeed, yspeed):
            self.x = x
            self.y = y
            self.xspeed = xspeed
            self.yspeed = yspeed
            self.ksud = pygame.image.load("BOM.png")
            self.hitbox  = self.ksud.get_rect()
            self.rect  = self.ksud.get_rect()
            self.rect.topleft = (self.x,self.y)
            self.ksud = pygame.transform.scale(self.ksud,(self.ksud.get_width()//25,self.ksud.get_height()//25))
            self.color = color
            self.hitbox = (self.x + 57, self.y + 33, 29, 52) # NEW
        def draw(self, window):
            self.rect.topleft = (self.x,self.y)
            player_rect = self.ksud.get_rect(center = self.rect.center) 
            player_rect.centerx += 0 # 10 is just an example
            player_rect.centery += 0 # 15 is just an example
            self.hitbox = (self.x + 10, self.y + 10, 15, 15) # NEW
            window.blit(self.ksud,self.rect)

    







    # the rect in the middile 
    class tinyrect:
        def __init__(self,x,y,height,width,color):
            self.x = x
            self.y = y
            self.height = height
            self.width = width
            self.color = color
            self.rect = pygame.Rect(x,y,height,width)
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)

    tiny1 = tinyrect(300,0,1,500,white)

    #------------------------------------



    # collision things

    # fps class
    clock = pygame.time.Clock()
    pygame.event.get()

    # ReDraw The WIndow

    # -----------------------------------------------------------------------------------------------
            
    # score 1 for player 1
    font = pygame.font.Font("lolfont.ttf", 49)
    score = 0
    loltext = font.render("Score: "+str(score), True,(255,255,255))
    lolrect = loltext.get_rect()
    lolrect.center = ((200,100))



    # score for player 2
    font = pygame.font.Font("Candarai.ttf", 49)
    player2score = 0
    text = font.render("Score: "+str(player2score), True,(255,255,255))
    rects = text.get_rect()
    rects.center = ((400,100))

      #-------------------------------- enemy shoots left and right
    class health:
        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 = 10
            self.rect = pygame.Rect(x,y,height,width)
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
            self.hitbox = (self.x + 20, self.y, 18,10)

        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)


            self.hitbox = (self.x +-60 , self.y + 5, 38,10)
            pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 150, 15)) # NEW
            pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 150 - (5 * (10 - self.health)), 15))


    enemy1 = health(200,100,0,0,white)
    enemy2 = health(390,100,0,0,white)
    healthing = [enemy1,enemy2]

    # this part is the enemyshooting at the player
    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 = 10
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
           #-------------------------------------------------------
            # Make a Reference Copy of the bitmap for later rotation

 

            self.hitbox = (self.x + 20, self.y, 18,10)
            self.isLookingAtPlayer = False
            self.look_at_pos = (x,y)
            self.rect = pygame.Rect(x,y,height,width)
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)



            self.hitbox = (self.x +-60 , self.y + 5, 38,10)
            pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 100, 10)) # NEW
            pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 100 - (5 * (10 - self.health)), 10))

    enemyshoot1 = enemyshoot(300,300,10,10,white)
    enemyshooting = [enemyshoot1]

    

      #-------------------------------- enemy shoots left and right
    class collisions:
        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 = 10
            self.rect = pygame.Rect(x,y,height,width)
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
            self.hitbox = (self.x + 20, self.y, 18,10)

        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)



    collision1 = collisions(3,0,5,1225,white)
    collision2 = collisions(599,0,5,1225,white)
    collisionss = [collision1,collision2]

    

  #-------------------------------- enemy shoots left and right
    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 = 10
            self.hitbox = (self.x + -20, self.y + 30, 5, 5)
           #-------------------------------------------------------
            # Make a Reference Copy of the bitmap for later rotation


            self.hitbox = (self.x + 20, self.y, 18,10)
            self.isLookingAtPlayer = False
            self.look_at_pos = (x,y)
        def draw(self):
            self.rect.topleft = (self.x,self.y)
            pygame.draw.rect(window,self.color,self.rect)

            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)
            self.image = pygame.transform.rotate(self.shootsright, angle)
            self.rect  = self.image.get_rect(center = self.rect.center)

            window.blit(self.image, self.rect)
            self.hitbox = (self.x +-60 , self.y + 5, 38,10)
            pygame.draw.rect(window, (255,0,0), (self.hitbox[0], self.hitbox[1] - 60, 100, 10)) # NEW
            pygame.draw.rect(window, (0,255,0), (self.hitbox[0], self.hitbox[1] - 60, 100 - (5 * (10 - self.health)), 10))

    enemyshoot1 = enemyshoot(300,300,10,10,white)
    # -----------------------------------------------------------------------------------------------
    def ReDrawWindow():
        for collisions in collisionss:
            collisions.draw()
        window.fill((0,0,0))
        player2.draw()
        player1.draw()
        ball1.draw()


        tiny1.draw()
        window.blit(loltext,lolrect)
        window.blit(text,rects)
        for bull in bulls:
            bull.draw(window)
        for health in healthing:
            health.draw()
        for shootss in shootsright:
            shootss.draw(window)
        for enemyshoot in enemyshooting:
            enemyshoot.draw()



    snow_list=[]
    no_of_circles=100;
    clock.tick(FPS)
    for i in range(no_of_circles):
        x = random.randrange(0, 600)
        y = random.randrange(0, 500)
        snow_list.append([x,y])

    clock = pygame.time.Clock()

    #Initialize values for color (RGB format)
    WHITE=(255,255,255)
    RED=(255,0,0)
    GREEN=(0,255,0)
    BLUE=(0,0,255)
    BLACK=(0,0,0)
    # score lol


    bulls = []
    shootsright = []
    playing = True
    while playing:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                playing = False
                break;
    


        for shootss in shootsright:
            shootss.x += shootss.xspeed
            shootss.y += shootss.yspeed
            if shootss.x > 700 or shootss.x < 0 or shootss.y > 500 or shootss.y < 0:
                    
                shootsright.pop(shootsright.index(shootss))
        if len(shootsright) < 1:
            for enemyshoot in enemyshooting:
                BULLET_SPEED = 10
                start_x = round(enemyshoot.x+enemyshoot.width+-35)
                start_y = round(enemyshoot.y + enemyshoot.height+-25)
                target_x = player1.x+player1.width//2
                target_y = player1.y+player1.width//2
                delta_x, delta_y = target_x - start_x, target_y - start_y
                distance = math.sqrt(delta_x ** 2 + delta_y ** 2)
                dir_x = BULLET_SPEED * delta_x / distance
                dir_y = BULLET_SPEED * delta_y / distance
                distance = math.sqrt(dir_x**2 + dir_y**2)
                if distance > 0:
                    shootsright.append(enemyboolss(start_x,start_y,(0,0,0),dir_x, dir_y))




        for point in snow_list:
            point[1]+=1
            pygame.draw.circle(window, (255,255,255), point, 2)

            if(point[1] >= 600):
                point[0] = random.randrange(0, 600)
                point[1] = random.randrange(-10, -5)

        pygame.display.flip()
        clock.tick(FPS)



        ball1.move()


        if ball1.rect.colliderect(collision1.rect):
            if enemy1.health > -22:
                enemy1.health -= 5
                ball1.speed.y += 5
                ball1 = Ball(290,200,20,20,white)
                player2score += 1
                text = font.render("Score:" + str(player2score), True, (255,255,255))
                rects.center = ((400,100))
                font1 = pygame.font.SysFont('comicsans', 50)
                detexto = font1.render('~Player One Has Scored!!!~', 1, (255,0,0))
                window.blit(detexto, (290 - (detexto.get_width()/2),200))
                pygame.display.update()
                i = 0
                while i < 300:
                    pygame.time.delay(10)
                    i += 1
                    for event in pygame.event.get():
                        if event.type == pygame.QUIT:
                            i = 301
                            pygame.quit()
         
                
            


        if ball1.rect.colliderect(collision2.rect):
            if enemy2.health > -22:
                enemy2.health -= 5
                ball1.speed.y += 5
                ball1 = Ball(290,200,20,20,white)
                player2score += 1
                loltext = font.render("Score:" + str(player2score), True, (255,255,255))
                lolrect.center = ((200,100))
                font1 = pygame.font.SysFont('comicsans', 50)
                detexto = font1.render('~Player Two Has Scored!!!~', 1, (255,0,0))
                window.blit(detexto, (290 - (detexto.get_width()/2),200))
                pygame.display.update()
                i = 0
                while i < 300:
                    pygame.time.delay(10)
                    i += 1
                    for event in pygame.event.get():
                        if event.type == pygame.QUIT:
                            i = 301
                            pygame.quit()

        # ball hit paddle
        for player in [player1, player2]:
            if ball1.rect.colliderect(player.rect):
                ball1.speed.x *= -1
                ball1.speed.x += 0.2 * abs(ball1.speed.x) / ball1.speed.x
                # Ball collide upper part of paddle
                if ball1.rect.colliderect(player.pad_top()):
                    # Ball go up
                    ball1.speed.y = -abs(ball1.speed.y)
                # Ball collide lower part of paddle
                elif ball1.rect.colliderect(player.pad_bottom()):
                    # Ball fo down
                    ball1.speed.y = abs(ball1.speed.y)

        # key event
        keys = pygame.key.get_pressed()

        if keys[pygame.K_UP]:   player2.up()
        if keys[pygame.K_DOWN]: player2.down()
        if keys[pygame.K_w]:    player1.up()
        if keys[pygame.K_s]:    player1.down()



        ReDrawWindow()

        pygame.display.update()

    pygame.quit()
game_intro()
game_loop()