本文整理汇总了Python中Input.update方法的典型用法代码示例。如果您正苦于以下问题:Python Input.update方法的具体用法?Python Input.update怎么用?Python Input.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input.update方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
def draw(self):
Render.clear_layer(5)
self.opened = True
print self.width, self.height
x = 5
y = 5
button_text = 'Close'
button = Button(button_text,
self.width / 2,
self.height - 3,
function=close_window,
target=Render.layers['overlay_console'])
dragging = False
click_x = None
mouse = Input.mouse
while True:
Input.update()
Render.clear_layer(Render.layers['overlay_console'])
Render.draw_rect(Render.layers['overlay_console'], x, y,
self.width,
self.height,
frame=True,
f_color=terminal.color_from_argb(255, 100, 100, 255),
bk_color=terminal.color_from_argb(192, 32, 32, 128),
title="POP_UP TEST!")
Render.print_rect(Render.layers['overlay_console'], x + 2, y + 2, self.width - 4, self.height - 4, self.text)
if mouse.lbutton and x <= mouse.cx <= x + self.width and (mouse.cy == y or dragging):
if click_x is None:
click_x = mouse.cx - x
x = mouse.cx - click_x # (width / 2)
y = mouse.cy
dragging = True
else:
dragging = False
click_x = None
if button.draw(x, y) == 'close':
self.opened = False
Render.clear_layer(Render.layers['overlay_console'])
return
# libtcod.console_flush()
# graphics.draw_image(x, y, enlarge=True)
# graphics.draw_image(x + 1, y + 1, enlarge=True)
# graphics.clear()
# graphics.draw_font(0,0)
GameState.render_ui()
示例2: main
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
def main():
# Loop until the user clicks the close button.
done = False
loopCount = 0
while not done:
loopCount += 1
Input.update()
if(Input.Trigger(Input.Close)):
done = True
map.update()
Graphics.update()
示例3: run
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
def run(self):
global finished
# main event loop
Input.update()
self.finished = Input.finished
self.viewport.run()
Input.reset()
self.clock.tick(FPS)
self.currentFPS = int(self.clock.get_fps())
#fps counter is in the title bar
pygame.display.set_caption(caption % (self.currentFPS))
示例4: beastiary
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
def beastiary(width=10, height=10, title=None, text=None):
# calculate total height for the header (after auto-wrap) and one line per option
if width is None:
width = Constants.MAP_CONSOLE_WIDTH - 10
if height is None:
height = libtcod.console_get_height_rect(0, 0, 0, width, Constants.SCREEN_HEIGHT, text) + 7
pop = libtcod.console_new(width, height)
# print the header, with auto-wrap
libtcod.console_set_default_foreground(pop, Constants.UI_PopFore)
libtcod.console_set_default_background(pop, Constants.UI_PopBack)
libtcod.console_print_frame(pop, 0, 0, width, height, clear=True,
flag=libtcod.BKGND_SET,
fmt=title)
# blit the contents of "window" to the root console
x = 0
y = 0
button_text = 'Click to Continue'
button = Button(button_text,
width / 2,
height - 3,
function=close_window)
img = libtcod.image_load('Images//cipher_warden_80x80_test_01.png')
libtcod.image_set_key_color(img, Color(0, 0, 0))
# show the background image, at twice the regular console resolution
libtcod.image_blit_2x(img, pop, 9, 2)
libtcod.console_set_default_foreground(pop, Constants.UI_PopFore)
libtcod.console_set_default_background(pop, Constants.UI_PopBack)
Render.print_rect(pop, 3, 3, width - 6, height, text)
background = libtcod.console_new(Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT)
libtcod.console_blit(0, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT, background, 0, 0, 1.0, 1.0)
dragging = False
click_x = None
while True:
Input.update()
mouse = Input.mouse
Render.blit(background, 0)
# libtcod.console_blit(background, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT, 0, 0, 0, 1.0, 1.0)
libtcod.console_blit(pop, 0, 0, width, height, 0, x, y, 1.0, .85)
if mouse.lbutton and x <= mouse.cx <= x + width and (mouse.cy == y or dragging):
if click_x is None:
click_x = mouse.cx - x
x = mouse.cx - click_x # (width / 2)
y = mouse.cy
dragging = True
else:
dragging = False
click_x = None
if button.draw(x, y) == 'close':
return
libtcod.console_flush()
示例5: display_mainMenu
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
def display_mainMenu():
# new_game()
width = Constants.SCREEN_WIDTH
height = Constants.SCREEN_HEIGHT
Render.draw_rect(10, 0, 0, width, height,
frame=True,
f_color=Color('dark azure'),
bk_color=Color('darkest azure'),
title="DEEP FRIED SUPERNOVA v0.01")
Render.print_rect(10, 4, 4, width, height, 'Welcome to Deep Fried Supernova')
# blit the contents of "window" to the root console
x = 0
y = 0
button_text = 'New Game'
ng_button = Button(button_text,
width / 2,
height - 12,
length=16,
function=new_game,
target=10)
button_text = 'Continue Game'
ct_button = Button(button_text,
width / 2,
height - 9,
length=16,
function=continue_game,
target=10)
button_text = 'Quit'
qt_button = Button(button_text,
width / 2,
height - 6,
length=16,
function=close_window,
target=10)
img = libtcod.image_load('diner_logo_sm.png')
# libtcod.image_set_key_color(img, Color(0, 0, 0))
# show the background image, at twice the regular console resolution
#libtcod.image_blit_2x(img, mm, 37, 2)
#libtcod.console_blit(mm, 0, 0, width, height, 0, 0, 0, 1.0, 1.0)
while True:
Input.update()
if qt_button.draw(0,0) == 'close':
return
if ct_button.draw(0,0) == 'continue':
return
ng_button.draw(0, 0)
terminal.refresh()
示例6: target_mode
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
def target_mode(source, target=None, ranged_componenet=None):
""" Reset Params """
targets = []
target_x = 0
target_y = 0
if source is None:
source = GameState.get_player()
""" If no target supplied, Enter Targeting mode """
if target is None:
tile_effected = set([])
# Utils.message('Choose Target. Left Click/Space to execute. Right Click/ESC to cancel.', libtcod.gold)
''' Get list of visible enemies to cycle through '''
target_list = GameState.current_level.closest_monsters(ranged_componenet.max_range)
if target_list:
target_list = cycle(target_list)
target = next(target_list)[0]
''' Used to detect mouse movement '''
mouse = Input.mouse
mouse_last_x, mouse_last_y = mouse.cx, mouse.cy
mouse_moved = False
while True:
''' Clear Screen '''
Render.clear_layer(layers['overlay_console'])
"""
Render.draw_rect(layers['overlay_console'], 0, 0,
Constants.MAP_CONSOLE_WIDTH,
Constants.MAP_CONSOLE_HEIGHT,
frame=True,
f_color=terminal.color_from_argb(255, 255, 100, 100),
bk_color=terminal.color_from_name('transparent'),
title="Targeting Mode - Right Click/ESC to Cancel")
# """
''' Get Inputs '''
Input.update()
key = Input.key
''' determine if mouse moved, otherwise use auto-target '''
if mouse.cx != mouse_last_x or mouse.cy != mouse_last_y:
mouse_moved = True
moues_last_x, mouse_last_y = mouse.cx, mouse.cy
if mouse_moved:
target_x, target_y = Utils.to_map_coordinates(mouse.cx, mouse.cy)
elif target:
target_x, target_y = target.x, target.y
else:
target_x, target_y = source.x, source.y
''' determine line of fire (You may not be able to hit every enemy you see) '''
line = Utils.get_line((source.x, source.y),
(target_x, target_y),
walkable=True,
ignore_mobs=True,
max_length=ranged_componenet.max_range)
for point in line:
if point == (None, None):
break
point = Utils.to_camera_coordinates(point[0], point[1])
#libtcod.console_set_char_background(0, point[0], point[1], libtcod.lighter_blue, libtcod.BKGND_SET)
Render.draw_char(layers['overlay_console'], point[0], point[1], 0x2588, terminal.color_from_argb(128, 64, 64, 255))
if len(line) > 0:
index = Utils.find_element_in_list((None, None), line)
if index is None:
point = line[-1]
else:
point = line[index - 1]
circle = Utils.get_circle_points(point[0], point[1], ranged_componenet.aoe)
if circle:
tile_effected = set(circle)
for points in circle:
points = Utils.to_camera_coordinates(points[0], points[1])
Render.draw_char(layers['overlay_console'], points[0], points[1], 0x2588, terminal.color_from_argb(128, 200, 32, 32))
Render.draw_char(layers['overlay_console'], points[0], points[1], 0xE000, terminal.color_from_argb(128, 255, 0, 0))
if mouse.lbutton_pressed or key == terminal.TK_SPACE:
# target_tile = (target_x, target_y)
# print tile_effected
for target in tile_effected:
# target = Map.to_map_coordinates(target[0], target[1])
monster = GameState.current_level.get_monster_at((target[0], target[1]))
if monster is not None:
print "Monster: " + str(monster) + " at " + str(target)
targets.append(monster)
break
if mouse.rbutton_pressed or key == terminal.TK_ESCAPE:
break
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
class Engine:
def __init__(self, screen_size, fps):
self._tmx_root = None # Will be used to store the currently loaded tmx-file:
self._fps = fps # Save fps
self._CLOCK = pygame.time.Clock() # Create pygame.Clock for fps-control
self._draw_tile_ids = False # DEBUG: Draw all ids:
# Create instance of Graphics-Engine:
self.graphics = Graphics(self,screen_size)
# Create instance of World:
self.world = World(self)
# Create instance of input-engine
self.input = Input(self)
# Create actors-controller
self.actors = GameActorController(self)
# Create sound-controller (not jet programmed...)
self.sound = Sound(self)
# Finally, first map (temporary):
self._load_tmx("Forest_N1_1.tmx")
# Var changed by self.load_new_level. If not false, in the next update cycle, the level gets loaded.
self._load_new_level = False
def update(self):
"""
Updates everything. Should be called once per frame.
"""
# Check if new level should be loaded:
if self._load_new_level:
self._load_tmx(self._load_new_level)
self._load_new_level = False
# Handle events:
self._handle_events()
# Update input:
self.input.update()
# Update world:
self.world.update()
# Update Game-Actors:
self.actors.update()
# Update screen:
self.graphics.update()
# Make sure engine doesn't run faster than 60 fps:
self._CLOCK.tick(self._fps)
def _load_tmx(self, filepath):
"""
Loads the tmx-file 'filepath' and parses it.
TODO: Maybe it would be better to move the part that parses tile-csv to the world-class....
"""
# Empty self.actors:
self.actors = GameActorController(self)
# TODO: Find a way to empty self.world
self.world = World(self)
# Open and parse the tmx-file
self._tmx_root = ET.parse(filepath).getroot()
# Get grid-size (in tiles)
grid_size = (int(self._tmx_root.attrib["width"]), int(self._tmx_root.attrib["height"]))
# Set the grid-size in the world:
self.world.set_gid_size(grid_size)
# Get tile-size (in pixels)
tile_size = (int(self._tmx_root.attrib["tilewidth"]), int(self._tmx_root.attrib["tileheight"]))
# Set the tile-size in the world:
self.world.set_tile_size(tile_size)
######
# Next, process the tilesets:
# For tileset..
for tileset in self._tmx_root.findall("tileset"):
# If tileset is "world":
if tileset.attrib["name"] == "world":
# Dor tile in this tileset:
for tile in tileset.findall("tile"):
# For property in tile:
for property in tile.find("properties").findall("property"):
# Update tile-property
self.world.set_tile_property(int(tile.attrib["id"]), property.attrib["name"], property.attrib["value"])
######
# Next, process the layers: Where is what tile?
# For every layer...
all_layers = self._tmx_root.findall("layer")
for layer in range(len(all_layers)):
# Get and save the raw csv data which contains information about where which tile is:
csv_data = all_layers[layer].find("data").text
# First, split the csv in rows:
splitted_data = csv_data.split("\n")
# For row in csv_data:
for row in range(len(splitted_data)):
# Make sure the row isn't empty:
if not splitted_data[row] == "":
splitted_row = splitted_data[row].split(",")
# For column in csv_data (= for tile)
for column in range(len(splitted_row)):
#.........这里部分代码省略.........
示例8: __init__
# 需要导入模块: import Input [as 别名]
# 或者: from Input import update [as 别名]
class Controller:
mouseSensitivity = 0.15
movementSpeed = 0.005
def __init__(self):
self.model = None
self.view = None
self.running = True
self.t = pygame.time.get_ticks()
self.input = Input()
self.wireframe = False
#self.input.mouseEntersScreen = lambda: pygame.mouse.set_pos(640/2, 480/2)
def update(self):
tiempoActual = pygame.time.get_ticks()
dt = tiempoActual - self.t
self.t = tiempoActual
(mouseX,mouseY) = pygame.mouse.get_pos()
(dx,dy) = pygame.mouse.get_rel()
self.input.update()
if self.input.isCloseRequested:
self.running = False
if self.input.keyPress(pygame.K_ESCAPE):
self.running = False
self.view.camera.yaw(dx * Controller.mouseSensitivity)
self.view.camera.pitch(dy * Controller.mouseSensitivity)
if self.input.keyRelease(pygame.K_f):
pygame.display.toggle_fullscreen()
self.view.reshape()
if self.input.keyHold(pygame.K_w):
self.view.camera.walkForward(Controller.movementSpeed*dt)
if self.input.keyHold(pygame.K_s):
self.view.camera.walkBackwards(Controller.movementSpeed*dt)
if self.input.keyHold(pygame.K_a):
self.view.camera.strafeLeft(Controller.movementSpeed*dt)
if self.input.keyHold(pygame.K_d):
self.view.camera.strafeRight(Controller.movementSpeed*dt)
if self.input.keyHold(pygame.K_SPACE):
self.view.camera.moveUp(Controller.movementSpeed*dt)
if self.input.keyHold(pygame.K_LSHIFT):
self.view.camera.moveDown(Controller.movementSpeed*dt)
if (not self.wireframe) and self.input.keyPress(pygame.K_p):
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE )
self.wireframe = True
elif self.wireframe and self.input.keyPress(pygame.K_p):
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL )
self.wireframe = False
fx,fy,fz = self.view.camera.getFocus()
fx,fy,fz = int(fx),int(fy),int(fz)
if self.input.buttonPress(1):
#print fx,fy,fz
self.model.set(fx,fy,fz,4)
elif self.input.buttonPress(3):
#print fx,fy,fz
self.model.set(fx,fy,fz,0)
def close(self):
pygame.quit()