本文整理汇总了Python中world.World.draw方法的典型用法代码示例。如果您正苦于以下问题:Python World.draw方法的具体用法?Python World.draw怎么用?Python World.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类world.World
的用法示例。
在下文中一共展示了World.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
def main():
# Init graphics
pygame.init()
window = pygame.display.set_mode((1060, 760)) # This is the size of the field + contestant area. (5300 x 3800)
pygame.display.set_caption('Robotex 2011 Simulator')
screen = pygame.display.get_surface()
# Init world.
world = World(screen)
# Add 11 balls (coordinates are world-coords)
#random.seed(3)
for i in range(11):
world.add_object(Ball(Point(random.uniform(10,world.width-10),random.uniform(10,world.height-10))))
# Create two robots
robot1 = Robot(world, "Robot A", Point(12+45/2, 12+35/2), beacon_point = Point(world.width + 50, world.cy))
robot1.rotate(3.1415/2)
robot2 = Robot(world, "Robot B", Point(world.width-(12+45/2), world.height-(12+35/2)), beacon_point = Point(-50, world.cy))
robot2.rotate(-3.1415/2)
world.add_object(robot1)
world.add_object(robot2)
# Start robot command servers
RobotServer(robot1, 5000).serve()
RobotServer(robot2, 5001).serve()
# Do the simulation/drawing/event cycle
last_sim = -1000
last_draw = -1000
while True:
t = get_ticks()
if (t - last_sim) > 1:
# Simulate world (~1 iteration once every millisecond or so)
# NB: This is kinda hard-coded into the logic currently,
# i.e. World.simulate() and Ball.simulate() and anyone else is
# free to assume that a simulation step is 1ms. In particular,
# the ball computes it's friction coefficient like that.
world.simulate()
last_sim = t
if (t - last_draw) > 40:
# Draw a frame once every 40 milliseconds or so (~25 fps)
BACKGROUND_BLUE = (120,119,253)
screen.fill(BACKGROUND_BLUE)
world.draw(screen)
pygame.display.flip()
last_draw = t
# Process input
input(pygame.event.get())
示例2: game
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
def game(stdscr):
curses.curs_set(0)
stdscr.nodelay(1)
world = World(stdscr, 160, 80)
room1 = Room(world, world.dims[0]/2-4,world.dims[1]/2-4,8,10)
room2 = Room(world, room1.x + room1.w + 1, room1.y + room1.h - 1, 10, 1)
room1.add_opening(room1.x + room1.w, room1.y + room1.h - 1)
room2.add_opening(room1.x + room1.w, room1.y + room1.h - 1)
world.rooms = [room1, room2]
world.player.room = room1
world.draw()
while True:
world.do_turn()
if world.exiting:
break
time.sleep(1/60.0)
示例3: App
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
class App(object):
def __init__(self):
self.world = World()
self.win = pyglet.window.Window(fullscreen=True, vsync=True)
self.win.set_exclusive_keyboard()
for i in dir(self):
if i.startswith('on_'):
setattr(self.win, i, getattr(self, i))
self.camera = Camera(self.win, zoom=100.0)
self.hud = Hud(self.win)
clock.set_fps_limit(60)
def on_mouse_drag(self, x, y, dx, dy, buttons, mods):
pass
def on_mouse_motion(self, x, y, dx, dy):
pass
def on_mouse_press(self, x, y, button, mods):
pass
def on_mouse_release(self, x, y, button, mods):
pass
def mainLoop(self):
while not self.win.has_exit:
try:
self.win.dispatch_events()
self.world.step()
self.camera.worldProjection()
self.world.draw()
self.camera.hudProjection()
self.hud.draw()
clock.tick()
self.win.flip()
except (SystemExit):
sys.exit(0)
except:
pass
示例4: Game
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
class Game(pyglet.window.Window):
def __init__(self, thinker_colors, thinkers):
config = pyglet.gl.Config(buffer_size=32,
alpha_size=8,
double_buffer=True)
super(Game, self).__init__(width=1024, height=768,
config=config, resizable=True)
self.world = World(10, 8)
self.thinker_colors = thinker_colors
self.thinkers = thinkers
self.world.add_tanks(thinker_colors)
pyglet.clock.schedule_interval(self.update_closure(), 1.0/60.0)
font = pyglet.font.load("terminal", bold=True)
color = (0.0, 1.0, 1.0, 1.0)
fmt = '%(fps).1f'
self.fps_display = pyglet.clock.ClockDisplay(font=font,
color=color,
format=fmt)
self.keys = key.KeyStateHandler()
self.push_handlers(self.keys)
def update_closure(self):
def update(dt):
for tank, thinker in zip(self.world.tanks, self.thinkers):
# only think on tanks that aren't doing anything
if tank.brain and tank.is_idle():
thinker_think(tank, thinker)
self.world.update(dt)
return update
def on_draw(self):
self.clear()
self.world.draw()
self.fps_display.draw()
示例5: simple_scenario_with_plot
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
def simple_scenario_with_plot():
the_map = Map('s1')
#obstacle = Polygon([(30,15), (35,15), (35,20), (30,20)], safety_region_length=4.0)
#the_map.add_obstacles([obstacle])
tend = 50
dT = 1
h = 0.05
N = int(tend/h) + 1
N2 = int(tend/dT) + 1
x0 = np.array([0, 0, 0.5, 3.0, 0, 0])
xg = np.array([120, 120, 0])
myDynWnd = DynamicWindow(dT, N2)
v = Vessel(x0, xg, h, dT, N, [myDynWnd], is_main_vessel=True, vesseltype='viknes')
v.current_goal = np.array([50, 50])
world = World([v], the_map)
myDynWnd.the_world = world
n = 0
for t in np.linspace(0, tend, N):
world.update_world(t, n, dT)
n += 1
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal', autoscale_on=False,
xlim=(-10, 10), ylim=(-10, 10))
#fig, ax = plt.subplots()
ax.grid()
world.draw(ax, N)
print "N, N2, n: ", N, N2, n
myDynWnd.draw(ax, N2)
plt.show()
示例6: main
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
def main():
pygame.init()
world = World(pygame.display.set_mode(SCREEN_SIZE))
pygame.display.set_caption('Gatherers')
background = pygame.Surface(world.screen.get_size())
background = background.convert()
background.fill(BACKGROUND_COLOR)
world.screen.blit(background, (0,0))
pygame.display.flip()
clock = pygame.time.Clock()
gatherers = pygame.sprite.Group()
for i in range(20):
x = random.randint(0,world.screen.get_width())
y = random.randint(0,world.screen.get_height())
world.addGoody((x,y))
while 1:
clock.tick(30)
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
elif event.type == MOUSEBUTTONDOWN:
m = pygame.mouse.get_pressed()
if m[0]:
world.addGatherer(pygame.mouse.get_pos())
if m[2]:
world.addEnemy(pygame.mouse.get_pos())
world.update()
world.screen.blit(background, (0,0))
world.draw()
pygame.display.flip()
示例7: World
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
from time import sleep
from Tkinter import *
import time, threading
import random
from snake import Snake
from ptitpois import Ptitpois
from world import World
w = World()
vasya = Snake()
w.add(vasya,5, 5)
w.draw()
w.start()
示例8: get
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
class Engine:
@staticmethod
def get():
return Engine.instance
def __init__(self):
Engine.instance = self
self.screenWidth = 1280
self.screenHeight = 720
pygame.init()
if hasattr(pygame, 'GL_SWAP_CONTROL'):
pygame.display.gl_set_attribute(pygame.GL_SWAP_CONTROL,1)
pygame.display.set_mode((self.screenWidth, self.screenHeight),pygame.OPENGL | pygame.DOUBLEBUF)
pygame.display.set_caption('LD28')
# GL setup
glEnable(GL_BLEND)
glEnable(GL_TEXTURE_2D)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glDisable(GL_CULL_FACE)
glDepthMask(GL_FALSE)
glDisable(GL_DEPTH_TEST)
TextureManager()
self.keysDown = pygame.key.get_pressed()
self.keysDownLastFrame = self.keysDown
from world import World
self.world = World()
def key_down(self, k):
return self.keysDown[k]
def key_pressed(self, k):
return self.keysDown[k] and not self.keysDownLastFrame[k]
def update(self, delta):
self.keysDownLastFrame = self.keysDown
self.keysDown = pygame.key.get_pressed()
self.world.update(delta)
def draw(self):
#glClearColor(0,0,0,1)
glClearColor(128/255.0,215/255.0,255/255.0,1)
glClear(GL_COLOR_BUFFER_BIT)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, self.screenWidth, self.screenHeight, 0, -10, 10)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
self.world.draw()
pygame.display.flip()
def run(self):
last_time = time.time()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
now = time.time()
if now < last_time:
last_time = now
delta = now - last_time
delta = clamp(delta, 0, 0.1)
last_time = now
self.update(delta)
self.draw()
示例9:
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
k.do_damage(1)
explode_sound.play()
SCORE += 10
# Check player and coin
if pygame.sprite.collide_circle(time_power, player):
time_sound.play()
countdown.inc()
coin_placed = False
if player.health <= 0 or countdown.get() < 0:
explode_sound.play()
GAME_STATE = 0
#Draw objects
world.draw(screen)
visible_kamas.draw(screen)
player.draw(screen)
exploder.draw(screen)
bullets.draw(screen)
time_power.draw(screen)
# Draw ui stuff
distance = math.sqrt((WIDTH/2 - time_power.rect.centerx)**2 + (HEIGHT/2 - time_power.rect.centery)**2)
if distance > 400:
arrow.draw(screen)
if time_power.rect.left > -2*WIDTH and time_power.rect.right < 3*WIDTH \
and time_power.rect.top > -2*HEIGHT and time_power.rect.bottom < 3*HEIGHT:
minimap.draw(screen, kamas_on_minimap, time_power)
else:
minimap.draw(screen, kamas_on_minimap)
示例10: str
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
dt_accum += dt
if dt_accum >= 1:
frame_rate.string = str(frame_accum)
dt_accum = 0
frame_accum = 0
# process events
input.handle()
# Update world
world.update(dt)
# Update camera
view.center = world.player._sprite.position
## Draw
window.clear(sf.Color(120, 120, 120)) # clear screen
window.view = view
# Draw the world
world.draw(window)
#### Draw GUI stuff, reset view
window.view = window.default_view
# Draw framerate
window.draw(frame_rate)
window.display() # update the window
示例11: Run
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
#.........这里部分代码省略.........
self.holdingSpace = False
self.WFPS = 60
self.FPSlist = [ self.WFPS ]
self.events = [ ]
def eventListener( self ):
if p.mouse.get_pressed( ) == ( 1, 0, 0 ) and self.world.player.shoot_timer < 0:
self.world.player.shoot( {
"dad" : self.world.player,
"color" : ( 250, 250, 0 ),
"colorindex" : ( 20, 100, 0 ),
"angle" : self.world.player.rotation,
"radius" : self.world.s1.sliderpos,
"speed" : 7,
"damage" : 3,
"lifetime" : 90,
"pos" : self.world.player.pos,
} )
self.world.player.shoot_timer = 2
if p.mouse.get_pressed( ) == ( 0, 0, 1 ) and self.world.player.rocketshoot_timer <= 0:
self.world.player.rocketshoot( )
for e in self.events:
if e.type == p.QUIT:
self.active = False
p.quit()
quit()
if e.type == p.KEYDOWN:
if e.unicode == "d":
self.world.player.vx = self.world.player.speed
if e.unicode == "a":
self.world.player.vx = -self.world.player.speed
if e.unicode == "w":
self.world.player.vy = -self.world.player.speed
if e.unicode == "s":
self.world.player.vy = self.world.player.speed
if e.unicode == " ":
self.holdingSpace = True
if e.key == p.K_ESCAPE:
self.active = False
if e.type == p.KEYUP:
if e.key == p.K_d and self.world.player.vx > 0:
self.world.player.vx = 0
if e.key == p.K_SPACE:
self.holdingSpace = False
if e.key == p.K_a and self.world.player.vx < 0:
self.world.player.vx = 0
if e.key == p.K_s and self.world.player.vy > 0:
self.world.player.vy = 0
if e.key == p.K_w and self.world.player.vy < 0:
self.world.player.vy = 0
def update( self ):
self.world.update( )
def draw( self ):
self.world.draw( )
def loop( self ):
clk = p.time.Clock( )
while self.active:
lasttime = time.time( )
self.events = p.event.get( )
self.eventListener( )
self.update( )
self.draw( )
FPS = 0
for x in self.FPSlist:
FPS += x
Messages.message( self.scr, round( FPS / len( self.FPSlist ), 1 ), ( 10, 10 ), p.Color( 'magenta' ) )
p.display.update( )
now = time.time( )
self.FPSlist.append( round( 1.0 / ( now - lasttime ), 0 ) )
if len( self.FPSlist ) > 100: del self.FPSlist[ 0 ]
clk.tick( self.WFPS )
示例12: main
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
def main():
# initialize pygame
pygame.init()
# initialize screen
info = display.Info()
screenSize = (info.current_w, info.current_h)
screen = display.set_mode(screenSize, pygame.FULLSCREEN)
mouse.set_visible(False)
# intialize clock
clock = time.Clock()
infoFont = font.Font(font.match_font('arial'), 12)
# initialize game world
world = World(screen)
# start music
mixer.music.load("resources/pad.ogg")
mixer.music.set_volume(0.1)
mixer.music.play(-1)
# begin main game loop
done = False
while not done:
# check for program exit signal
for e in event.get():
if e.type == pygame.QUIT:
done = True
# check for input
keys = key.get_pressed()
if keys[pygame.K_ESCAPE]:
done = True
# update game
world.update(clock.tick())
# render game
world.draw()
# draw fps
fps = clock.get_fps()
if DISPLAY_FPS:
text = infoFont.render(str(int(round(fps))), True, (255, 255, 255))
position = (screen.get_width() / 2 - text.get_width() / 2, 32)
screen.blit(text, position)
# add particles until the processor can't handle it
if fps > FRAME_RATE + 5:
world.addParticle()
# flip buffer
display.flip()
# clean up
pygame.quit()
示例13: Game
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
class Game(pyglet.window.Window):
"""Contains the game logic.
It creates the world and the player. It ensures every object has time to
update and draw itself. It also handles the game logic like gravity.
"""
def __init__(self, *args, **kwargs):
super(Game, self).__init__(*args, **kwargs)
self.FRAMES_PER_SEC = 60
self.TERMINAL_VELOCITY = 10.0
self.GAME_SPEED = 4.0
self.SKY_COLOR = (135/255.0, 206/255.0, 235/255.0, 1.0)
self.FOG_START = 20.0
self.FOG_END = 60.0
self.FOV = 65.0
self.GRAVITY = 0.5
self.exclusive = False
self.world = World()
self.player = Player((0, 50, 0))
self.world.load_chunks(self.player.position)
self.world.update(float('inf'))
self.player.velocity[1] = -1
self.setup_opengl()
self.setup_crosshair()
self.clear()
self.set_exclusive_mouse(True)
pyglet.clock.schedule_interval(self.update, 1.0/self.FRAMES_PER_SEC)
def setup_opengl(self):
"""Sets up OpenGL settings.
Enables culling, depth and fog.
"""
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glEnable(GL_FOG)
glFogfv(GL_FOG_COLOR, (GLfloat * 4)(*self.SKY_COLOR))
glHint(GL_FOG_HINT, GL_DONT_CARE)
glFogi(GL_FOG_MODE, GL_LINEAR)
glFogf(GL_FOG_START, self.FOG_START)
glFogf(GL_FOG_END, self.FOG_END)
def setup_crosshair(self):
"""Creates the crosshair in the middle of the screen.
"""
width, height = self.get_size()
size = 10
x = width/2
y = height/2
self.crosshair = vertex_list(4, ('v2i', (x - size, y, x + size, y, x,
y - size, x, y + size)))
def clear(self):
super(Game, self).clear()
glClearColor(*self.SKY_COLOR)
glColor3d(1, 1, 1)
def set_exclusive_mouse(self, exclusive):
super(Game, self).set_exclusive_mouse(exclusive)
self.exclusive = exclusive
def setup_3d(self):
"""Sets up the 3D view.
"""
width, height = self.get_size()
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(self.FOV, width / float(height), 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
x, y = self.player.rotation
glRotatef(x, 0, 1, 0)
# Invert it otherwise moving up means looking down
glRotatef(y, -math.cos(math.radians(x)), 0, -math.sin(math.radians(x)))
x, y, z = self.player.position
glTranslatef(-x, -y, -z)
def setup_2d(self):
"""Sets up the 2D view.
"""
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
width, height = self.get_size()
gluOrtho2D(0, width, 0, height)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def draw_crosshair(self):
"""Draws the crosshair.
"""
glColor3d(0.25, 0.25, 0.25)
self.crosshair.draw(GL_LINES)
def on_draw(self):
"""Draws the world in 3D and the crosshair in 2D.
"""
self.clear()
#.........这里部分代码省略.........
示例14: main
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
def main():
# Read two parameters identifying modules for the first and the second robots.
if (len(sys.argv) < 3):
print "Usage: python main.py <first_robot> <second_robot> [random seed]"
print ""
print "The <first_robot> and <second_robot> should identify modules containing classes Robot and RobotServer"
print "E.g if you invoke "
print " python main.py telliskivi ekrs"
print "The simulator will import telliskivi.Robot, telliskivi.RobotServer, ekrs.Robot, ekrs.RobotServer"
sys.exit(1)
# Try to import modules
r1module = __import__(sys.argv[1])
r2module = __import__(sys.argv[2])
(a,b,c,d) = (r1module.Robot, r1module.RobotServer, r2module.Robot, r2module.RobotServer) # Testing
random_seed = int(sys.argv[3]) if len(sys.argv) > 3 else None
# random seeds 1,2,3,4 are already interesting use cases
# Init graphics
pygame.init()
window = pygame.display.set_mode((1060, 760)) # This is the size of the field + contestant area. (5300 x 3800)
pygame.display.set_caption('Robotex 2011 Simulator')
screen = pygame.display.get_surface()
# Init world.
world = World(screen)
# Add 11 balls (coordinates are world-coords)
# Make sure the balls are added symmetrically. That means the first ball goes in the center
world.add_object(Ball(Point(world.width/2, world.height/2)))
for i in range(5):
while True:
xpos = random.uniform(10,world.width-10)
ypos = random.uniform(10,world.height-10)
# Make sure the positions do not get in the robot's starting corners ( 0..60px, i.e. 0..60px )
if not ((xpos < 60 and ypos < 60) or (xpos > world.width - 60 and ypos > world.height - 60)):
break
world.add_object(Ball(Point(xpos, ypos)))
world.add_object(Ball(Point(world.width-xpos, world.height-ypos)))
# Create two robots
robot1 = r1module.Robot(world, "Robot A", "TOPLEFT")
robot2 = r2module.Robot(world, "Robot B", "BOTTOMRIGHT")
world.add_object(robot1)
world.add_object(robot2)
# Start robot command servers
r1module.RobotServer(robot1, 5000).serve()
r2module.RobotServer(robot2, 5001).serve()
# Do the simulation/drawing/event cycle
last_sim = -1000
last_draw = -1000
while True:
t = get_ticks()
if (t - last_sim) > 1:
# Simulate world (~1 iteration once every millisecond or so)
# NB: This is kinda hard-coded into the logic currently,
# i.e. World.simulate() and Ball.simulate() and anyone else is
# free to assume that a simulation step is 1ms. In particular,
# the ball computes it's friction coefficient like that.
world.simulate()
last_sim = t
if (t - last_draw) > 40:
# Draw a frame once every 40 milliseconds or so (~25 fps)
BACKGROUND_BLUE = (120,119,253)
screen.fill(BACKGROUND_BLUE)
world.draw(screen)
pygame.display.flip()
last_draw = t
# Process input
input(pygame.event.get())
示例15: in
# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import draw [as 别名]
c.rotate( -ev.rel[1]*0.01, -ev.rel[0]*0.01 )
handle_key[K_w] = lambda k, d: c.set_translation( z = (0.5 if d else 0.) )
handle_key[K_s] = lambda k, d: c.set_translation( z = (-0.5 if d else 0.) )
handle_key[K_a] = lambda k, d: c.set_translation( x = (-0.5 if d else 0.) )
handle_key[K_d] = lambda k, d: c.set_translation( x = (0.5 if d else 0.) )
handle_key[K_p] = lambda k, d: pdb.set_trace()
handle_key[K_UP] = lambda k, d: c.set_rotation( x = (0.01 if d else 0.) )
handle_key[K_DOWN] = lambda k, d: c.set_rotation( x = (-0.01 if d else 0.) )
handle_key[K_RIGHT] = lambda k, d: c.set_rotation( y = (0.01 if d else 0.) )
handle_key[K_LEFT] = lambda k, d: c.set_rotation( y = (-0.01 if d else 0.) )
event = pygame.event.poll()
while event.type not in ( NOEVENT, QUIT ):
event = pygame.event.poll()
while event.type != QUIT:
event = pygame.event.poll()
while event.type not in ( NOEVENT, QUIT ):
if event.type in handle_event:
handle_event[ event.type ]( event )
event = pygame.event.poll()
r.begin_frame()
c.update( r )
w.draw( r, c )
r.end_frame()