本文整理汇总了Python中Player.update方法的典型用法代码示例。如果您正苦于以下问题:Python Player.update方法的具体用法?Python Player.update怎么用?Python Player.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def update(self):
self.move()
if self.health <= 0:
all_sprites_list.remove(self)
Player.update(self)
示例2: Game
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
class Game(object):
def __init__(self, screen):
self.deaths = 0
self.screen = screen
self.level = Level('reallevel')
self.spawn()
self.game_area = screen.subsurface((0, 40, screen.get_width(), screen.get_height() - 40))
self.cam = Camera(self.player, self.level.bounds, self.game_area.get_size())
self.hud = screen.subsurface((0, 0, screen.get_width(), 40))
self.deathtext = pygame.font.Font(None, 20)
def spawn(self):
self.player = Player((self.level.spawnPoint), self.level, self)
def quit(self):
self.done = True
def loop(self):
self.done = False
self.clock = pygame.time.Clock()
while not self.done:
dt = self.clock.tick(30)
#input
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
self.quit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
self.player.jump()
#update
self.player.update(dt)
self.cam.update(self.player.rect)
#draw
self.hud.fill((80, 80, 80))
text = self.deathtext.render("deaths: " + str(self.deaths), True, (0, 255, 0))
self.hud.blit(text, (0, 0))
self.game_area.fill((0,0,0))
self.cam.draw_background(self.game_area, self.level.background)
self.cam.draw_sprite(self.game_area, self.player)
#refresh
pygame.display.flip()
示例3: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def main():
height = 400
width = height*16/9
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()
running = True
elapsed_time = 0
updates = 0
update_time = 0
player = Player(width/2, height/2, 1)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
break
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
player.direction += 20
if event.key == pygame.K_RIGHT:
player.direction -= 20
if event.key == pygame.K_UP:
player.velocity += .5
if event.key == pygame.K_DOWN:
player.velocity -= .5
delta = clock.tick()
update_time += delta
elapsed_time += delta
#all game logic goes here everything within the if statement is run 60 times per second
if update_time >= 1000/60:
if player.x_pos > width:
player.x_pos = 0
if player.x_pos + player.width < 0:
player.x_pos = width
if player.y_pos > height:
player.y_pos = 0
if player.y_pos + player.height < 0:
player.y_pos = height
player.update()
updates += 1
update_time = 0
if elapsed_time >= 1000:
pygame.display.set_caption("FPS: " + str(clock.get_fps()) + " Updates: " + str(updates))
updates = 0
elapsed_time = 0
screen.fill((255, 255, 255))
screen.blit(player.image, (player.x_pos, player.y_pos))
pygame.display.flip()
示例4: draw
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def draw(self):
"""Contains main game loop"""
background = pygame.image.load(os.path.join("sky.jpg"))
controller = Controller()
collide = CollisionManager()
player = Player(self.surface)
enemy_manager = EnemyManager(self.surface)
level = LevelLoader.LevelLoader(self.surface, enemy_manager)
level.load(1)
while self.is_alive:
self.clock.tick(FPS)
self.surface.blit(background, (0, 0))
controller.get_input(pygame.key.get_pressed(), player, level, player.sword)
if player.lives > 0:
player.move(level)
player.update_jump()
pygame.draw.rect(self.surface, BLUE, player, 0)
player.bullet_manager.update_bullets(self.surface)
player.bullet_manager.check_hit(enemy_manager)
player.bullet_manager.clean_bullets(level)
player.update()
enemy_manager.update(player)
enemy_manager.draw()
level.draw_terrain()
health_count = game_font.render(str(player.lives), 1, (255, 255, 255))
self.surface.blit(lives_message, (0, 0))
self.surface.blit(health_count, (150, 0))
if player.lives <= 0:
self.surface.blit(lose_message, (200, 200))
pygame.display.flip()
示例5: Play
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
class Play(DirectObject):
def __init__(self, parent):
#Turn off default mouse control
base.disableMouse()
base.setFrameRateMeter(True)
#globalClock = ClockObject.getGlobalClock()
#globalClock.setMode(ClockObject.MLimited)
#globalClock.setFrameRate(1000)
#Set windows properties
self.props = WindowProperties()
self.props.setCursorHidden(True)
#props.setFullscreen(1)
#props.setSize(int(base.pipe.getDisplayWidth()), int(base.pipe.getDisplayHeight()))
self.props.setMouseMode(WindowProperties.MRelative)
base.win.requestProperties(self.props)
self.transition = Transitions(loader)
self.transition.setFadeColor(0,0,0)
self.parent = parent
base.accept("escape", self.togglePause)
self.setupSounds()
self.startLevel(0, True)
self.task = taskMgr.add(self.update, "updateTask")
def fadeOut(self):
self.transition.fadeOut(1)
def fadeIn(self):
self.transition.irisIn(1)
def togglePause(self):
if self.parent.paused:
self.props.setCursorHidden(True)
base.win.requestProperties(self.props)
base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2)
taskMgr.add(self.task)
self.parent.paused = False
self.parent.continueImage.hide()
self.parent.restartImage.hide()
self.parent.exitImage.hide()
self.parent.mainFrame.hide()
self.playingBGM.setTime(self.bgmTime)
self.playingBGM.play()
else:
self.props.setCursorHidden(False)
base.win.requestProperties(self.props)
taskMgr.remove(self.task)
self.parent.paused = True
self.parent.mainFrame.show()
self.parent.continueImage.show()
self.parent.restartImage.show()
self.parent.exitImage.show()
self.bgmTime = self.playingBGM.getTime()
self.playingBGM.stop()
def chaseBGM(self, chasing = False):
if chasing and self.playingBGM != self.bgFast:
self.playingBGM.stop()
self.playingBGM = self.bgFast
self.bgmTime = 0
self.playingBGM.play()
elif not chasing and self.playingBGM != self.bgSlow:
self.playingBGM.stop()
self.playingBGM = self.bgSlow
self.bgmTime = 0
self.playingBGM.play()
def initModels(self):
self.map = MapGen(self)
# self.player = Player(self)
# self.level = Level()
self.enemies = []
def transitionFunc(self, level, next = False):
tSequence = Sequence(Func(self.fadeOut), Wait(1), Func(self.startLevel, level, next),
Func(self.fadeIn))
tSequence.start()
#level number, next = true if next level (false = respawning)
def startLevel(self, level, next = False):
# per pixel lighting
render.clearLight()
render.setShaderAuto()
try:
self.level.initLight()
except AttributeError:
pass
try:
self.player.initHandLight()
except AttributeError:
pass
# """
# render.clearLight()
# render.setShaderAuto()
# """
# self.map = MapGen(self)
# self.player = Player(self)
#.........这里部分代码省略.........
示例6: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def main():
pygame.init()
screen_width = 700
screen_height = 400
screen = pygame.display.set_mode([screen_width,screen_height])
icon = pygame.Surface((1, 1))
icon.set_alpha(0)
pygame.display.set_icon(icon)
pygame.display.set_caption("Game")
all_sprites_list = pygame.sprite.Group()
player = Player()
all_sprites_list.add(player)
done = False
clock = pygame.time.Clock()
score = 0
while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# Set the speed based on the key pressed
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
print "Left"
player.changespeed(-3,0)
if event.key == pygame.K_RIGHT:
print "Right"
player.changespeed(3,0)
if event.key == pygame.K_UP:
print "Up"
player.changespeed(0,-3)
if event.key == pygame.K_DOWN:
print "Down"
player.changespeed(0,3)
# Reset speed when key goes up
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
player.changespeed(3,0)
if event.key == pygame.K_RIGHT:
player.changespeed(-3,0)
if event.key == pygame.K_UP:
player.changespeed(0,3)
if event.key == pygame.K_DOWN:
player.changespeed(0,-3)
screen.fill(white)
player.update()
all_sprites_list.draw(screen)
clock.tick(20)
pygame.display.flip()
pygame.quit()
示例7: Game_State
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
#.........这里部分代码省略.........
self.ds = None
self.extras = []
def restart(self):
return Game_State(self.levelname, self.levelhandle, text=self.introte, name=self.inname,final=self.final)
def getbinpos(self, spriteobj, skip=False):
obj = spriteobj.rect
top = obj.top - self.search_padding
left = obj.left - self.search_padding
right = obj.right + self.search_padding
bottom = obj.bottom + self.search_padding
pos = [(left, top), (right, top), (left, bottom), (right, bottom)]
for i in range(0, 4):
pos[i] = (math.floor(pos[i][0]/self.gridsize)*self.gridsize, math.floor(pos[i][1]/self.gridsize)*self.gridsize)
newbins = list(set(pos))
if not skip:
spriteobj.current_bin_pos = newbins
else:
return newbins
def get_binobjs(self, obj):
positions = obj.current_bin_pos
hashset = []
for p in positions:
h = self.hashgrid.get(p)
if h != None:
hashset += h
return hashset
def check_active_dialog(self):
pass
def update_score(self, dt):
if dt >= 5:
if self.current_score_rate > 0:
self.current_score_rate -= 5
self.current_score += self.current_score_rate
self.time_flag += dt
def nextl(self):
if self.levelname == '../images/ASCIILEVEL1.txt':
self.music.stop()
GAME_GLOBALS.GAME_STATE = Game_State(levelname='../images/bigelevatorthing.txt', level = level2.init, prev = self, health = self.Player.current_health, name=2, score = self.current_score, final= True, text = "Kill the enemies")
elif self.levelname == '../images/ASCIILEVEL0.txt':
self.music.stop()
GAME_GLOBALS.GAME_STATE = Game_State(levelname='../images/ASCIILEVEL1.txt', level = level1.init, prev = self, health = self.Player.current_health, name=1, score = self.current_score, final= False, text = "Survive")
elif self.levelname == '../images/bigelevatorthing.txt':
self.music.stop()
GAME_GLOBALS.GAME_STATE = Game_State(levelname='../images/ASCIILEVEL3.txt', level = level3.init, prev = self, health = self.Player.current_health, name=3, score = self.current_score, final= False, text = "Escape")
elif self.levelname == '../images/ASCIILEVEL3.txt':
self.music.stop()
GAME_GLOBALS.GAME_STATE = Game_State(levelname='../images/ASCIILEVEL4.txt', level = level4.init, prev = self, health = self.Player.current_health, name=4, score = self.current_score, final= False, text = "Freedom")
def update(self, event):
self.getbinpos(self.Player)
worldob = self.get_binobjs(self.Player)
dt = float(time.time() - self.timer)
if dt >= 1:
pass
if dt >= 3:
self.intro_text.set_alpha(self.intro_text.get_alpha() - (self.fade_rate + 2))
if self.intro_text.get_alpha() <= 0:
pass
示例8: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def main():
global cameraX, cameraY
pygame.init()
screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH)
pygame.display.set_caption("Use arrows to move!")
timer = pygame.time.Clock()
up = down = left = right = running = False
bg = Surface((32,32))
bg.convert()
bg.fill(Color("#8888ff"))
entities = pygame.sprite.Group()
player = Player(32, 32)
platforms = []
x = y = 0
# Menu 1
lt = []
lt.append(menuItem(100, 100, 200, 50, "Jogar", 22, (255, 255, 255)))
lt.append(menuItem(100, 100, 200, 50, "Tutorial", 22, (255, 255, 255)))
lt.append(menuItem(100, 100, 200, 50, "Sair", 22, (255, 255, 255)))
m = menu(lt, (30, 100), 20)
op = 0
fases = loadLevels2()
# Menu 2
lt = []
for i in fases:
lt.append(menuItem(100, 100, 200, 50, i[1], 22, (255, 255, 255)))
m2 = menu(lt, (30, 100), 20)
op2 = 0
while True:
for event in pygame.event.get():
if event.type == QUIT:
return
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return
if event.key == pygame.K_DOWN:
m.selected += 1
if m.selected > len(m.itens):
m.selected = 1
if event.key == pygame.K_UP:
m.selected -= 1
if m.selected < 1:
m.selected = len(m.itens)
if event.key == pygame.K_RETURN:
if m.selected == len(m.itens):
return
op = m.selected
screen.fill(Color("#8888ff"))
m.draw(screen)
pygame.display.update()
while op == 1:
while op == 1:
for event in pygame.event.get():
if event.type == QUIT:
return
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
op = 0
if event.key == pygame.K_DOWN:
m2.selected += 1
if m2.selected > len(m2.itens):
m2.selected = 1
if event.key == pygame.K_UP:
m2.selected -= 1
if m2.selected < 1:
m2.selected = len(m2.itens)
if event.key == pygame.K_RETURN:
op2 = m2.selected
screen.fill(Color("#8888ff"))
m2.draw(screen)
pygame.display.update()
if op2:
c = 1
for i in fases:
if c == op2:
level = i[0]
c += 1
x = 0
y = 0
# build the level
for row in level:
for col in row:
if col == "J":
player.rect.left = x
player.rect.top = y
#.........这里部分代码省略.........
示例9:
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
tigerwoods.firing = True
firetime_t = pygame.time.get_ticks()
# cooldown
if firetime + cooldown < pygame.time.get_ticks():
fired = False
if firetime_e + cooldown_e < pygame.time.get_ticks():
fired = False
# update phase
if player.direction[0] == 1 and player.rect.right > 600:
if (player.rect.right) < 14400:
advanceVelocity = scrollVelocity
if (vpCoordinate) >= 13200:
advanceVelocity = 0
player.update(14400, 720, dt, obstacleRects)
for enemy in enemy_list:
enemy.update(vpCoordinate, vpCoordinate + 1200, dt, aiRects)
tigerwoods.update(vpCoordinate,vpCoordinate + 1200, dt, player, aiRects)
# drawing player shots
for x in shots:
col = False
x.update(player.rect.right, player.rect.centery, dt)
if x.rect.left > vpCoordinate + 1200 or x.rect.right < vpCoordinate:
shots.remove(x)
continue
if x.rect.colliderect(tigerwoods.rect):
shots.remove(x)
tigerwoods.hp -= 1
if tigerwoods.hp <= 0:
示例10:
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
screen.blit(stext, (130, 6))
screen.blit(pause, (100, 250 + buffer_height))
key = pygame.key.get_pressed()
if key[K_ESCAPE]:
sys.exit()
if key[K_o]:
break
pygame.display.update()
pygame.event.pump()
player.update(key)
for p in all_projs:
p.updateLocation()
for e in all_enemies:
p.contactEnemy(e)
p.contactPlayer(player)
enemies_alive = False
for e in all_enemies:
e.updateLocation()
e.contactPlayer(player)
if e.alive:
enemies_alive = True
#pygame.sprite.spritecollide(e, all_projs, True)
示例11: GameState
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
#.........这里部分代码省略.........
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
self.camera.draw()
# Redraw the current blur texture
glPushAttrib(GL_VIEWPORT_BIT)
# Change the viewport to match the size of the texture
glViewport(0, 0, self.blurTexture.getTexWidth(),
self.blurTexture.getTexHeight())
self.drawMotionBlur(self.player.drunkAmount)
self.drawScene()
# Copy the contents of the frame buffer into our blur texture
self.blurTexture.bind()
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0,
self.blurTexture.getTexWidth(),
self.blurTexture.getTexHeight(),
0)
self.blurTexture.unbind()
# Clear the fram buffer again
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glPopAttrib()
# Blend in the motion blur with the background color
self.drawMotionBlur(self.player.drunkAmount)
# Draw the scene on top of the motion blur
self.drawScene()
def update(self, dt):
'''
Updates the game simulation based on the amount of time that has passed
since the previous frame.
'''
# Update the input system
self.updateInput(dt)
# Update the avatar
self.player.update(dt)
# Update the camera
self.camera.setTarget(self.player.pos, self.player.rot)
self.camera.update(dt)
for i in range(len(self.npcs)):
self.npcs[i].update(dt)
# Calculate the FPS
self.numFrames += 1
self.frameTime += dt
if self.frameTime > 0.5:
self.fps = float(self.numFrames) / self.frameTime
self.frameTime = 0.0
self.numFrames = 0
print 'FPS: %f' % (self.fps)
def updateInput(self, dt):
'''
Updates the state of the input system and processes all currently active
actions.
'''
示例12: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def main():
pygame.init()
screen = pygame.display.set_mode(DISPLAY)
pygame.display.set_caption('Super Mario')
timer = pygame.time.Clock()
objects = pygame.sprite.Group()
levels = ["-------------------------",
"- -",
"- -",
"- -",
"--- ----",
"- -",
"- -",
"- ---- -",
"- -",
"- ----- -",
"- ---- -",
"- -",
"- -",
"---- -----",
"- -",
"- -",
"- ---- --- -",
"- -",
"-------------------------"]
player = Player(40, 40)
left = right = up = False
objects.add(player)
platforms = []
x = 0
y = 0
for row in levels:
for col in row:
if col == "-":
platform = Platform(x, y)
platforms.append(platform)
objects.add(platform)
x += PLATFORM_WIDTH
y += PLATFORM_HEIGHT
x = 0
running = True
while running:
timer.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == KEYDOWN:
if event.key == K_a:
left = True
if event.key == K_d:
right = True
if event.key == K_w:
up = True
if event.type == KEYUP:
if event.key == K_a:
left = False
if event.key == K_d:
right = False
if event.key == K_w:
up = False
screen.fill(Color(BG_COLOR))
player.update(left, right, up, platforms)
objects.draw(screen)
pygame.display.update()
print(objects)
pygame.quit()
示例13: Player
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
rabbit = Player('resources/dot.png')
block = Sprite('resources/dot.png')
block2 = Sprite('resources/dot.png')
block3 = Sprite('resources/dot.png')
super(Sprite,block).move((400,175))
super(Sprite,block2).move((410,175))
super(Sprite,block3).move((420,175))
drawables = [rabbit,block,block2,block3]
while True:
DISPLAY.fill(WHITE)
for n in drawables:
n.draw(DISPLAY)
CD.setObjects(drawables[0],n)
CD.checkCollision()
pygame.draw.line(DISPLAY, BLACK, (0,200),(800,200),2)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN or event.type == KEYUP:
rabbit.update(event)
CD.setObjects(rabbit,block)
CD.checkCollision()
rabbit.move()
rabbit.updateVel(0,GRAVITY)
pygame.display.update()
fpsClock.tick(FPS)
示例14: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def main():
#setup or define variables and initialize them
pygame.init()
Text_color = (0,0,200)
score = 0
sound = pygame.mixer.music.load("data/main.ogg")
frame = pygame.time.Clock()
screen = Display().createWindow(640, 640)
player_shoot = True
enemy_shoot = True
display_enemy = True
screen.fill((0,0,234))
size = pygame.display.get_surface().get_rect().size
P_pos = [size[0]/2, size[1]-100]
bullet_speed = 6 #bullet speed for player
P_image = load_image("player.png", True)
E_image = load_image("enemy.png", False)
E_shot = load_image("Enemyshot.png", False)
P_shot = load_image("Playershot.png", False)
back = load_image("background.png", True)
back = pygame.transform.scale(back,(650, 650))
back_rect = back.get_rect()
back_rect.topleft = 0, -10
player = Player(P_image, P_shot, P_pos, bullet_speed)
player.set_speed(50)
EnemyList = []
displayPlayer = True
EnemyAddCounter = 120
EnemyOneCounter = 60
pygame.mouse.set_visible(True)
bullets = [] #EnemyBullets list
shot_speed = 8 #bullet speed for enemy
Display().setTitle("Space Shooter")
life = 5
#open the score flat-file
file = open("data/score.pck", "r")
f = file.read()
p_score = int(f)
file.close()
if(p_score == 0 or p_score < 20):
file = open("data/score.pck", "w")
file.write(str(20))
p_score = 20
file.close()
pygame.mixer.music.play(-1, 0.0)
while True:
#the game-loop:
screen.fill((0,0,234))
EnemyAddCounter -= 1
EnemyOneCounter -= 1
if(EnemyAddCounter == 0):
EnemyAddCounter = 120
enemy = Enemy(E_image, E_shot, (random.randint(0, 315), -10), shot_speed)
enemy.set_speed(5)
EnemyList.append(enemy)
if(EnemyOneCounter ==0):
EnemyOneCounter = 60
enemy = Enemy(E_image, E_shot, (random.randint(320, 575), -10),shot_speed)
enemy.set_speed(5)
EnemyList.append(enemy)
screen.blit(back, back_rect)
createText("Score: " +str(score), 12, (255, 255, 255),10, 10,None )
createText("Top Score: "+str(p_score), 12, (255,255,255) ,10, 30, None)
createText("Life: "+str(life), 12, Text_color ,10, 50, None)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.key == K_LEFT and (player.img_rect.left - 50) >= 0:
player.move("left")
if event.key == K_RIGHT and (player.img_rect.right + 50) <= 670:
player.move("right")
if event.key == K_UP and (player.img_rect.top - 30) >=0:
player.move("up")
if event.key == K_DOWN and (player.img_rect.bottom + 50) <= 640:
player.move("down")
if event.key == K_SPACE and player_shoot:
player.shoot()
for enemy in EnemyList:
if(random.randint(0, 50) == 2) and enemy_shoot == True:
enemy.shoot()
if display_enemy:
enemy.move_bullets()
enemy.move()
enemy.update()
for enemy in EnemyList:
if enemy.img_rect.y > 640:
EnemyList.remove(enemy)
else:
for bull in player.bullets:
if bull.colliderect(enemy.img_rect):
bullets = enemy.bullets
EnemyList.remove(enemy)
#.........这里部分代码省略.........
示例15: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import update [as 别名]
def main():
play = True
pyg.init()
clock = pyg.time.Clock()
player = Player(540, 578)
enemy = Enemy()
left = right = up = boost = start = False
e_alive = pl_alive = True
everything = pyg.sprite.Group()
everything.add(player, enemy)
platforms = []
level = ["------------------------------------------------------------------------------------",
"- ",
"- ",
"- ",
"- ",
"- -----------------------------------------------------------",
"- --- -",
"- ----- -",
"- -",
"-- -",
"- -",
"- -",
"- -",
"- ---- -",
"- -",
"- -",
"- --- -",
"- -",
"- -",
"------------------------------"]
screen = pyg.display.set_mode(DISPLAY)
bg = Surface((WIN_W,WIN_H))
bg.fill(BG_COLOUR)
bl_x = bl_y = 0
for row in level:
for symbol in row:
if symbol == '-':
block = Blocks(bl_x,bl_y)
everything.add(block)
platforms.append(block)
bl_x += PLATFORM_W
bl_y += PLATFORM_H
bl_x = 0
total_lvl_w = len(level[0]) * PLATFORM_W # stage's width
total_lvl_h = len(level) * PLATFORM_H # stage's height
camera = Camera(cam_cfg, total_lvl_w, total_lvl_h)
while play:
pyg.display.set_caption('BroFormer: FPS = ' + str(int(clock.get_fps())))
for event in pyg.event.get():
if event.type == pyg.QUIT:
play = False
if event.type == KEYDOWN:
if event.key == K_LEFT: left = True
if event.key == K_RIGHT: right = True
if event.key == K_UP: up = True
if event.key == 304: boost = True
if event.type == KEYUP:
if event.key == K_LEFT: left = False
if event.key == K_RIGHT: right = False
if event.key == K_UP: up = False
if event.key == 304: boost = False
if not start:
if player.rect.x in ENEMY_START_BOX_X:
if player.rect.y in ENEMY_START_BOX_Y:
start = True
enemy.update(player.rect.x, player.rect.y, start, e_alive)
player.update(enemy.pl_alive, left, right, up, boost, platforms)
enemy.pl_alive = True
camera.update(player)
for something in everything:
screen.blit(something.image, camera.apply(something))
pyg.display.update()
screen.blit(bg, (0,0))
clock.tick(60)
pyg.quit()