简体   繁体   English

Pygame:为什么window不会出现?

[英]Pygame: Why won't window appear?

I've been trying to make a basic pokemon-esque game with my son.我一直在尝试和我儿子制作一个基本的口袋妖怪式游戏。 It has been a rather ad-hoc learning experience.这是一次相当临时的学习经历。

I've gotten most things to work one way or another, but the following code doesn't seem to want to cooperate.我已经让大多数事情以一种或另一种方式工作,但下面的代码似乎不想合作。 All that should be happening is the screen appearing, filled white, with the two 'pokemon' being draw upon it.应该发生的只是屏幕出现,充满白色,两个“口袋妖怪”被画在上面。 As is, the screen pops up for a split second, then closes.照原样,屏幕弹出一秒钟,然后关闭。 Any guidance would be much appreciated!任何指导将不胜感激!

import pygame
import random
import sys



Boomeroo = pygame.image.load("C:\\Users\\19168\\Desktop\\1stgame\\img\\Boomeroo.png")
Caterpetal = pygame.image.load("C:\\Users\\19168\\Desktop\\1stgame\\img\\Caterpetal.png")


class Pokemon():
   def __init__(self, x, y, name):
    
        self.name = name
        self.x = x
        self.y = y
        self.img = None
    

    def draw(self, screen):
        screen.blit(self.img, (self.x, self.y))

class Playerpoke(Pokemon):
    def __init__(self, x, y, name):
        super().__init__(x, y, name)
    
        self.x = 50
        self.y = 100
        self.img = Caterpetal
        self.name = "Caterpetal"



class Wild(Pokemon):
    def __init__(self, x, y, name):
        super().__init__(x, y, name)
   
        self.x = 280
        self.y = 380
        self.pic = Boomeroo
        self.name = "Boomeroo"



class Game():
    def __init__(self):

        pygame.init()
    

        self.screen = pygame.display.set_mode((400,400))

        self.player = Playerpoke(self,50,100)
        self.wild = Wild(self,280,380)

        self.clock = pygame.time.Clock()



    def redraw():

        self.player.draw(self.screen)
        self.wild.draw(self.screen)
        self.screen.fill((255,255,255))
        pygame.display.update()
    

    def main(self):
        running = True
        while running:
    
            self.redraw()
            self.clock.tick(60)

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False

pygame.quit()

You have to call the main method.您必须调用main方法。 Create a Game instance and invoke main :创建一个Game实例并调用main

game = Game()
game.main()
pygame.quit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM