本文整理汇总了Python中World.World.update方法的典型用法代码示例。如果您正苦于以下问题:Python World.update方法的具体用法?Python World.update怎么用?Python World.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World.World
的用法示例。
在下文中一共展示了World.update方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
class Application:
def __init__(self):
pygame.init()
pygame.display.set_caption('SideScroller')
pygame.display.set_mode([1024,600])
self.world = World()
self.world.addManager('player',MovementManager())
self.world.addManager('scrollable',ScrollManager())
self.world.addManager('friction',FrictionManager())
self.world.load('lvl/maps.txt','lvl/1.txt')
self.clock = pygame.time.Clock()
self.go = True
def loop(self):
while self.go:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
sys.exit()
self.clock.tick(60)
self.world.update( events )
self.world.draw(pygame.display.get_surface())
pygame.display.flip()
示例2: __init__
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
#.........这里部分代码省略.........
abs_ee_poses = [Arms.get_ee_state(0),
Arms.get_ee_state(1)]
joint_poses = [Arms.get_joint_state(0),
Arms.get_joint_state(1)]
states = [None, None]
for arm_index in [0, 1]:
nearest_obj = self.world.get_nearest_object(
abs_ee_poses[arm_index])
if (nearest_obj == None):
states[arm_index] = ArmState(ArmState.ROBOT_BASE,
abs_ee_poses[arm_index],
joint_poses[arm_index], Object())
else:
# Relative
rel_ee_pose = World.transform(
abs_ee_poses[arm_index],
'base_link', nearest_obj.name)
states[arm_index] = ArmState(ArmState.OBJECT,
rel_ee_pose,
joint_poses[arm_index], nearest_obj)
return states
def execute_action(self, dummy=None):
'''Starts the execution of the current action'''
if (self.session.n_actions() > 0):
if (self.session.n_frames() > 0):
self.session.save_current_action()
action = self.session.get_current_action()
if (action.is_object_required()):
if (self.world.update_object_pose()):
self.session.get_current_action().update_objects(
self.world.get_frame_list())
self.arms.start_execution(action)
else:
return [RobotSpeech.OBJECT_NOT_DETECTED,
GazeGoal.SHAKE]
else:
self.arms.start_execution(action)
return [RobotSpeech.START_EXECUTION + ' ' +
str(self.session.current_action_index), None]
else:
return [RobotSpeech.EXECUTION_ERROR_NOPOSES + ' ' +
str(self.session.current_action_index), GazeGoal.SHAKE]
else:
return [RobotSpeech.ERROR_NO_SKILLS, GazeGoal.SHAKE]
def speech_command_cb(self, command):
'''Callback for when a speech command is receieved'''
if command.command in self.responses.keys():
rospy.loginfo('\033[32m Calling response for command ' +
command.command + '\033[0m')
response = self.responses[command.command]
if (not self.arms.is_executing()):
if (self._undo_function != None):
response.respond()
self._undo_function = None
else:
response.respond()
else:
if command.command == Command.STOP_EXECUTION:
示例3: str
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
if event.key == pygame.K_UP:
world.herosayjin.move(0, -10)
if event.key == pygame.K_DOWN:
world.herosayjin.move(0, 10)
if event.key == pygame.K_SPACE:
world.herosayjin.fire()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
world.herosayjin.move(10, 0)
if event.key == pygame.K_RIGHT:
world.herosayjin.move(-10, 0)
if event.key == pygame.K_UP:
world.herosayjin.move(0, 10)
if event.key == pygame.K_DOWN:
world.herosayjin.move(0, -10)
screen.blit(image_background, (0, 0))
label = myfont.render("Life:" + str(world.health), 1, (0, 0, 0))
screen.blit(label, (world.width - label.get_width(), 0))
label = myfont.render("Points:" + str(world.points), 1, (0, 0, 0))
screen.blit(label, (0, 0))
world.update()
world.draw(screen)
pygame.display.flip()
clock.tick(20)
pygame.quit()
示例4: main
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
#.........这里部分代码省略.........
if event.key == pygame.K_1 or event.key == pygame.K_KP1:
enemy_type = "Ghoul"
if event.key == pygame.K_2 or event.key == pygame.K_KP2:
enemy_type = "Bat"
if event.key == pygame.K_w:
inputs["up"] = True
if event.key == pygame.K_s:
inputs["down"] = True
if event.key == pygame.K_a:
inputs["left"] = True
if event.key == pygame.K_d:
inputs["right"] = True
if event.key == pygame.K_SPACE:
inputs["a"] = True
if event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
inputs["b"] = True
if event.type == pygame.KEYUP:
if event.key == pygame.K_w:
inputs["up"] = False
if event.key == pygame.K_s:
inputs["down"] = False
if event.key == pygame.K_a:
inputs["left"] = False
if event.key == pygame.K_d:
inputs["right"] = False
if event.key == pygame.K_SPACE:
inputs["a"] = False
if event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
inputs["b"] = False
#MAIN UPDATING PROCEDURE
world.update(inputs)
#BEGIN DRAWING PROCEDURES
leftx = camerax + window_width / 4
rightx = camerax + window_width - (window_width/4)
if world.simon.rect.x < leftx:
camerax -= world.simon.move
elif world.simon.rect.x > rightx:
camerax += world.simon.move
topy = cameray + window_height / 4
bottomy = cameray + window_height - (window_height/4)
if world.simon.rect.y < topy:
cameray -= 1
elif world.simon.rect.y > bottomy:
cameray += 5
camera = pygame.Rect(camerax, cameray, window_width, window_height)
screen.fill(bg_color)
screen.blit(world.background, (-camerax, -cameray))
for sprite in world.all_sprites:
if camera.colliderect(sprite.rect):
screen.blit(sprite.image,
(sprite.rect.x-camera.x-sprite.hitboxoffset,
sprite.rect.y-camera.y))
if debugging_masks:
box = world.goal
pygame.draw.rect(screen, (255, 0, 0), (box.x-camera.x,
box.y-camera.y,
示例5: World
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
done = False
world = World()
debug = True
#################
### Game loop ###
#################
while not done:
# Read cotrols
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
world.hero.startJump()
elif event.type == pygame.KEYUP:
if event.key == pygame.K_w:
world.hero.endJump()
# Update
world.update(pygame.key.get_pressed())
#Render
world.render(screen)
pygame.display.flip()
clock.tick(60)
# Be IDLE friendly
pygame.quit()
示例6: gui
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
class gui():
def __init__(self):
self.world = World(200, 200)
self.animal_info_window = None
builder = Gtk.Builder()
builder.add_from_file("MainWindow.glade")
builder.connect_signals(self)
self.window = builder.get_object("applicationwindow1")
self.drawing_area = builder.get_object("drawingarea1")
self.debug_lbl = builder.get_object("debug_lbl")
self.window.realize()
self.window.set_reallocate_redraws(True)
self.window.set_title("Animals")
self.window.connect('delete_event', Gtk.main_quit)
self.window.connect('destroy', lambda quit: Gtk.main_quit())
self.scrollbar1 = builder.get_object("scrollbar1")
self.window.show_all()
self.timer_interval = builder.get_object("timer_adjustment").get_value()
self.timer_id = GObject.timeout_add(self.timer_interval, self.on_timer_event)
self.selected_animal = None
self.is_food_smell = False
self.world_version = 0
self.restart_if_all_dead = True
self.dbg_text = ""
def on_configure(self, widget, event):
self.world.width = widget.get_allocated_width()
self.world.height = widget.get_allocated_height()
return True
def on_draw(self, widget, cr):
#Animals
for animal in self.world.animals:
if animal == self.selected_animal:
cr.set_source_rgb(1, 0.84, 0)
else:
cr.set_source_rgb(0.6, 0.7, 0.5)
cr.arc(animal.x, animal.y, animal.size, 0, TWO_PI)
cr.fill()
cr.set_source_rgb(0,0,0)
for x, y in animal.sensors_positions:
cr.arc(x, y, 1, 0, TWO_PI)
cr.fill()
cr.move_to(animal.x, animal.y)
cr.line_to(animal.x+math.cos(animal.angle)*animal.size,
animal.y+math.sin(animal.angle)*animal.size)
cr.stroke()
for food in self.world.food:
cr.set_source_rgb(0.3, 0.3, 0.3)
cr.arc(food.x, food.y, food.size, 0, TWO_PI)
cr.fill()
cr.arc(food.x, food.y, World.MAX_EATING_DISTANCE + food.size, 0, TWO_PI)
cr.set_line_width(0.1)
cr.stroke()
if self.is_food_smell:
r1 = cairo.RadialGradient(food.x, food.y, food.size, food.x, food.y, food.smell_size)
r1.add_color_stop_rgba(0, 0.3, 0.6, 0.3, 0.2)
r1.add_color_stop_rgba(1, 0.3, 0.6, 0.3, 0.01)
cr.set_source(r1)
cr.arc(food.x, food.y, food.smell_size, 0, TWO_PI)
cr.fill()
return False
def on_timer_event(self):
self.world.update()
if self.animal_info_window:
self.animal_info_window.update_graphics()
self.animal_info_window.drawing_area1.queue_draw()
self.animal_info_window.drawing_area2.queue_draw()
self.drawing_area.queue_draw()
self.add_to_dbg("world version={}".format(self.world_version))
self.add_to_dbg("animal count=" + str(len(self.world.animals)))
self.add_to_dbg("world time={}".format(self.world.time))
self.debug_lbl.set_text(self.dbg_text)
self.dbg_text = ""
if self.restart_if_all_dead and len(self.world.animals) == 0:
self.world.restart()
self.world_version += 1
return True
def add_to_dbg(self, text):
self.dbg_text += text + "\n"
#.........这里部分代码省略.........
示例7: main
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
#.........这里部分代码省略.........
current_state = "menu"
pygame.display.flip()
elif current_state == "links":
if main_menu.links(screen,mouse_pos,time_passed_seconds) == "link":
current_state = "menu"
pressed_keys = pygame.key.get_pressed()
if pressed_keys[pygame.K_ESCAPE]:
current_state = "menu"
pygame.display.flip()
elif current_state == "level select":
selected_level = main_menu.level_select(screen, mouse_pos, time_passed_seconds, main_world)
if selected_level is not None:
current_state = "game"
main_world.game_over = False
pygame.mixer.music.stop()
main_world.set_up_level(selected_level)
main_world.level_index = main_world.levels.index(selected_level)
pressed_keys = pygame.key.get_pressed()
if pressed_keys[pygame.K_ESCAPE]:
current_state = "menu"
pygame.display.flip()
elif current_state == "credits":
main_menu.credits(screen,mouse_pos,time_passed_seconds)
pressed_keys = pygame.key.get_pressed()
if pressed_keys[pygame.K_ESCAPE]:
current_state = "menu"
pygame.display.flip()
elif current_state == "game":
movement = vec2()
pressed_keys = pygame.key.get_pressed()
if pressed_keys[pygame.K_a]:
movement.x -= 1
if pressed_keys[pygame.K_d]:
movement.x += 1
if pressed_keys[pygame.K_w]:
movement.y -= 1
if pressed_keys[pygame.K_s]:
movement.y += 1
if pressed_keys[pygame.K_SPACE]:
main_world.player.fullscan(mouse_pos)
pressed_buttons = pygame.mouse.get_pressed()
if pressed_buttons[0]:
main_world.player.shoot(mouse_pos)
if pressed_buttons[2]:
main_world.player.firewall(mouse_pos)
"""Update"""
main_world.update(mouse_pos, movement, time_passed_seconds)
"""Render"""
screen.fill((0, 0, 0))
main_world.render(screen)
fps_string = "[FPS: {:.4}]".format(clock.get_fps())
caption_string = "Sector Shoot-em-up! Current level: " + main_world.levels[main_world.level_index] + ". " + fps_string
pygame.display.set_caption(caption_string)
if main_world.game_over:
current_state = "lose"
sleep_timer = 3
if main_world.game_won:
current_state = "win"
sleep_timer = 3
pygame.display.flip()
elif current_state == "lose":
screen.fill((0, 0, 0))
main_font = pygame.font.Font(None, 40)
screen.blit(main_font.render(("GAME OVER!"),
True, (0, 0, 204)), (400, 300))
pygame.display.flip()
sleep_timer -= time_passed_seconds
if sleep_timer <= 0:
current_state = "menu"
elif current_state == "win":
screen.fill((0, 0, 0))
main_font = pygame.font.Font(None, 40)
screen.blit(main_font.render(("YOU WON!"),
True, (0, 0, 204)), (400, 300))
pygame.display.flip()
sleep_timer -= time_passed_seconds
if sleep_timer <= 0:
current_state = "menu"
pygame.quit()
示例8: MyBot
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import update [as 别名]
class MyBot(object):
"""
The Bot is charged with recieving commands from the server,
updating the internal world state, and sending commands
back to the game server.
"""
def __init__(self, stdin, stdout, stderr):
"""
This method enters the input/output loop and never returns.
"""
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.state = None
game_params = self.get_game_params(stdin)
self.world = World(game_params)
self.finish_turn()
self.take_turns(stdin)
@token_loop
def take_turns(self, tokens):
" Take turns, when we're told to go. "
if tokens[0] == 'go':
self.world.update(self.state['map_data'])
self.do_turn()
self.state['map_data'] = []
else:
self.state['map_data'].append(tokens)
@token_loop
def get_game_params(self, tokens):
"""
Get the game's initial parameters
Currently all values are 32bit signed integers,
except player_seed is a 64bit signed integer.
"""
if tokens[0] == 'ready':
return self.state
else:
key, val = tokens
self.state[key] = int(val)
def issue_order(self, order):
'issue an order by writing the proper ant location and direction'
(row, col), direction = order
self.stdout.write('o %s %s %s\n' % (row, col, direction))
self.stdout.flush()
def finish_turn(self):
'finish the turn by writing the go line'
self.stdout.write('go\n')
self.stdout.flush()
def do_turn(self):
"""
do turn is run once per turn
"""
# loop through all my ants and try to give them orders
# the ant_loc is an ant location tuple in (row, col) form
for ant_loc in self.world.my_ants():
# try all directions in given order
directions = ('n', 'e', 's', 'w')
for direction in directions:
# the destination method will wrap around the map properly
# and give us a new (row, col) tuple
new_loc = self.world.map.destination(ant_loc, direction)
# passable returns true if the location is land
if (self.world.map.passable(new_loc)):
# an order is the location of a current ant and a direction
self.issue_order((ant_loc, direction))
# stop now, don't give 1 ant multiple orders
break
# check if we still have time left to calculate more orders
if self.world.time_remaining() < 10:
break
self.finish_turn()