本文整理汇总了Python中Camera.Camera.update方法的典型用法代码示例。如果您正苦于以下问题:Python Camera.update方法的具体用法?Python Camera.update怎么用?Python Camera.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera.Camera
的用法示例。
在下文中一共展示了Camera.update方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
def setup():
global prevFrame, frame, mCamera
global mDetector, mCascade
global POWS, GPIOS, powVals, gpioVals
global mSynth
sc.start()
mSynth = sc.Synth("fmSynth")
#mSynth = sc.Synth("PMCrotale")
GPIO.setmode(GPIO.BCM)
for pin in (POWS+GPIOS):
GPIO.setup(pin, GPIO.OUT)
mCamera = Camera(CAM_RES)
mCamera.update()
frame = cv2.blur(cv2.cvtColor(mCamera.frame, cv2.COLOR_RGB2GRAY), (4,4))
prevFrame = frame
# Setup SimpleBlobDetector parameters.
mParams = cv2.SimpleBlobDetector_Params()
mParams.minThreshold = 16;
mParams.maxThreshold = 32;
mParams.filterByArea = True
mParams.minArea = 64
mParams.maxArea = 10e3
mParams.filterByConvexity = True
mParams.minConvexity = 0.001
mParams.filterByInertia = True
mParams.minInertiaRatio = 0.001
mDetector = cv2.SimpleBlobDetector(mParams)
mCascade = None
if len(sys.argv) > 1:
mCascade = cv2.CascadeClassifier(sys.argv[1])
else:
print "Please provide a cascade file if you want to do face/body detection."
示例2: Level
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
class Level():
def __init__(self, w, h, filename, data_dir):
self.width = w
self.height = h
self._data_dir = data_dir
os.chdir(self._data_dir)
self.background = pygame.Surface((self.width, self.height))
self.background = self.background.convert()
self.background.fill((153, 217, 234))
self.objects = pygame.sprite.LayeredUpdates()
self.gravity = .5
self.camera = Camera(800, 600)
self._filename = filename
self._load_objects()
self.player = self._get_player_from_objects()
self.input_binds = []
self.gui_manager = GuiManager()
self.build_manager = BuildManager(self.spawn_object)
def get_filename(self):
return self._filename
def _get_player_from_objects(self):
for obj in self.objects:
if obj.type == PLAYER:
return obj
return None
def get_obj(self, obj_name):
for obj in self.objects:
if obj_name == obj.name:
return obj
return None
def _load_objects(self):
obj_filename = os.path.join('level_data', self._filename)
parser = configparser.ConfigParser()
if obj_filename not in parser.read(obj_filename):
print(obj_filename + 'not found/cant be read')
object_list = parser.sections()
for objname in object_list:
obj_type = parser[objname]['type']
var_dict = {'name': objname}
for option in parser[objname]:
value = parser[objname][option]
var_dict[option] = to_num(value)
self.objects.add(ObjFactory(obj_type, var_dict))
def clear(self):
while self.objects:
cur_layer = self.objects.get_top_layer()
self.objects.remove_sprites_of_layer(cur_layer)
self.background.fill((153, 217, 234))
def load(self, new_file=None):
if new_file:
self._filename = new_file
self.clear()
self._load_objects()
self.player = self._get_player_from_objects()
def update(self):
#update object positions
for obj in self.objects:
obj.update()
if obj.obey_gravity:
obj.do_gravity(self.gravity)
if obj.type == BUILD_PROC:
self.build_manager.check_build(obj)
self.check_collisions()
self.camera.update(self.player)
def draw(self, screen):
screen.blit(self.background, (0, 0))
for sprite_layer in self.objects.layers():
for sprite in self.objects.get_sprites_from_layer(sprite_layer):
if self.camera.on_screen(sprite.rect) and sprite.visible:
translated = self.camera.translate_to(sprite.rect)
sprite.draw(screen, translated)
#calls collide for each object against each object besides itself
#objects' collide function carries out what it means to collide and how to respond
def check_collisions(self):
for a_obj in self.objects:
for b_obj in self.objects:
if a_obj == b_obj:
continue
a_obj.collide(b_obj)
def objects_at(self, x, y):
col_objs = [obj for obj in self.objects if obj.rect.collidepoint(x, y)]
if col_objs:
return col_objs
else:
return None
def spawn_object(self, var_dict):
self.objects.add(ObjFactory(var_dict['type'], var_dict))
示例3: str
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
elif game_state == 'Playing':
if keys_pressed[pygame.K_SPACE]:
if player.on_any_platform(platform_controller, floor):
player.sprite_index_y = 3
if player.vel_y >= JUMP_VELOCITY/2:
player.vel_y = -JUMP_VELOCITY
player.update()
player.combo()
player.collide_platform(floor,0)
platform_controller.collide_set(player)
platform_controller.score = player.score
camera.update(player.score)
platform_controller.generate_new_platforms(camera)
if player.fallen_off_screen(camera):
game_state = 'Game Over'
# game_display.fill(black)
# image = pygame.transform.scale(image, (800,desired_height))
game_display.blit(background,(0,0))
floor.draw(game_display, camera)
platform_controller.draw(game_display, camera)
player.draw(game_display, camera)
message_display(game_display, str(player.score), 25, 30, 36, white)
示例4: Level
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
class Level(object):
def __init__(self, window, space, filename, input_handler, game_clock):
self.music = 'elec_Spin.wav'
# Open level file
self.window = window
self.space = space
self.name = filename
self.input_handler = input_handler
self.game_clock = game_clock
self.game_clock.reset()
#next level default is none
self.next_level = "none"
# Load level background and the objects in the level
# level_width, level_width, background, powerups, platforms
self._load(self.name)
self.player = Player()
self.player.body.position.x = 0
self.player.body.position.y = 100
self.gameobjects = pygame.sprite.Group()
# Add objects to space
self.player.add_to(self.space)
for p in self.platforms:
p.add_to(self.space)
for p in self.powerups:
p.add_to(self.space)
# Bind input
input_handler.bind_player(self.player) # Remember to unbind on level end
# Create camera
self.camera = Camera(self.window, self.level_width, self.level_height, self.player)
print 'current level: ', self.name
print 'next level: ', self.next_level
def update(self):
self.space.step(1.0/self.window.framerate)
self.camera.update()
if not self.player.alive:
self.reload()
self.player.update(self.level_width)
# Keep the player within the level
self._constrain_to_level(self.player)
for p in self.platforms:
p.update()
for p in self.powerups:
p.update
collisions.PlayerZiplineCollision.post_collision_callback(self.space, self.player)
collisions.PowerupCollision.post_collision_callback()
def draw(self, screen):
# Display Background
screen.fill([0,0,0])
screen.blit(self.background, (0-Camera.offset_x, 600-self.background.get_height()+Camera.offset_y))
#self.background.draw(screen)
# Environment
for p in self.platforms:
p.draw(screen)
# Powerups
for p in self.powerups:
p.draw(screen)
# Player
self.player.draw(screen)
# Draw UI
self.game_clock.draw(screen)
def delete(self):
# Remove all objects contained in this level from the pymunk space, and mark for gc
for p in self.platforms:
p.delete()
# Powerups
for p in self.powerups:
p.delete()
self.player.delete()
def reload(self):
# Pop current state off the stack and replace with an identical one
old_state = self.window.pop_state()
state = Level(self.window, old_state.space, old_state.name, old_state.input_handler, old_state.game_clock)
#.........这里部分代码省略.........
示例5: Level
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
class Level(Scene):
def __init__(self, director, player):
Scene.__init__(self, director)
self.player = player
self.enemyGroup = EntityGroup([])
self.bulletGroup = EntityGroup([])
self.groups = []
self.groups.append(self.enemyGroup)
self.groups.append(self.bulletGroup)
self.bg = None
self.collisionBg = None
self.camera = Camera()
self.HUD = HUD(self.director, (0, 467), True, player)
hudLayer = Layer(self.director)
hudLayer.append(self.HUD)
self.layers.append(hudLayer)
self.mouseHoveringHUD = False
self.danger = False
self.dangerLevel = 0
self.gameOver = False
def update(self, time):
if self.gameOver:
mainMenu = MainMenu.MainMenu(self.director)
self.director.setScene(mainMenu)
return
if self.danger:
self.dangerLevel = 210
self.danger = False
if self.collisionBg != None:
self.player.update(time, self)
for group in self.groups:
group.update(time, self)
self.camera.update(self.player)
Scene.update(self, time)
if self.gameOver:
game_over_scene = MessageScene(self.director, self)
game_over_scene.set_message("Has Muerto.")
self.director.setScene(game_over_scene)
def processEvent(self, event):
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
m = MessageScene(self.director, self)
self.director.setScene(m)
self.player.controller.processEvent(event)
Scene.processEvent(self, event)
def drawDanger(self, screen):
if self.dangerLevel > 0:
s = pygame.Surface((1000,750)) # the size of your rect
s.set_alpha(self.dangerLevel) # alpha level
s.fill((255, 0, 0)) # this fills the entire surface
screen.blit(s, (0,0))
self.dangerLevel -= 10
def drawRaytracing(self, screen):
surf = self.director.screen
collisionBg = self.collisionBg.convert()
collisionBg.set_colorkey((0,0,0))
collisionMap_mask = pygame.mask.from_surface(collisionBg)
s = pygame.Surface((800,600))
#s = pygame.Surface.convert(collisionMap_mask)
s.fill((0,0,0))
for bicho in self.enemyGroup:
if bicho.controller.detect_player():
pygame.draw.line(s, (255,255,255), \
(self.player.rect.x + self.camera.state.x, \
self.player.rect.y + self.camera.state.y), \
(bicho.rect.x + self.camera.state.x, \
bicho.rect.y + self.camera.state.y), 3)
s.convert()
s.set_colorkey((0,0,0))
line_mask = pygame.mask.from_surface(s)
overlap = collisionMap_mask.overlap_area(line_mask , (self.camera.state.x, self.camera.state.y))
print overlap
screen.blit(self.collisionBg, (self.camera.state.x,self.camera.state.y))
screen.blit(s, (0,0))
def draw(self, screen):
screen.fill(0x000000)
#.........这里部分代码省略.........
示例6: game
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
#.........这里部分代码省略.........
if col == "I":
i = Sword(x, y, directory)
platforms.append(i)
entities.add(i)
if col == "E":
e = Enemy(x, y, directory)
enemy.append(e)
entities.add(e)
x += 32
y += 32
x = 0
y = 0
total_level_width = (len(level[0])-2)*32
total_level_height = len(level)*32
camera = Camera(total_level_width, total_level_height)
entities.add(player)
font = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',20) #Форматиране на текста в score line-а
while 1:
timer.tick(60)
#Пояснителен текст
lives_text = font.render("LIVES:", 1,(255,255,255))
for e in pygame.event.get(): #Проверка за натиснати бутони
if e.type == QUIT: raise SystemExit, "QUIT"
if e.type == KEYDOWN and e.key == K_ESCAPE:
menu_game()
if e.type == KEYDOWN and e.key == K_SPACE:
up = True
if e.type == KEYDOWN and e.key == K_LEFT:
left = True
if e.type == KEYDOWN and e.key == K_RIGHT:
right = True
if e.type == KEYUP and e.key == K_SPACE:
up = False
if e.type == KEYUP and e.key == K_RIGHT:
right = False
if e.type == KEYUP and e.key == K_LEFT:
left = False
# Извеждане на фона
for y in range(32):
for x in range(64):
screen.blit(bg, (x*32 , y*32))
#Текст, който показва прогреса по събиране на точки и броя скокове, които са направени
# Ъпдейтване на играча и извеждане на всичко останало
for i in enemy:
i.update(True, platforms, total_level_height)
player.update(up, left, right, running, platforms, enemy, gears, total_level_height)
for e in entities:
screen.blit(e.image, camera.apply(e))
camera.update(player, WIN_WIDTH, WIN_HEIGHT)
screen.blit(lives_text, (900 , 4))
for i in range(player.lives):
screen.blit(lives_image, ((1100 - i*35), 0))
#Текст, който показва прогреса по събиране на точки и броя скокове, които са направени
scoretext = font.render("Score:"+str(player.score)+"/"+str(player.gears_count*16)+" Jumps:"+str(player.jumps), 1,(255,255,255))
screen.blit(scoretext, (10 , 4))
#Проверка дали играта е свършила
if player.score == player.gears_count*16: #Ако са събрани всички зъбни колела, изведи съобщение и се върни в началното меню
font_end = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30)
end_text_first_line = font_end.render("Congratulations! ", 1,(255,0,0))
end_text_second_line = font_end.render("You collected maximum points! ", 1,(255,0,0))
screen.blit(end_text_first_line, (500 , 350))
screen.blit(end_text_second_line, (430 , 380))
screen.blit(scoretext, (10 , 4))
pygame.display.update()
pygame.time.delay(2000)
pygame.event.wait()
current_level+=1
game('Level_'+str(current_level), player.lives)
if player.lives == 0: #Ако играча е загубил всичките си животи, изведи съобщение и се върни в началното меню
font_end = pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30)
end_text_first_line = font_end.render("Game Over! ", 1,(255,0,0))
end_text_second_line = font_end.render("You died!", 1,(255,0,0))
screen.blit(end_text_first_line, (500 , 350))
screen.blit(end_text_second_line, (515 , 380))
pygame.display.update()
pygame.time.delay(2000)
pygame.event.wait()
menu_game()
pygame.display.update()
示例7: Player
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
import sys
from Camera import Camera
from Player import Player
from SpriteSheet import SpriteSheet
pygame.init()
clock = pygame.time.Clock()
screen_size = width, height = (1280, 720)
black = (0, 0, 0)
# needs to be set before any images are loaded
screen = pygame.display.set_mode(screen_size)
peter = Player(SpriteSheet('..\\assets\\pete3a.png', 32, 48), pygame.Rect(10, 10, 32, 48), 8, 2)
camera = Camera(screen_size, peter)
camera.load_map('test_map_1.json')
camera.load_action_map('..\\assets\\action.map')
while 1:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
screen.fill(black)
camera.update(screen)
pygame.display.flip()
示例8: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
class Graphx:
"""Main class of the graphx engine"""
def __init__(self):
#glutInit(sys.argv)
self.width, self.height = 1280, 800
pygame.init()
self.screen = pygame.display.set_mode((self.width, self.height), OPENGL | DOUBLEBUF)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(65.0, self.width/float(self.height), 0.01, 1000.0)
glMatrixMode(GL_MODELVIEW)
glEnable(GL_DEPTH_TEST)
self.camera = Camera((0.0, 100, 0), (0.0, 0, 0))
#Base
vertices = np.array([[100.0, -10.0, 100.0, Conf.GRAPHX.BASE_COLOR[0],Conf.GRAPHX.BASE_COLOR[1],Conf.GRAPHX.BASE_COLOR[2]], \
[-100.0, -10.0, 100.0, Conf.GRAPHX.BASE_COLOR[0],Conf.GRAPHX.BASE_COLOR[1],Conf.GRAPHX.BASE_COLOR[2]], \
[-100.0, -10.0, -100.0,Conf.GRAPHX.BASE_COLOR[0],Conf.GRAPHX.BASE_COLOR[1],Conf.GRAPHX.BASE_COLOR[2]], \
[100.0, -10.0, -100.0, Conf.GRAPHX.BASE_COLOR[0],Conf.GRAPHX.BASE_COLOR[1],Conf.GRAPHX.BASE_COLOR[2]]], \
dtype=np.float32)
self.vertexPositions = vbo.VBO(vertices)
#Create the index buffer object
indices = np.array([[0,1,2], [0, 3, 2]], dtype=np.int32)
self.indexPositions = vbo.VBO(indices, target=GL_ELEMENT_ARRAY_BUFFER)
self.uniform_values = {}
self.uniform_locations = {}
# ihm management
#self.ihm = IHM(self.width, self.height, self.screen)
def setShader(self, shader, unif):
glUseProgram(shader)
self.shader = shader
self.uniform_values = unif;
for name in unif:
self.uniform_locations[name] = glGetUniformLocation(self.shader, name)
def draw_base(self):
self.indexPositions.bind()
self.vertexPositions.bind()
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
glVertexPointer(3, GL_FLOAT, 24, self.vertexPositions )
glColorPointer(3, GL_FLOAT, 24, self.vertexPositions+12 )
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, None)
self.indexPositions.unbind()
self.vertexPositions.unbind()
glDisableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_COLOR_ARRAY)
# display axes
glBegin(GL_LINES)
glColor3f(1, 0, 0)
glVertex3f(0, 0, 0)
glVertex3f(1, 0, 0)
glColor3f(0, 1, 0)
glVertex3f(0, 0, 0)
glVertex3f(0, 1, 0)
glColor3f(0, 0, 1)
glVertex3f(0, 0, 0)
glVertex3f(0, 0, 1)
glEnd()
def clear(self, shader=None):
#glClearColor(1,1,1,1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
#display the base, update the camera and flip the display
def update(self, lookat=(0, 0, 0)):
self.camera.update()
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
self.camera.look(lookat);
for name in self.uniform_values:
#print "setting ", name, ":", self.uniform_locations[name], "=", self.uniform_values[name]()
glUniform1f(self.uniform_locations[name], self.uniform_values[name]())
self.draw_base()
#self.ihm.draw()
pygame.display.flip()
# handle events
def event(self, e):
self.camera.event(e)
示例9: World
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
class World(DirectObject):
gameStateDict = {"Login" : 0,"CreateLobby":4, "EnterGame": 1, "BeginGame": 2, "InitializeGame":3}
gameState = -1
# Login , EnterGame , BeginGame
responseValue = -1
currentTime = 0
idleTime = 0
mySequence = None
pandaPace = None
jumpState = False
isWalk = False
previousPos = None # used to store the mainChar pos from one frame to another
host = ""
port = 0
vehiclelist = {} # Stores the list of all the others players characters
characters = []
def __init__(self):
self.login = "test2"
base.setFrameRateMeter(True)
#input states
inputState.watchWithModifiers('forward', 'w')
inputState.watchWithModifiers('left', 'a')
inputState.watchWithModifiers('brake', 's')
inputState.watchWithModifiers('right', 'd')
inputState.watchWithModifiers('turnLeft', 'q')
inputState.watchWithModifiers('turnRight', 'e')
self.keyMap = {"hello": 0, "left": 0, "right": 0, "forward": 0, "backward": 0, "cam-left": 0, "cam-right": 0,
"chat0": 0, "powerup": 0, "reset": 0}
base.win.setClearColor(Vec4(0, 0, 0, 1))
# Network Setup
self.cManager = ConnectionManager(self)
self.startConnection()
#self.cManager.sendRequest(Constants.CMSG_LOGIN, ["username", "password"])
# chat box
# self.chatbox = Chat(self.cManager, self)
# Set up the environment
#
self.initializeBulletWorld(False)
#self.createEnvironment()
Track(self.bulletWorld)
# Create the main character, Ralph
self.mainCharRef = Vehicle(self.bulletWorld, (100, 10, 5, 0, 0, 0), self.login)
#self.mainCharRef = Character(self, self.bulletWorld, 0, "Me")
self.mainChar = self.mainCharRef.chassisNP
#self.mainChar.setPos(0, 25, 16)
# self.characters.append(self.mainCharRef)
# self.TestChar = Character(self, self.bulletWorld, 0, "test")
# self.TestChar.actor.setPos(0, 0, 0)
self.previousPos = self.mainChar.getPos()
taskMgr.doMethodLater(.1, self.updateMove, 'updateMove')
# Set Dashboard
self.dashboard = Dashboard(self.mainCharRef, taskMgr)
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
# Accept the control keys for movement and rotation
self.accept("escape", self.doExit)
self.accept("a", self.setKey, ["left", 1])
self.accept("d", self.setKey, ["right", 1])
self.accept("w", self.setKey, ["forward", 1])
self.accept("s", self.setKey, ["backward", 1])
self.accept("arrow_left", self.setKey, ["cam-left", 1])
self.accept("arrow_right", self.setKey, ["cam-right", 1])
self.accept("a-up", self.setKey, ["left", 0])
self.accept("d-up", self.setKey, ["right", 0])
self.accept("w-up", self.setKey, ["forward", 0])
self.accept("s-up", self.setKey, ["backward", 0])
self.accept("arrow_left-up", self.setKey, ["cam-left", 0])
self.accept("arrow_right-up", self.setKey, ["cam-right", 0])
self.accept("h", self.setKey, ["hello", 1])
self.accept("h-up", self.setKey, ["hello", 0])
self.accept("0", self.setKey, ["chat0", 1])
self.accept("0-up", self.setKey, ["chat0", 0])
self.accept("1", self.setKey,["powerup", 1])
self.accept("1-up", self.setKey,["powerup", 0])
self.accept("2", self.setKey,["powerup", 2])
self.accept("2-up", self.setKey,["powerup", 0])
self.accept("3", self.setKey,["powerup", 3])
self.accept("3-up", self.setKey,["powerup", 0])
self.accept("r", self.doReset)
self.accept("p", self.setTime)
#taskMgr.add(self.move, "moveTask")
# Game state variables
#.........这里部分代码省略.........
示例10: main_game
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
def main_game(self):
# Set the default control flags
up = down = left = right = False
exit_game = False
walking = False
self.load_level() # Create the environment assets
level_size = (len(self.level[0]) * self.block_size[0], len(self.level) * self.block_size[1])
camera = Camera(level_size, self.window_size)
mouse = Mouse(pygame.mouse.get_pos())
mouse_clicked = False
mosue_right_clicked = False
while not exit_game:
# Reset control flags each loop
mouse_clicked = False
mouse_right_clicked = False
# Handle pygame
self.clock.tick(self.fps)
# Load title displaying true FPS
current_fps = float(self.clock.get_fps())
pygame.display.set_caption("The Forming | FPS: " + str(current_fps))
# Event Handling
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
# Keydown events
if event.type == KEYDOWN:
if event.key == K_UP or event.key == K_w:
up = True
elif event.key == K_DOWN or event.key == K_s:
down = True
elif event.key == K_LEFT or event.key == K_a:
left = True
elif event.key == K_RIGHT or event.key == K_d:
right = True
if event.type == KEYUP:
if event.key == K_UP or event.key == K_w:
up = False
elif event.key == K_DOWN or event.key == K_s:
down = False
elif event.key == K_LEFT or event.key == K_a:
left = False
elif event.key == K_RIGHT or event.key == K_d:
right = False
# Mouse events
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
mouse_clicked = True
elif event.button == 3:
mouse_right_clicked = True
if event.type == MOUSEBUTTONUP:
if event.button == 1:
mouse_clicked = False
elif event.button == 3:
mouse_right_clicked = False
# Update the entities
camera.update(self.player)
self.player.update(up, down, left, right, level_size)
for tile in self.environment_entities:
self.screen.blit(tile.image, camera.apply(tile))
for player in self.player_entities:
self.screen.blit(player.image, camera.apply(player))
mouse.update(pygame.mouse.get_pos())
pygame.display.update()
示例11: Level
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import update [as 别名]
#.........这里部分代码省略.........
Xiuhtecuhtli(LEVEL_WIDTH/4, LEVEL_HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)),
Tlaloc(LEVEL_WIDTH/4*2, LEVEL_HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)),
Mictlantecuhtli(LEVEL_WIDTH/4*3, LEVEL_HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)),
]
#Nahui
self.Nahui = NahuiTochtli(1, HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT))
#Enemies
self.NoE = 6
self.Enem = []
self.Enem.append(Cortes(LEVEL_WIDTH, HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)))
self.Enem.append(Spanish3(LEVEL_WIDTH/5*3, HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)))
self.Enem.append(Spanish3(LEVEL_WIDTH/5*3, HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)))
self.Enem.append(Spanish1(LEVEL_WIDTH/5*2, HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)))
self.Enem.append(Spanish3(LEVEL_WIDTH/5, HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)))
self.Enem.append(Spanish2(LEVEL_WIDTH/5, HEIGHT, (LEVEL_WIDTH, LEVEL_HEIGHT)))
for i in range(self.NoE):
self.Enem[i].speed_x += float(random.randint(0,47) / 100)
#Codex
self.Cdx = Codex()
#Prepare scene and camera
self.level_background = Level_Sprite("bg/levels/"+str(self.level_number)+"/bg.png", (0, LEVEL_HEIGHT))
self.level_foreground = Level_Sprite("bg/levels/"+str(self.level_number)+"/fg.png", (0, LEVEL_HEIGHT))
self.hud = HUD((LEVEL_WIDTH, LEVEL_HEIGHT))
self.camera = Camera(complex_camera, LEVEL_WIDTH, LEVEL_HEIGHT)
def codex_update(self):
self.Cdx.update()
def spanish_move(self, time):
for i in range(self.NoE):
self.Enem[i].ai(self.Nahui, time)
self.Enem[i].update()
def nahui_move(self, time, key, events):
self.Nahui.move(time,key)
self.Nahui.update(None)
for event in events:
if event.type == KEYUP:
self.Nahui.update(event.key)
def gods_update(self):
for god in self.Teo:
god.update(self.Nahui, self.Enem)
def control_attacks(self):
for i in range(self.NoE):
if abs(self.Enem[i].rect.centerx - self.Nahui.rect.centerx) <= 90:
if self.Nahui.on_attack == True:
self.Enem[i].hitBy(self.Nahui)
if self.Enem[i].on_attack == True:
#Attack when invocation
if self.Nahui.on_invoke == False:
self.Nahui.hitBy(self.Enem[i])
elif self.Nahui.on_invoke == True:
self.Enem[i].hitBy(self.Nahui)
if abs(self.Enem[i].rect.centery - self.Nahui.rect.centery) < 50:
if self.Nahui.on_invoke == False: