예제 #1
0
from FGAme import World, RegularPoly

world = World()
p = RegularPoly(4, 100, pos=(400, 300), world=world, omega=2, adamping=0.1)
# FIXME: p.external_torque = lambda t: - p.inertia * p.theta
world.run()
예제 #2
0
# -*- coding: utf8 -*-_
'''
Este exemplo demonstra a resposta a colisões com atrito utilizando duas caixas
AABB.
'''

from FGAme import World, Circle

# Cria mundo com coeficiente de atrito global não-n'ulo
world = World(dfriction=0.5, gravity=300, restitution=0.0)
world.add_bounds(width=10)

N = 5
aabbs = []
for i in range(N):
    aabbs.append(
        Circle(25 + 5 * i, pos=(400, 50 + i * 100), world=world, color='red'))
aabbs[0].make_static()
#aabbs[0].boost((0, 700))

#@world.listen('frame-enter')
# def print_vels():
#    meansqr = sum(x.vel.y ** 2 for x in aabbs) ** 0.5
# print('  vels: (%5.3f)' % meansqr +
#      '; '.join(['%5.3f' % x.vel.y for x in aabbs]))

# print('  pos: ' +
#      '; '.join(['%5.3f' % x.pos.y for x in aabbs]))

world.register_energy_tracker()
# Inicia a simulação
예제 #3
0
        j = y / self.tilesize
        return i, j

    @coords.setter
    def coords(self, value):
        self.pos_sw = asvector(value) * self.tilesize + self.tileorigin


if __name__ == '__main__':
    from FGAme import World

    ts = '''
    |            oo
    |        oo     xxxxxxxxxxxxxxxxxx
    |           xxx
    |       xxx
    |                                        ii
    |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxiiiixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    '''

    w = World()
    tm = TileManager((30, 30))
    tm.register_spec('brick', 'x', color='red')
    tm.register_spec('coin', 'o', shape='circle', color='yellow')
    tm.register_spec('spike', 'i', color='black')
    tm.add_tilemap(ts)

    w.add(tm)
    w.run()
예제 #4
0
# -*- coding: utf8 -*-_

'''
Este exemplo demonstra a resposta a colisões com atrito utilizando duas caixas
AABB.
'''

from FGAme import World, AABB

print(AABB)

# Cria mundo com coeficiente de atrito global não-nulo
world = World(dfriction=0.1)
world.set_bounds(width=10)

# Cria objetos
A = AABB(pos=(400, 100), shape=(50, 50), color='black')
B = AABB(pos=(150, 500), shape=(50, 50), vel=(200, -400), color='red')

# Inicia a simulação
world.add([A, B])
world.listen('key-down', 'p', world.toggle_pause)
world.run()
예제 #5
0
from FGAme import World, listen, pos
from random import uniform

world = World(friction=0.2, restitution=0.9, gravity=0)
world.add.margin(10)
world.add.rectangle(
    pos=pos.middle - (300, +150),
    vel=(270, 420 + uniform(0, 200)),
    shape=(50, 50),
    theta=0.2,
    color='random',
)

listen('key-down', 'space', world.toggle_pause)
world.track.energy()
world.run()
예제 #6
0
'''
Este exemplo demonstra a resposta a colisões com atrito utilizando duas caixas
AABB.
'''

from FGAme import World, AABB, Circle, RegularPoly, Rectangle, pi

stacks = []
stacks.append('aabbs')
stacks.append('rects')
stacks.append('circles')
stacks.append('polys')


# Cria mundo com coeficiente de atrito global não-nulo
world = World(dfriction=0.5, gravity=500, restitution=0.7, adamping=0.1)
world.add_bounds(width=10)

# Cria pilha de AABBs
if 'aabbs' in stacks:
    A = AABB(pos=(100, 70), shape=(100, 50), color='red', mass='inf')
    B = AABB(pos=(125, 150), shape=(50, 50))
    C = AABB(pos=(125, 250), shape=(70, 50))
    D = AABB(pos=(125, 300), shape=(100, 20))
    aabbs = [B, C, D]
    world.add([A, B, C, D])

# Cria pilha de Retângulos
if 'rects' in stacks:
    A = Rectangle(pos=(100, 370), shape=(100, 50), color='red', mass='inf')
    B = Rectangle(pos=(125, 450), shape=(50, 50))