本文整理汇总了Python中ship.Ship.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Ship.draw方法的具体用法?Python Ship.draw怎么用?Python Ship.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ship.Ship
的用法示例。
在下文中一共展示了Ship.draw方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import draw [as 别名]
class Game(object):
def __init__(self):
self.width = 2000
self.height = 2000
self.screen_width = w
self.screen_height = h
self.offset = {'x': 0, 'y': 0}
self.safe_zone = [{'x': 0, 'y': 0}, {'x': 400, 'y': 400}]
self.player = Ship(self)
game_worlds.append(RedSpace(self, {'x': self.width, 'y': self.height}))
game_worlds.append(BlueSpace(self, {'x': self.width, 'y': self.height}))
self.current_level = game_worlds[0]
def draw_assets(self):
if screen is None:
return
self.current_level.draw(screen)
self.player.draw(screen)
def set_offset(self, x, y):
self.offset = {'x': x, 'y': y}
def update_assets(self):
self.player.update()
self.current_level.update()
def change_level(self, level, player_loc=None):
self.current_level = self.get_worlds_list()[level]
if player_loc is None:
self.player.loc = {'x': 100, 'y': 100}
else:
self.player.loc = {'x': player_loc['x'], 'y': player_loc['y']}
def check_collisions(self, obj):
for item in self.current_level.game_assets:
# Optimisation don't figure out collisions for object that's nowhere near
if not (max(item.loc['x'],obj.loc['x']) - min(item.loc['x'],obj.loc['x'])) \
> self.screen_width/2:
if item.check_collision(obj):
obj.has_been_hit(item)
return True
return False
def get_worlds_list(self):
return game_worlds
示例2: main
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import draw [as 别名]
def main():
WINSIZE = 640,480
NUMBER_OF_STARS = 250
STARTING_ANGLE = 180
CLOSEST_STAR_COLOR = (255, 255, 255)
STAR_SIZE_IN_PIXELS = 1
#_V_ = 1
pygame.init()
pygame.key.set_repeat(1,1)
screen = pygame.display.set_mode(WINSIZE,pygame.SWSURFACE)
stars = Starfield(screen,screen.get_rect(),NUMBER_OF_STARS,STARTING_ANGLE,(40,4),STAR_SIZE_IN_PIXELS,CLOSEST_STAR_COLOR)
ship1 = Ship(screen)
done = False
while not done:
screen.fill(THECOLORS["black"])
stars.update()
ship1.draw()
ship1.resetSprt()
pygame.display.update()
events = pygame.event.get()
for e in events:
if(e.type == QUIT):
done = True
break
elif (e.type == KEYDOWN):
if(e.key == K_ESCAPE):
done = True
break
#Test for movement
dx,dy = 0,0
if(e.key == K_DOWN):
dy += 1
if(e.key == K_UP):
dy -= 1
if(e.key == K_LEFT):
dx -= 1
if(e.key == K_RIGHT):
dx += 1
ship1.move(dx,dy)
#if(e.key == K_PLUS):
#stars.set_speed((
print "Exiting!"
return
示例3: open
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import draw [as 别名]
pygame.display.update()
winn.play()
#new level
nlev = open('nlev.txt').read()
exec(nlev)
screen = pygame.image.load('2.jpg').convert_alpha()
walls.update()
walls.draw(screen)
invaders.update()
my_ship.update()
invaders.draw(screen)
my_ship.draw(screen)
bombs.update()
rockets.update()
bombs.draw(screen)
rockets.draw(screen)
if boom:
boom = False
clock.tick(20)
w = []
n = ["exp" + str(i) + ".png" for i in range(0,8)]
for i in n:
w.append(pygame.image.load(i).convert_alpha())
for i in range(8):
screen.blit(w[i], p)
pygame.display.update()
示例4: GameState
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import draw [as 别名]
class GameState(State):
def __init__(self):
State.__init__(self, "Game")
self.characterPosition = Vector(5, 7)
self.character_colors = [RED, BLUE, WHITE, ORANGE, PURPLE]
self.background_color = BLACK
self.wall_color = Color.multiply(GREEN, 0.5)
self.map = []
self.offset = 0.0
self.initial_scroll_speed = self.scroll_speed = 0.5
self.scroll_speed_increment = 0.1
self.sharpness = 1.1
self.ship_steer_speed = 0.1
self.ship = Ship(Vector(6, 1), self.character_colors[0], Color.multiply(self.character_colors[0], 0.8))
self.simulationPause = False
self.sprites = []
for y in range(PIXEL_DIM_Y*2 + 1):
self.map.append(self.generate_map_slice())
def reset(self):
self.sprites = []
self.offset = 0.0
self.scroll_speed = self.initial_scroll_speed
def generate_map_slice(self):
if len(self.map) == 0:
left = random.choice(range(6))
right = random.choice(range(6))
else:
last_slice = self.map[-1]
left = last_slice[0] + random.choice([-1, 0, 1])
right = last_slice[1] + random.choice([-1, 0, 1])
left = left if 0 <= left < PIXEL_DIM_X else last_slice[0]
right = right if 0 <= right < PIXEL_DIM_X else last_slice[1]
while (left + right) >= (PIXEL_DIM_X - 1):
if random.choice([0, 1]) == 0:
left -= 1
else:
right -= 1
return [left, right]
def update(self, dt):
State.update(self, dt)
self.offset += self.scroll_speed * dt
self.scroll_speed += self.scroll_speed_increment * dt
if self.offset >= 1.0:
while self.offset >= 1.0:
self.offset -= 1.0
self.check_collision()
del self.map[0]
self.map.append(self.generate_map_slice())
self.ship.update(dt)
self.ship.animation.duration = 1.0/self.scroll_speed
self.sprites = [sprite for sprite in self.sprites if not sprite.ended]
for sprite in self.sprites:
sprite.update(dt)
def draw(self, rgb):
State.draw(self, rgb)
for y in range(PIXEL_DIM_Y):
left, right = self.map[y][0], self.map[y][1]
for lx in range(left):
pixel = Vector(lx, y)
rgb.setPixel(pixel, self.wall_color)
for rx in range(right):
pixel = Vector(PIXEL_DIM_X - 1 - rx, y)
rgb.setPixel(pixel, self.wall_color)
self.ship.draw(rgb)
for sprite in self.sprites:
sprite.draw(rgb)
@staticmethod
def draw_pixel_at(rgb, position, color):
x_rest = position.x % 1
y_rest = position.y % 1
rest = math.sqrt(x_rest*x_rest + y_rest*y_rest)
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import draw [as 别名]
class Game:
def __init__(self, screen_width=120, screen_height=70):
self.screen_width = screen_width
self.screen_height = screen_height
libtcod.console_init_root(self.screen_width, self.screen_height, 'Heliopause', False)
self.buffer = libtcod.ConsoleBuffer(self.screen_width, self.screen_height)
self.console = libtcod.console_new(self.screen_width, self.screen_height)
self.galaxy_map_console = libtcod.console_new(self.screen_width, self.screen_height)
self.set_minimap(20)
self.targeting_width = 20
self.targeting_height = 26
self.targeting_buffer = libtcod.ConsoleBuffer(self.targeting_width, self.targeting_height)
self.targeting_console = libtcod.console_new(self.targeting_width, self.targeting_height)
libtcod.console_set_default_foreground(self.targeting_console, libtcod.white)
libtcod.console_set_default_background(self.targeting_console, libtcod.black)
self.ship_info_width = 20
self.ship_info_height = 8
self.ship_info_buffer = libtcod.ConsoleBuffer(self.ship_info_width, self.ship_info_height)
self.ship_info_console = libtcod.console_new(self.ship_info_width, self.ship_info_height)
libtcod.console_set_default_foreground(self.ship_info_console, libtcod.white)
libtcod.console_set_default_background(self.ship_info_console, libtcod.black)
self.message_height = 4
self.message_width = self.screen_width
self.messages = collections.deque([])
self.message_console = libtcod.console_new(self.message_width, self.message_height)
libtcod.console_set_default_foreground(self.message_console, libtcod.white)
libtcod.console_set_default_background(self.message_console, libtcod.black)
self.landing_screen_width = self.screen_width / 2 - 2
self.landing_screen_height = self.screen_height - 4
self.landing_console = libtcod.console_new(self.landing_screen_width, self.landing_screen_height)
libtcod.console_set_default_foreground(self.landing_console, libtcod.white)
libtcod.console_set_default_background(self.landing_console, libtcod.black)
self.mouse = libtcod.Mouse()
self.key = libtcod.Key()
galaxy_seed, ship_value = self.title_screen_loop()
# Loading Screen
libtcod.console_set_default_background(self.console, libtcod.black)
libtcod.console_clear(self.console)
self.galaxy = Galaxy(self.screen_width, self.screen_height, seed=galaxy_seed)
self.sector, self.starfield, self.nebula = self.galaxy.sectors[self.galaxy.current_sector].load_sector(self.console, self.buffer)
starting_planet = self.sector.planets[randrange(1, len(self.sector.planets))]
self.player_ship = Ship(self.sector, starting_planet.sector_position_x, starting_planet.sector_position_y, ship_value=ship_value)
self.add_message("Taking off from {0}".format(starting_planet.name))
self.current_screen = 'flight'
# self.add_message("Nebula Colors: r:{0} g:{1} b:{2}".format(
# round(self.nebula.r_factor,2),
# round(self.nebula.g_factor,2),
# round(self.nebula.b_factor,2)))
def title_screen_loop(self):
self.current_screen = 'title'
self.sector = Sector(self.screen_width, self.screen_height, self.buffer)
self.starfield = Starfield(self.sector, max_stars=50)
self.nebula = Nebula(self.sector, r_factor=random(), g_factor=random(), b_factor=random(), seed=randrange(1,1000000))
self.ships = [ [ Ship(self.sector, 0, 0), [self.screen_width/2-16, self.screen_height/2-8] ] for i in range(1) ]
done = False
xpos = 0.0
speed = 3
galaxy_starting_seed = str(randrange(1,1000000))
cursor_blinked = 0.0
cursor = collections.deque(['|', ''])
title = [
' _ _ _ _',
'| | | | | (_)',
'| |__| | ___| |_ ___ _ __ __ _ _ _ ___ ___',
'| __ |/ _ \\ | |/ _ \\| \'_ \\ / _` | | | / __|/ _ \\',
'| | | | __/ | | (_) | |_) | (_| | |_| \\__ \\ __/',
'|_| |_|\\___|_|_|\\___/| .__/ \\__,_|\\__,_|___/\\___|',
' | |',
' |_|',
]
while not done:
libtcod.sys_check_for_event(libtcod.KEY_PRESSED|libtcod.KEY_RELEASED|libtcod.EVENT_MOUSE, self.key, self.mouse)
self.starfield.scroll(0.0, speed)
self.starfield.draw()
self.sector.update_visibility(xpos, 0)
xpos += speed
self.nebula.draw()
#.........这里部分代码省略.........
示例6: World
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import draw [as 别名]
class World(ShowBase):
def __init__(self):
ShowBase.__init__(self)
print("- init game")
self.ship_control_type = 1 #0 keyboard, 1 mouse, 2 joystick
self.accept('escape', self.do_exit)
self.accept('r', self.do_reset)
self.start_menu = StartMenu(self)
def do_exit(self):
self.cleanup()
print("- end game")
sys.exit(0)
def cleanup(self):
print("-- clean up")
#self.joypad.clean()
def do_reset(self):
self.cleanup()
self.setup()
def setup(self):
print("-- start level")
self.bg = Background(self)
self.ship = Ship(self)
self.init_world()
self.init_ship()
self.init_lights()
self.init_camera()
self.mouse_collision = MouseCollision(self)
self.ship_collision = ShipCollision(self)
self.rock1 = Rock(self, 5, 5)
self.rock2 = Rock(self, -5, 6)
self.rock3 = Rock(self, -5, 3)
#self.joypad = Joypad()
# Tasks
self.taskMgr.add(self.update, 'update')
self.taskMgr.add(self.bg.update, 'updateBackground')
self.taskMgr.add(self.ship.update, 'updateShip')
#self.taskMgr.add(self.joypad.update, 'updateJoypad')
def init_world(self):
print("-- init world")
self.bg.draw()
def init_ship(self):
print("-- init ship")
self.ship.draw()
def init_lights(self):
print("-- init lights")
# Light
alight = AmbientLight('ambientLight')
alight.setColor(Vec4(0.1, 0.1, 0.1, 1))
alightNP = render.attachNewNode(alight)
dlight = DirectionalLight('directionalLight')
dlight.setDirection(Vec3(1, 1, -1))
dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
dlightNP = render.attachNewNode(dlight)
render.clearLight()
render.setLight(alightNP)
render.setLight(dlightNP)
def init_camera(self):
print("-- init camera")
self.disableMouse()
lens = OrthographicLens()
lens.setFilmSize(20, 15) # Or whatever is appropriate for your scene
#.........这里部分代码省略.........
示例7: Level
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import draw [as 别名]
class Level(GameState):
"""Level is a GameState with behavior for one full game level.
Contains Sprites player, enemy, shield, hbullet, cannon, and Group player_bullets
"""
def __init__(self, manager):
"""manager is required to be a child of GameManager with these functions:
-kill_player()
-next_level()
-add_score(amount)
-give_energy(amount)
-spend_energy(amount)
-give_life()
"""
GameState.__init__(self, manager)
self.player = Ship(*opt.player_args)
self.enemy = EnemyBase(opt.mover_args, opt.spinner_args, opt.shooter_args, self.player)
self.shield = EnemyShield(self.enemy, opt.shield_filename, formation, formation_center)
self.hbullet = HomingBullet(opt.homer_filename, self.player, opt.homer_speed)
self.cannon = Cannon(opt.deactivated_cannon_args, opt.standby_cannon_args,
opt.firing_cannon_args, self.player)
self.ion_field = IonField(*opt.ion_field_args)
self.player_bullets = Group()
self.reset_positions()
def update(self):
self.player.update()
self.enemy.update()
self.shield.update()
self.hbullet.update()
self.cannon.update()
self.player_bullets.update()
self.ion_field.update()
self.collisions()
def handle_events(self, events, keys):
return (event_handlers.check_quit(events, keys) and
event_handlers.check_shoot_button(events, keys, self.shoot) and
event_handlers.move_player(events, keys, self.player))
def draw(self, screen):
self.ion_field.draw(screen)
self.enemy.draw(screen)
self.shield.draw(screen)
self.player.draw(screen)
self.hbullet.draw(screen)
self.cannon.draw(screen)
self.player_bullets.draw(screen)
def collisions(self):
"""Handles collisions
"""
player = self.player
enemy = self.enemy
shield = self.shield
hbullet = self.hbullet
cannon = self.cannon
ion_field = self.ion_field
player_bullets = self.player_bullets
#player with homing bullet
if collide_mask(player, hbullet) and not collide_mask(player, ion_field):
self.kill_player()
#player with enemy base
if collide_mask(player, enemy):
#if base in moving phase, give player energy
if enemy.get_state_number() == EnemyBase.MOVING:
self.manager.give_energy(opt.energy_from_enemy)
#if base in spinning or shooting phase, kill player
elif enemy.get_state_number() == EnemyBase.SPINNING:
self.kill_player()
elif enemy.get_state_number() == EnemyBase.SHOOTING:
self.kill_player()
#player with cell
#-hitting a cell will bounce the player a bit to the left
#-if the player hit the cell twice in a short enough span,
# the cell is eaten and the player gets energy
#-in case of multiple collisions, deal with cell closest to player's center
#
#TODO: This still isn't quite right.
#Should be able to eat top/bottom rows with diagonal movement.
#(vertical movement should still move player all the way left)
pc_collides = spritecollide(player, shield, False, collide_mask)
center_cell = self.find_centermost_cell(pc_collides)
if center_cell is not None:
player.rect.right = center_cell.rect.left - opt.cell_bounceback
if not center_cell.marked:
#.........这里部分代码省略.........