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


Python Texture.draw方法代码示例

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


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

示例1: __init__

# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import draw [as 别名]
class Menu_log:

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

	def __init__( self ):
		self.text = Text( "menu/KGHAPPY.ttf", 27, 255 )
		self.texture = Texture( "menu/exit.png", 255 )
		self.type = 0

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

		self.texture.setX( width/2 - self.texture.getWidth()/2 )
		self.texture.setY( height/2 - self.texture.getHeight()/2 )
		self.texture.setColor( 30, 0, 255 )

		self.text.createText( "m-menu  b-back", [ 0xFF, 0xFF, 0xFF ] )
		self.text.setX( width/2 - self.text.getWidth()/2 )
		self.text.setY( height/2 - self.text.getHeight()/2 )

#-------------------------------------------------------------------------------------------------------
	
	def draw( self, window ):
		if self.type == 1:
			self.texture.draw( window )
			self.text.draw( window )

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

	def getState( self ):
		return self.type

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

	def setState( self, t ):
		self.type = t

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

	def handle( self, event ):

		if event.type == pygame.KEYDOWN:

			if event.key == pygame.K_m:
				if self.type == 0:
					self.type = 1
				elif self.type == 1:
					self.type = 2

			elif event.key == pygame.K_b:
				if self.type == 1:
					self.type = 0
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:55,代码来源:menu_log.py

示例2: __init__

# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import draw [as 别名]
class Wall:

#-------------------------------------------------------------------------------------------------------
	
	def __init__( self ):
		self.bg_one = Texture( "wall/14.png" )
		self.bg_two = Texture( "wall/14.png" )

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

	def load( self ):
		self.bg_two.setX( self.bg_two.getWidth() )
		

#-------------------------------------------------------------------------------------------------------
	
	def draw( self, window, move = True, vel = 2 ):

		if self.bg_one.getAlpha() == 255 and move:
			self.bg_one.setX( self.bg_one.getLeft() - vel )
			self.bg_two.setX( self.bg_two.getLeft() - vel )
		
			if self.bg_one.getLeft() <= -self.bg_one.getWidth():
				self.bg_one.setX( self.bg_one.getWidth() )
			elif self.bg_two.getLeft() <= -self.bg_two.getWidth():
				self.bg_two.setX( self.bg_two.getWidth() )
			
		
		self.bg_one.draw( window )
		self.bg_two.draw( window )

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

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

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

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

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

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

示例3: __init__

# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import draw [as 别名]
class Menu_title:

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

	def __init__( self ):
		self.texture =  Texture( "menu/belt.png" )
		self.text = Text( "menu/KGHAPPY.ttf", 80 )

#-------------------------------------------------------------------------------------------------------		
		
	def load( self, width ):
		
		self.texture.setX( ( width / 2 ) - ( self.texture.getWidth() / 2 ) )
		self.texture.setY( 10 )

		self.text.createText( "Ninja", [ 0x7F, 0x99, 0x95 ] )
		self.text.setX( ( width / 2 ) - ( self.text.getWidth() / 2 ) )
		self.text.setY( 0 )

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

	def draw( self, window ):
		self.texture.draw( window )
		self.text.draw( window )

#-------------------------------------------------------------------------------------------------------
		
	def getBot( self ):
		return self.texture.getBot()

#-------------------------------------------------------------------------------------------------------
	
	def fadein( self, i = 1, m = 255 ):
		self.texture.fadein( i, m )
		self.text.fadein( i, m )

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

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

示例4: Planet

# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import draw [as 别名]
class Planet(object):
    """
    This class represents a planet with all of the necessary information.
    """

    def __init__(self, name, strategy, radius, latitudes, longitudes, rotation_speed, central_body, mass,
                 textureimage, longitude_of_the_ascending_node, argument_of_the_perihelion, inclination_to_ecliptic,
                 periapsis=0., apoapsis=0., angle=1.0):
        """
        Sets all the necessary attributes.
        """
        self.original_radius = radius
        self.name = name
        self.strategy = strategy
        self.position = BetterVector(periapsis, 0, 0)
        self.radius = radius
        self.latitudes = latitudes
        self.longitudes = longitudes
        self.rotation_speed = rotation_speed / 365 / 24 / 60 / 60
        self.central_body = central_body
        self.rotation = 0
        self.mass = mass
        self.textureimage = textureimage
        self.angle = angle
        self.periapsis = periapsis
        self.apoapsis = apoapsis
        self.texture = Texture(self.textureimage)
        self.sphere = gluNewQuadric()
        self.calc_speed()
        self.longitude_of_the_ascending_node = longitude_of_the_ascending_node
        self.argument_of_the_perihelion = argument_of_the_perihelion
        self.inclination_to_ecliptic = inclination_to_ecliptic
        self.is_real = False
        self.time = 0
        self.showTexture = True
        self.speed = 0

        gluQuadricNormals(self.sphere, GLU_SMOOTH)
        gluQuadricTexture(self.sphere, GL_TRUE)

    def draw(self):
        """
        Draws a planet, its position adn radius is divided by 100000.
        """
        glPushMatrix()
        glLoadIdentity()

        if self.is_real:
            glTranslated(self.position.x / 100000, self.position.y / 100000, self.position.z / 100000)
            glRotatef(self.rotation * 360, 0, 0, 1)
            glRotatef(-25, 1, 0, 0)
            glRotatef(45, 0, 0, 1)
            self.texture.draw()
            gluSphere(self.sphere, self.original_radius / 100000, self.latitudes, self.longitudes)
        else:
            glTranslated(self.position.x / 100000000, self.position.y / 100000000, self.position.z / 100000000)
            glRotatef(self.rotation * 360, 0, 0, 1)
            glRotatef(-25, 1, 0, 0)
            glRotatef(45, 0, 0, 1)
            self.texture.draw()
            if self.name == "Moon":
                gluSphere(self.sphere, 3, self.latitudes, self.longitudes)
            elif self.name == "Earth":
                gluSphere(self.sphere, 6, self.latitudes, self.longitudes)
            else:
                gluSphere(self.sphere, 25, self.latitudes, self.longitudes)

        glPopMatrix()

    def tick(self, dt, solar_system):
        """
        calculates and sets the position of the planet
        """
        vec = self.strategy.orbiting(self, dt, solar_system)
        self.position = BetterVector(vec.x, vec.y, vec.z)
        self.strategy.rotation(self, dt, solar_system)

    def toggle_real(self, is_real):
        """
        Toggles the :attr:`is_real` 
        """
        self.is_real = not is_real

    def calc_speed(self):
        """
        Calculates the speed, based on the distance to and the mass of its central body.

        :return: the speed im m/s
        """
        v = 0
        if self.central_body is not None:
            g = 6.67408 * 10 ** -11
            if self.name == "Moon":
                m = g * self.central_body.mass * 10
            else:
                m = g * self.central_body.mass * 10
            r = abs((self.position - self.central_body.position).magnitude) * 1000  # km -> m
            v = sqrt(m / r)
            v += self.central_body.calc_speed()
        self.speed = v  # m/s
#.........这里部分代码省略.........
开发者ID:sgeyer-tgm,项目名称:SolarSystem,代码行数:103,代码来源:models.py

示例5: __init__

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

#.........这里部分代码省略.........
			if self.core.getState() == 0:
				
				if self.menu_play_button.getState() == 0:
					self.menu_exit_log.handle( event )

				#HANDLE IF AUTHOR BUTTON == OFF AND SCORE BUTTON == OFF
				if self.menu_author_log.getState() == 0 and self.menu_score_log.getState() == 0:
					self.menu_play_button.handle( event )
					self.menu_git_button.handle( event )
					self.menu_google_button.handle( event )
					self.menu_music_button.handle( event )
					self.menu_chunk_button.handle( event )
				if self.menu_score_log.getState() == 0:
					self.menu_author_log.handle( event )
				if self.menu_author_log.getState() == 0:
					self.menu_score_log.handle( event )

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

			if self.core.getState() == 1:
				
				self.menu_log.handle( event )
				#HANDLE IF MENU_LOG == OFF
				if self.menu_log.getState() == 0:
					self.hero.handle( event )
				
#-------------------------------------------------------------------------------------------------------

	def states( self ):

#-------------------------------------------------------------------------------------------------------STATE -1

		if self.core.getState() == -1:
			self.intro.draw( self.core.getWindow() )
			if self.intro.getQuit():
				self.intro.free()
				del self.intro
				self.menu_music.play()#MENU MUSIC
				self.core.setState( 0 )
		

#-------------------------------------------------------------------------------------------------------STATE 0

		if self.core.getState() == 0:

			#FADE IN
			if self.menu_play_button.getState() != 1 and self.menu_exit_log.getState() == 0:
				self.menu_background.fadein( 5 )
				self.menu_title.fadein( 5 )
				self.menu_play_button.fadein( 5 )
				self.menu_git_button.fadein( 5 )
				self.menu_google_button.fadein( 5 )
				self.menu_facebook_button.fadein( 5 )
				self.menu_twitter_button.fadein( 5 )
				self.menu_music_button.fadein( 5 )
				self.menu_chunk_button.fadein( 5 )
				self.menu_author_log.fadein( 5 )
				self.menu_game_log.fadein( 5 )
				self.menu_settings_log.fadein( 5 )
				self.menu_score_log.fadein( 5 )
				self.menu_music.setVolume( 1.0 )

			#DRAW ALWAYS IN MENU STATE
			self.menu_background.draw( self.core.getWindow() )
			self.menu_title.draw( self.core.getWindow() )
			self.menu_exit_log.draw( self.core.getWindow() )
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:70,代码来源:engine.py

示例6: __init__

# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import draw [as 别名]
class Intro:

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

		self.counter = 0
		self.quit = False

		#Textures
		self.preview = Text( "intro/Jaapokki-Regular.otf", 37 )
		self.shuriken = Texture( "intro/shuriken.png" )
		self.title = Text( "intro/Jaapokki-Regular.otf", 37 )
		self.author = Text( "intro/Jaapokki-Regular.otf", 37 )
		self.produced = Text( "intro/Jaapokki-Regular.otf", 37 )

		self.text_one = Text( "intro/Jaapokki-Regular.otf", 37 )
		self.text_two = Text( "intro/Jaapokki-Regular.otf", 37 )
		self.text_three = Text( "intro/Jaapokki-Regular.otf", 37 )
		self.text_four = Text( "intro/Jaapokki-Regular.otf", 37 )

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

		self.preview.createText( "When nothing makes sense...", [ 0xFF, 0xFF, 0xFF ] )
		self.preview.setX( width/2 - self.preview.getWidth()/2 )
		self.preview.setY( height/2 - self.preview.getHeight()/2 )

		self.title.createText( "Ninja", [ 0x70, 0xB7, 0x59 ] )
		self.title.setX( width/2 - self.title.getWidth()/2 - self.shuriken.getWidth() -10 )
		self.title.setY( height/2 - self.title.getHeight()/2 )
		
		
		self.shuriken.setX( self.title.getRight() +10 )
		self.shuriken.setY( height/2 - self.shuriken.getHeight()/2 )
		
		self.author.createText( "Adrian Michalek", [ 0xFF, 0xFF, 0xFF ] )
		self.author.setX( width/2 - self.author.getWidth()/2 )
		self.author.setY( height/2 - self.author.getHeight()/2 )

		self.produced.createText( "produced by", [ 0x70, 0xB7, 0x59 ] )
		self.produced.setX( width/2 - self.produced.getWidth()/2 )
		self.produced.setY( height/2 - self.produced.getHeight()/2 - self.author.getHeight() -10 )

		
		self.text_one.createText( "It's not a final version.", [ 0xFF, 0xFF, 0xFF ] )
		self.text_one.setX( width/2 - self.text_one.getWidth()/2 )
		self.text_one.setY( height/2 - self.text_one.getHeight()-20 )

		self.text_two.createText( "You can develop game by your own.", [ 0xFF, 0xFF, 0xFF ] )
		self.text_two.setX( width/2 - self.text_two.getWidth()/2 )
		self.text_two.setY( height/2 - self.text_two.getHeight()/2-10 )

		self.text_three.createText( "It's a open source code build with pygame library.", [ 0xFF, 0xFF, 0xFF ] )
		self.text_three.setX( width/2 - self.text_three.getWidth()/2 )
		self.text_three.setY( height/2 )

		self.text_four.createText( "Have a nice time!", [ 0x70, 0xB7, 0x59 ] )
		self.text_four.setX( width/2 - self.text_four.getWidth()/2 )
		self.text_four.setY( height/2 + self.text_four.getHeight()/2 +10 )

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

	def free( self ):
		#DELETE ALL
		del self.counter
		del self.quit
		
		self.preview.free()
		del self.preview

		self.shuriken.free()
		del self.shuriken
		
		self.title.free()
		del self.title
		
		self.author.free()
		del self.author

		self.produced.free()
		del self.produced
		
		self.text_one.free()
		del self.text_one

		self.text_two.free()
		del self.text_two

		self.text_three.free()
		del self.text_three

		self.text_four.free()
		del self.text_four

#-------------------------------------------------------------------------------------------------------
	
	def draw( self, screen ):
		
#.........这里部分代码省略.........
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:103,代码来源:intro.py

示例7: __init__

# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import draw [as 别名]
class Menu_music_button:

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

	def __init__( self, path, on = 0 ):

		self.sprite = Sprite( path, 4 )

		self.scratch = Texture( "menu/scratch.png" )
		self.click = pygame.mixer.Sound( "menu/click.wav" )

		self.type = 0
		self.state = 0
		self.on = on
		self.mouseup = 0

#-------------------------------------------------------------------------------------------------------
	
	def load( self, y ):
		self.sprite.setX( 10 )
		self.sprite.setY( y )
		
		self.scratch.setX( 10 )
		self.scratch.setY( y )

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

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

#-------------------------------------------------------------------------------------------------------
	
	def draw( self, window ):
		self.sprite.draw( window )
		if self.type == 1:
			self.scratch.draw( window )

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

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

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

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

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

	def getState( self ):
		if self.state != self.type:
			self.state = self.type
			#print "true!"
			return True
		return False

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

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

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

	def handle( self, event ):
			
		self.focus = False
		self.sprite.setOffset( 0 )

		if event.type == pygame.MOUSEBUTTONDOWN:
			self.focus = True
			self.mouseup = 1
		elif event.type == pygame.MOUSEBUTTONUP:
			self.mouseup = 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()
					if self.type == 0:
						self.type = 1
					else:
						self.type = 0
				if self.focus == True or self.mouseup == 1:
					self.sprite.setOffset( 2 )
				else:
					self.sprite.setOffset( 1 )
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:97,代码来源:menu_music_button.py

示例8: __init__

# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import draw [as 别名]
class Menu_score_log:

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

	def __init__( self ):

		self.sprite = Sprite( "menu/position.png", 4 )
		self.window = Texture( "menu/window.png" )
		self.click = pygame.mixer.Sound( "menu/click.wav" )

		self.on = 0
		self.type = 0
		self.text = Text( "menu/KGHAPPY.ttf", 30 )

#-------------------------------------------------------------------------------------------------------
	
	def load( self, x, width, titlebot, bot ):

		self.sprite.setX( x )
		self.sprite.setY( bot +10 )
		
		self.window.setX( width/2 - self.window.getWidth()/2 )
		self.window.setY( titlebot -20 )
		

		self.text.createText( "SCORES", [ 0xd5, 0xad, 0x51 ] )
		self.text.setX( self.window.getLeft() + self.window.getWidth()/2 - self.text.getWidth()/2 )
		self.text.setY( self.window.getTop() +50 )

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

	def draw( self, screen ):
		if self.type == 1:
			self.window.draw( screen )
			self.text.draw( screen )
		else:
			self.sprite.draw( screen )

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

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

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

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

	def getState( self ):
		return self.type

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

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

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

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

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

	def handle( self, event ):
			
		self.focus = False
		if event.type == pygame.MOUSEBUTTONDOWN:
			self.focus = True
		
		if self.type == 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.sprite.setOffset( 2 )
						if self.type == 0:
							self.type = 1
					else:
						self.sprite.setOffset( 1 )
		if event.type == pygame.KEYDOWN:
			if event.key == pygame.K_ESCAPE or event.key == pygame.K_SPACE:
				if self.type == 1:
					if self.on == 0:
						self.click.play()
					self.type = 0
开发者ID:Adriqun,项目名称:C-CPP-SDL2,代码行数:98,代码来源:menu_score_log.py


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