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


Python Level.draw方法代码示例

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


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

示例1: main

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
def main():
    pygame.init()
    screen = display.set_mode(DISPLAY, FLAGS, DEPTH)
    display.set_caption("Use arrows to move!")
    timer = time.Clock()

    up = down = left = right = space = False
    bg = Surface((BLOCK_SIZE, BLOCK_SIZE))
    bg.convert()
    bg.fill(Color("#000000"))

    current_level = Level(LEVEL_W, LEVEL_H)
    player = Player(100, 100)
    entities = pygame.sprite.Group()
    entities.add(player)

    while True:
        timer.tick(FPS)
        for e in pygame.event.get():
            if e.type == QUIT: raise SystemExit, "QUIT"
            if e.type == KEYDOWN and e.key == K_ESCAPE:
                raise SystemExit, "ESCAPE"
            if e.type == KEYDOWN and e.key == K_UP:
                up = True
            if e.type == KEYDOWN and e.key == K_DOWN:
                down = True
            if e.type == KEYDOWN and e.key == K_LEFT:
                left = True
            if e.type == KEYDOWN and e.key == K_RIGHT:
                right = True
            if e.type == KEYDOWN and e.key == K_SPACE:
                space = True

            if e.type == KEYUP and e.key == K_UP:
                up = False
            if e.type == KEYUP and e.key == K_DOWN:
                down = False
            if e.type == KEYUP and e.key == K_LEFT:
                left = False
            if e.type == KEYUP and e.key == K_RIGHT:
                right = False
            if e.type == KEYUP and e.key == K_SPACE:
                space = False

            if e.type == MOUSEBUTTONUP:
                pos = pygame.mouse.get_pos()
                print current_level._identify_img(pos[0]/BLOCK_SIZE, pos[1]/BLOCK_SIZE)

        # draw background
        for y in range(LEVEL_H):
            for x in range(LEVEL_W):
                screen.blit(bg, (x * BLOCK_SIZE, y * BLOCK_SIZE))

        # update player, draw everything else
        player.update(up, down, left, right, space, current_level)
        player.draw(screen)
        #entities.draw(screen)
        current_level.draw(screen)

        pygame.display.flip()
开发者ID:joaompinto,项目名称:Zunga,代码行数:62,代码来源:main.py

示例2: Game

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class Game(object):
    fps = 100

    def __init__(self, screen):
        self.screen = screen
        self.level = Level(self.screen.get_size())
    
    def quit(self):
        self.done = True

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self):
        self.level.draw(self.screen)


    def run(self):
        self.done = False
        self.clock = pygame.time.Clock()
        self.level.restart()

        while not self.done:
            # input
            for event in pygame.event.get():
                if event.type == QUIT:
                    self.quit()
                elif event.type == KEYDOWN and event.key == K_ESCAPE:
                    self.quit()

            self.update()
            self.draw()
            pygame.display.flip()
开发者ID:RMeiselman,项目名称:The-Elements-of-Sundae,代码行数:36,代码来源:game.py

示例3: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class GameContext:
	def __init__(self, engine):
		self.engine = engine
		self.font = engine.game_data[FONT]
		self.current_level = 0
		self.current_level_id = self.engine.game_data[LEVELS][self.current_level]
		self.level = Level(load(self.engine.game_data[LEVEL_DATA][self.current_level_id][FILE]), engine)
		controls = engine.game_data[CONTROLS]
		self.down_control_map = {
			controls[LEFT]: self.level.player.left_down,
			controls[RIGHT]: self.level.player.right_down,
			controls[JUMP]: self.level.player.jump_start,
		}
		self.up_control_map = {
			controls[LEFT]: self.level.player.left_up,
			controls[RIGHT]: self.level.player.right_up,
			controls[JUMP]: self.level.player.jump_end,
		}
		print "Game Created"
	def handle_mouse_up_event(self, event):
		pass
	def handle_key_down_event(self, event):
		if self.down_control_map.has_key(event.key):
			self.down_control_map[event.key]()
	def handle_key_up_event(self, event):
		if event.key == K_ESCAPE:
			self.engine.context = MenuContext(self.engine)
		elif self.down_control_map.has_key(event.key):
			self.up_control_map[event.key]()
	def update(self, delta):
		self.level.update(delta)
	def display(self):
		self.level.draw(self.engine.screen)
开发者ID:matthewstevens,项目名称:CrazyAnt,代码行数:35,代码来源:engine.py

示例4: start

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
    def start(self):
        level = Level()
        level.init()
        (entities, trans) = parse_gsl_file(Config.data_path+'/testfile.gsl')
        
        
#        parse_emdl_file(entities, Config.data_path+'/map/level10.map', level)
        
        
        while True:
            self.console.process_input()
            self.input(pygame.event.get())
            self.screen.fill((0, 0, 0))
            pygame.time.wait(100)
            level.update_on_events()
            level.update()
            
            level.draw(self.screen)
            
            if self.show_states == True:
                level.draw_debug(self.screen)
                
            self.console.draw()    


            #self.screen.blit(surface, (0, 0))
            pygame.display.flip()
开发者ID:denever,项目名称:lettere,代码行数:29,代码来源:game.py

示例5: draw

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
 def draw (self, screen):
     rtn = Level.draw(self, screen)
     # draw options
     w, h = conf.RES
     self.draw_options(screen, (0, 0, w, h), players = self.num_cars,
                       graphics = conf.GRAPHICS)
     return True or rtn
开发者ID:ikn,项目名称:spaaace,代码行数:9,代码来源:title.py

示例6: GamePlay

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class GamePlay(GameState):
    def __init__(self):
        super(GamePlay, self).__init__()

        self.level = Level()

    def get_event(self, event):
        if event.type == pg.QUIT:
            self.quit = True

        self.level.get_event(event)

    def update(self, dt):
        self.level.update(dt)

    def draw(self, screen):
        self.level.draw(screen)
开发者ID:ToBaer94,项目名称:PrototypingPlatformer,代码行数:19,代码来源:gameplay_state.py

示例7: Game

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class Game(ApplicationState):
    fps = 60

    def setup(self):
        self.level = Level(self.app.screen.get_size())
        self.level.restart()

    def resume(self):
        self.clock = pygame.time.Clock()
        pygame.mixer.music.unpause()

    def quit(self):
        self.done = True

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self, screen):
        self.level.draw(screen)
开发者ID:jwsander,项目名称:CS112-Spring2012,代码行数:22,代码来源:game.py

示例8: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class Main:

	def __init__(self, SCREEN):
		# Initiate pygame and display.
		init()
		display.init()
		display.set_caption('The Platformer')
		# Create fps and set main display.
		self.fpsClock = time.Clock()
		self.mainDisplay = display.set_mode(SCREEN)

		# Level
		self.level_1 = Level()		

	# All events from mouse/keyboard/gamepad?
	def playerEvent(self):
		for eventput in event.get():
			if eventput.type == KEYDOWN and eventput.key == K_ESCAPE:
				return 'QUIT'
			self.level_1.playerEvent(eventput)

	# Updates variables
	def update(self):
		self.level_1.update()

	# Draws to the screen when finished
	def draw(self):

		self.level_1.draw(self.mainDisplay)
		
		
	# Main loop. Everything in order.
	def loop(self,FPS):
		while True:
			if (self.playerEvent() == 'QUIT'):
				quit()
				sys.exit()
			self.update()
			self.draw()
			display.update()
			self.fpsClock.tick(FPS)
开发者ID:vncastanheira,项目名称:platformer,代码行数:43,代码来源:main.py

示例9: Game

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class Game(ApplicationState):
    fps = 60

    def setup(self):
        self.level = Level(self.app.screen.get_size())
        self.level.restart()

    def resume(self):
        self.clock = pygame.time.Clock()
        pygame.mixer.music.unpause()

    def handle_event(self, event):
        if event.type == KEYDOWN and event.key == K_ESCAPE:
            self.app.set_state(PauseMenu)

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self, screen):
        self.level.draw(screen)
开发者ID:HampshireCS,项目名称:CS112-Spring2012,代码行数:23,代码来源:game.py

示例10: _setup

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
 def _setup(self):
     self._load_resources()
     
     level = Level(self.IMAGE_CACHE)
     level.load("test", "test.txt")
     self.background = level.draw()
     self.screen.blit(self.background, (0, 0))
     
     self.sprites = pygame.sprite.RenderUpdates()
     self.player = Player(image=self.IMAGE_CACHE['sprites'], pos=level.player_spawn(), frame=(0, 1))
     self.sprites.add(self.player)
     
     pygame.display.flip()
开发者ID:jakebarnwell,项目名称:PythonGenerator,代码行数:15,代码来源:game.py

示例11: GameState

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class GameState(AppState):
    fps = 60

    def setup(self):
        AppState.setup(self)

        self.level = Level(self.screen.get_size())
        self.level.restart()

    def resume(self):
        self.clock = pygame.time.Clock()

    def handle_event(self, event):
        if event.type == KEYDOWN and event.key == K_ESCAPE:
            self.app.set_state(PauseState)

    def update(self):
        dt = self.clock.tick(self.fps)
        self.level.update(dt)

    def draw(self):
        self.level.draw(self.screen)
        pygame.display.flip()
开发者ID:HampshireCS,项目名称:cs143-Spring2012,代码行数:25,代码来源:game.py

示例12: __init__

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
class LD26Main:
    def __init__(self, width=800,height=600):
        pygame.init()
        self.width = width
        self.height = height
        self.screen = pygame.display.set_mode((self.width, self.height))
        self.state = "menu"
        pygame.display.set_caption("Shoot Guys")

    def load_sprites(self):
        self.player_group = CameraSpriteGroup()
        self.player_bullet_group = CameraSpriteGroup()
        self.player_max_hp = 20
        self.player_healthbar = HealthBar(self.player_max_hp, self.player_max_hp, "res/player_healthbar.png", (128, 16))
        self.player_healthbar.rect.x = -55
        self.player_healthbar.rect.y = 10
        self.player_hb_group = CameraSpriteGroup()
        self.player_hb_group.add(self.player_healthbar)

        self.enemy_group = CameraSpriteGroup()
        self.enemy_bullet_group = CameraSpriteGroup()
        self.health_bar_sprites = CameraSpriteGroup()
        self.max_badguys = 0
        self.guys_killed = 0

        self.levels = [{"img":"res/levels/level1.png", "badguys":2, "goal":6}, {"img":"res/levels/level2.png", "badguys":5, "goal":10}]
        self.cur_level = 0

        self.load_level(0)
        self.menu = Menu()
        self.win = Win()
        self.die = Die()

    def load_level(self, levelnum):
        if levelnum >= len(self.levels):
            self.state = "win"
        else:
            leveldict = self.levels[levelnum]
            self.player = Player((self.width, self.height))
            self.player_group.add(self.player)
            self.level = Level((self.width, self.height), leveldict["img"])
            self.bdrop1 = Backdrop(self.level.dims, 1)
            self.bdrop2 = Backdrop(self.level.dims, 2)
            self.max_badguys = leveldict["badguys"]
            self.guys_killed = 0
            self.kill_goal = leveldict["goal"]
            self.player_healthbar.set_hp(self.player_max_hp)

    def go(self):
        self.load_sprites()
        self.clock = pygame.time.Clock()
        while 1:
            self.clock.tick(60)
            self.screen.fill((0, 0, 0))

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == K_ESCAPE:
                        if self.state == "game":
                            self.state = "menu"
                        else:
                            sys.exit()

                    elif event.key == K_RETURN:
                        if self.state == "menu":
                            self.state = "game"
                        elif self.state == "win" or self.state == "die":
                            self.load_level(0)
                            self.state = "game"

            if self.state == "menu":
                self.do_menu()
            elif self.state == "game":
                self.do_main_game()
            elif self.state == "win":
                self.do_win()
            else:
                self.do_die()

            pygame.display.flip()

    def do_die(self):
        self.die.update()
        self.die.draw(self.screen)

    def do_win(self):
        self.win.update()
        self.win.draw(self.screen)

    def do_menu(self):
        self.menu.update()
        self.menu.draw(self.screen)

    def do_main_game(self):
        if self.guys_killed > self.kill_goal:
            self.cur_level += 1
            self.player.kill()
            self.load_level(self.cur_level)
#.........这里部分代码省略.........
开发者ID:larsendt,项目名称:ld26,代码行数:103,代码来源:main.py

示例13: main

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
def main():
    pygame.init()
    edit_mode = False
    width = 800
    height = 600
    screen = pygame.display.set_mode((width, height), pygame.OPENGL|pygame.DOUBLEBUF)
    vertex_circle = GLSolidCircle(4)
    fp_circle = GLCircle(10)
    marker_circle = GLSolidCircle(3)

    glClearColor(*background_color)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0.0, width, height, 0.0)

    level = Level()
    groups = [
        { 'dudes': [Dude( 250, 250, 1 ), Dude( 275, 250, 1 ),
                    Dude( 250, 275, 1 ), Dude( 275, 275, 1 ) ]},
        { 'dudes': [Dude( 500, 250, 0 ), Dude( 525, 250, 0 ),
                    Dude( 500, 275, 0 ), Dude( 525, 275, 0 ) ]},
    ]

    sel_group = 0
    sel_dude = 0
    mx, my = 0, 0

    def validate_sel_dude(x,z):
        n = len( groups[ sel_group ][ 'dudes' ] )
        return x if x < n else z

    while True:
    	global poly
        glClear(GL_COLOR_BUFFER_BIT)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        for event in pygame.event.get():
            if event.type == QUIT:
                return
            if event.type == KEYDOWN:
                if event.key == K_e:
                    edit_mode = not edit_mode
                    if poly != None and len(level.polys[poly]) < 3:
                    	level.del_poly(poly)
                    	poly = None

                elif event.key == K_TAB:
                    sel_group = (sel_group + 1) % len(groups)
                    # don't let the dindex point to an invalid dude.
                    sel_dude = validate_sel_dude( sel_dude, 0 )

                elif edit_mode:
                    if event.key == K_s:
                        level.save_file( 'level.dat' )
                    if event.key == K_l:
                        poly = None
                        level.load_file('level.dat')

                elif event.key == K_w:
                    sel_dude = validate_sel_dude( 0, sel_dude )
                elif event.key == K_a:
                    sel_dude = validate_sel_dude( 1, sel_dude )
                elif event.key == K_s:
                    sel_dude = validate_sel_dude( 2, sel_dude )
                elif event.key == K_d:
                    sel_dude = validate_sel_dude( 3, sel_dude )

            if event.type == MOUSEBUTTONDOWN:      
                if edit_mode:
                    do_edit_action( level, event )
                elif event.button == 1:
                    for dude in groups[sel_group]['dudes']:
                        dude.issue_orders()
            if event.type == MOUSEMOTION:
                mx, my = event.pos

        if edit_mode:
            pass
            #screen.blit(text, text.get_rect())

        # draw
        level.draw( screen, edit_mode )
        for index,group in enumerate(groups):
            for dindex, dude in enumerate(group['dudes']):
                sel_level = 0
                if sel_group == index:
                    sel_level = 2 if dindex == sel_dude else 1
                dude.draw( screen, sel_level )

        if edit_mode:
        	level.draw_vertex_circle( mx, my , vertex_circle)
        	level.draw_poly_vertex( poly, marker_circle )
        	level.draw_guide_line( poly, mx, my )
            	
        else:
            # show movement plan
            # todo: get this crap out of the renderer
            fp = level.get_firing_position_near( mx, my )
#.........这里部分代码省略.........
开发者ID:chrisforbes,项目名称:navmeshgame,代码行数:103,代码来源:main.py

示例14: elif

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]
                sound_manager.stop_background_music()
            elif(not sound_manager.playing_background_music):
                sound_manager.play_background_music(LAVA_MUSIC_PATH)

        if (sound_manager.playing_background_music and sound_manager.music_playing == LAVA_MUSIC_PATH and lava.state == ENDED):
            configuration.save_score(player.score)
            sound_manager.stop_background_music()

        if (player_score != player.score):
            sound_manager.play_effect(MONEY_SOUND_PATH)

        player_score = player.score

        #Drawing
        surface.fill((0, 0, 255))
        level.draw(surface, camera)
        player.draw(surface, camera)
        lava.draw(surface, camera)

        label = font.render("Score: %d R" % (player.score), 1, (255, 255, 255))
        surface.blit(label, (0, 0))
        if (lava.state == EMERGING):
            label = font.render("LAVA EMERGING: RUN TO THE SURFACE!", 1, (255, 0, 0))
            surface.blit(label, (0, 30))

    
    elif conf.state == MENU_STATE:
        if (sound_manager.playing_background_music and sound_manager.music_playing != MENU_MUSIC_PATH):
            sound_manager.stop_background_music()
        elif (not sound_manager.playing_background_music):
            sound_manager.play_background_music(MENU_MUSIC_PATH)
开发者ID:reiknight,项目名称:ld29,代码行数:33,代码来源:main.py

示例15: GamePlay

# 需要导入模块: from level import Level [as 别名]
# 或者: from level.Level import draw [as 别名]

#.........这里部分代码省略.........

    def create_tower_info(self):
        self.tower_info = []
        name = self.selected_tower.name
        attack = self.selected_tower.damage
        range = self.selected_tower.radius
        up_cost = self.selected_tower.upgrade_cost
        if type(self.selected_tower).__name__ == "FireTower":
            tick_frequency = self.selected_tower.tick_frequency

        if self.selected_tower.tier <= self.selected_tower.max_tier:
            self.tower_info.append(self.create_text(str(name)))
            self.tower_info.append(self.create_text("Damage: " + str(attack)))
            if type(self.selected_tower).__name__ == "FireTower":
                self.tower_info.append(self.create_text("Damage every " + str(tick_frequency) + "ms"))
            else:
                self.tower_info.append(self.create_text("Range: " + str(range)))
            self.tower_info.append(self.create_text("Cost to Upgrade: " + str(up_cost)))
        else:
            self.tower_info.append(self.create_text(str(name)))
            self.tower_info.append(self.create_text("Damage: " + str(attack)))
            if type(self.selected_tower).__name__ == "FireTower":
                self.tower_info.append(self.create_text("Damage every " + str(tick_frequency) + "ms"))
            else:
                self.tower_info.append(self.create_text("Range: " + str(range)))
            self.tower_info.append(self.create_text("Max upgrade tier reached"))

    def create_text(self, text):
        text = str(text)
        font = pg.font.Font(None, 24)
        render_text = font.render(text, True, pg.Color("black"))
        return render_text

    def draw_tower_preview(self, screen):
        try:

            if self.props["can_build"] == "True" and self.selected is not None:
                radius = self.level.tower_list[self.selected].radius
                pg.draw.rect(self.screen, pg.Color("black"), [self.cursor_x * self.level.tile_renderer.tmx_data.tilewidth,
                                                              self.cursor_y * self.level.tile_renderer.tmx_data.tileheight,
                                                              self.level.tile_renderer.tmx_data.tilewidth,
                                                              self.level.tile_renderer.tmx_data.tileheight
                                                              ], 1
                             )

                pg.draw.circle(screen, pg.Color("black"), ([self.cursor_x * self.level.tile_renderer.tmx_data.tilewidth + 16,
                                                                  self.cursor_y * self.level.tile_renderer.tmx_data.tileheight + 16]), radius, 1)
                screen.blit(pg.image.load(path.join(tower_dir, "tower" + str(self.selected+1) + ".png")), (self.cursor_x * self.level.tile_renderer.tmx_data.tilewidth,
                                                                  self.cursor_y * self.level.tile_renderer.tmx_data.tileheight))
        except KeyError:
            pass
            # print "Key 'can_build' not in dictionary 'self.props'"
            # print "Mouse cursor must be outside of the map area (e.g. on top of the UI)"

    def draw_ui(self, screen):
        screen.blit(self.ui, (0, 512))
        screen.blit(self.tower_ui_1, (0+21, 512+19))
        screen.blit(self.tower_ui_2, (0+110, 512+19))
        screen.blit(self.tower_ui_3, (0+193, 512+19))
        screen.blit(self.tower_ui_4, (0+277, 512+19))
        screen.blit(self.tower_ui_5, (0+363, 512+19))




        if self.selected_tower is not None:
开发者ID:Pala106,项目名称:PygameTowerDefense,代码行数:70,代码来源:gameplay_state.py


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