Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.6 kB
2
Indexable
Never
import pygame
import random
from pygame.locals import *

pygame.init()
width = 800
height = 600
screen = pygame.display.set_mode((width,height) )
pygame.display.set_caption("Eggs")
egg_counts = [0 for i in range(0,4)]


font = pygame.font.Font('Oswald-VariableFont_wght.ttf', 32)
class Player:
    def __init__(self, number):
        self.number = number
        self.text_img = font.render('0', False, (255, 0, 0))
        self.text = self.text_img.get_rect()
        if number % 2 ==0:
            self.image = pygame.image.load("player2.png")
            self.text.x = 100
            self.text.y = 550
        else:
            self.image = pygame.image.load("player1.png")
            self.text.x = 600
            self.text.y = 550
        self.rectangle = self.image.get_rect()
        self.rectangle.x = random.randint(0, width-150)
        self.rectangle.y = random.randint(0, height-150)
        self.points = 0





    def draw(self, screen):
        screen.blit(self.image, self.rectangle)
        screen.blit(self.text_img, self.text)


    def move(self, x, y):
        self.rectangle.x+=x
        self.rectangle.y+=y
    def checkCollisions(self, eggs):
        for egg in eggs:
            if self.rectangle.colliderect(egg.rectangle) and self.number%2 == egg.number%2:
                self.points +=1
                self.text_img = font.render(str(self.number), False, (255, 0, 0))
        
                eggs.remove(egg)
                if egg.number%2 == 0:
                    r = random.choice([2])
                    eggs.append(Egg())
                else:
                    r = random.choice([1])
                    eggs.append(Egg())

                break

class Egg:
    def __init__(self):
        self.number = random.randint(0, 4)
        if self.number == 1:
            self.image = pygame.image.load("jajko1.png")
        elif self.number == 2:
            self.image = pygame.image.load("jajko2.png")
        elif self.number == 3:
            self.image = pygame.image.load("jajko3.png")
        else:
            self.image = pygame.image.load("jajko4.png")
        self.rectangle = self.image.get_rect()
        self.rectangle.x = random.randint(0, width-50)
        self.rectangle.y = random.randint(0, height-50)
    def jajkos(self):
        if self.number %2 ==0:
            self.image = pygame.image.load("jajko1.png")
        else:
            self.image= pygame.image.load("jajko2.png")
    def draw(self, screen):
        screen.blit(self.image, self.rectangle)



eggs = [Egg(),Egg(), Egg(), Egg()]

players = [Player(1), Player(2)]

running = True
while running == True:
    screen.fill( (89, 179, 66) ) #RGB

    for event in pygame.event.get():
        if event.type == QUIT:
            running = False
        if event.type == KEYDOWN:
            if event.key == K_a:
                players[0].move(-10,0)
            if event.key == K_d:
                players[0].move(10,0)
            if event.key == K_w:
                players[0].move(0,-10)
            if event.key == K_s:
                players[0].move(0,10)
            if event.key == K_LEFT:
                players[1].move(-10,0)
            if event.key == K_RIGHT:
                players[1].move(10,0)
            if event.key == K_UP:
                players[1].move(0,-10)
            if event.key == K_DOWN:
                players[1].move(0,10)

    for player in players:
        player.checkCollisions(eggs)
        player.draw(screen)

    for egg in eggs:
        egg.draw(screen)

    pygame.display.update()

pygame.quit()