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


Python Scene.draw方法代码示例

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


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

示例1: draw

# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import draw [as 别名]
 def draw(self, screen):
     s = pygame.Surface((SCREEN_W, SCREEN_H))
     self.pausedScene.draw(s)
     self.bluredBackground = self.blur(s, self.b)
     if self.b < 10:
         self.b = self.b + 0.1
     screen.blit(self.bluredBackground, (0, 0))
     Scene.draw(self, screen)
开发者ID:dgalaktionov,项目名称:Aleph,代码行数:10,代码来源:MessageScene.py

示例2: draw

# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import draw [as 别名]
    def draw(self, screen):
        screen.fill(0x000000)

        if self.bg:
            screen.blit(self.bg, self.camera.state)

        if Constants.DEBUG:
            self.drawRaytracing(screen)
        self.player.draw(screen, self.camera)
        for group in self.groups:
            group.draw(screen, self.camera)
        self.drawDanger(screen);
        
        # TODO: move maps and characters to its own layer
        Scene.draw(self, screen)  # draws rest of layers
开发者ID:dgalaktionov,项目名称:Aleph,代码行数:17,代码来源:Level.py

示例3: main

# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import draw [as 别名]
def main():
	# 初始化
	pygame.init()
	screen = pygame.display.set_mode((WIDTH, HEIGHT))
	pygame.display.set_caption("T-Rex Rush-公众号: Charles的皮卡丘")
	clock = pygame.time.Clock()
	# 得分
	score = 0
	# 加载一些素材
	jump_sound = pygame.mixer.Sound("./music/jump.wav")
	jump_sound.set_volume(6)
	die_sound = pygame.mixer.Sound("./music/die.wav")
	die_sound.set_volume(6)
	pygame.mixer.init()
	pygame.mixer.music.load("./music/bg_music.mp3")
	pygame.mixer.music.set_volume(0.6)
	pygame.mixer.music.play(-1)
	font = pygame.font.Font('./font/simkai.ttf', 20)
	# 实例化
	dinosaur = Dinosaur(WIDTH, HEIGHT)
	scene = Scene(WIDTH, HEIGHT)
	plants = pygame.sprite.Group()
	pteras = pygame.sprite.Group()
	# 产生障碍物事件
	GenPlantEvent = pygame.constants.USEREVENT + 0
	pygame.time.set_timer(GenPlantEvent, 1500)
	GenPteraEvent = pygame.constants.USEREVENT + 1
	pygame.time.set_timer(GenPteraEvent, 5000)
	# 游戏是否结束了
	running = True
	# 是否可以产生障碍物flag
	flag_plant = False
	flag_ptera = False
	t0 = time.time()
	# 主循环
	while running:
		for event in pygame.event.get():
			if event.type == QUIT:
				sys.exit()
				pygame.quit()
			if event.type == GenPlantEvent:
				flag_plant = True
			if event.type == GenPteraEvent:
				if score > 50:
					flag_ptera = True
		key_pressed = pygame.key.get_pressed()
		if key_pressed[pygame.K_SPACE]:
			dinosaur.is_jumping = True
			jump_sound.play()
		screen.fill(BACKGROUND)
		time_passed = time.time() - t0
		t0 = time.time()
		# 场景
		scene.move()
		scene.draw(screen)
		# 小恐龙
		dinosaur.is_running = True
		if dinosaur.is_jumping:
			dinosaur.be_afraid()
			dinosaur.jump(time_passed)
		dinosaur.draw(screen)
		# 障碍物-植物
		if random.random() < sigmoid(score) and flag_plant:
			plant = Plant(WIDTH, HEIGHT)
			plants.add(plant)
			flag_plant = False
		for plant in plants:
			plant.move()
			if dinosaur.rect.left > plant.rect.right and not plant.added_score:
				score += 1
				plant.added_score = True
			if plant.rect.right < 0:
				plants.remove(plant)
				continue
			plant.draw(screen)
		# 障碍物-飞龙
		if random.random() < sigmoid(score) and flag_ptera:
			if len(pteras) > 1:
				continue
			ptera = Ptera(WIDTH, HEIGHT)
			pteras.add(ptera)
			flag_ptera = False
		for ptera in pteras:
			ptera.move()
			if dinosaur.rect.left > ptera.rect.right and not ptera.added_score:
				score += 5
				ptera.added_score = True
			if ptera.rect.right < 0:
				pteras.remove(ptera)
				continue
			ptera.draw(screen)
		# 碰撞检测
		if pygame.sprite.spritecollide(dinosaur, plants, False) or pygame.sprite.spritecollide(dinosaur, pteras, False):
			die_sound.play()
			running = False
		# 显示得分
		score_text = font.render("Score: "+str(score), 1, (0, 0, 0))
		screen.blit(score_text, [10, 10])
		pygame.display.flip()
		clock.tick(60)
#.........这里部分代码省略.........
开发者ID:Guaderxx,项目名称:Games,代码行数:103,代码来源:Game7.py

示例4: draw

# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import draw [as 别名]
 def draw(self):
     Scene.draw(self)
     self.sprite.draw()
开发者ID:choiseungil29,项目名称:CLogic,代码行数:5,代码来源:TestScene.py

示例5: GameEngine

# 需要导入模块: from Scene import Scene [as 别名]
# 或者: from Scene.Scene import draw [as 别名]
class GameEngine(object):
    """
    The Fortune Engine GameEngine is a main loop wrapper around pygame.
    It manages the event and drawing loops allowing the user to just
    register for user events and drawing time in the draw loop.
    """
    instance = None

    def __init__(self, width=1200, height=900, always_draw=False,
                 fps_cap=15, version=False, title="FortuneEngine"):
        """
        Constructor for the game engine.

        @param width:        Window width
        @param height:       Window height
        @param always_draw:  Boolean to set the animation mode to always
                             draw vs draw when set_dirty is called
        @param fps_cap:      Sets the framerate cap. Set to 0 to disable
                             the cap. Warning: setting the cap to 0 when
                             always draw = False will cause cpu 100% when
                             not driving.
        @param version:      If true, use new rendering system, false uses
                             only the draw system
        @param title:        Window Title
        """
        GameEngine.instance = self
        pygame.init()
        pygame.mouse.set_visible(False)
        self.__version = version #true is new, false is old

        # Window Settings
        self.width = width
        self.height = height
        size = width, height
        self.screen = pygame.display.set_mode(size)
        pygame.display.set_caption(title)
        self.__fps = DrawableFontObject("", pygame.font.Font(None, 17))
        self.__fps.setPosition(0, 0)
        self.__scene = Scene(self.__fps)

        # Engine Internal Variables
        self.__fps_cap = fps_cap
        self.__showfps = False
        self.__dirty = True
        self.__always_draw = always_draw
        self.__font = pygame.font.Font(None, 17)
        self.__run_event = False

        # Variables to hold game engine elements and callbacks
        self.__event_cb = []
        self.__draw_lst = []
        self.__object_hold = {}


        # Game Timers
        self.__active_event_timers = []
        self.__active_event_timers_tick = []

        # Game Clock
        self.clock = pygame.time.Clock()
        self.__tick_time = 0

        # Inspector
        self._inspector = GameInspect(self.__object_hold)

        # Time Profiler Timers
        self.__draw_time = {}
        self.__draw_calls = {}
        self.__event_time = {}
        self.__event_calls = {}
        self.__timer_time = {}
        self.__timer_calls = {}

        # Initialize Py Console
        self.console = GameEngineConsole(self, (0, 0, width, height / 2))

        # Disable Mouse Usage
        # TODO Allow mouse motion on request
        pygame.event.set_blocked(pygame.MOUSEMOTION)

    def set_dirty(self):
        """
        Sets the dirty flag to force the engine to draw the next time
        it enters the draw flag.
        """
        self.__dirty = True

    def get_scene(self):
        """
        Returns the scene object

        @return:    Returns the scene object held by the game engine
        """
        return self.__scene

    def start_event_timer(self, function_cb, time):
        """
        Starts a timer that fires a user event into the queue every "time"
        milliseconds

#.........这里部分代码省略.........
开发者ID:sugarlabs,项目名称:Lemonade,代码行数:103,代码来源:GameEngine.py


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