本文整理汇总了Python中Player.move方法的典型用法代码示例。如果您正苦于以下问题:Python Player.move方法的具体用法?Python Player.move怎么用?Python Player.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Player
的用法示例。
在下文中一共展示了Player.move方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scene
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
class Scene(State):
def __init__(self):
super(Scene, self).__init__()
self.all_object_list = pygame.sprite.Group()
self.troll_list = pygame.sprite.Group()
self.bullet_list = pygame.sprite.Group()
self.player = Player()
self.background = Object()
self.hud = HUD()
self.score = 0
self.game_over = False
def init(self):
self.read_scene()
# Scale background to screen size
self.background.image = pygame.transform.scale(self.background.image, (SCREEN_WIDTH, SCREEN_HEIGHT))
def process_events(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
return
#self.player.change_color(BLUE)
elif event.type == pygame.KEYDOWN:
if (event.ket == pygame.K_p):
self.pause()
def update(self):
if (not self.is_running):
return
# TEST
pos = pygame.mouse.get_pos()
self.player.rect.x = pos[0]
self.player.rect.y = pos[1]
def draw(self, screen):
screen.fill(WHITE)
#screen.blit(self.background.image, self.background.rect)
self.background.draw(screen)
self.all_object_list.draw(screen)
def read_scene(self):
with open(ResourceManager.scene_path_list[0]) as file:
self.read_background(file)
self.read_player(file)
def read_background(self, file):
file.readline()
image_id = int(file.readline().strip().split(' ')[1])
self.background.init('Image', None, file_name = ResourceManager.image_path_list[image_id])
def read_player(self, file):
file.readline()
image_id = int(file.readline().strip().split(' ')[1])
self.player.init('Image', None, file_name = ResourceManager.image_path_list[image_id], alpha = True)
self.player.move(*map(int, file.readline().strip().split(' ')[1:]))
self.player.rotate(float(file.readline().strip().split(' ')[1]))
self.player.scale(*map(int, file.readline().strip().split(' ')[1:]))
self.all_object_list.add(self.player)
示例2: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
def main():
global flag
global count
screen=Screen()
i=25
j=1
pm=Player(i,j)
screen.printpm(i,j,'P')
#flag=0
#screen.printScreen()
os.system("clear")
screen.genCoins()
screen.printScreen()
while(1):
print "Enter Move :",
ch=getchar()
if(ch=='q'):
break
pm.move(ch,screen)
print ""
os.system("clear")
screen.printScreen()
print "Score :",
print screen.getScore()
if(screen.getflag1()==1):
break
print ""
print "Game Over!!! Score is:",
print screen.getScore()
示例3: move
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
def move(direction): # Deplace le joueur si possible
flee = random.randint(1,6)
if Map.isMonster(Player.getPosition()) == 0 or flee == 6:
answer = Map.check(Player.getPosition(),direction)
if answer == 0:
return 'Il y a un mur dans cette direction'
elif answer == 1 :
Player.move(direction)
Player.editTime(10)
return Map.getDescript(Player.getPosition())
else :
win()
exitGame()
else:
Player.editHealth(-1)
Player.editTime(1)
return "Votre adversaire vous attrappe par le col et frappe a l'estomac. Battez-vous que diable!"
示例4: move
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
def move(direction): # Deplace le joueur si possible
flee = random.randint(1,6)
if Map.isMonster(Player.getPosition()) == 0 or flee == 6:
answer = Map.check(Player.getPosition(),direction)
if answer == 0:
return "You can't go this way. Unless, of course, you can walk through walls!"
elif answer == 1 :
Player.move(direction)
Player.editTime(10)
return Map.getDescript(Player.getPosition())
else :
win()
exitGame()
else:
Player.editHealth(-1)
Player.editTime(1)
return "Votre adversaire vous attrappe par le col et frappe a l'estomac. Battez-vous que diable!"
示例5: move
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
def move(direction): # Deplace le joueur si possible
global visited
flee = random.randint(1,6)
if Map.isMonster(Player.getPosition()) == 0 or flee == 6:
answer = Map.check(Player.getPosition(),direction)
if answer == 0:
return 'There is a wall in this direction.'
elif answer == 1 :
Player.move(direction)
Player.editTime(10)
if Map.getVisited(Player.getPosition()) == 0:
Map.setMonster(Player.getPosition(),Player.getLevel())
Map.setVisited(Player.getPosition())
visited += 1
return Map.getDescript(Player.getPosition())
else :
win()
exitGame()
else:
Player.editHealth(-1)
Player.editTime(1)
return "You opponent pulls you by the collar and punches you in the stomach. Fight for heaven's sake!"
示例6: draw
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [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()
示例7: get_key_map
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
Room.rooms.append(Room(7, 6, 23, 28, path, False))
def get_key_map(key):
if key == curses.KEY_DOWN:
return "down"
elif key == curses.KEY_UP:
return "up"
elif key == curses.KEY_LEFT:
return "left"
elif curses.KEY_RIGHT:
return "right"
return None
fill(start, 1)
while True:
c = g.win.getch()
if c == 27 or c == ord('q'):
break
if c == ord('n'):
fill(start, 1)
if p.move(get_key_map(c)):
dungeonTurn(p, p.room)
for r in Room.rooms:
r.display()
if p.isDead() :
break
g.display(get_key_map(c))
clear_curses()
if (p.isDead()):
print("You were killed !")
else:
print("Game over")
示例8: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
def main():
# print
while(1):
global lives
global score
if(lives==0):
break
screen=Screen(score)
screen.generatecoin()
screen.printscreen()
pl=Player(24,1)
dn=Donkey(4,1)
# dn.donkeyposition(screen)
while(1):
global cnt
global firefl
cnt+=1
ch=getchar()
if(ch=='q'):
lives=0
break
if(cnt==10):
fb=Fireball(dn.getx(),dn.gety())
fb.move(screen)
firefl=1
cnt=-10000
if(firefl==1):
fb.move(screen)
if(fb.getx()==pl.getx() and fb.gety()==pl.gety()):
lives-=1
score=screen.getscore()
score-=50
os.system("clear")
break
if(dn.getx()==pl.getx() and dn.gety()==pl.gety()):
lives-=1
os.system("clear")
score=screen.getscore()
score-=50
break
dn.move(screen)
if(firefl==1):
# fb.move(screen)
if(fb.getx()==pl.getx() and fb.gety()==pl.gety()):
lives-=1
score=screen.getscore()
score-=50
os.system("clear")
break
if(dn.getx()==pl.getx() and dn.gety()==pl.gety()):
lives-=1
os.system("clear")
score=screen.getscore()
score-=25
break
pl.move(ch,screen)
if(firefl==1):
# fb.move(screen)
if(fb.getx()==pl.getx() and fb.gety()==pl.gety()):
lives-=1
score=screen.getscore()
score-=50
os.system("clear")
break
if(dn.getx()==pl.getx() and dn.gety()==pl.gety()):
lives-=1
os.system("clear")
score=screen.getscore()
score-=50
break
if(pl.gety()==28 and pl.getx()==1):
score=screen.getscore()
score+=50
os.system("clear")
print "Bravo!!! You saved your Queen"
print 'You get 50 bonus points'
lives=3
break
print "Your Score:"
print screen.getscore()
print "Ooops!!! Game Over: Your Final Score was:",
print screen.getscore()
示例9: Level
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
from Treasure import *
from Player import *
from Level import *
# the current_level variable will all store the level the
# player currently is at
current_level = Level()
level_list = [current_level]
my_player = Player(current_level)
current_level.print_level(my_player)
# main loop
ongoing_game = True
while ongoing_game:
user_input = input("enter command: ")
# get user command
if user_input == "h" or user_input == "j" or\
user_input == "k" or user_input == "l":
# if grid square to the left is within bounds
result = my_player.move(user_input)
current_level.print_level(my_player)
示例10: exit
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit(0)
if event.type == pygame.KEYDOWN:
key_switch(True)
if event.type == pygame.KEYUP:
key_switch(False)
if event.type == pygame.MOUSEBUTTONDOWN:
print "Mouse button down"
mouse_position = pygame.mouse.get_pos()
player.acc[1]+=1
arrows.append([math.atan2(mouse_position[1]-(player.pos_rot[1]+32),mouse_position[0]-(player.pos_rot[0]+26)),player.pos_rot[0]+32,player.pos_rot[1]+32])
player.move()
if pygame.time.get_ticks()>=time_limit:
running = 0
exitcode = 1
if healthvalue[0] <= 0:
running = 0
exitcode = 0
if player.acc[1]!=0:
accuracy = player.acc[0]*1.0/player.acc[1]*100
else:
accuracy = 0
show_final(screen, accuracy, exitcode)
while 1:
for event in pygame.event.get():
示例11: Player
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
ypos = 300
player = Player()
img = pygame.image.load('Player.png')
GameRunning = True
pygame.display.set_caption("MAE Game Testing")
# GAME LOOP
while True:
# PROCESSES
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
mov_x_change, mov_y_change = player.move(event)
xpos += mov_x_change
ypos += mov_y_change
if GameRunning:
total_frames += 1
pygame.display.flip()
screen.fill(black)
player.show(img, xpos, ypos)
clock.tick(FPS)
示例12: main
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [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)
#.........这里部分代码省略.........
示例13: game
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
#.........这里部分代码省略.........
for event in pygame.event.get(): # Vaatab millise eventiga parajasti tegu on
if event.type == pygame.QUIT: # kui vajutatakse üleval X siis laheb tsükkel kinni
running = False
state = 0
elif event.type == KEYDOWN: # kui hoida klahvi all, siis object liigub
if event.key == K_ESCAPE and living and player.left_right == 0: # kui player on elus ja ei liigu, siis laseb escape vajutades pausi peale panna
option = menu(False, full_scr = full_scr, sound = sound) # käivitab menu funktsiooni
pygame.mixer.music.unpause()
sound = option[1]
# kui muutusi toimub valikutes, vahetab need kohe ära
if option[3] != full_scr:
if option[3]:
full_scr = True
screen = pygame.display.set_mode((gamewidth, gameheight), FULLSCREEN)
else:
full_scr = False
screen = pygame.display.set_mode((gamewidth, gameheight))
if not sound:
pygame.mixer.music.stop()
clean = option[2]
if option[0] == 0:
pygame.mixer.music.stop()
state = 3
running = False
elif option[0] == 2:
running = False
state = 0
if event.key == K_RIGHT: # liigub paremale
if player.left_right == 0:
player.direction = "R" # suund vaja animatsiooni jaoks
player.move(6)
if sound:walking.play(-1) # mängib liikumise heli
elif event.key == K_LEFT: # liigub vasakule
if player.left_right == 0:
player.direction = "L"
player.move(-6)
if sound:walking.play(-1)
elif event.key == K_p:
print("cheat")
cheat = not cheat
elif event.key == K_UP:
player.jump()
elif event.type == KEYUP: # kui klahv üles tõuseb, siis liikumine lõppeb.
if event.key == K_RIGHT: # l6petab paremale liikumise
player.move(-6)
walking.stop()
elif event.key == K_LEFT: # l6petab vasakule liikumise
player.move(6)
walking.stop()
elif event.type == MOUSEBUTTONDOWN and event.button == 1: # bossi pea sihtimine
if cx in range(590,675) and cy in range(236,320):
dmg_boss = True # kui hiir on õiges kohas ja vajutada vasakut nuppu, siis võtab bossi eludest maha teatud arv elusid
for enemy in current_enemy.enemy_flying: # teiste liikuvate vastaste tapmine
if enemy.rect.collidepoint((cx, cy)): # kui collidepoint ühtib hiire positsiooniga
if sound:enemy_flying_wav.play()
current_enemy.enemy_flying.remove(enemy)
else: # kui on level shifti aeg, siis hoiab mängijat ühe koha peal
示例14: Player
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [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)
示例15: World
# 需要导入模块: import Player [as 别名]
# 或者: from Player import move [as 别名]
class World(object):
def __init__(self):
self.gravity = 1
self.floors = []
# Background debe pertenecer a mapa? opinar
self.backGround = Sprite()
self.backGround.src = None
self.backGround.dst = None
self.floor = Sprite()
self.floor.src = None
self.floor.setDstSize(800, 128)
self.floor.setDstPos(0, 600 - 128)
self.floors.append(self.floor)
self.wallA = Sprite()
self.wallA.src = None
self.wallA.setDstSize(128, 64)
self.wallA.setDstPos(250, 600 - 225)
self.floors.append(self.wallA)
self.wallB = Sprite()
self.wallB.src = None
self.wallB.setDstSize(256, 64)
self.wallB.setDstPos(512, 600 - 400)
self.floors.append(self.wallB)
self.player = Player(10, 26, 0) # <-- (velocidad x) (velocidad y) (velocidad en el aire x sin implementar)
self.player.setSrcSize(64, 64)
self.player.setSrcPos(0, 0)
self.player.setDstSize(64, 64)
self.player.setDstPos(100, 100)
def update(self):
updating = True
i = 0
# print self.floors
while updating and i < len(self.floors): # <-- evitando el break de carlos
# print i
if not self.player.collide(self.floors[i]):
self.player.src.y = 64
self.player.onAir = True
if self.player.goTo.y < 64:
self.player.goTo.y += self.gravity
else:
self.player.src.y = 0
self.player.onAir = False
self.player.goTo.y = 0
self.player.dst.y = self.floors[i].dst.y - self.player.dst.h + 1
updating = False
i = i + 1
self.player.move()
def draw(self, renderer, images): # el orden en que se dibuja todo:
self.backGround.draw(renderer, images.getImage("background"))
self.floor.draw(renderer, images.getImage("floor"))
self.wallA.draw(renderer, images.getImage("wall"))
self.wallB.draw(renderer, images.getImage("wall"))
self.player.draw(renderer, images.getImage("player"))