Пример #1
0
def render(board):
    # for loop through the event queue
    for event in pygame.event.get():
        # Check for KEYDOWN event
        if event.type == KEYDOWN:
            # If the Esc key is pressed, then exit the main loop
            if event.key == K_ESCAPE:
                pygame.exit()
        # Check for QUIT event. If QUIT, then set running to false.
        elif event.type == QUIT:
            pygame.exit()

    y = 0
    for i in range(len(board)):
        x = 0
        for j in range(len(board[i])):
            #print("The current element is " + str(board[i][j]))
            if (board[i][j] == 1):
                pygame.draw.rect(screen, (0, 0, 255), (x, y, 60, 60), 0)
            elif (board[i][j] == 2):
                pygame.draw.rect(screen, (0, 255, 0), (x, y, 60, 60), 0)
            elif (board[i][j] == 3):
                pygame.draw.rect(screen, (255, 255, 0), (x, y, 60, 60), 0)
            else:
                pygame.draw.rect(screen, (255, 255, 255), (x, y, 60, 60), 0)
            x += 60
        y += 60

    for i in range(60, 821, 60):
        pygame.draw.line(screen, (250, 0, 0), (i, 0), (i, 840), 2)
        pygame.draw.line(screen, (250, 0, 0), (0, i), (840, i), 2)

    # Update the display
    pygame.display.flip()
Пример #2
0
def game_loop():
    x = (game_width * 0.45)
    y = (game_height * 0.8)

    x_change = 0

    gameExit = False

    while not gameExit:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.exit()
                quit()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    x_change = -5
                elif event.key == pygame.K_RIGHT:
                    x_change = 5
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                    x_change = 0

        x += x_change
        screen.fill(white_color)
        ball.position(screen, game_width, game_height, x, y)

        if x > display_width - ball_width or x < 0:
            gameExit = True

        pygame.display.update()
        clock.tick(60)
Пример #3
0
 def displaycell(self, x, y):
     for i in range(10):
         print self.worldmap[x][y].nowstate, self.worldmap[x][y].nextstate
         self.updateworld()
         self.evolution()
         time.sleep(0.3)
     pygame.exit()
Пример #4
0
 def MotionCtrl(self):
     #print self.yaw
     #self.twist.linear.x = 0
     for event in pygame.event.get():
         #if event.type == pygame.QUIT:
         #    pygame.exit() #if sys is imported
         if event.type == pygame.KEYDOWN:
             if event.key == pygame.K_UP:
                 self.twist.linear.x = self.twist.linear.x+0.1;
                 print("Hey, you pressed the key, UP!")
                 print self.twist.linear.x
             if event.key == pygame.K_DOWN:
                 print("Hey, you pressed the key, DOWN!")
                 self.twist.linear.x = self.twist.linear.x-0.1;
                 print self.twist.linear.x
             if event.key == pygame.K_LEFT:
                 print("Hey, you pressed the key, LEFT!")
                 self.twist.angular.z = self.twist.angular.z+0.4;
                 print self.twist.angular.z
             if event.key == pygame.K_RIGHT:
                 print("Hey, you pressed the key, RIGHT!")
                 self.twist.angular.z= self.twist.angular.z-0.4;
                 print self.twist.angular.z
             if event.key == pygame.K_SPACE:
                 self.twist.angular.z=0;
                 self.twist.linear.x=0;
                 print("Fully stop!!")
             if event.key == pygame.K_q:
                 print("Pygame exit!")
                 pygame.exit()
     self.cmd_vel_pub.publish(self.twist)
     print "Current angle is:"+'{0:+.4f}'.format(self.yaw)+'   '+"Current postion is:"+'{0:+.4f}'.format(self.odomx)+' '+'{0:+.4f}'.format(self.odomy)
Пример #5
0
    def run(self):
        self.seconds = 0.0
        self.clearScreen()
        self.delay = 10
        folderName = "random"
        fileIndex = 0

        # print "Hello:"
        while True: 
            self.input(pygame.event.get())
            i = self.curveSet.drawPoints()
            if (self.seconds >= 20000.0) | (i == -1):
                print "Seconds: ", self.seconds
                self.saveScreen(fileIndex, folderName)
                self.clearScreen()
                self.curveSet.selectCurves()
                self.seconds = 0.0
                fileIndex += 1

            pygame.time.wait(self.delay)
            self.seconds = self.seconds + 1.0
            pygame.display.flip()
         
        pygame.quit()   
        pygame.exit()
Пример #6
0
 def event_processor(self):
     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             pygame.exit()
             sys.exit()
         if event.type == pygame.KEYDOWN:
             if event.key == pygame.K_SPACE:
                 self.bird.flap()
def MENÚPREINCIPAL():  #SERÁ EL MENÚ DE OPCIONES
    while True:
        global click, font2
        screen.fill(black)
        texto("PROYECTO ARCADEMY", fuente, bg_color, screen, 20, 20)
        font2 = pygame.font.Font(None, 100)
        mx, my = pygame.mouse.get_pos()

        Boton1 = pygame.Rect(50, 100, 450, 80)
        Boton2 = pygame.Rect(50, 200, 450, 80)
        Boton3 = pygame.Rect(50, 300, 450, 80)
        Boton4 = pygame.Rect(50, 400, 450, 80)
        #        Boton4 = pygame.Rect(50,500,200,50)
        if Boton1.collidepoint((mx, my)):
            if click:
                PONG()
        if Boton2.collidepoint((mx, my)):
            if click:
                PONG_1vs1()
        if Boton3.collidepoint((mx, my)):
            if click:
                BATTLE()
        if Boton4.collidepoint((mx, my)):
            if click:
                BATTLEPARADOS()


#        if Boton5.collidepoint((mx, my)):
#            if click:
#                 snake()
        pygame.draw.rect(screen, black, Boton1)
        text_surface2 = font2.render("PONG", True, bg_color)
        screen.blit(text_surface2, (50, 100))
        pygame.draw.rect(screen, black, Boton2)
        text_surface3 = font2.render("PONG 1vs1", True, bg_color)
        screen.blit(text_surface3, (50, 200))
        pygame.draw.rect(screen, black, Boton3)
        text_surface4 = font2.render("BATTLE", True, bg_color)
        screen.blit(text_surface4, (50, 300))
        pygame.draw.rect(screen, black, Boton4)
        text_surface2 = font2.render("BATTLE 1vs1", True, bg_color)
        screen.blit(text_surface2, (50, 400))

        click = False
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.type == pygame.K_ESCAPE:
                    pygame.exit()
                    sys.exit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    click = True

        pygame.display.update()
        mainclock.tick(60)
Пример #8
0
    def __init__(self):
        self.board = [
        ["-","-","-"],
        ["-","-","-"],
        ["-","-","-"]
        ]

        self.X = 600
        self.Y = 740

        self.white = [255,255,255]
        self.black = [0, 0, 0]

        self.quitGame = False
        self.moveCounter = 0  #even = x, odd = o
        self.playing = True

        pygame.init()
        self.gameDisplay = pygame.display.set_mode((self.X,self.Y))
        self.gameDisplay.fill(self.white)
        self.drawGrid()
        pygame.display.set_caption("Tic-Tac-Toe")

        self.font = pygame.font.Font('Montserrat-Regular.ttf', 32)
        self.text = self.font.render('Tic Tac Toe', True, self.black, self.white)

        self.textRect = self.text.get_rect()
        self.textRect.center = (self.X // 2, 150 // 2)
        self.gameDisplay.blit(self.text, self.textRect)

        pygame.display.update()


        self.x_img = pygame.image.load("./images/x.png")
        self.o_img = pygame.image.load("./images/o.png")

        while not self.quitGame:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quitGame = True
                    pygame.exit()
                    exit()
                if self.playing:
                    if event.type == pygame.MOUSEBUTTONDOWN:
                        self.x, self.y = pygame.mouse.get_pos()
                        print("x", self.x, "y", self.y)
                        if self.moveCounter % 2 == 0: #even = x
                            # self.text = self.font.render('Player 1 Turn', True, self.black, self.white)
                            # self.gameDisplay.blit(self.text, self.textRect)
                            # pygame.display.update()

                            self.player1_move(self.x, self.y)
                        else:
                            # self.text = self.font.render('Player 2 Turn', True, self.black, self.white)
                            # self.gameDisplay.blit(self.text, self.textRect)
                            # pygame.display.update()

                            self.player2_move(self.x, self.y)
Пример #9
0
 def play(self):
     self.drawScene()
     while True:
         for event in pygame.event.get():
             if event.key == pygame.K_w:
                 print('w')
                 ##move forward by 1
                 pass
     if event.type == pygame.local.QUIT:
         pygame.exit()
         sys.exit()
Пример #10
0
def _quit():
    while True:
        s = messagebox.askyesno("Attention", "Are you sure you want to exit?")
        print(s)
        if s == True:
            messagebox.showinfo("Hey", "Hope you liked this game")
            print("exit")
            pygame.exit()
            sys.exit()
        else:
            main_menu()
Пример #11
0
def welcome():
    while True:
        gameScreen.blit(backGround, (0, 0))

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.exit()
                sys.quit()
            if event.type == pygame.KEYDOWN:
                if event.key == K_SPACE:
                    gameLoop()
        pygame.display.update()
        clock.tick(30)
Пример #12
0
def options():
    while True:
        # events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.exit()
                return

        # update

        # draw
        screen.fill(BACKGROUND)
        clock.tick(60)
        pygame.display.flip()
Пример #13
0
    def main(self):
        self.init_pygame()
        self.set_up_display()
        self.set_up_map()
        self.spawn_player()

        self.running = True

        try:
            self.run()
        except KeyboardInterrupt:
            self.running = False
            print('done')
            pygame.exit()
Пример #14
0
def show_gameOver():
    screen.blit(background, [0, 0])
    mostrarTxt(screen, "SHOOTER", 65, width / 2, height / 4)
    mostrarTxt(screen, "Instrucciones", 27, width / 2, height / 2)
    mostrarTxt(screen, "Presione una tecla", 20, width / 2, height * 3 / 4)
    pygame.display.flip()
    espera = True

    while espera:
        clock.tick(60)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.exit()
            if event.type == pygame.KEYUP:  #si alguna tecla se levanto es pq se presionó
                espera = False
Пример #15
0
def main():
    signal.signal(signal.SIGINT, sigintHandler)
    pygame.init()

    # Set the tile dimensions to this
    # Arbitrary default if there was no
    # param.
    if (sys.argv.__len__() < 2):
        N = 3
    else:
        N = int(sys.argv[1])
        
        Game(N)
        #Computer_Game(N)
    pygame.exit()
Пример #16
0
def showscreen():   
    BG()
    draw_text(screen, "asteroid invasion", 50, WIDTH / 2, HEIGHT / 4)
    draw_text(screen, "Arrow keys move, Space to fire", 22,WIDTH / 2, HEIGHT / 2)
    draw_text(screen,'highscore: '+str(highscore),18,WIDTH/2,400)
    draw_text(screen, "Press up arrow to start", 18, WIDTH / 2, HEIGHT * 3 / 4)
    pygame.display.flip()
    waiting = True
    while waiting:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
                pygame.exit()
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_UP:
                    waiting = False
Пример #17
0
def goToSleep(snakeList, lead_x, lead_y, score, snakeLength, gamePlay):
    # drawSnake(snakeList, lead_x, lead_y, score, snakeLength, gamePlay) # don't draw anything!
    gameDisplay.fill(background)
    displayMessage("Press 'Q' to exit to main menu or 'R' to resume the game",
                   white, (0, resolution[1] - 30))
    pygame.display.update()

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.exit()
                exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE or event.key == pygame.K_q:
                    return True
                if event.key == pygame.K_r:
                    return False
Пример #18
0
def options():
    running = True
    while running:
        screen.fill((0, 0, 0))

        draw_text('Options', med_font, (255, 255, 255), screen, 175, 20)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print('quit')
                pygame.exit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    running = False

        pygame.display.update()
        timer.tick(60)
Пример #19
0
    def run(self):
        """ Run the game loop"""
        clock = pygame.time.Clock()
        self.running = True

        try:
            while self.running:
                dt = clock.tick(FPS) / 1000.
                self.last_position_update += dt
                self.handle_input()
                self.update(dt)
                self.draw(screen)
                pygame.display.flip()

        except KeyboardInterrupt:
            self.running = False
            pygame.exit()
Пример #20
0
def main():
	pygame.init()
	global DISPLAYSURF
	

	FPSCLOCK = pygame.time.Clock()
	DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
	pygame.display.set_caption('Pong')
	
	while True: #el bucle del joc
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.exit()
				sys.exit()
	
	pygame.display.update()
	FPSCLOCK.tick(FPS)
Пример #21
0
 def start(self):
     DISPLAYSURF.fill(self.background)
     START_SURF, START_RECT = makeText('New Game', WHITE, GREEN, WINDOWWIDTH*0.3, WINDOWHEIGHT*0.7)
     EXIT_SURF, EXIT_RECT = makeText('Exit', WHITE, GREEN, WINDOWWIDTH*0.6, WINDOWHEIGHT*0.7)
     DISPLAYSURF.blit(START_SURF, START_RECT)
     DISPLAYSURF.blit(EXIT_SURF, EXIT_RECT)
     
     pygame.display.update()
     FPSCLOCK.tick(FPS)
     
     for event in pygame.event.get(): # event handling loop
         if event.type == MOUSEBUTTONUP:
             if START_RECT.collidepoint(event.pos):
                 self.room = 'world'
                 self.playable = True
             if EXIT_RECT.collidepoint(event.pos):
                 pygame.exit()
                 sys.quit()
Пример #22
0
    def menu(self):
        while True:

            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.exit()
                    exit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if self.button_area.collidepoint(event.pos):
                        self.start_game_click()

            if self.button_area.collidepoint(pygame.mouse.get_pos()):
                self.draw_button_over()
            else:
                self.draw_button_normal()

            self.screen.blit(self.BACKGROUND, (0, 0))
            pygame.display.update()
Пример #23
0
def getBoard(state):

    graphics(state)

    gettingInput = True
    while gettingInput:
        for e in pygame.event.get():
            if e.type == QUIT:
                pygame.exit()
                raise SystemExit()
            elif e.type == pygame.KEYDOWN:
                gettingInput = False
            elif e.type == pygame.MOUSEBUTTONUP:
                pos = pygame.mouse.get_pos()
                x = pos[0] // SCALE
                y = pos[1] // SCALE
                state[x, y] = 1
                graphics(np.transpose(state))

    return np.transpose(state)
Пример #24
0
def Title_Screen():
    x = 1
    Screen.blit(Background_image,(0,0))
    pygame.display.update() 
    while x != 0 :
        for event in pygame.event.get():       
            if event.type == QUIT:
                sys.exit()
                pygame.exit()
            if event.type == KEYDOWN:
                if event.key == K_RETURN:
                    x = 0
                    break
        Text_rect = pygame.Rect((100,800),(200,200))
        label = Font_type.render("Please press enter",52,(0,255,255))
        Screen.blit(label,Text_rect)
        pygame.display.update()
        Clock.tick(3)
        Screen.blit(Background_image,(0,0))
        pygame.display.update()
        Clock.tick(3)
Пример #25
0
def pltantmon(): #SE DEFINE EL MOVIMIENTO QUE VA A TENER LA PELOTA CUANDO SE ENCUENTRE CON UN RECTÁNGULO O CON UN BORDE DE LA VENTANA 
    #SE MUKTIPLICA POR -1 YA QUE ES EL QUE ALTERARÁ LA DIRECCIÓN DE LA PELOTA SIN AUNMENTARLA 
    global plt_speed_x, plt_speed_y, marcadorj1, marcadorj2ia, screen_width, screen_height
    plt.x += plt_speed_x 
    plt.y += plt_speed_y
    if plt.top <= 0 or plt.bottom >= screen_height:
        plt_speed_y *= -1
    if plt.left <= 0:
        marcadorj1 += 1
        plt_restart()
    if plt.right >= screen_width:
        marcadorj2ia += 1
        plt_restart()
    if plt.colliderect(player1) or plt.colliderect(player2): #CAMBIO DE DIRECCIÓN SI LA PELOTA CHOCA CON LOS RECTÁNGULOS DE LOS JUGADORES
        plt_speed_x *= -1
    if marcadorj1== 10:
        pygame.exit()
        sys.exit()
    if marcadorj2ia== 10:
        pygame.exit()
        sys.exit()
Пример #26
0
def welcomeScreen():
    bx = 0
    sounds['intro'].play(-1)
    while True:
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN
                                      and event.key == K_ESCAPE):
                pygame.exit()
                sys.exit()
            elif event.type == KEYDOWN and (event.key == K_SPACE
                                            or event.key == K_UP):
                return

        screen.blit(sprites['background'], (0, 0))
        screen.blit(sprites['player'], (0, 350))
        screen.blit(sprites['base'], (bx, 800))
        screen.blit(sprites['base'], (bx + 1700, 800))
        bx -= 1
        if bx <= -1700:
            bx = 0
        pygame.display.update()
        fpsclock.tick(fps)
Пример #27
0
def showscreen():
    BG()
    draw_text(screen, "asteroid invasion", 50, WIDTH / 2, HEIGHT / 4)
    draw_text(screen, "left and right arrow to move",
              20, WIDTH / 2, HEIGHT / 2 - 12.5)
    draw_text(screen, "press space to shoot", 20, WIDTH / 2, HEIGHT / 2-50)
    draw_text(screen, "if red bar turns green ", 20, WIDTH / 2, HEIGHT / 2+22)
    draw_text(screen, "press arrow up to use sonicshot",
              20, WIDTH / 2, HEIGHT / 2 + 44)
    draw_text(screen, 'highscore: '+str(highscore), 18, WIDTH/2, 400)
    draw_text(screen, "Press up arrow to start", 18, WIDTH / 2, HEIGHT * 3 / 4)
    pygame.display.flip()
    waiting = True
    while waiting:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
                pygame.exit()
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_UP:
                    waiting = False
Пример #28
0
def exitConfirmScreen():
    running = True
    clicked = False
    while running:
        DISPLAYSURFACE.fill((0,0,0))
        draw_text('Confirm Exit?', bigfont, (255,255,255), DISPLAYSURFACE, 500, 200)
        dx, dy = pygame.mouse.get_pos()

        #define and draw yes/no buttons
        yesButton = pygame.Rect(480, 300, 50, 50)
        noButton = pygame.Rect(680, 300, 50, 50)
        pygame.draw.rect(DISPLAYSURFACE, (255,255,255), yesButton)
        draw_text('Yes', font, (0,0,0), DISPLAYSURFACE, 490, 320)
        pygame.draw.rect(DISPLAYSURFACE, (255,255,255), noButton)
        draw_text('No', font, (0,0,0), DISPLAYSURFACE, 695, 320)

        if yesButton.collidepoint(dx,dy):
            if clicked:
                pygame.exit()
                sys.exit()
        elif noButton.collidepoint(dx,dy):
            if clicked:
                running = False

        clicked = False
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    clicked = True
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    running = False
        fpsClock.tick(FPS)
        pygame.display.update()
    return running
Пример #29
0
def deathScreen():
    darkenScreen()
    global target
    target = 'None'
    dead = True
    while dead:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.exit()
                exit()
            upgrade_screenWidth = int(constants.displaySize[0] * .6)
            upgrade_screenHeight = int(constants.displaySize[1] * .4)
            xpos = (constants.displaySize[0] - upgrade_screenWidth) / 2
            ypos = (constants.displaySize[1] - upgrade_screenHeight) / 2
            color = (211, 211, 211)
            upgrade_screen = pygame.draw.rect(
                mainDisplay, color,
                (xpos, ypos, upgrade_screenWidth, upgrade_screenHeight))
            textColor = (0, 0, 0)
            displayText(
                "You Died!", constants.menuButtonFont, 35,
                (constants.displaySize[0] - getTextDimension(
                    "width", "You Died!", constants.menuButtonFont, 35)) / 2,
                ypos + (constants.displaySize[1] * .05), (0, 0, 0),
                constants.displaySize[0] / 2 + 100)
            button("I'm Going Back", constants.menuButtonFont, 15, textColor,
                   xpos + (upgrade_screenWidth * .1),
                   ypos + (upgrade_screenHeight * .5),
                   constants.menuButtonWidth, constants.menuButtonHeight,
                   constants.menuButtonColorLight,
                   constants.menuButtonColorDark, continueLife)
            button(
                "Take Me Home", constants.menuButtonFont, 15, textColor,
                xpos + (upgrade_screenWidth / 2) + (upgrade_screenWidth * .1),
                ypos + (upgrade_screenHeight * .5), constants.menuButtonWidth,
                constants.menuButtonHeight, constants.menuButtonColorLight,
                constants.menuButtonColorDark, mainMenu)
            pygame.display.flip()
Пример #30
0
    def run(self):
        CurrentPlayer = 0
        self.MenuTimeOut = 5

        while True:
            self.input(pygame.event.get())
            timex = pygame.time.get_ticks()
            # changed from using get_ticks() to datetime.now(), seems more accurate
            #         while ((pygame.time.get_ticks() - timex) < (1000/SPEEDUP)):

            d = datetime.datetime.now().second
            while (datetime.datetime.now().second == d):
                self.input(pygame.event.get())

            start = datetime.datetime.now()
            # time out of onscreen menu if no key activity for 5 seconds
            if self.MenuTimeOut > 0:
                self.MenuTimeOut -= 1
#            print self.MenuTimeOut

            else:
                self.Player1.MenuDepth = 0
                self.Player1.Menu.clearMenu(self.screen, self.Player1.menu_key)
                self.Player2.MenuDepth = 0
                self.Player2.Menu.clearMenu(self.screen, self.Player2.menu_key)

            self.Player1.dec()
            self.Player2.dec()
            self.showTime()
            self.showAppWarning()

            # print end - start
            pygame.display.flip()
            end = datetime.datetime.now()

        pygame.exit()
Пример #31
0
def main():
	#ALustetaan pygame
	pygame.init()
	#taustakuvan nimi
	bg = "img/background.png"
	beat = pygame.mixer.Sound("sounds/GGJ13_Theme.wav")
	beat.set_volume(0.0)
	hello = pygame.mixer.Sound("sounds/hello.wav")
	beat.play(-1)
	#FPS:aa varten kello
	clock = pygame.time.Clock()
	#ikkuna
	screen = pygame.display.set_mode([860,640])
	#kaljakoppa
	beer_case = pygame.image.load("img/koppa.png").convert_alpha()
	beer_case = pygame.transform.scale(beer_case,[130,130])
	#Game over bg
	gameoverpic = pygame.image.load("img/game_over_screen.png").convert()
	gameoverpic = pygame.transform.scale(gameoverpic, [600,600])
	MAX_X = screen.get_width()
	MAX_Y = screen.get_height()
	CENTER = [(MAX_X/2),(MAX_Y/2)]
	posx = 400
	posy = 400
	
	#Muutama vari rgb:na
	vari1 = (200,178,87)
	vari2 = (100,13,13)
	
	
	#pelisilmukan paattymisehto
	done = False
	#gameover ruudun paattymisehto
	gameover = False
	#sanat joihin tallennetaan & verrataan
	sana = ""
	kirjain = ""
	sanalista = []
	
	#Pelaajan luonti
	player = Player(posx,posy)
	#Friendon luonti
	friendo = Friendo(55,posy)
	#Typykka
	typykka = Typy(150,posy-12)
	#Sytamet
	sydan1 = Hearts(180,20)
	sydan2 = Hearts(260,20)
	sydan3 = Hearts(340,20)
	sydan4 = Hearts(420,20)
	sydan5 = Hearts(500,20)
	#Tausta
	background = pygame.image.load(bg).convert()
	
	#Kayttajan syottama teksti objekti fontti jne
	fontti = pygame.font.Font("freesansbold.ttf",20)
	tulostus = fontti.render(sana,True,vari2)
	
	#ALoitusviesti / palauteviesti
	message = "Try to earn a beer by doing stuff"
	
	#Vinkki/ hint pelaajalle
	a_hint = "Try typing a command"
	
	#Ladataan voittoruutu animaatio
	win_images = glob.glob("img/fireworks*.png")
	win_images.sort()
	win_anim = pyganim.PygAnimation([(win_images[0],0.2),
									(win_images[1],0.2),
									(win_images[2],0.2),
									(win_images[3],0.2),
									(win_images[4],0.2)])
	
	#Helikopteri ;)
	heli = glob.glob("img/kopteri*.png")
	heli.sort()
	for i in range(len(heli)):
		kuva = pygame.image.load(heli[i]).convert_alpha()
		heli[i] = pygame.transform.scale(kuva,[100,100])
	helikopteri = pyganim.PygAnimation([(heli[0],0.1),
									(heli[1],0.1),
									(heli[2],0.1),
									(heli[3],0.1)])
	helikopteri.play()
	
	#animoidaan friendo ja typykka
	friendo.img.play()
	typykka.img.play()
	sydan1.img.play()
	sydan2.img.play()
	sydan3.img.play()
	sydan4.img.play()
	sydan5.img.play()
	
	
	#Aloitusruutu
	bg = pygame.image.load("img/main_screen.png").convert()
	bg = pygame.transform.scale(bg,[860,640])
	show = True
	while show == True:
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				sys.exit()
			if event.type == KEYDOWN:
				if event.key == K_RETURN:
					show = False
				elif event.key == K_ESCAPE:
					pygame.quit()
					sys.exit()
		screen.blit(bg,[0,0])
		pygame.display.update()
	
	
	#pelisilmukka 1 voitettu vai ei
	won1 = False
	
	#Pelisilmukka1
	#arvaukset ja vaarat arvaukset
	arvauksia = 10
	beer_x = 130
	beer_y = 240
	while done == False:
		
		#FPS = 60
		clock.tick(60)
		#katotaan eventit / 
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				sys.exit()
			if event.type == KEYDOWN:
				#shifti pois aiheuttamasta erroreita
				if event.key == K_RSHIFT or event.key == K_LSHIFT or event.key == K_UP  or event.key == K_DOWN or event.key == K_LEFT or event.key == K_RIGHT:
					continue
				if event.key == K_RETURN:
					sanalista = sana.split()
					sana = ""
					break
				#Muutetaan painallukset kirjain muotoon
				kirjain = str(chr(event.key))
				#lisataan painettu nappain sanaan
				sana += kirjain
				if event.key == K_BACKSPACE:
					sana = sana[0:-2] 
		screen.blit(background,[0,0])
		tulostus = fontti.render(">"+sana,True,vari2)
		screen.blit(tulostus,[0,605])
		
		#palaute viesti annetusta komennosta
		text1 = fontti.render(message,True,vari2,vari1)
		screen.blit(text1,[0,0])
		
		#hint, vinkki pelaajalle jos ei tajua mita pitaa teha
		hint = fontti.render(a_hint,True,vari2,vari1)
		screen.blit(hint,[0,150])
		
		#otetaan kirjoitetut komennot listaan, ja verrataan niita sanoihin
		command = etsisanat(sanalista)
		sanalista = []
		if command == "get_naked":
			beer_x += 10
			player.state = 2
			player.pisteet += 3
			if player.nekkid == False:
				player.nekkid = True
		elif command == "get_dressed":
			beer_x += 10
			player.pisteet += 1
			player.state = 1
		elif command == "move_left":
			player.x += -15
		elif command == "move_right":
			player.x += 15
		elif command == "suicide":
			player.state = 4
			done = True
			gameover = True
		elif command == "dance":
			beer_x += 10
			player.pisteet += 3
			player.state = 5
		elif command == "wiggle_wiggle":
			beer_x += 10
			player.pisteet += 2
			player.state = 6
		elif command == "get_first":
			message = "one does not simply drink beer without beer"
		elif command == "winwin":
			beer_x += 20
			player.pisteet += 5
			player.state = 7
		elif command == "sing":
			beer_x += 10
			player.state = 8
			player.pisteet += 2
		elif command == "dark_side":
			message = "Already tried, they didn't have cookies..."
		elif command == "unknown":
			arvauksia -= 1
			if arvauksia == 0:
				done = True
				gameover = True
			message = "Syntax Error, Key value error, division by zero!"
		elif command == "moonwalk":
			player.state = 9
			player.pisteet += 4
		elif command == "killed":
			friendo.img = pyganim.PygAnimation([(friendo.kuvat[1],0.2)])
			friendo.img.play()
		elif command == "heli":
			player.state = 11
		elif command == "beer":
			message = "Can't reach the beer, must use force"
		elif command == "force":
			beer_x += 2
			message = "Used THE FORCE, got a beer! happy now, so let's get naked"
			player.pisteet += 3
		elif command == "skip":
			done = True
			won1 = True
		elif command == "penus":
			message = "Behold The mighty Penus Torvalds!"
			player.pisteet += 3
		elif command == "smoke":
			message = "So you started smoking? huh?"
			player.pisteet += 3
			player.state = 14
		elif command == "happy_ending":
			message = "You had a \"healthy\" massage.."
		elif command == "jump":
			player.state = 12
		elif command == "fuck_you":
			player.state = 13
		elif command == "stop":
			player.state = 1
		
	
		#ja piirretaan sen ruudulle
		#mittarin piirto
		friendo.update(screen)
		player.update(screen)
		#helikopteri purkka
		if player.state == 11:
			helikopteri.blit(screen,[player.x+50,player.y+100])
		typykka.update(screen)
		sydan1.update(screen)
		if arvauksia > 2:
			sydan2.update(screen)
			a_hint = "Play with yourself... furiously!(and yes we are monitoring your webcam)"
		if arvauksia > 4:
			sydan3.update(screen)
			a_hint = "HINT: What would pewds do. you can start by gettin rid of your clothes."
		if arvauksia > 6:
			sydan4.update(screen)
			a_hint = "HINT: Dance monkey DANCE!"
		if arvauksia > 8:
			a_hint = "HINT: keep an open mind. makers of this game ar nasty ppl"
			sydan5.update(screen)
		screen.blit(beer_case,[beer_x,beer_y])
		pygame.display.update()
		
		#Katsotaan ollaanko voitettu eli pisteet >= 8
		if player.pisteet >= 8:
			won1 = True
			done = True
		
	
	#Tason 1 voittoruutu:
	if won1 == True:
		player.state = 1
		win_anim.play()
		bg = pygame.image.load("img/level1_won.png").convert()
		bg = pygame.transform.scale(bg,[860,640])
		#Naytetaan voittoruutu, kunnes painetaan nappainta
		loop_dis = True
		while loop_dis == True:
			for event in pygame.event.get():
				if event.type == QUIT:
					pygame.quit()
					sys.exit()
				elif event.type == KEYDOWN:
					loop_dis = False
					break
			screen.blit(bg,[0,0])
			win_anim.blit(screen,[350,350])
			pygame.display.update()
	
	#Taso 2
	movex = 0
	if gameover == True:
		done = True
	else:
		done = False
	taustat = pyganim.PygAnimation([("img/jate01.png",1.0), ("img/jate02.png",1.0)])
	taustat.play()
	bouncer = Bouncer(100, 400)
	effects = Effect_holder(400, 400)
	update_pic = False
	damage = 0
	instructions = "Use left and right arrow keys to move and go fight the bouncer"

	while done == False:
		clock.tick(60)
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				sys.exit()
			if event.type == KEYDOWN:
				if event.key == K_UP or event.key == K_DOWN:
					player.state = 10
					damage = 0.2
				if event.key == K_LEFT:
					movex = -5
				if event.key == K_RIGHT:
					movex = 5
			if event.type == KEYUP:
					movex = 0
					player.state = 1
					damage = 0
		player.x += movex			
		taustat.blit(screen,[0,0])
		#ja piirretaan sen ruudulle
		bouncer.health -= damage
		player.update(screen)
		random_int = random.randint(0,100)
		if random_int < 5:
			update_pic = True
		if player.state == 10:
			effects.update(screen, update_pic)
		if bouncer.health <= 0:
			done = True
		update_pic = False
		text2 = fontti.render(instructions,True,vari1,vari2)
		text1 = fontti.render("The evil bouncer isn't lettin ya in. BEAT HIM UP! (up and down arrows)",True,vari2,vari1)
		screen.blit(text1,[50,600])
		screen.blit(text2,[50,620])
		bouncer.update(screen)
		player.update(screen)
		pygame.display.update()
	if won1 == True:
		bouncer. x -= 50
		bouncer.y -= 140
		player.state = 1
		win_anim.play()
		bg = pygame.image.load("img/level_2_won.png").convert()
		bg = pygame.transform.scale(bg,[860,640])
		#Naytetaan voittoruutu, kunnes painetaan nappainta
		loop_dis = True
		while loop_dis == True:
			for event in pygame.event.get():
				if event.type == QUIT:
					pygame.quit()
					sys.exit()
				elif event.type == KEYDOWN:
					loop_dis = False
					break
			screen.blit(bg,[0,0])
			win_anim.blit(screen,[350,350])
			bouncer.update(screen)
			pygame.display.update()


	    #pelisilmukan paattymisehto
	done = False
    #sanat joihin tallennetaan & verrataan

	#Taso 3 info
	bg = "img/info_pelille.png"
	tausta = pygame.image.load(bg)
	tausta = pygame.transform.scale(tausta,[860,640])
	time_now = pygame.time.get_ticks()
	end_time = time_now + 5000
	loop = True
	while loop == True and gameover == False:
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				sys.exi()
		screen.blit(tausta,[0,0])
		pygame.display.update()
		if pygame.time.get_ticks() > end_time:
			loop = False

    #Taso 3
	#lista kaikista spriteista
	all_sprites = pygame.sprite.Group()

	#lista kaikista pulloista
	pullot = pygame.sprite.Group()

	#mailan luonti
	paddle = Paddle(vari1)
	paddle.rect.y = MAX_Y - paddle.image.get_height()
	all_sprites.add(paddle)
    #Pelaajan luonti
	player = Player(posx,posy)
	tausta = Valot(0,0)
	polizei = Polizei(610,450)
	muumi = Moomin(90, 450)
	v_pisteet = 0
	o_pisteet = 0
	paddle_lista = pygame.sprite.Group()
	paddle_lista.add(paddle)

	for i in range(100):
		if i % 2 == 0:
			polku = "img/beer_green.png"
		else:
			polku = "img/beer_orange.png"
		bottle = Bottle(vari2,polku)
		bottle.rect.x = random.randint(10,MAX_X-10)
		bottle.rect.y = random.randint(-4000,-100)
		all_sprites.add(bottle)
		pullot.add(bottle)

	#animoidaan friendo
	#Pelisilmukka
	if gameover == True:
		player.state = 4
		player.img = player.kuvat[3]
	change = 0
	time_now = pygame.time.get_ticks()
	end_time = time_now+25000
	player.state = 5
	tulostus = fontti.render("Collect more green bottles to score the babe!",True,(200,70,70))
	paddle.rect.x = MAX_X/2 - paddle.image.get_width()
	while done == False and gameover == False:
	    #FPS = 60
	    clock.tick(60)
	    #katotaan eventit / 
	    for event in pygame.event.get():
	        if event.type == QUIT:
	            pygame.quit()
	            sys.exit()
	        if event.type == KEYDOWN:
	        	if event.key == K_LEFT:
	        		change = -5
	        	if event.key == K_RIGHT:
	        		change = 5
	        if event.type == KEYUP:
	        	change = 0
	    paddle.rect.x += change
	    #katotaan ettei pelaaja mee luos ruudulta
	    if paddle.rect.x <0:
	    	paddle.rect.x = 0
	    if paddle.rect.x > MAX_X-paddle.image.get_width():
	    	paddle.rect.x = MAX_X-paddle.image.get_width()
	    #liikutetaan pulloja alaspain ruudulla
	    for pullo in pullot:
	    	x_change = random.randint(-2,2)
	    	y_change = random.randint(1,6)
	    	pullo.rect.x += x_change
	    	pullo.rect.y += y_change

	    poistettavat = pygame.sprite.spritecollide(paddle,pullot,True)
	    for i in poistettavat:
	    	if i.vari == "green":
	    		v_pisteet += 1
	    	else:
	    		o_pisteet += 1

	    #valojen vilkkumisen randomisuus
	    random_int = random.randint(0,100)
	    if random_int < 10:
	        update_pic = True
	    tausta.update(screen, update_pic)
	    update_pic = False
	    #ja piirretaan sen ruudulle
	    #player.update(screen)
	    polizei.update(screen)
	    muumi.update(screen)
	    all_sprites.draw(screen)
	    screen.blit(tulostus,[100,100])
	    pygame.display.update()
	    if pygame.time.get_ticks() > end_time:
	    	done = True
	time_now = pygame.time.get_ticks()
	end_time = time_now + 6000
	went_home = True
	end_time2 = end_time + 6000
	done_once = False
	while went_home == True and gameover == False:
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.exit()
				sys.exit()
		screen.fill((200,200,199))
		beat.set_volume(1.0)
		tulostus = fontti.render("And you went home with",True,vari1)
		screen.blit(tulostus,[300,100])
		if pygame.time.get_ticks() > end_time:
			beat.stop()
			if done_once == False:
				hello.play()
				done_once = True
			polizei.x = 220
			polizei.y = 400
			polizei.update(screen)
		if pygame.time.get_ticks() > end_time2:
			went_home = False
		pygame.display.update()

	#Game over screen
	if gameover == True:
		loop_this = True
		while loop_this == True:
			for event in pygame.event.get():
				if event.type == QUIT:
					loop_this = False
				if event.type == KEYDOWN:
					loop_this = False
			screen.blit(gameoverpic,[0,0])
			screen.blit(player.img,[player.x,player.y])
			pygame.display.update()
	pygame.quit()
import pygame.event

#initialisation de pygame
pygame.init()

#déterminer la mesure de la fenêtre
fenetreLargeur = 800
fenetreHauteur = 600

#créer la fenêtre
fenetre = pygame.display.set_mode((fenetreLargeur, fenetreHauteur))
# donner un titre à la fenêtre
pygame.display.set_caption("Faire bouger des formes !")

while True:
    #tout effacer en remplissant l'écran de noir
    fenetre.fill((0, 0, 0))
    #dessiner un rectangle avec des coordonnées aléatoire
    pygame.draw.rect(fenetre, (255, 0, 0), (random.randint(
        0, fenetreLargeur), random.randint(0, fenetreHauteur), 20, 20))

    #vérifier la file des événements
    for event in pygame.event.get():
        if event.type == QUIT:
            # si la fenêtre a été fermée, arrêté pygame et terminer le programme
            pygame.exit()
            sys.exit()

    #afficher l'écran
    pygame.display.update()
Пример #33
0
def main():
    while stop == 1:
    	pygame.event.pump()
    	for event in pygame.event.get():
        	if event.type == pygame.QUIT:
            		crashed = True

        ############################
        	if event.type == pygame.KEYDOWN:
            		if event.key == pygame.K_LEFT:
                		print "Left!"
				go_left()
	    		elif event.key == pygame.K_RIGHT:
                		print "Right!"
				go_right()
	    		elif event.key == pygame.K_UP:
				print "Forward!"
				go_forward()
	    		elif event.key == pygame.K_DOWN:
				print "Back!"
				go_backward()
	    		elif event.key == pygame.K_SPACE:
				print "Stop!"
				do_stop()
	    		elif event.key == pygame.K_ESCAPE:
				print "Exit!"
				pygame.quit()
				quit()
        	elif event.type == pygame.KEYUP:
            		if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT or event.key == pygame.K_UP or event.key == pygame.K_DOWN or event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE:
                		print "Key released!"
        ######################
    ##
    
   ##         
    
    #clock.tick(60)
    # put code continuously run here
   # ch = window.getch()
   # print ("getkey: " + str(ch) + "\n")
   # if ch == curses.KEY_UP:
    #    print("FORWARD!\n")
#	go_forward()
    #if ch == curses.KEY_DOWN:
     #   print("BACK!\n")
#	go_backward()
#    if ch == curses.KEY_LEFT:
#        print("LEFT!\n")
#	go_left()
#    if ch == curses.KEY_RIGHT:
#        print("RIGHT!\n")
#	go_right()
#    if ch == 32:
#        print("STOP!\n")
#	do_stop()
#    if ch == 48:
#        stop == ch
#        print("Exiting.. " + str(ch))
#        curses.nocbreak()
#        window.keypad(0)
#        curses.echo()
#        curses.endwin()
#        sys.exit(99)
        # else :
        # print(ch)


#print(str(ch))
    pygame.exit()
    exit()
Пример #34
0
def Character_select_screen():
    x = 1
    a = 0
    Screen.blit(Space,(0,0))
    F1 = pygame.Rect((100,650),(300,300))
    F2 = pygame.Rect((500,650),(300,300))
    F3 = pygame.Rect((900,650),(300,300))
    Name = pygame.Rect((1000,100),(1000,50))
    CurrentChar = pygame.Rect((500,200),(250,300))
    pygame.draw.rect(Screen,(0,0,0),CurrentChar,0)
    pygame.draw.rect(Screen,(0,0,0),Name,0)
    Screen.blit(Fighters[0],F1)
    Screen.blit(Fighters[1],F2)
    Screen.blit(Fighters[2],F3)
    pygame.display.update()
    while x != 0:
        for event in pygame.event.get():       
            if event.type == QUIT:
                pygame.exit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_RETURN:
                    x = 0
                    Player_1 = a
                    break
                if event.key == K_RIGHT:
                    a += 1
                    if a > 2:
                        a = 0
                    label = Font_type.render(str(Fighter_names[a]),52,(0,255,255))
                    pygame.draw.rect(Screen,(0,0,0),Name,0)
                    Screen.blit(label,Name)
                    pygame.draw.rect(Screen,(0,0,0),CurrentChar,0)
                    Screen.blit(Fighters[a],CurrentChar)
                    pygame.display.update()
                if event.key == K_LEFT:
                    a -= 1
                    if a < 0:
                        a = 2
                    label = Font_type.render(str(Fighter_names[a]),52,(0,255,255))
                    pygame.draw.rect(Screen,(0,0,0),Name,0)
                    Screen.blit(label,Name)
                    pygame.draw.rect(Screen,(0,0,0),CurrentChar,0)
                    Screen.blit(Fighters[a],CurrentChar)
                    pygame.display.update()
    x = 1
    while x != 0:
        for event in pygame.event.get():       
            if event.type == QUIT:
                pygame.exit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_RETURN:
                    x = 0
                    Player_2 = a
                    break
                if event.key == K_RIGHT:
                    a += 1
                    if a > 2:
                        a = 0
                    label = Font_type.render(str(Fighter_names[a]),52,(0,255,255))
                    pygame.draw.rect(Screen,(0,0,0),Name,0)
                    Screen.blit(label,Name)
                    pygame.draw.rect(Screen,(0,0,0),CurrentChar,0)
                    Screen.blit(Fighters[a],CurrentChar)
                    pygame.display.update()
                if event.key == K_LEFT:
                    a -= 1
                    if a < 0:
                        a = 2
                    label = Font_type.render(str(Fighter_names[a]),52,(0,255,255))
                    pygame.draw.rect(Screen,(0,0,0),Name,0)
                    Screen.blit(label,Name)
                    pygame.draw.rect(Screen,(0,0,0),CurrentChar,0)
                    Screen.blit(Fighters[a],CurrentChar)
                    pygame.display.update()
    return Player_1,Player_2
Пример #35
0
def Combo_seq_screen(b,c):
    combo_P1 = 0
    combo_P2 = 0
    Screen.blit(Water,(0,0))
    Area = pygame.Rect((100,100),(600,600))
    Char = pygame.Rect((800,500),(300,300))
    Combo = pygame.Rect((800,900),(50,50))
    Timer = pygame.Rect((800,100),(150,75))
    Player = pygame.Rect((1000,100),(200,200))
    Screen.blit(Fighters[b],Char)
    pygame.draw.rect(Screen,(255,255,255),Combo)
    x = 0 #garbage value
    index = 0
    timer = pygame.time.Clock()
    fps = 1.5 #modified later
    player = []
    Comp = []
    a = 13.0
    #for event in pygame.event.get():
    while a >= 0: 
        while x <= 3:
            random.seed()
            index = random.randint(0,3)
            pygame.draw.rect(Screen,(255,255,255),Area)
            Screen.blit(Arrows[index],(random.randint(100,600),random.randint(100,600)))
            pygame.display.update()
            Comp.append(index)
            x += 1
            timer.tick(fps)
        x = 0 #reset garbage variable
        pygame.draw.rect(Screen,(255,255,0),Area)
        pygame.display.update(Area)
        pygame.time.delay(1000)
        pygame.draw.rect(Screen,(255,255,255),Area)
        pygame.display.update(Area)
        while (x <= 3):
            if a <= 0:
                break
            label = Font_type.render(str(int(a)),15,(255,0,0))
            pygame.draw.rect(Screen,(255,255,255),Timer)
            Screen.blit(label, Timer)
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.exit()
                    sys.exit()
                if event.type == KEYDOWN:
                    if event.key == K_RIGHT:
                        x += 1
                        player.append(2)
                    elif event.key == K_UP:
                        x += 1
                        player.append(0)
                    elif event.key == K_LEFT:
                        x += 1
                        player.append(3)
                    elif event.key == K_DOWN:
                        x += 1
                        player.append(1)
            a -= .001
            timer.tick(1000)
        x = 0
        if Comp == player:
            combo_P1 += 1
            pygame.draw.rect(Screen,(255,255,255),Combo)
            label = Font_type.render(str(combo_P1),15,(255,0,0))
            Screen.blit(label,Combo)
            pygame.display.update()
        else:
            pygame.display.update()
        Comp = []
        player = []
        a -= .001
        timer.tick(1000)
    pygame.event.clear()
    Screen.blit(Water,(0,0))
    pygame.display.update()
    pygame.time.delay(5000) # delay b4 P2 start
    Area = pygame.Rect((100,100),(600,600))
    Char = pygame.Rect((800,500),(300,300))
    Combo = pygame.Rect((800,900),(50,50))
    Timer = pygame.Rect((800,100),(150,75))
    Player = pygame.Rect((1000,100),(200,200))
    pygame.draw.rect(Screen,(255,255,255),Area)
    pygame.draw.rect(Screen,(255,255,255),Timer)
    Screen.blit(Fighters[c],Char)
    pygame.draw.rect(Screen,(255,255,255),Combo)
    pygame.display.update()
    pygame.time.delay(5000) #delay before P2 start game
    x = 0 #garbage value
    index = 0
    timer = pygame.time.Clock()
    fps = 2.1 #modified later
    player = []
    Comp = []
    a = 23.0
    #for event in pygame.event.get():
    while a >= 0: 
        while x <= 3:
            random.seed()
            index = random.randint(0,3)
            pygame.draw.rect(Screen,(255,255,255),Area)
            Screen.blit(Arrows[index],(random.randint(100,600),random.randint(100,600)))
            pygame.display.update()
            Comp.append(index)
            x += 1
            label = Font_type.render(str(int(a)),15,(255,0,0))
            a -= 1
            timer.tick(fps)
        x = 0 #reset garbage variable
        while (x <= 3):
            if a <= 0:
                break
            label = Font_type.render(str(int(a)),15,(255,0,0))
            pygame.draw.rect(Screen,(255,255,255),Timer)
            Screen.blit(label, Timer)
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == QUIT:
                    sys.exit()
                    pygame.exit()
                if event.type == KEYDOWN:
                    if event.key == K_RIGHT:
                        x += 1
                        player.append(2)
                    elif event.key == K_UP:
                        x += 1
                        player.append(0)
                    elif event.key == K_LEFT:
                        x += 1
                        player.append(3)
                    elif event.key == K_DOWN:
                        x += 1
                        player.append(1)
            a -= .001
            timer.tick(1000)
        x = 0
        if Comp == player:
            combo_P2 += 1
            pygame.draw.rect(Screen,(255,255,255),Combo)
            label = Font_type.render(str(combo_P2),15,(255,0,0))
            Screen.blit(label,Combo)
            pygame.display.update()
        else:
            pygame.display.update()
        a -= .001
        Comp = []
        player = []
        timer.tick(1000)
    return combo_P1,combo_P2
Пример #36
0
def start():
    clearLCD()
    printLCD('Loading...', 0, 0)
    os.system('clear')
    print('Loading...')
    red.on()
    pygame.init()
    screen = pygame.display.set_mode((475, 475), 0, 32)
    screen.fill(black)
    poke_ball = '/home/pi/pokedex/images/Logo.png'
    pokemon_ball = pygame.image.load(poke_ball).convert_alpha()
    screen.blit(pokemon_ball, (0, 0))
    orange.off()
    green.off()
    blue.off()
    screen.fill(black)
    poke_ball = '/home/pi/pokedex/images/Logo.png'
    pokemon_ball = pygame.image.load(poke_ball).convert_alpha()
    screen.blit(pokemon_ball, (0, 0))
    time.sleep(1)
    pygame.display.update()
    imageLCD('pokeball')
    os.system('clear')
    print('Press the scan (blue) button to scan')
    print('Press the reset (red) button to exit')
    while True:
        if button1.is_pressed:
            os.system('clear')
            red.off()
            orange.off()
            blue.off()
            green.on()
            while True:
                pp1 = digit()
                if pp1 == 1:
                    break
                elif pp1 == 2:
                    os.system('clear')
                    clearLCD()
                    pygame.exit()
                    sys.exit()
                elif pp1 == 0:
                    cameratest()
                else:
                    start()
            screen.fill(black)
            bars1 = '/home/pi/pokedex/images/bars.png'
            bars = pygame.image.load(bars1).convert_alpha()
            screen.blit(bars, (0, 0))
            pygame.display.update()
            clearLCD()
            printLCD('Enter a number:', 0, 0)
            print('Enter a Pokemon number: ')
            pp1 = digit()
            pdisplay = str(pp1)
            printLCD(pdisplay, 0, 0)
            print pp1
            time.sleep(wait)
            pp2 = digit()
            ppdisplay = str(pp2)
            pdisplay1 = pdisplay + ppdisplay
            printLCD(pdisplay1, 0, 0)
            print pp2
            time.sleep(wait)
            pp3 = digit()
            ppdisplay = str(pp3)
            pdisplay = pdisplay1 + ppdisplay
            printLCD(pdisplay, 0, 0)
            print pp3
            p1 = str(pp1)
            p2 = str(pp2)
            p3 = str(pp3)
            pokemon2 = p1 + p2 + p3
            check = int(pokemon2)
            if check >= 252:
                blue.off()
                green.off()
                orange.off()
                red.off()
                error2 = '/home/pi/pokedex/images/error.png'
                error = pygame.image.load(error2).convert_alpha()
                screen.fill(black)
                screen.blit(error, (0, 0))
                pygame.display.update()
                pokeerror = 0
                while pokeerror == 0:
                    clearLCD()
                    printLCD('ERROR!!!', 0, 0)
                    os.system('clear')
                    print("THAT'S NOT A POKEMON!!!")
                    print('Press the reset (red) button to go back')
                    if button1.is_pressed:
                        start()
                    red.on()
                    time.sleep(0.25)
                    red.off()
            pokemon1 = '/home/pi/pokedex/images/' + pokemon2 + '.png'
            imageLCD(pokemon2)
            os.system('clear')
            print 'Now Showing Pokemon: ', pokemon2
            print('Press the reset (red) button to go back')
            pokemon = pygame.image.load(pokemon1).convert_alpha()
            break
        if button2.is_pressed:
            os.system('clear')
            clearLCD()
            pygame.quit()
            sys.exit()

    while True:
        red.off()
        orange.off()
        blue.off()
        green.on()
        if button1.is_pressed:
            start()
        screen.fill(black)
        screen.blit(pokemon, (0, 0))
        pygame.display.update()
Пример #37
0
  def pollingInput(self, events):


          for event in events:
              #print "got into pollingInput" 
        
              if (self.printEvent == True):
                print event
         
              #should kill here instead of send message...quick fix..zZ
              if(event.type == pygame.QUIT):
                message = 'quit'
                event = ''
                return message , event

              elif(event.type == pygame.KEYDOWN):


                          if(event.key == K_ESCAPE):
                            pygame.exit(); sys.exit()

                          elif(event.key == K_r):
                            try:
                              reload(gui)
                              print "Success! reloaded particles!"
                              message = "reload"
                              event = ''
                              return message , event
                              
                            except Exception,e:
                              print str(e)
                              print "Unable to reload Particles" 

                          elif(event.key == K_e):
                            message = 'erase'
                            event = ''
                            return message , event


                          elif(event.key == K_p):
                            if self.printEvent == True:
                              self.printEvent = False
                            else:
                              self.printEvent = True

                          elif(event.key == K_s):
                            message = 'shutdown'
                            event = ''
                            return message , event

                          elif(event.key == K_z):

                            message = 'sample'
                            event = ''
                            return message , event

                          elif(event.key == K_x):
                            message = 'stop_sample'
                            event = ''
                            return message , event

                          elif(event.key == K_PERIOD):
                            message = 'turn_on_logging'
                            event = ''
                            return message, event

                          elif(event.key == K_SLASH):
                            message = 'turn_off_logging'
                            event = ''
                            return message, event

              elif(event.type == pygame.KEYUP):
                pass
Пример #38
0
  client = True
  #Main Program Loop
  while(client):

              
        events = pygame.event.get()
        if events:

          #returns a signal and event for triggered events 
          signal, event = EventControl.pollingInput(events)
        
        if signal:
              if( signal == 'quit'):
                s.close()
                pygame.exit()
                sys.close()

              elif( signal == 'reload'):
                  
                    from gui import *
                    screen = DropDisplay()        
                

              elif signal == 'erase':
                screen.erase_screen()

                #TODO: fix hard coding...error hiding is the devil
                try:
                  os.remove('/home/blackpanther/Desktop/sdlHacking/working/log/client.log')
                except:
Пример #39
0
    def __init__(self):

	try: 
	        img   = pygame.image.load(pfad)
	except IOError:
		print "Sorry couldn't load Image " + pfad
		pygame.exit();

        sheet = img.subsurface(264, 0, 376, 256)

        # Kleine Mauern 32 x 16 -> scaled 64 x 32

        self.mauer01 = sheet.subsurface(  0,  0, 32, 16)
        self.mauer01 = pygame.transform.scale2x(self.mauer01)
        
        self.mauer02 = sheet.subsurface( 32,  0, 32, 16)
        self.mauer02 = pygame.transform.scale2x(self.mauer02)

        self.mauer03 = sheet.subsurface( 64,  0, 32, 16)
        self.mauer03 = pygame.transform.scale2x(self.mauer03)
        
        self.mauer04 = sheet.subsurface( 96,  0, 32, 16)
        self.mauer05 = sheet.subsurface(128,  0, 32, 16)

        self.mauer06 = sheet.subsurface(  0, 16, 32, 16)
        self.mauer07 = sheet.subsurface( 32, 16, 32, 16)
        self.mauer08 = sheet.subsurface( 64, 16, 32, 16)
        self.mauer09 = sheet.subsurface( 96, 16, 32, 16)

        self.mauer10 = sheet.subsurface(  0, 32, 32, 16)
        self.mauer11 = sheet.subsurface( 32, 32, 32, 16)
        self.mauer12 = sheet.subsurface( 64, 32, 32, 16)
        self.mauer13 = sheet.subsurface( 96, 32, 32, 16)

        # Grosse Bloecke 32x32

        self.mauer14 = sheet.subsurface(  0,  48, 32, 32)
        self.mauer14 = pygame.transform.scale2x(self.mauer14)
        
        self.mauer15 = sheet.subsurface( 32,  48, 32, 32)
        self.mauer16 = sheet.subsurface( 64,  48, 32, 32)
        self.mauer17 = sheet.subsurface( 96,  48, 32, 32)
        # Luecke
        self.mauer18 = sheet.subsurface(196,  48, 32, 32)

        # Grosse Bloecke 32 x 32
        self.mauer19 = sheet.subsurface(  0,  80, 32, 32)
        self.mauer20 = sheet.subsurface( 32,  80, 32, 32)
        self.mauer21 = sheet.subsurface( 64,  80, 32, 32)
        self.mauer22 = sheet.subsurface( 96,  80, 32, 32)
        self.mauer23 = sheet.subsurface(128,  80, 32, 32)
        self.mauer24 = sheet.subsurface(160,  80, 32, 32)
        self.mauer25 = sheet.subsurface(196,  80, 32, 32)

        self.mauer26 = sheet.subsurface(  0, 112, 32, 32)
        self.mauer27 = sheet.subsurface( 32, 112, 32, 32)
        self.mauer28 = sheet.subsurface( 64, 112, 32, 32)
        self.mauer29 = sheet.subsurface( 96, 112, 32, 32)
        self.mauer30 = sheet.subsurface(128, 112, 32, 32)

        # wieder halbe bloecke rechteck 32 x 16

        self.mauer31 = sheet.subsurface(  0, 144, 32, 16)
        self.mauer32 = sheet.subsurface( 32, 144, 32, 16)
        self.mauer33 = sheet.subsurface( 64, 144, 32, 16)
        self.mauer34 = sheet.subsurface( 96, 144, 32, 16)
        self.mauer35 = sheet.subsurface(128, 144, 32, 16)

        # viertel bloecke quadratisch 16 x 16
        self.mauer36 = sheet.subsurface(  0, 160, 16, 16)
        self.mauer37 = sheet.subsurface( 16, 160, 16, 16)
        self.mauer38 = sheet.subsurface( 32, 160, 16, 16)
        self.mauer39 = sheet.subsurface( 48, 160, 16, 16)
        self.mauer40 = sheet.subsurface( 64, 160, 16, 16)
        self.mauer41 = sheet.subsurface( 80, 160, 16, 16)

        # viertel bloecke rechteckig 16 x 8

        self.mauer42 = sheet.subsurface(  0, 176, 16,  8)
        self.mauer43 = sheet.subsurface( 16, 176, 16,  8)
        self.mauer44 = sheet.subsurface( 32, 176, 16,  8)
        self.mauer45 = sheet.subsurface( 48, 176, 16,  8)
        self.mauer46 = sheet.subsurface( 64, 176, 16,  8)
        self.mauer47 = sheet.subsurface( 80, 176, 16,  8)

        # achtel bloecke quadratisch 8 x 8
        self.mauer48 = sheet.subsurface(  0, 184,  8,  8)
        self.mauer49 = sheet.subsurface(  8, 184,  8,  8)
        self.mauer50 = sheet.subsurface( 16, 184,  8,  8)
        self.mauer51 = sheet.subsurface( 24, 184,  8,  8)
        self.mauer52 = sheet.subsurface( 32, 184,  8,  8)
        self.mauer53 = sheet.subsurface( 48, 184,  8,  8)


        # Pillars / Saeulen

        self.pillar01 = sheet.subsurface(  0, 192, 16, 64)
        self.pillar01 = pygame.transform.scale2x(self.pillar01)
        
        self.pillar02 = sheet.subsurface( 16, 192, 16, 64)
        self.pillar02 = pygame.transform.scale2x(self.pillar02)
        
        self.pillar03 = sheet.subsurface( 32, 192, 16, 64)
        self.pillar03 = pygame.transform.scale2x(self.pillar03)

        self.pillar04 = sheet.subsurface( 48, 220, 16, 36)
        self.pillar04 = pygame.transform.scale2x(self.pillar04)

        self.pillar05 = sheet.subsurface( 64, 238, 16, 18)
        self.pillar05 = pygame.transform.scale2x(self.pillar05)

        self.pillar06 = sheet.subsurface( 80, 240, 32, 16)
        self.pillar06 = pygame.transform.scale2x(self.pillar06)
Пример #40
0
def replay():
    # Loop variables
    game_over = False
    game_close = False
    snake_len = 1
    speed_cont = 10
    snake_list = list()
    speed_x = speed_y = 0
    pos_x = on_grid_random()
    pos_y = on_grid_random()
    pos_x_apple = on_grid_random()
    pos_y_apple = on_grid_random()

    while not game_over:
        while game_close:

            # Final score
            screen.fill(black)
            message(f"{len(snake_list)} points! P - Play again / E - Exit", red)
            pygame.display.update()

            # Checking permanence
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_e:
                        game_over = True
                        game_close = False
                    elif event.key == pygame.K_p:
                        replay()

        # Detecting events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_over = True
            if event.type == pygame.KEYDOWN:
                # Commands
                if event.key == pygame.K_UP and speed_y != 10:
                    speed_x = 0
                    speed_y = -10
                elif event.key == pygame.K_DOWN and speed_y != -10:
                    speed_x = 0
                    speed_y = 10
                elif event.key == pygame.K_LEFT and speed_x != 10:
                    speed_x = -10
                    speed_y = 0
                elif event.key == pygame.K_RIGHT and speed_x != -10:
                    speed_x = 10
                    speed_y = 0

        # Borders
        if pos_x + 10 > width:
            pos_x = 0
        if pos_x < 0:
            pos_x = width - 10
        if pos_y + 10 > height:
            pos_y = 0
        if pos_y < 0:
            pos_y = height - 10

        # URM
        pos_x += speed_x
        pos_y += speed_y
        screen.fill(black)

        # Apple spawner
        apple = pygame.draw.rect(screen, red, [pos_x_apple, pos_y_apple, 10, 10])

        # Snake builder
        snake_head = [pos_x, pos_y]
        snake_list.append(snake_head)

        # Snake existence conditions
        if len(snake_list) > snake_len:
            del snake_list[0]
        for snake_tail in snake_list[:-1]:
            if snake_tail == snake_head:
                game_close = True

        # Functional
        snake_builder(snake_list)
        score(snake_len - 1)
        pygame.display.update()

        # Snake body and velocity increase
        if snake_builder(snake_list, True).colliderect(apple):
            snake_len += 1
            collision = True
            while collision:
                pos_x_apple = on_grid_random()
                pos_y_apple = on_grid_random()
                collision = False
                for xy in snake_list:
                    part = pygame.Rect(xy[0], xy[1], 17, 17)
                    if part.collidepoint(pos_x_apple, pos_y_apple):
                        collision = True
                        break
            speed_cont += snake_len * 0.01
        clock.tick(speed_cont)

    # Exit
    pygame.quit()
Пример #41
0
    def main(self):
        xspeed_init = 3  #x방향 공스피드
        yspeed_init = 3  #y방향 공 스피드
        max_lives = 5  #최대 생명력=5
        paddle_speed = 30  #막대기 스피드
        score = 0  #점수
        black = (0, 0, 0)  # 배경색
        GREEN = (0, 255, 0)  #점수 색깔
        WHITE = (255, 255, 255)
        width = 640  #게임판 옆길이
        height = 480  #게임판 높이
        size = width, height  #게임판 크기

        pygame.init()  #필수
        screen = pygame.display.set_mode(size)  #게임판 만들기
        #screen = pygame.display.set_mode(size, pygame.FULLSCREEN)

        gamestart = pygame.image.load("GAMESTART.png").convert()
        gamestartrect = gamestart.get_rect()

        paddle = pygame.image.load("stick.png").convert()
        paddlerect = paddle.get_rect()  #막대기 만들기

        ball = pygame.image.load("ball.png").convert()
        ball.set_colorkey((255, 255, 255))
        ballrect = ball.get_rect()  #공 만들기

        pong = pygame.mixer.Sound('Blip_1-Surround-147.wav')
        pong.set_volume(10)

        wall = Wall()  #벽돌
        wall.build_wall(width)  #벽돌 길이=맵길이

        # 게임 준비
        screen.blit(gamestart, (0, 0))
        pygame.display.update()
        time.sleep(10)

        paddlerect = paddlerect.move((width / 2) - (paddlerect.right / 2),
                                     height - 20)  #패들 위치 선정
        ballrect = ballrect.move(width / 2, height / 2)  #공 위치 선정
        xspeed = xspeed_init
        yspeed = yspeed_init
        lives = max_lives  #최대 수명
        clock = pygame.time.Clock()
        pygame.key.set_repeat(1, 30)  # 키 이동의 자연스러움
        pygame.mouse.set_visible(0)  # 마우스 숨기기
        while 1:
            # 초당 60
            clock.tick(60)
            # 키 입력
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.exit()
                    sys.exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()
                    if event.key == pygame.K_LEFT:
                        paddlerect = paddlerect.move(-paddle_speed, 0)
                        if (paddlerect.left < 0):
                            paddlerect.left = 0
                    if event.key == pygame.K_RIGHT:
                        paddlerect = paddlerect.move(paddle_speed, 0)
                        if (paddlerect.right > width):
                            paddlerect.right = width

            # 막대기가 공을 치는지 확인
            if ballrect.bottom >= paddlerect.top and \
                  ballrect.bottom <= paddlerect.bottom and \
                  ballrect.right >= paddlerect.left and \
                  ballrect.left <= paddlerect.right:
                yspeed = -yspeed
                pong.play(0)

                offset = ballrect.center[0] - paddlerect.center[0]
                # offset > 0 means ball has hit RHS of paddle
                # 공이 막대기를 치는 위치에 따른 각도 변화
                if offset > 0:
                    if offset > 30:
                        xspeed = 7
                    elif offset > 23:
                        xspeed = 6
                    elif offset > 17:
                        xspeed = 5
                else:
                    if offset < -30:
                        xspeed = -7
                    elif offset < -23:
                        xspeed = -6
                    elif xspeed < -17:
                        xspeed = -5

            # move paddle/ball
            ballrect = ballrect.move(xspeed, yspeed)
            if ballrect.left < 0 or ballrect.right > width:
                xspeed = -xspeed
                pong.play(0)
            if ballrect.top < 0:
                yspeed = -yspeed
                pong.play(0)

            # 공이 패들을 지나쳣는지 확인 - 목숨 깍임
            if ballrect.top > height:
                lives -= 1
                # 목숨이 깍였을때 새로운공 생김
                xspeed = xspeed_init
                rand = random.random()
                if random.random() > 0.5:
                    xspeed = -xspeed
                yspeed = yspeed_init
                ballrect.center = width * random.random(), height / 2
                if lives == 0:
                    msg = pygame.font.Font(None,
                                           70).render("Game Over", True,
                                                      (255, 255, 255))
                    msgrect = msg.get_rect()  #게임오버 메시지 출력
                    msgrect = msgrect.move(width / 2 - (msgrect.center[0]),
                                           height / 3)  #게임오버 메시지 위치
                    screen.blit(msg, msgrect)
                    pygame.display.flip()
                    #점수 저장
                    f = open("점수.txt", "a")
                    f.write(strftime("%Y/%D %I:%M:%S", localtime()))
                    f.write("에 플레이한 플레이어의 점수는")
                    f.write(str(score))
                    f.write("입니다")
                    f.write("\n")
                    f.close()

                    # process key presses
                    #     - ESC to quit
                    #     - any other key to restart game
                    while 1:
                        restart = False
                        for event in pygame.event.get():
                            if event.type == pygame.QUIT:
                                sys.exit()
                            if event.type == MOUSEBUTTONDOWN:
                                restart = True
                            if event.type == pygame.KEYDOWN:
                                if event.key == pygame.K_ESCAPE:
                                    pygame.exit()
                                    sys.exit()
                                if not (event.key == pygame.K_LEFT
                                        or event.key == pygame.K_RIGHT):
                                    restart = True
                        if restart:  #죽고 재시작
                            screen.fill(black)
                            wall.build_wall(width)
                            lives = max_lives
                            score = 0
                            break

            if xspeed < 0 and ballrect.left < 0:
                xspeed = -xspeed
                pong.play(0)
            if xspeed > 0 and ballrect.right > width:
                xspeed = -xspeed
                pong.play(0)

            # 공이 벽돌에 부딪혔는지 확인하고 벽돌을 삭제하고 볼 방향을 변경
            index = ballrect.collidelist(wall.brickrect)
            if index != -1:
                if ballrect.center[0] > wall.brickrect[
                        index].right or ballrect.center[0] < wall.brickrect[
                            index].left:
                    xspeed = -xspeed
                else:
                    yspeed = -yspeed
                pong.play(0)
                wall.brickrect[index:index + 1] = []
                score += 1

            screen.fill(black)
            lifetext = pygame.font.Font(None,
                                        40).render(str(lives), True,
                                                   (0, 255, 0), black)  #생명력
            lifetextrect = lifetext.get_rect()
            lifetextrect = lifetextrect.move(width / 2 - lifetextrect.right, 0)
            screen.blit(lifetext, lifetextrect)

            scoretext = pygame.font.Font(None,
                                         40).render(str(score), True,
                                                    (0, 255, 0), black)  #점수
            scoretextrect = scoretext.get_rect()
            scoretextrect = scoretextrect.move(width - scoretextrect.right, 0)
            screen.blit(scoretext, scoretextrect)

            for i in range(0, len(wall.brickrect)):
                screen.blit(wall.brick, wall.brickrect[i])

            # 클리어 후
            if wall.brickrect == []:
                lives = max_lives
                wall.build_wall(width)
                xspeed = xspeed_init
                yspeed = yspeed_init
                ballrect.center = width / 2, height / 3

            screen.blit(ball, ballrect)
            screen.blit(paddle, paddlerect)
            pygame.display.flip()