本文整理汇总了Python中World.add_entity方法的典型用法代码示例。如果您正苦于以下问题:Python World.add_entity方法的具体用法?Python World.add_entity怎么用?Python World.add_entity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.add_entity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import World [as 别名]
# 或者: from World import add_entity [as 别名]
class Game:
def __init__(self, *args):
"""Constructor for the Game class,ensures that the Game class starts on the correct state
state: The phase the game is running in, determines what world and entities should be created
"""
self.world = World(startup_screen_backdrop)
self.world.state = "startup"
def startup(self):
"""Creates a new startup textbox, with specified text, and places it in the location on the specified world
world: Essentially the window to which entities are added to,
should be a World object
entity: Arbitrary label to hold a new TextBox Entity
"""
self.world = World(startup_screen_backdrop)
hordelogo = MainImage(self.world)
hordelogo.location = Vector((screen_size[0]/2),(screen_size[1]/3))
self.world.add_entity(hordelogo)
btn_new = ButtonImageNew(self.world)
w,h = hordelogo.image.get_size()
btn_new.location = Vector(hordelogo.location.get_x(), hordelogo.location.get_y() +h)
self.world.add_entity(btn_new)
btn_quit = ButtonImageQuit(self.world)
w,h = btn_new.image.get_size()
btn_quit.location = Vector(btn_new.location.get_x(), btn_new.location.get_y() + h)
self.world.add_entity(btn_quit)
def playerDead(self):
text = DeadText(self.world)
text.location = Vector((screen_size[0]/2),(screen_size[1]/3))
self.world.add_entity(text)
self.world.state = "idle"
def completed(self):
"""Creates a new startup textbox, with specified text, and places it in the location on the specified world
world: Essentially the window to which entities are added to,
should be a World object
entity: Arbitrary label to hold a new TextBox Entity
"""
self.world = World(startup_screen_backdrop)
hordelogo = MainImage(self.world)
hordelogo.location = Vector((screen_size[0]/2),(screen_size[1]/3))
self.world.add_entity(hordelogo)
btn_new = ButtonImageNew(self.world)
w,h = hordelogo.image.get_size()
btn_new.location = Vector(hordelogo.location.get_x(), hordelogo.location.get_y() +h)
self.world.add_entity(btn_new)
btn_quit = ButtonImageQuit(self.world)
w,h = btn_new.image.get_size()
btn_quit.location = Vector(btn_new.location.get_x(), btn_new.location.get_y() + h)
self.world.add_entity(btn_quit)
text = CompletedText(self.world)
text.location = Vector(220,120)
self.world.add_entity(text)
def runGame(self):
"""Creates the sprites essential to playing the game.
places the sprites in a specified location on the specified world
zombie_count: determines how many zombie entities will be created
food_count: determines how many food entities will be created
entity: Arbitrary label to hold a new entity. Should create a specified
entity and place on the specified world
Within the first if statement this function also specifies the state
that the zombie object should adopt (AI)
"""
self.world = World(startup_screen_backdrop)
i = 0
while i < zombie_count:
entity = Zombie(self.world)
entity.location = Vector(randint(80, w), randint(80, h))
entity.brain.set_state("exploring")
self.world.add_entity(entity)
i += 1
i = 0
while i < food_count:
entity = Food(self.world)
entity.location = Vector(randint(100, w), randint(100, h))
#.........这里部分代码省略.........
示例2: run
# 需要导入模块: import World [as 别名]
# 或者: from World import add_entity [as 别名]
def run():
pygame.init()
settings = Settings()
screen = pygame.display.set_mode(settings.SCREEN_SIZE, 0, 32)
world = World()
w, h = settings.WORLD_SIZE
camera = Camera(0, 0)
world.add_camera(camera)
clock = pygame.time.Clock()
hero_img = pygame.image.load("pictures\Top_Down_Survivor_2\Top_Down_Survivor/flashlight\idle\survivor-idle_flashlight_0.png").convert_alpha()
hero = Hero(world, hero_img)
world.add_entity(hero)
Move_Left = False
Move_Right = False
Move_Down = False
Move_Up = False
while True:
for event in pygame.event.get():
if event.type == QUIT:
return
if event.type == KEYDOWN:
if event.key == K_UP:
Move_Down = True
Move_Up = False
elif event.key == K_LEFT:
Move_Right = True
Move_Left = False
elif event.key == K_RIGHT:
Move_Left = True
Move_Right = False
elif event.key == K_DOWN:
Move_Up = True
Move_Down = False
elif event.type == KEYUP:
if event.key == K_UP:
Move_Down = False
elif event.key == K_LEFT:
Move_Right = False
elif event.key == K_RIGHT:
Move_Left = False
elif event.key == K_DOWN:
Move_Up = False
#elif event.type == MOUSEMOTION:
#pos = pygame.mouse.get_pos()
#hero.rotatewithcursor(pos)
camera.moveCamera(Move_Left, Move_Right, Move_Up, Move_Down)
time_passed = clock.tick(30)
world.process(time_passed)
world.render(screen)
pygame.display.update()
示例3: run
# 需要导入模块: import World [as 别名]
# 或者: from World import add_entity [as 别名]
def run():
pygame.display.set_caption("Villager Simulation")
sizes = pygame.display.list_modes()
SCREEN_SIZE = sizes[0]
Owidth, Oheight = SCREEN_SIZE
screen = pygame.display.set_mode(SCREEN_SIZE, FULLSCREEN | HWSURFACE, 32)
fade = CrossFade(screen)
all_sprites = pygame.sprite.Group(fade)
#Load the image the world will be based on, then set the world size proportionate to it
world_img = pygame.image.load("Images/Perlin/SmallMapPerlin.png").convert()
mini_img = pygame.image.load("Images/Perlin/SmallMapPerlin2.png").convert()
size = world_img.get_size()
w_size = size[0]*TILE_SIZE, size[1]*TILE_SIZE
world = World(SCREEN_SIZE, w_size, font, world_img, mini_img)
#world.background = me_double_size(world.background)
Villager_image = pygame.image.load("Images/Entities/Villager.png").convert()
Farmer_image = pygame.image.load("Images/Entities/Farmer.png").convert()
Lumberjack_image = pygame.image.load("Images/Entities/Lumberjack.png").convert()
placing_lumberyard_img = pygame.image.load("Images/Buildings/Dark_LumberYard.png").convert()
placing_lumberyard_img.set_colorkey((255,0,255))
placing_house_img = pygame.image.load("Images/Buildings/Dark_House.png").convert()
placing_house_img.set_colorkey((255,0,255))
placing_dock_img = pygame.image.load("Images/Buildings/Dark_Dock.png").convert()
placing_dock_img.set_colorkey((255,0,255))
placing_manor_img = pygame.image.load("Images/Buildings/Dark_Manor.png").convert()
placing_manor_img.set_colorkey((255,0,255))
bad_lumberyard_img = pygame.image.load("Images/Buildings/Red_Lumberyard.png").convert()
bad_lumberyard_img.set_colorkey((255,0,255))
clip = Clips(world, (Owidth, Oheight))
pygame.image.save(world.minimap_img, "Images/LargeImages/WaterShadeTest.png")
lumber1 = LumberYard(world, lumber_yard_img)
lumber1.location = Vector2(4*TILE_SIZE, 4*TILE_SIZE)
lumber1.tile_x, lumber1.tile_y = 4,4
world.add_entity(lumber1)
for Villager_no in xrange(VILLAGER_COUNT): #Adds all Wood Cutters
villager = Lumberjack(world, Villager_image)
villager.location = lumber1.location.copy()
villager.LastLumberYard = lumber1
villager.brain.set_state("Searching")
world.add_entity(villager)
world.population+=1
for FARMER in xrange(FARMER_COUNT): #Adds all the farmers
farmer = Farmer(world, Farmer_image)
farmer.location = Vector2(20,20)
farmer.brain.set_state("Planting")
world.add_entity(farmer)
world.population+=1
selected_building = "LumberYard"
selected_img = pygame.image.load("Images/Buildings/Dark_LumberYard.png").convert()
selected_img.set_colorkey((255,0,255))
SCREENSHOTNUM = 12
world.clock.tick()
while True:
time_passed = world.clock.tick(60)
time_passed_seconds = time_passed/1000.
pos = Vector2(*pygame.mouse.get_pos())
for event in pygame.event.get():
if event.type == QUIT:
quit()
if event.type == MOUSEBUTTONDOWN:
if ( pos.x > clip.minimap_rect.x and pos.y > clip.minimap_rect.y ):
pass
else:
if event.button == 1 and held == 1:
held = 1
start = Vector2(*pygame.mouse.get_pos())
draw = True
if ( pos.x < clip.side.w ) and (pos.y < clip.side.top_rect.h):
for L in clip.side.tiles:
for T in L:
if T == None:
continue
if T.rect.collidepoint((pos.x, pos.y)):
if T.selected:
T.selected = False
else:
T.selected = True
#.........这里部分代码省略.........