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


Python Sprite.getHeight方法代码示例

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


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

示例1: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import getHeight [as 别名]
class Menu_play_button:

#-------------------------------------------------------------------------------------------------------

	def __init__( self ):
		self.text = Text( "menu/KGHAPPY.ttf", 80 )
		self.sprite = Sprite( "menu/blankbutton.png", 4 )
		self.click = pygame.mixer.Sound( "menu/click.wav" )

		self.next = 0
		self.on = 0
		self.mouseup = 0

#-------------------------------------------------------------------------------------------------------
	
	def load( self, width, height ):

		self.text.createText( "play", [ 0x82, 0xae, 0x20 ] )
		self.text.setX( width/2 - self.text.getWidth()/2 )
		self.text.setY( height/2 - self.text.getHeight()/2 -10 +120 )

		self.sprite.setX( width/2 - self.sprite.getWidth()/2 )
		self.sprite.setY( height/2 - self.sprite.getHeight()/2 +120 )

#-------------------------------------------------------------------------------------------------------
	
	def draw( self, window ):
		self.sprite.draw( window )
		self.text.draw( window )

#-------------------------------------------------------------------------------------------------------

	def fadein( self, i = 1, m = 255 ):
		self.sprite.fadein( i, m )
		self.text.fadein( i, m )

#-------------------------------------------------------------------------------------------------------

	def fadeout( self, i = 1, m = 0 ):
		self.sprite.fadeout( i, m )
		self.text.fadeout( i, m )

#-------------------------------------------------------------------------------------------------------

	def setState( self ):
		if self.on == 0:
			self.on = 1
		else:
			self.on = 0
		#print self.on

#-------------------------------------------------------------------------------------------------------
	
	def handle( self, event ):
		
		self.focus = False
		if event.type == pygame.MOUSEBUTTONDOWN:
			self.focus = True
			self.mouseup = 1
		elif event.type == pygame.MOUSEBUTTONUP:
			self.mouseup = 0
			
		
		self.sprite.setOffset( 0 )
		self.x, self.y = pygame.mouse.get_pos()

		if self.x > self.sprite.getLeft() and self.x < self.sprite.getRight() and self.sprite.getAlpha() == 255:
			if self.y > self.sprite.getTop() and self.y < self.sprite.getBot():
				if self.focus == True:
					if self.on == 0:
						self.click.play()
					self.next = 1

				if self.focus == True or self.mouseup == 1:
					self.sprite.setOffset( 2 )
				else:
					self.sprite.setOffset( 1 )

#-------------------------------------------------------------------------------------------------------

	def getAlpha( self ):
		return self.sprite.getAlpha()

#-------------------------------------------------------------------------------------------------------

	def getState( self ):
		return self.next

#-------------------------------------------------------------------------------------------------------

	def setNext( self, n ):
		self.next = n

#-------------------------------------------------------------------------------------------------------

	def getLeft( self ):
		return self.sprite.getLeft()

#-------------------------------------------------------------------------------------------------------

#.........这里部分代码省略.........
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:103,代码来源:menu_play_button.py

示例2: __init__

# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import getHeight [as 别名]
class Hero:

#-------------------------------------------------------------------------------------------------------
	
	def __init__( self ):

		self.hero = Sprite( "hero/0.png", 8 )
		self.hero.setOffset( 4 )

		self.move = 8
		self.delay = 2
		self.startstate = 0
		self.stateD = False
		self.stateA = False
		self.stateSpace = False
		self.spacecounter = 0

#-------------------------------------------------------------------------------------------------------

	def load( self, width, height ):
		self.hero.setX( 0 )
		self.hero.setY( height - 130 - self.hero.getHeight() )

		self.minX = width/4
		self.maxX = width*4/5

#-------------------------------------------------------------------------------------------------------
	
	def draw( self, window ):
		
		if self.hero.getAlpha() == 255:

			if self.startstate == 0:
				if self.hero.getX() < self.minX:
					self.hero.setX( self.hero.getX() + 3 )
				else:
					self.startstate = 1
			else:
				if self.stateD and self.hero.getRight() < self.maxX:
					self.hero.setX( self.hero.getX() + 7 )
				elif self.hero.getRight() >= self.maxX:
					self.stateD = False

				if self.hero.getX() > self.minX +5:
					self.hero.setX( self.hero.getX() - 3 )
				if self.stateA and self.hero.getX() > self.minX +5:
					self.hero.setX( self.hero.getX() - 4 )


			self.move += 1
			if self.move >= 4 * self.delay:
				self.move = 0

		self.hero.setOffset( self.move / self.delay )
		self.hero.draw( window )

#-------------------------------------------------------------------------------------------------------

	def handle( self, event ):

		if self.startstate == 1:
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_d:
					self.stateD = True
				elif event.key == pygame.K_a:
					self.stateA = True

				if event.key == pygame.K_SPACE:
					self.stateSpace = True
			elif event.type == pygame.KEYUP:
				if event.key == pygame.K_d:
					self.stateD = False
				elif event.key == pygame.K_a:
					self.stateA = False

				if event.key == pygame.K_SPACE:
					self.stateSpace = False
		
#-------------------------------------------------------------------------------------------------------

	def fadein( self, i = 1, m = 255 ):
		self.hero.fadein( i, m )

#-------------------------------------------------------------------------------------------------------

	def fadeout( self, i = 1, m = 0 ):
		self.hero.fadeout( i, m )
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:89,代码来源:hero.py


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