本文整理汇总了Python中GameState类的典型用法代码示例。如果您正苦于以下问题:Python GameState类的具体用法?Python GameState怎么用?Python GameState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GameState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play_animation
def play_animation(self, animation_name, source, target_x, target_y):
animation_params = {}
animation_params['origin'] = (source.x, source.y)
animation_params['target'] = (target_x, target_y)
animation_params['target_angle'] = Utils.get_angle(source.x, source.y, target_x, target_y)
GameState.add_animation(animation_name, animation_params)
示例2: explosive_death
def explosive_death(monster):
# transform it into a nasty corpse! it doesn't block, can't be
# attacked and doesn't move
# TODO: String build this message more inteligently
Utils.message('The ' + monster.name + ' EXPLODES!!!!! You gain ' + str(monster.fighter.xp) + ' experience points.',
libtcod.orange)
monster.char = ' '
monster.color = None
monster.blocks = False
monster.fighter = None
monster.ai = None
monster.name = ''
GameState.schedule.release(monster)
animation_params = {}
animation_params['origin'] = (monster.x, monster.y)
animation_params['target'] = (monster.x, monster.y)
GameState.add_animation('Burst', animation_params)
# TODO: Damage surrounding things.....
ranged_component = Ranged(0, aoe=3)
# TODO: BORKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
UI.target_mode(monster, target=monster.pos, ranged_componenet=ranged_component)
monster.send_to_back()
示例3: draw
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()
示例4: objects
def objects():
# libtcod.console_clear(consoles['entity_console'])
Utils.clear_layer(layers['entity_console'])
for object in Map.get_all_objects():
if object != GameState.get_player():
object.draw()
GameState.get_player().draw()
示例5: process_mouse_clicks
def process_mouse_clicks(self, mouse):
(map_x, map_y) = Utils.to_map_coordinates(mouse.cx, mouse.cy)
if map_x is not None and map_y is not None:
# walk to target tile
if mouse.lbutton_pressed and GameState.continue_walking:
GameState.continue_walking = False
self.owner.clear_path()
return 0
if mouse.lbutton_pressed and GameState.current_level.is_explored(map_x, map_y):
self.owner.clear_path()
GameState.continue_walking = self.owner.move_astar_xy(map_x, map_y, True)
return self.end_turn(Constants.TURN_COST)
if mouse.rbutton_pressed:
GameState.continue_walking = False
self.owner.clear_path()
GameState.current_level.require_recompute()
animation_params = {}
animation_params['origin'] = (self.owner.x, self.owner.y)
animation_params['target'] = (self.owner.x, self.owner.y)
animation_params['target_angle'] = 0
GameState.add_animation('Teleport', animation_params)
self.owner.x, self.owner.y = Utils.to_map_coordinates(mouse.cx, mouse.cy)
animation_params = {}
animation_params['origin'] = (self.owner.x, self.owner.y)
animation_params['target'] = (self.owner.x, self.owner.y)
animation_params['target_angle'] = 0
GameState.add_animation('Teleport', animation_params)
return 1
return 0
示例6: message
def message(new_msg, color=None):
import textwrap
# split the message if necessary, among multiple lines
if len(GameState.get_msg_queue()) == Constants.MSG_HEIGHT:
GameState.del_msg(0)
GameState.add_msg(new_msg)
'''
示例7: StateMachine
class StateMachine(State, Receiver, InputHandler):
__states = {}
# _startState = StartState()
# _creditState = CreditsState()
# _gameState = GameState()
# _charSelectState = CharSelectState()
def __init__(self, type, aBatch, aBackground, aForeGround, aWindow, aMessenger):
self._type = type
self._startState = StartState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._creditState = CreditsState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._gameState = GameState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._charSelectState = CharSelectState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._charSettings = SettingsState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self.__states = {self._startState, self._creditState, self._gameState, self._charSelectState, self._charSettings}
def onEnter(self):
pass
def onExit(self):
pass
def onReceive(self, message):
if message.msg == States.Start:
self.setNotActive()
self._startState.onEnter()
elif message.msg == States.Credits:
self.setNotActive()
self._creditState.onEnter()
elif message.msg == States.Game:
self.setNotActive()
self._gameState.onEnter()
elif message.msg == States.CharSelect:
self.setNotActive()
self._charSelectState.onEnter()
elif message.msg == States.Settings:
self.setNotActive()
self._charSettings.onEnter()
def setNotActive(self):
for state in self.__states:
if state.isActive:
state.onExit()
state._active = False
def handleKeyPress(self, symbol, modifiers):
for state in self.__states:
if state.isActive:
state.handleKeyPress(symbol, modifiers)
def handleKeyRelease(self, symbol, modifiers):
for state in self.__states:
if state.isActive:
state.handleKeyRelease(symbol, modifiers)
示例8: take_turn
def take_turn(self):
# a basic monster takes its turn. If you can see it, it can see you
monster = self.owner
player = GameState.get_player()
if GameState.current_level.is_visible(obj=monster):
self.active = True
GameState.continue_walking = False
# move towards player if far away
if self.active:
dist = monster.distance_to(player)
if dist > self.attack_range:
# monster.move_astar(player)
self.reload -= 1
# close enough, attack! (if the player is still alive.)
elif player.fighter.hp > 0 and self.reload <= 0 and GameState.current_level.is_visible(obj=monster):
""" DISABLE """
#Animate.follow_line(self.owner, player)
self.play_animation('Shot', self.owner, player.x, player.y )
monster.fighter.attack(player)
self.reload = 3
else:
# Move away?
self.reload -= 1
return Constants.TURN_COST
示例9: inspect_tile
def inspect_tile(x, y):
global delay, map_old_x, map_old_y, new_animation
if 0 < x < Constants.MAP_CONSOLE_WIDTH and 0 < y < Constants.MAP_CONSOLE_HEIGHT:
# Mouse over Inspection
camera_x, camera_y = GameState.get_camera()
map_x, map_y = (camera_x + x, camera_y + y)
if map_x is map_old_x and map_y is map_old_y:
if time.time() - delay > Constants.INSPECTION_DELAY:
# Post-Delay
if GameState.current_level.map_array[map_x][map_y].explored:
obj = [obj for obj in GameState.current_level.get_all_objects() if obj.x == map_x and obj.y == map_y]
if len(obj) == 0:
pass
else:
# print "animating..."
#TODO: Re-implement Inspection (make a mode, not always on)
#Animate.inspect_banner(x, y, obj[0].name, new_animation)
new_animation = False
else:
# Pre-Delay
pass
else:
# 88Render.clear_animations()
new_animation = True
map_old_x = map_x
map_old_y = map_y
delay = time.time()
示例10: executeTopAction
def executeTopAction(self, action):
game = self._game
gameState = GameState(game)
game.processAction(action, True)
atMaxDepth = (self._depth >= game._maxSimulationDepth)
if game.deathTokens() == 0:
score = -1000
elif not atMaxDepth:
game.iteratePlayerIndex()
score = game.simulateSingleTurn(self)
else:
score = game.score(self.initialPlayer)
gameState.restoreGame()
return score
示例11: __init__
def __init__(self, type, aBatch, aBackground, aForeGround, aWindow, aMessenger):
self._type = type
self._startState = StartState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._creditState = CreditsState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._gameState = GameState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._charSelectState = CharSelectState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self._charSettings = SettingsState(aBatch, aBackground, aForeGround, aWindow, type, aMessenger)
self.__states = {self._startState, self._creditState, self._gameState, self._charSelectState, self._charSettings}
示例12: draw_stat_bars
def draw_stat_bars():
pos = Pos(Constants.MAP_CONSOLE_WIDTH + 4, 35)
# SHOW PLAYER STAT BARS
draw_box_bar(pos.x, pos.y, 14, '', GameState.get_player().fighter.hp, GameState.get_player().fighter.base_max_hp,
Color("178, 0, 45"),
Color("64, 0, 16"), layers['side_panel_console'])
draw_box_bar(pos.x, pos.y + 1, 14, '', GameState.get_player().fighter.sp, GameState.get_player().fighter.base_max_sp,
Color("0, 30, 255"),
Color("0, 10, 64"), layers['side_panel_console'])
draw_box_bar(pos.x, pos.y + 2, 14, '', GameState.get_player().fighter.xp, 1000, # TODO: will be NEXT_LVL_XP
Color("255, 255, 0"),
Color("65, 65, 0"), layers['side_panel_console'])
# RENDER MONSTER HEALTH BARS
temp_y = 3
for object in GameState.get_visible_objects():
if object.fighter and (object is not GameState.get_player()): # and Fov.is_visible(obj=object)
if temp_y < 17: # TODO: Make constant to scale UI
draw_box_bar(Constants.MAP_CONSOLE_WIDTH + 1, temp_y, 17, object.name, object.fighter.hp, object.fighter.max_hp,
Color("0, 255, 0"),
Color("0, 64, 0"),
layers['side_panel_console'])
temp_y += 2
示例13: render_messages
def render_messages():
Render.clear_layer(layers['messages'])
y = 3 + Constants.MAP_CONSOLE_HEIGHT
for line in GameState.get_msg_queue():
if y < Constants.SCREEN_HEIGHT - 1:
line_height = 1
Render.print_rect(layers['messages'], Constants.MSG_X, y, Constants.MSG_WIDTH, line_height, line)
y += line_height
示例14: equip
def equip(self):
# if the slot is already being used, dequip whatever is there first
old_equipment = GameState.get_equipped_in_slot(self.slot)
if old_equipment is not None:
old_equipment.dequip()
# equip object and show a message about it
self.is_equipped = True
Utils.message('Equipped ' + self.owner.name + ' on ' + self.slot + '.', libtcod.light_green)
示例15: newGame
def newGame( self, numPlayers ):
print 'New Game of', numPlayers, 'players'
self.gameState = GameState()
self.gameState.init_new(numPlayers, now())
self.state = 'REGISTRATION'
self.findXMLFileName()
self.mainloop(numPlayers)