本文整理汇总了Python中vec.vec函数的典型用法代码示例。如果您正苦于以下问题:Python vec函数的具体用法?Python vec怎么用?Python vec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: touch
def touch(self,sprite,oldsprite):
# takes a sprite, calculates collision with it, returns it bundled in a tuple with a tuple of the sides the sprite touched
relspritepos = vec(BLKX*(sprite.blk.x-self.blk.x)+sprite.pos.x,BLKY*(sprite.blk.y-self.blk.y)+sprite.pos.y)
# print 'NOW COLLISION:\nrelspritepos =',relspritepos
reloldspritepos = vec(BLKX*(oldsprite.blk.x-self.blk.x)+oldsprite.pos.x,BLKY*(sprite.blk.y-self.blk.y)+oldsprite.pos.y)
# print 'reloldspritepos =',reloldspritepos
spritebottom = relspritepos.y
# print 'spritebottom =',spritebottom
spriteleft = relspritepos.x
# print 'spriteleft =',spriteleft
spriteright = relspritepos.x+sprite.dim.x-1.
# print 'spriteright =',spriteright
oldspritebottom = reloldspritepos.y
# print 'oldspritebottom =',oldspritebottom
oldspriteleft = reloldspritepos.x
# print 'oldspriteleft =',oldspriteleft
oldspriteright = reloldspritepos.x+oldsprite.dim.x-1.
# print 'oldspriteright =',oldspriteright,'\nTILE STATE:\nself.top =',self.top,'\nself.bottom =',self.bottom,'\nself.left =',self.left,'\nself.right =',self.right
sides = [] # sides from which the tile was impacted upon; returned as part of a tuple with the sprite itself
if (spritebottom <= self.top+1 and self.top+1 <= oldspritebottom) and (spriteright >= self.left and self.right >= spriteleft):
sprite.vel.y = 0
sprite.pos.y = self.top+1.
sprite.blk = self.blk
if not sprite.walks:
sprite.F.x += sprite.F.y*self.fric
sides.append('top')
return (sides,sprite)
示例2: menuinit
def menuinit():
global u, f, p, zoom, beta
u = vec(0, 0, 1)
f = vec(1, 0, 0)
p = f
beta = 0
zoom = 100
示例3: AtoB
def AtoB(self, pos_a):
"""
A -- position relative to user interface window
B -- position on game map
"""
return (vec(pos_a) - vec(self.pos)) / self.get_zoom() + self.window_pos
示例4: rblit_map
def rblit_map(self, to, render_tab, window_pos, window_end, zoom):
"""
scale map visible through window to dim and blit
window_dim = dim * scale
"""
terr = self.game.map
# total area
cmax_ij = terr.size()
cmin_ij = 0,0
# window covered area
vmin_ij = map(int, window_pos / FIELD_DIM)
vmax_ij = map(int, window_end / FIELD_DIM + vec(1,1))
min_ij = max(vmin_ij[0], cmin_ij[0]), max(vmin_ij[1], cmin_ij[1])
max_ij = min(vmax_ij[0], cmax_ij[0]), min(vmax_ij[1], cmax_ij[1])
for j in range(min_ij[1], max_ij[1]):
for i in range(min_ij[0], max_ij[0]):
t = terr.get(i,j)
a = self.BtoA(vec(i,j) * FIELD_DIM)
render_tab[t].render(scale = zoom).rblit(to, a)
示例5: attack
def attack(self, entity):
"""Try to attack other players in range"""
# Fetch components
body = self.engine.entities.bodies.get(entity)
character = self.engine.entities.characters.get(entity)
if not body or not character:
return
# Find players in range
for other_entity in self.engine.entities.players:
if entity == other_entity:
continue
# Fetch components
other_body = self.engine.entities.bodies.get(other_entity)
other_character = self.engine.entities.characters.get(other_entity)
other_animation = self.engine.entities.animations.get(other_entity)
if not other_body or not other_character:
continue
# Check if other player near enough
if (vec(other_body) - vec(body)).length() > character.attack_range:
continue
# Try to attack, succeeds if cool down has finished
if character.attack(other_character):
other_body.bounce_from(body)
if other_animation:
other_animation.play('hit')
示例6: __init__
def __init__(self, **kwargs):
""" Proxy dodajace funkcjonalnosc content (rblit) dzieki czemu mozna wstawic do CBoxa
game -- obiekt Game ktory bedzie reprezentowany
"""
self.game = kwargs.pop('game')
self.env = kwargs.pop('env')
self.ctrl = kwargs.pop('ctrl')
super(GameBox, self).__init__(**kwargs)
self.window_pos = vec(0, 0)
self.window_dim = None #(20,20) #self.dim
self._rscale = 1.0
self._dscale = 1.0
self.map_dim = vec(self.game.map.size()) * 24
self.selected = None
# warstwa sladow
#self.tracks
self.on(self.ctrl, et.MOUSEBUTTONDOWN, self.onclick)
示例7: benchmark
def benchmark(integrator):
m1 = mass.mass(m_SUN, vec(0, 0, 0), vec(0, 0, 0))
m2 = mass.mass(m_SUN, vec(1, 0, 0), vec(0, 0, 0))
def test():
integrator([m1, m2])
import timeit
print(timeit.timeit(test, number=10000) / 10000)
示例8: __init__
def __init__(self):
self.entities = Entities()
self.events = Events()
self.running = True
self.width = 640
self.height = 480
self.level = vec()
self.scroll = vec()
示例9: compute_init
def compute_init(b, z0):
(z,info) = sp.sparse.linalg.cgs(A_cgs_init, vec(b), x0=vec(z0), tol=1e-2)
if info > 0:
print 'cgs convergence to tolerance not achieved'
elif info <0:
print 'cgs gets illegal input or breakdown'
z = np.reshape(z, x_shape, order='F')
return z
示例10: init
def init():
global u, f, p, zoom, target, beta
beta = 0.2
u = vec(-math.cos(beta), 0, math.sin(beta))
f = vec(math.sin(beta), 0, math.cos(beta))
p = vec(0, 0, 1)
zoom = 80
target = None
示例11: __init__
def __init__(self, height, diameter, detail=12):
d = 2 * math.pi / detail
r = diameter * 0.5
vs = [(math.sin(i * d) * r, math.cos(i * d) * r) for i in range(detail)]
self.verts = [vec(v[0], height * 0.5, v[1]) for v in vs]
self.verts += [vec(v[0], height * -0.5, v[1]) for v in vs]
self.polys = [(i, i + detail, (i+1) % detail + detail, (i+1) % detail) for i in range(detail)]
self.polys.append(range(detail))
self.polys.append(range(detail, detail*2)[::-1])
示例12: main
def main():
m1 = mass.mass(m_SUN, vec(0, 0, 0), vec(0, 0, 0))
m2 = mass.mass(m_EARTH, vec(r_EARTH, 0, 0), vec(0, 107300, 0))
initial_radius = m1.q.dist(m2.q)
for masses in run_time([m1, m2], 0.01, explicit, iters=100000): pass
final_radius = m1.q.dist(m2.q)
print('delta_distance = %f (%.3f%%)' % (
final_radius - initial_radius,
(final_radius - initial_radius) * 100 / initial_radius))
示例13: __init__
def __init__(self, rect):
super().__init__(rect.left, rect.top, rect.width, rect.height)
self.real = vec(self.x, self.y)
self.standing = False
self.ontops = set()
self.underneaths = set()
# Physics properties
self.velocity = vec()
self.dumping = vec(0.01)
self.friction = vec(0.03, 0)
self.restitution = 0.2
self.mass = 1.0
示例14: initstone
def initstone():
global stone
A, B, C, D = vec(1,1,1).norm(), vec(-1,1,-1).norm(), vec(-1,-1,1).norm(), vec(1,-1,-1).norm()
a, b, c, d = A.times(-1), B.times(-1), C.times(-1), D.times(-1)
def flatten(*args):
for arg in args:
for x in arg:
yield x
vertexdata = list(flatten(A,B,C, A,C,D, A,D,B, C,B,D, a,c,b, a,d,c, a,b,d, c,d,b))
normaldata = list(flatten(d,d,d, b,b,b, c,c,c, a,a,a, D,D,D, B,B,B, C,C,C, A,A,A))
stone = makedrawable(GL_TRIANGLES, vertexdata, None, normaldata)
示例15: rblit
def rblit(self, to):
render_tab = self.env.render_tab
zoom = self.get_zoom()
to.set_clip(Rect(self.pos, self.dim))
self.rblit_map(to,
render_tab = render_tab,
window_pos = self.window_pos,
window_end = self.window_end,
zoom = zoom,
)
sgame = sorted(self.game, lambda a,b: cmp(a.z, b.z))
for x in sgame:
if x.__class__ in self.env.render_tab:
ni = self.env.render_tab[x.__class__].render(scale = zoom)
ni.rblit(to, self.BtoA(x.pos))
if self.selected:
to.draw_rect(self.BtoA(self.selected.pos), self.selected.dim * zoom, (0.5,0.5,0.5), 1)
if self.border:
to.draw_rect(vec(self.pos), self.dim, (0.5,0.5,0.5), 1)
# draw ghost under mouse cursor if any
mpos = vec(pygame.mouse.get_pos())
o = self.env.order
a = o.action
p = o.get_next_param_type()
if a == 'move' and p == 'point':
ghost = render_tab['move'].render(scale = zoom)
elif a == 'build' and p == 'point':
struct = o.args[1]
if struct in render_tab:
ghost = render_tab[struct].render(scale = zoom)
else:
ghost = None
if ghost:
ghost.rblit(to, mpos - ghost.dim / 2.0)
to.set_clip(None)