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


Python pygame.Surface方法代码示例

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


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

示例1: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self, dt=0.2, res=(32, 32), init_pos=(3, 3), init_std=0, wall=None, gravity=(0.0, 0.0)):
        pygame.init()

        self.dt = dt
        self.res = res
        if os.environ.get('SDL_VIDEODRIVER', '') == 'dummy':
            pygame.display.set_mode(res, 0, 24)
            self.screen = pygame.Surface(res, pygame.SRCCOLORKEY, 24)
            pygame.draw.rect(self.screen, (0, 0, 0), (0, 0, res[0], res[1]), 0)
        else:
            self.screen = pygame.display.set_mode(res, 0, 24)
        self.gravity = gravity
        self.initial_position = init_pos
        self.initial_std = init_std
        self.space = pymunk.Space()
        self.space.gravity = self.gravity
        self.draw_options = pymunk.pygame_util.DrawOptions(self.screen)
        self.clock = pygame.time.Clock()
        self.wall = wall
        self.static_lines = None

        self.dd = 2 
开发者ID:simonkamronn,项目名称:kvae,代码行数:24,代码来源:box_gravity.py

示例2: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self, dt=0.2, res=(32, 32), init_pos=(3, 3), init_std=0, wall=None):
        pygame.init()

        self.dt = dt
        self.res = res
        if os.environ.get('SDL_VIDEODRIVER', '') == 'dummy':
            pygame.display.set_mode(res, 0, 24)
            self.screen = pygame.Surface(res, pygame.SRCCOLORKEY, 24)
            pygame.draw.rect(self.screen, (0, 0, 0), (0, 0, res[0], res[1]), 0)
        else:
            self.screen = pygame.display.set_mode(res, 0, 24)
        self.gravity = (0.0, 0.0)
        self.initial_position = init_pos
        self.initial_std = init_std
        self.space = pymunk.Space()
        self.space.gravity = self.gravity
        self.draw_options = pymunk.pygame_util.DrawOptions(self.screen)
        self.clock = pygame.time.Clock()
        self.wall = wall
        self.static_lines = None

        self.dd = 2 
开发者ID:simonkamronn,项目名称:kvae,代码行数:24,代码来源:pong.py

示例3: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self, position=(400, 150)):
		pygame.sprite.Sprite.__init__(self)
		self.img_1 = pygame.Surface((285, 100))
		self.img_1_front = pygame.Surface((281, 96))
		self.img_1.fill((255, 255, 255))
		self.img_1_front.fill((0, 0, 0))
		self.img_1.blit(self.img_1_front, (2, 2))
		self.img_2 = pygame.Surface((285, 100))
		self.img_2_front = pygame.Surface((281, 96))
		self.img_2.fill((255, 255, 255))
		self.img_2_front.fill((24, 196, 40))
		self.img_2.blit(self.img_2_front, (2, 2))
		self.text = 'easy'
		self.font = pygame.font.Font('./resource/fonts/m04.ttf', 42)
		self.textRender = self.font.render(self.text, 1, (255, 255, 255))
		self.img_1.blit(self.textRender, (60, 29))
		self.img_2.blit(self.textRender, (60, 29))
		self.image = self.img_1
		self.rect = self.image.get_rect()
		self.rect.center = position 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:22,代码来源:CHOICE.py

示例4: loadLevel

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def loadLevel(self, game_level):
		with open(os.path.join(self.levels_path, game_level), 'r') as f:
			lines = f.readlines()
		# 游戏地图
		self.game_map = gameMap(max([len(line) for line in lines]) - 1, len(lines))
		# 游戏surface
		height = Config.get('block_size') * self.game_map.num_rows
		width = Config.get('block_size') * self.game_map.num_cols
		self.game_surface = pygame.Surface((width, height))
		self.game_surface.fill(Config.get('bg_color'))
		self.game_surface_blank = self.game_surface.copy()
		for row, elems in enumerate(lines):
			for col, elem in enumerate(elems):
				if elem == 'p':
					self.player = pusherSprite(col, row)
				elif elem == '*':
					self.game_map.addElement('wall', col, row)
				elif elem == '#':
					self.game_map.addElement('box', col, row)
				elif elem == 'o':
					self.game_map.addElement('target', col, row) 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:23,代码来源:Game12.py

示例5: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self, imagepath, position, size=(11, 13), is_highest=False, bg_color=None, **kwargs):
		pygame.sprite.Sprite.__init__(self)
		# 导入图片
		self.images = []
		image = pygame.image.load(imagepath)
		for i in range(12):
			self.images.append(pygame.transform.scale(image.subsurface((i*20, 0), (20, 24)), size))
		if is_highest:
			self.image = pygame.Surface((size[0]*8, size[1]))
		else:
			self.image = pygame.Surface((size[0]*5, size[1]))
		self.rect = self.image.get_rect()
		self.rect.left, self.rect.top = position
		# 一些必要的变量
		self.is_highest = is_highest
		self.bg_color = bg_color
		self.score = '00000' 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:19,代码来源:scene.py

示例6: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self):
        def make_surface(tl):
            w = 40
            surface = pygame.Surface((w, 3 * w), pygame.SRCALPHA)
            surface.fill(COLOR_ALUMINIUM_5 if tl != 'h' else COLOR_ORANGE_2)
            if tl != 'h':
                hw = int(w / 2)
                off = COLOR_ALUMINIUM_4
                red = COLOR_SCARLET_RED_0
                yellow = COLOR_BUTTER_0
                green = COLOR_CHAMELEON_0
                pygame.draw.circle(surface, red if tl == tls.Red else off, (hw, hw), int(0.4 * w))
                pygame.draw.circle(surface, yellow if tl == tls.Yellow else off, (hw, w + hw), int(0.4 * w))
                pygame.draw.circle(surface, green if tl == tls.Green else off, (hw, 2 * w + hw), int(0.4 * w))
            return pygame.transform.smoothscale(surface, (15, 45) if tl != 'h' else (19, 49))
        self._original_surfaces = {
            'h': make_surface('h'),
            tls.Red: make_surface(tls.Red),
            tls.Yellow: make_surface(tls.Yellow),
            tls.Green: make_surface(tls.Green),
            tls.Off: make_surface(tls.Off),
            tls.Unknown: make_surface(tls.Unknown)
        }
        self.surfaces = dict(self._original_surfaces) 
开发者ID:carla-simulator,项目名称:scenario_runner,代码行数:26,代码来源:no_rendering_mode.py

示例7: setup

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def setup(self, scene, ball):
        """Setup a level with a certain level number"""
        scene.qubit_num = self.level
        self.circuit_grid_model = CircuitGridModel(scene.qubit_num, CIRCUIT_DEPTH)

        # the game crashes if the circuit is empty
        # initialize circuit with identity gate at the end of each line to prevent crash
        # identity gate are displayed by completely transparent PNG
        for i in range(scene.qubit_num):
            self.circuit_grid_model.set_node(i, CIRCUIT_DEPTH - 1, CircuitGridNode(node_types.IDEN))

        self.circuit = self.circuit_grid_model.compute_circuit()
        self.statevector_grid = StatevectorGrid(self.circuit, scene.qubit_num, 100)
        self.right_statevector = VBox(WIDTH_UNIT * 90, WIDTH_UNIT * 0, self.statevector_grid)
        self.circuit_grid = CircuitGrid(0, ball.screenheight, self.circuit_grid_model)

        # computer paddle

        self.left_paddle.image = pygame.Surface([WIDTH_UNIT, int(round(ball.screenheight / 2 ** scene.qubit_num))])
        self.left_paddle.image.fill((255, 255, 255))
        self.left_paddle.image.set_alpha(255)
        self.left_paddle.rect = self.left_paddle.image.get_rect()
        self.left_paddle.rect.x = 9 * WIDTH_UNIT

        # player paddle for detection of collision. It is invisible on the screen

        self.right_paddle.image = pygame.Surface([WIDTH_UNIT, int(round(ball.screenheight / 2 ** scene.qubit_num))])
        self.right_paddle.image.fill((255, 0, 255))
        self.right_paddle.image.set_alpha(0)
        self.right_paddle.rect = self.right_paddle.image.get_rect()
        self.right_paddle.rect.x = self.right_statevector.xpos 
开发者ID:HuangJunye,项目名称:QPong,代码行数:33,代码来源:level.py

示例8: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self):
        super().__init__()

        # get ball screen dimensions
        self.screenheight = round(WINDOW_HEIGHT * 0.7)
        self.screenwidth = WINDOW_WIDTH
        self.width_unit = WIDTH_UNIT

        self.left_edge = self.width_unit
        self.right_edge = self.screenwidth - self.left_edge

        self.top_edge = self.width_unit * 0
        self.bottom_edge = self.screenheight - self.top_edge

        # define the ball sizes
        self.height = self.width_unit
        self.width = self.width_unit

        # create a pygame Surface with ball size
        self.image = pygame.Surface([self.height, self.width])

        self.image.fill(WHITE)

        self.rect = self.image.get_rect()

        self.x = 0
        self.y = 0
        self.speed = 0
        self.initial_speed_factor = 0.8
        self.direction = 0

        # initialize ball action type, measure and bounce flags
        self.ball_action = NOTHING
        self.measure_flag = NO

        # initialize ball reset on the left
        self.reset_position = LEFT
        self.reset()

        self.sound = Sound()
        self.score = Score() 
开发者ID:HuangJunye,项目名称:QPong,代码行数:43,代码来源:ball.py

示例9: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self, circuit, qubit_num, num_shots):
        pygame.sprite.Sprite.__init__(self)
        self.image = None
        self.rect = None
        self.ball = Ball()
        self.block_size = int(round(self.ball.screenheight / 2 ** qubit_num))
        self.basis_states = comp_basis_states(circuit.width())
        self.circuit = circuit

        self.paddle = pygame.Surface([WIDTH_UNIT, self.block_size])
        self.paddle.fill(WHITE)
        self.paddle.convert()

        self.paddle_before_measurement(circuit, qubit_num, num_shots) 
开发者ID:HuangJunye,项目名称:QPong,代码行数:16,代码来源:statevector_grid.py

示例10: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def update(self):
        self.image = pygame.Surface([(self.circuit.width() + 1) * 3 * WIDTH_UNIT, self.ball.screenheight])
        self.image.convert()
        self.image.fill(BLACK)
        self.rect = self.image.get_rect() 
开发者ID:HuangJunye,项目名称:QPong,代码行数:7,代码来源:statevector_grid.py

示例11: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self, circuit_grid_model):
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.Surface([GRID_WIDTH * (18 + 2),
                                     GRID_HEIGHT * (3 + 1)])
        self.image.convert()
        self.image.fill(WHITE)
        self.rect = self.image.get_rect()
        pygame.draw.rect(self.image, BLACK, self.rect, LINE_WIDTH)

        for wire_num in range(circuit_grid_model.max_wires):
            pygame.draw.line(self.image, BLACK,
                             (GRID_WIDTH * 0.5, (wire_num + 1) * GRID_HEIGHT),
                             (self.rect.width - (GRID_WIDTH * 0.5), (wire_num + 1) * GRID_HEIGHT),
                             LINE_WIDTH) 
开发者ID:HuangJunye,项目名称:QPong,代码行数:17,代码来源:circuit_grid.py

示例12: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def __init__(self,pos,image=pygame.Surface([24,24])):
        pygame.sprite.Sprite.__init__(self)
        if not isinstance(image, pygame.Surface):
            self.image = load_image(image)
        else:
            self.image = image
        self.rect = self.image.get_rect()
        self.position = pos
        self.rect.center = self.position 
开发者ID:Zebreu,项目名称:ConvolutionalEmotion,代码行数:11,代码来源:zengame.py

示例13: make_image_from_data

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def make_image_from_data(self, image_data):
        # For mono and grayscale, we need a palette because the evaluation function
        # only returns a single integer instead of an (R, G, B) tuple.
        if self.scheme == 'color':
            image = pygame.Surface((self.thumb_width, self.thumb_height))
        else:
            image = pygame.Surface((self.thumb_width, self.thumb_height), depth=8)
            palette = tuple([(i, i, i) for i in range(256)])
            image.set_palette(palette)

        for r, row in enumerate(image_data):
            for c, color in enumerate(row):
                image.set_at((r, c), color)

        return image 
开发者ID:CodeReclaimers,项目名称:neat-python,代码行数:17,代码来源:evolve_interactive.py

示例14: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def update(self, screen):
		clock = pygame.time.Clock()
		background = pygame.Surface(screen.get_size())
		count = 0
		flag = True
		while True:
			count += 1
			clock.tick(60)
			self.components.clear(screen, background)
			self.components.update()
			if count % 10 == 0:
				count = 0
				flag = not flag
			if flag:
				self.components.draw(screen)
			else:
				screen.blit(self.PI.image, self.PI.rect)
			pygame.display.flip()
			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					sys.exit(0)
					pygame.quit()
				elif event.type == pygame.MOUSEBUTTONDOWN:
					if event.button == 1:
						mouse_pos = pygame.mouse.get_pos()
						if self.RB.rect.collidepoint(mouse_pos):
							return True 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:29,代码来源:PAUSE.py

示例15: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import Surface [as 别名]
def update(self, screen):
		clock = pygame.time.Clock()
		background = pygame.Surface(screen.get_size())
		count = 0
		flag = True
		while True:
			count += 1
			clock.tick(60)
			self.components.clear(screen, background)
			self.components.update()
			if count % 10 == 0:
				count = 0
				flag = not flag
			if flag:
				self.components.draw(screen)
			else:
				screen.blit(self.EI.image, self.EI.rect)
			pygame.display.flip()
			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					sys.exit(0)
					pygame.quit()
				elif event.type == pygame.MOUSEBUTTONDOWN:
					if event.button == 1:
						mouse_pos = pygame.mouse.get_pos()
						if self.CB.rect.collidepoint(mouse_pos):
							return True 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:29,代码来源:END.py


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