当前位置: 首页>>代码示例>>Python>>正文


Python Screen.draw方法代码示例

本文整理汇总了Python中screen.Screen.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Screen.draw方法的具体用法?Python Screen.draw怎么用?Python Screen.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在screen.Screen的用法示例。


在下文中一共展示了Screen.draw方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Game

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import draw [as 别名]
class Game(object):
    def __init__(self):
        pygame.mixer.pre_init(44100, 16, 2, 4096) # setup mixer to avoid sound lag
        pygame.init()
        pygame.display.set_caption("lakeception")
        
        self.world = World("Test World", (100,100), debug=False)
                                       # resolution, viewport
        self.screen = Screen(self.world, (800, 475), (25, 11))
        self.screen = Screen(self.world, (800, 475), (99, 99)) # debug res

        self.input = Input(self)
        
        self.fps = 60
        self.clock = pygame.time.Clock()
        
        self.ANIMATE = pygame.USEREVENT+0
        self.animationRate = 1 * 1000
        # Temporarily (?) disabled animations, because moving + animating was
        # an INTENSE visual experience
        # pygame.time.set_timer(self.ANIMATE, self.animationRate)
        
        self.updated = True
        self.quitting = False
        self.muted = False
        self.inspecting = False
        self.editing = False

        pygame.mixer.init()
        # From https://www.freesound.org/people/juskiddink/sounds/60507/
        # albeit a bit mixed to allow for looping
        tracks = []
        tracks.append(pygame.mixer.Sound(os.path.join(sys.path[0],'60507__juskiddink__waves2.ogg')))
        tracks.append(pygame.mixer.Sound(os.path.join(sys.path[0],'sea-space.ogg')))
        # Play & loop crashing waves in the background
        # Set the volume to an unobtrusive level
        tracks[0].set_volume(0.1)
        tracks[0].play(-1)
        # Play the song at a slightly higher volume
        # tracks[1].set_volume(0.4)
        # tracks[1].play()
 
    def tick(self):
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                self.input.handleKey(event)
            elif event.type == self.ANIMATE:
                self.screen.draw()
                self.updated = False
            elif event.type == pygame.QUIT:
                self.quitting = True
        
        if self.updated:
            self.screen.draw(self.inspecting, self.editing)
            self.updated = False
        
        timeDelta = self.clock.tick(self.fps)
开发者ID:naderm,项目名称:lakeception,代码行数:59,代码来源:game.py

示例2: run

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import draw [as 别名]
def run(width, height):
    gamefield = Screen(width, height)

    while 1:
        get_events()

        gamefield.draw()

        refresh()
        pause(100)
开发者ID:alkurbatov,项目名称:trolls,代码行数:12,代码来源:core.py

示例3: main

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import draw [as 别名]
def main():

    pygame.init()
    glutInit()

    options = { 'BG': BG, 'ANGLE_VIEW' : ANGLE_VIEW}
    screen = Screen(WIDTH, HEIGHT, options)

    screen.launch()

    n = Node(Color())
    screen.add_object(n)

    while True:
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #Clear display

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print("Close painting")
                sys.exit()

        screen.draw()
        screen.refresh() 
开发者ID:Gmulti,项目名称:DirectoryWatcher,代码行数:25,代码来源:painting.py

示例4: Petris

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import draw [as 别名]
class Petris():
    """
    Application respresentation class.
    """
    def init(self):
        """
        Initialize application.
        """
        self.lines = 0
        self.score = 0
        self.level = 1

        self.screen = Screen()
        self.screen.init()
        self.screen.level = self.level
        self.screen.lines = self.lines

        random.seed()

        self.figures = []
        self.figures.append(FigureI())
        self.figures.append(FigureO())
        self.figures.append(FigureL())
        self.figures.append(FigureJ())
        self.figures.append(FigureT())
        self.figures.append(FigureS())
        self.figures.append(FigureZ())


    def destroy(self):
        """
        Free application resources.
        """
        self.screen.destroy()


    def _get_game_delay(self):
        """
        Returns real number of seconds for sleep time
        between figure falling steps.
        """
        seconds = 0.080 + 0.800 * pow(0.75, self.level - 1)

        if (seconds < 0.01):
            seconds = 0.01

        return seconds


    def _generate_figure(self):
        """
        Generate next figure to be fallen.
        """
        return self.figures[random.randint(0, len(self.figures) - 1)]


    def run(self):
        """
        Run main application loop.
        Return True if game was aborted by user, or False if he lose the game.
        """
        figure = None
        exiting = False
        fast_falling = False
        paused = False
        sleep_time = 0
        # Sleep with little portions to make keyboard more interactive.
        sleep_chunk = 0.2

        next_figure = self._generate_figure()
        
        while not exiting:
            # Create and initialize new figure.
            if not figure:
                figure = next_figure
                self.screen.move_figure_to_start(figure)

                next_figure = self._generate_figure()
                self.screen.set_next_figure(next_figure)

            self.screen.draw(figure)

            if sleep_time <= 0:
                sleep_time = self._get_game_delay()

            if sleep_time > sleep_chunk:
                sleep_time -= sleep_chunk
                time.sleep(sleep_chunk)
            else:
                time.sleep(sleep_time)
                sleep_time = 0
            
            # Keyboard input loop.
            ch = self.screen.getch()

            if ch == curses.ERR:
                # Key was not pressed.
                pass
            elif ch == ord("l") or ch == ord("L"):
                # Move right.
#.........这里部分代码省略.........
开发者ID:vchimishuk,项目名称:petris,代码行数:103,代码来源:petris.py

示例5: Scene

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import draw [as 别名]
fpsClock = pygame.time.Clock()

windowSurfaceObj = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.DOUBLEBUF)
pygame.display.set_caption("Street Pirates Vs. Ninja")
fontObj = pygame.font.Font('freesansbold.ttf', 42)
msg = "Hello world!"

scene = Scene([ [2, 2, 0], [1, 0, 0] ])
screen = Screen(windowSurfaceObj, scene)
listener = EventListener(scene)

bluecolor = pygame.Color(0, 0, 255)
msg = "Hello world"

while True:
    listener.listen()
    screen.draw()
    msg = str(scene._players[0].position())
    msg1 = str(scene._players[0].speed())
    # msg += str(scene._players[1].position())
    msgSurfaceObj = fontObj.render(msg, False, bluecolor)
    msgRectObj = msgSurfaceObj.get_rect()
    scene.update()
    msgRectObj.topleft = (10, 20)
    windowSurfaceObj.blit(msgSurfaceObj, msgRectObj)
    pygame.display.update()
    #scene.moveForward(0, 0.001)
    #scene.moveRight(0, .001)
    scene.moveLeft(0, .001)
    print msg + '!' + msg1
开发者ID:ClubEngine,项目名称:GameJam4,代码行数:32,代码来源:testMouvement.py

示例6: quit_program

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import draw [as 别名]
    else:
        pass

#This gets called to quit the game, called from the menu only currently.    
def quit_program():
    pygame.quit()
    sys.exit()

pygame.init()
FPS = 30
pygame.display.init()
pygame.display.set_mode((0,0), pygame.FULLSCREEN)
CANVAS = pygame.display.get_surface()
fpsClock = pygame.time.Clock()
pygame.display.set_caption('Jetpac: from "{} Python".format("Monty")')
main_screen = Screen(CANVAS, quit_program)

while True :
    """
    This while loop is the main game processor
    it passes all of the events from the event stack
    to the event_handler
    Then updates and draws all parts of the game
    """
    for event in pygame.event.get():
        event_handler(main_screen, event)
    main_screen.update()
    main_screen.draw()
    pygame.display.update()
    fpsClock.tick(FPS)
开发者ID:BenjaminGardner31,项目名称:JetpacClonePython,代码行数:32,代码来源:main.py

示例7: __init__

# 需要导入模块: from screen import Screen [as 别名]
# 或者: from screen.Screen import draw [as 别名]
class Main:
    """ Main class for the game. """

    def __init__(self, width, height, caption="Street Pirates Vs. Ninjas"):
        """
        Constructor.
        @param  self     [Main]     itself  
        @param  width    [Int]      width of the window
        @param  height   [Int]      height of the window
        @param  caption  [String]   caption of the window
        """
        self.width = width
        self.height = height

        # pygame objects initialization
        pygame.init()

        icon = pygame.image.load("assets/Icone.png")
        pygame.display.set_icon(icon)
        self._soundManager = SoundManager()
        self._soundManager.playMenuMusic()

        self._fpsClock = pygame.time.Clock()
        self._window = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)

        pygame.display.set_caption(caption)

        pygame.mouse.set_cursor(*pygame.cursors.tri_left)

        # game objects initialization
        self._scene = Scene([[100, 0, 0], [-100, 0, 0]], self)
        self._listener = EventListener(self._scene, self)
        self._startMenu = StartMenu(self)
        self._startMenu.drawSplashScreen()  # just before loading
        self._screen = Screen(self._window, self._scene, self._startMenu)
        self._startMenu.draw()

        # main object properties initialization
        self.state = GameState.START_MENU
        self.loop = True

    def start(self):
        """
        Launches the main loop of the game.
        @param  self     [Main]     itself
        """
        # main loop
        while self.loop:
            if self.state == GameState.START_MENU:
                self._listener.listen()
                self._startMenu.draw()
            elif self.state == GameState.IN_GAME:
                self._listener.listen()
                self._screen.draw()

            self._fpsClock.tick(30)

    def stop(self):
        """
        Definitely stop the main loop.
        @param  self     [Main]     itself
        """
        self.loop = False

    def changeState(self, state):
        self.state = state
        self._soundManager.stop()
        if state == GameState.IN_GAME:
            self._soundManager.playMusic("fightmusic")
开发者ID:ClubEngine,项目名称:GameJam4,代码行数:71,代码来源:main.py


注:本文中的screen.Screen.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。