from FGAme import World, AABB, pos world = World(friction=0.1, restitution=1, gravity=0) world.add_bounds(width=10) world.add( AABB( pos=pos.middle - (300, +150), vel=(270, 370), shape=(50, 50), color='random', ) ) world.register_energy_tracker() world.run()
from FGAme import World, RegularPoly, draw world = World() p = RegularPoly(4, 100, pos=(400, 300), world=world, omega=2, adamping=0.1) a = draw.Image("gaussiana.png", pos=(400, 300)) world.add(a, layer=-1) p.torque = lambda t: -p.inertia * p.theta world.run()
stacks.append('circles') stacks.append('polys') # Cria mundo com coeficiente de atrito global não-nulo world = World(friction=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)) C = Rectangle(pos=(125, 510), shape=(70, 50)) D = Rectangle(pos=(125, 550), shape=(100, 20)) world.add([A, B, C, D]) # Cria pilha de círculos if 'circles' in stacks: A = Circle(50, (250, 100), mass='inf', color='red') B = Circle(25, (320, 70), mass='inf', color='red') C = Circle(25, (380, 70), mass='inf', color='red')
# -*- coding: utf8 -*-_ ''' Este exemplo demonstra a resposta a colisões com atrito utilizando duas caixas AABB. ''' from FGAme import World, AABB # Cria mundo com coeficiente de atrito global não-nulo world = World(dfriction=0.1) world.add_bounds(width=10, col_layer=[0, 2]) # Cria objetos A = AABB(pos=(400, 100), shape=(50, 50), color='black', col_layer=2, col_group=1) B = AABB(pos=(150, 500), shape=(50, 50), vel=(200, -400), color='red', col_layer=2, col_group=1) def pause(): print('', B.bbox, '\n', A.bbox, '\n') world.toggle_pause() # Inicia a simulação world.add([A, B]) world.listen('key-down', 'space', pause) world.run()
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()
# Cria mundo com coeficiente de atrito global não-nulo world = World() world.add_bounds(width=10) stacks = [] stacks.append('aabbs') stacks.append('circles') stacks.append('rects') # Cria pilha de AABBs H = 550 dH = 200 if 'aabbs' in stacks: world.add(AABB(pos=(50, H), shape=(40, 40), color='red', vel=(200, 0))) for i in range(10): world.add(AABB(pos=(150 + i * 50, H), shape=(40, 40))) world.add(AABB(pos=(150 + 10 * 50, H), shape=(40, 40), color='red')) world.add(AABB(pos=(50, H - 50), shape=(40, 40), color='red', vel=(200, 0))) H -= dH # Cria pilha de círculos if 'circles' in stacks: world.add(Circle(20, pos=(50, H), color='red', vel=(200, 0))) for i in range(10): world.add(Circle(20, pos=(150 + i * 50, H))) world.add(Circle(20, pos=(150 + 10 * 50, H), color='red')) world.add(Circle(20, pos=(50, H - 50), color='red', vel=(200, 0))) H -= dH
# -*- 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()
from FGAme import World, Rectangle, pos from random import uniform world = World(friction=0.2, restitution=0.9, gravity=0) world.add_bounds(width=10) world.add( Rectangle( pos=pos.middle - (300, +150), vel=(270, 420 + uniform(0, 200)), shape=(50, 50), theta=0.2, color='random', ) ) world.listen('key-down', 'space', world.toggle_pause) world.register_energy_tracker() world.run()
from FGAme import Poly, World from FGAme.draw import RenderTree class Pointer(RenderTree): def __init__(self, button_center, mouse_pos): RenderTree.__init__(self) vertices = [] x = button_center[0] y = button_center[1] vertices.append((x, y + 1)) vertices.append((x + mouse_pos[0], y + mouse_pos[1])) vertices.append((x + mouse_pos[0], y + mouse_pos[1] - 2)) vertices.append((x, y - 1)) self.pointer = Poly(vertices, color='white') self.add(self.pointer) if __name__ == '__main__': game = World() game.add(Pointer()) game.run()
from FGAme import World, Circle, AABB, pos, conf, on_key_down import random conf.set_framerate(60) world = World() circle_list = [] for _ in range(5): circle = Circle(50, pos=pos.middle, world=world, color='random') circle_list.append(circle) o1 = AABB(pos=pos.middle, shape=(80, 71)) o2 = AABB(pos=pos.middle, shape=(80, 71), image='alien1') world.add(o1) world.add(o2, layer=2) @world.listen('frame-enter') def frame_enter_handler(): for circle in circle_list: x = random.random() * 800 y = random.random() * 600 circle.pos = x, y @on_key_down('space') def space(): world.toggle_pause() world.run()
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)) C = Rectangle(pos=(125, 510), shape=(70, 50)) D = Rectangle(pos=(125, 550), shape=(100, 20)) world.add([A, B, C, D]) # Cria pilha de círculos if 'circles' in stacks: A = Circle(50, (250, 100), mass='inf', color='red') B = Circle(25, (320, 70), mass='inf', color='red') C = Circle(25, (380, 70), mass='inf', color='red')
from FGAme import World, RegularPoly, draw world = World() p = RegularPoly(4, 100, pos=(400, 300), world=world, omega=2, adamping=0.1) a = draw.Image('gaussiana.png', pos=(400, 300)) world.add(a, layer=-1) p.torque = lambda t: -p.inertia * p.theta world.run()
from FGAme import World, AABB, Circle, Rectangle # Cria mundo com coeficiente de atrito global não-nulo world = World() world.add_bounds(width=10) stacks = [] stacks.append('aabbs') stacks.append('circles') stacks.append('rects') # Cria pilha de AABBs H = 550 dH = 200 if 'aabbs' in stacks: world.add(AABB(pos=(50, H), shape=(40, 40), color='red', vel=(200, 0))) for i in range(10): world.add(AABB(pos=(150 + i * 50, H), shape=(40, 40))) world.add(AABB(pos=(150 + 10 * 50, H), shape=(40, 40), color='red')) world.add(AABB(pos=(50, H - 50), shape=(40, 40), color='red', vel=(200, 0))) H -= dH # Cria pilha de círculos if 'circles' in stacks: world.add(Circle(20, pos=(50, H), color='red', vel=(200, 0))) for i in range(10): world.add(Circle(20, pos=(150 + i * 50, H))) world.add(Circle(20, pos=(150 + 10 * 50, H), color='red')) world.add(Circle(20, pos=(50, H - 50), color='red', vel=(200, 0))) H -= dH