本文整理汇总了Python中Vector.Vector.get_x方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.get_x方法的具体用法?Python Vector.get_x怎么用?Python Vector.get_x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.get_x方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameEntity
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import get_x [as 别名]
class GameEntity(object):
def __init__(self, world, name, image, text):
"""Base class used to construct a game entity.
Returns new GameEntity object
with the specified variables world, name,image, text, location, destination, speed, brain and id, this is a super
class and should ideally be used via inheritance
world: holds a world object. For game entities this should ideally be the
world game
name: holds the name of the particular entity being constructed e.g. zombie
image: holds the location of the image that will be used as the main image
for whatever GameEntity is constructed. This image holder will also be used to
store the image as a result of rotation for display
start_image: holds the location of the image that will be used as the main image
for whatever GameEntity is constructed. This one however will not be altered but
used as a reference to reset the rotational image when a new rotation is required.
text: holds the text that will be displayed in a textual entity; for example
the TextBox Entity
location: holds a default Vector of (0,0) that will be altered to set the location
of the enity that is created
destination: holds a default Vector of (0,0) that will be altered to set the destination
location of the entity
heading: holds a default Vector of (0,0) that will be altered to set the heading; vector
between two points with no size. Can be seen as the direction
last_heading: holds a default Vector of (0,0), this heading will typically be used
to remember the last heading that was used for rotating an entity image, so that rotation
does not get caught in an infinite loop
speed: holds a number variable default 0. that will be altered to set the speed
of the entity that is created
brain: holds a StateManager object that is used to manage the states that the
entity object will use
id: holds the numerial id for the entity object that is being created
"""
self.world = world
self.name = name
self.image = image
self.start_image = image
self.text = text
self.location = Vector(0,0)
self.destination = Vector(0,0)
self.heading = Vector(0,0)
self.last_heading = Vector(0,0)
self.speed = 0.
self.brain = StateManager()
self.id = 0
def render(self, surface):
"""Function to render the entity image to the screen
Blit in this particular function places the sepecified image
so that it its central point coorespondes to the location specified
w,h: holds the width and height of the image used as the
visual representation of the game entity
new_image_vector: A vector that holds the central point of an image
position: holds the value that represents the center of the image
at a specified location
"""
if self.speed != 0:
self.rotate_image()
w, h = self.image.get_size()
w = w/2
h = h/2
new_image_vector = Vector(w, h)
position = (self.location - new_image_vector)
surface.blit(self.image, (position.get_x(), position.get_y()))
def renderText(self, surface):
"""Function to render the entity text to the screen.
Blit in this particular function places the specified text
so that it appears in the center of the world it is created for
font: holds a new font object, usually using a filename and the
size of the font required Font(filename, size)
lines: holds the separate lines of the text box so that they can be rendered.
A new line is represented by a return character in the StartUpText(textBox) Code
center: holds the location of the textbox object, and renders text in relation
#.........这里部分代码省略.........