0

I'm using Python on my Raspberry Pi to code some games for my high school finals project, and I want to play them with a arcade kit (Game DIY Arcade Set Kits Replacement Parts USB Encoder to PC Joystick and Buttons). I already tested the arcade kit and it works perfectly in the Raspberry Pi 3 Model B. I tested the arcade kit with https://html5gamepad.com/

Already went to https://www.pygame.org/docs/ref/joystick.html and tried to code myself the buttons, but still nothing.

There is one of the games if it helps

import random    
import pygame
pygame.init()

WHITE = (255,255,255)
BLACK = (0,0,0)
PIPE = (0,255,128)
SKY = (102,178,255)
GROUND = (192,192,192)
GRASS = (0,153,76)
BIRD = (255,255,0)
BROWN = (124,115,46)
RED = (204,0,0)


size = (800,700)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("Flappy Block")

done = False

clock = pygame.time.Clock()

arial18 = pygame.font.SysFont('arial',18, False, False)
arial30 = pygame.font.SysFont('arial',30, False, False)

gameState = 1

pipes = []

Pontuação = 0
pontuaçãoMáxima = 0

class Bird():
    def __init__(self):
        self.x = 250
        self.y = 250
        self.yV = 0

    def flap(self):
        self.yV = -10

    def update(self):
        self.yV += 0.5
        self.y += self.yV
        if self.y >= 608:
            self.y = 608
            self.yV = 0
        if self.yV > 20:
            self.yV = 20

    def draw(self):
        pygame.draw.rect(screen,BIRD,(self.x,self.y,40,40))

    def reset(self):
        self.x = 250
        self.y = 250
        self.yV = 0

bird = Bird()

class Pipe():
    def __init__(self):
        self.centerY = random.randrange(130,520)
        self.x = 800
        self.size = 100

    def update(self):
        global pipes
        global bird
        global gameState
        global Pontuação
        self.x -= 4
        if self.x == 300:
            pipes.append(Pipe())
        if self.x <= -100:
            del pipes[0]
        if self.x >= 170 and self.x <= 290 and bird.y <= (self.centerY - self.size) or self.x >= 170 and self.x <= 290 and (bird.y + 40) >= (self.centerY + self.size):
            gameState = 3
        if self.x == 168 and bird.y > (self.centerY - 100) and bird.y < (self.centerY + 100):
            Pontuação += 1
        if bird.y >= 608:
            gameState = 3

    def draw(self):
        pygame.draw.rect(screen,PIPE,(self.x,0,80,(self.centerY - self.size)))
        pygame.draw.rect(screen,PIPE,(self.x,(self.centerY + self.size),80,(548 - self.centerY)))

pipes.append(Pipe())

# -------- Main Program Loop -----------
while not done:
    # --- Main event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                if gameState == 1:
                    gameState = 2
                elif gameState == 3:
                    bird.reset()
                    pipes = []
                    pipes.append(Pipe())
                    gameState = 2
                    Pontuação = 0
                else:
                    bird.flap()

    screen.fill(SKY)
    pygame.draw.rect(screen,GROUND,(0,650,800,50))
    pygame.draw.line(screen,GRASS,(0,650),(800,650),5)
    pygame.draw.line(screen,GRASS,(0,650),(800,650),5)

    if gameState == 1:
        pygame.draw.rect(screen,BLACK,(300,300,220,100))
        pygame.draw.rect(screen,WHITE,(300,300,220,100),5)
        text = arial18.render("Prima um botão para jogar",True,GRASS)
        textX = text.get_rect().width
        textY = text.get_rect().height
        screen.blit(text,((410 - (textX / 2)),(350 - (textY / 2))))

    if gameState == 2:
        bird.update()
        bird.draw()

        for pipe in pipes:
            pipe.update()
            pipe.draw()

        if Pontuação > pontuaçãoMáxima:
            pontuaçãoMáxima = Pontuação

        text = arial30.render(str(Pontuação),True,WHITE)
        textX = text.get_rect().width
        textY = text.get_rect().height
        screen.blit(text,((400 - (textX / 2)),(50 - (textY / 2))))

    if gameState == 3:
        for pipe in pipes:
            pipe.draw()
        bird.draw()

        pygame.draw.rect(screen,BLACK,(300,250,220,200))
        pygame.draw.rect(screen,WHITE,(300,250,220,200),5)
        text = arial18.render(("Pontuação: " + str(Pontuação)),True,GRASS)
        textX = text.get_rect().width
        textY = text.get_rect().height
        screen.blit(text,((410 - (textX / 2)),(300 - (textY / 2))))
        text = arial18.render(("Pontuação Máxima: " + str(pontuaçãoMáxima)),True,GRASS)
        textX = text.get_rect().width
        textY = text.get_rect().height
        screen.blit(text,((410 - (textX / 2)),(350 - (textY / 2))))
        text = arial18.render("Prima um botão para jogar",True,GRASS)
        textX = text.get_rect().width
        textY = text.get_rect().height
        screen.blit(text,((410 - (textX / 2)),(400 - (textY / 2))))
        text = arial30.render(str(Pontuação),True,WHITE)
        textX = text.get_rect().width
        textY = text.get_rect().height
        screen.blit(text,((410 - (textX / 2)),(50 - (textY / 2))))

    pygame.display.flip()

    clock.tick(60)

pygame.quit()
2
  • 1
    what is the problem and what is your question?
    – jsotola
    Commented Jun 11, 2019 at 17:35
  • I can't use an arcade kit (joystick and buttons) that I bought I believe the problem is in the code, however I can't anything in the Internet. Commented Jun 12, 2019 at 7:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.