def draw():
    #Lighting pass
    light_occluders = []
    for particle in particle_system.particles:
        x, y = particle.position
        light_occluders.append(
            occluder.Occluder([[x, y], [x, y + 1], [x + 1, y + 1], [x + 1,
                                                                    y]]))
    shad.set_occluders(light_occluders)

    mask, draw_pos = shad.get_mask_and_position(False)
    mask.blit(surf_falloff, (0, 0), special_flags=BLEND_MULT)

    surf_lighting.fill((50, 50, 50))
    surf_lighting.blit(mask, draw_pos, special_flags=BLEND_MAX)

    #Scene pass
    surface.fill((128, 128, 128))
    particle_system.draw(surface)

    #Composite pass
    surface.blit(surf_lighting, (0, 0), special_flags=BLEND_MULT)

    #Redraw the particle system.  In this case we don't want it shadowed
    particle_system.draw(surface)

    #Flip
    pygame.display.flip()
Exemple #2
0
    def update(self, dt, screen_size):
        self.position[0] += self.velocity[0] * dt
        self.position[1] += self.velocity[1] * dt
        if self.position[0] < 0:
            self.position[0] = 0
            self.velocity[0] *= -1.0
        elif self.position[0] > screen_size[0]:
            self.position[0] = screen_size[0]
            self.velocity[0] *= -1.0
        if self.position[1] < 0:
            self.position[1] = 0
            self.velocity[1] *= -1.0
        elif self.position[1] > screen_size[1]:
            self.position[1] = screen_size[1]
            self.velocity[1] *= -1.0

        self.angle = (self.angle + self.spin) % 360.0

        self.real_points = []
        angle_rad = radians(self.angle)
        for x, y in self.rel_points:
            rotated = rotate_point([self.radius * x, self.radius * y],
                                   angle_rad)
            self.real_points.append(
                [rotated[0] + self.position[0], rotated[1] + self.position[1]])

        self.occluder = occluder.Occluder(self.real_points)
        self.occluder.set_bounce(0.1)
Exemple #3
0
                     (0, 0, 255), (0, 0, 0)])

#Make another emitter
emitter2 = particles.Emitter()
emitter2.set_density(200)
emitter2.set_angle(45.0, 2.0)
emitter2.set_speed([800.0, 1200.0])
emitter2.set_life([1.0, 2.0])
emitter2.set_colors([(255, 0, 0), (255, 255, 0), (0, 255, 0), (0, 255, 255),
                     (0, 0, 255), (0, 0, 0)])

#Make an occluder
points1 = [[screen_size[0] // 2 - 50, screen_size[1] - 50],
           [screen_size[0] // 2 + 50, screen_size[1] - 50],
           [screen_size[0] // 2 - 10, screen_size[1] - 150]]
occluder1 = occluder.Occluder(points1)
#   Particles bouncing off the occluder will do so with this elasticity.
occluder1.set_bounce(0.5)

#Make the particle system
particle_system = particles.ParticleSystem()
#   Set the global acceleration of all particles
particle_system.set_particle_acceleration([0.0, 500.0])
#   Set the list of occluders
particle_system.set_particle_occluders([occluder1])
#   Add both emitters to the system
particle_system.add_emitter(emitter1, "emitter1")
particle_system.add_emitter(emitter2, "emitter2")


def get_input():
Exemple #4
0
newShots = []

# make window start in top left hand corner
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (0, 30)

# setup pygame window
WIN = pygame.display.set_mode([W, H])
pygame.display.set_caption("Networking Test")

#Holds all the lighting information
surf_lighting = pygame.Surface([W, H])

#Our shadowing object
shad = shadow.Shadow()
occluders = [
    occluder.Occluder([[350, 350], [160, 150], [400, 500]]),
    occluder.Occluder([[500, 200], [450, 200], [350, 300]])
]
shad.set_occluders(occluders)
shad.set_radius(300.0)

#Falloff multiplier
surf_falloff = pygame.image.load("light_falloff100.png")
#surf_falloff = pygame.transform.scale(surf_falloff,[1800,1800])
surf_falloff.convert()

NAME_FONT = pygame.font.SysFont("comicsans", 20)


# FUNCTIONS
def draw_players(players, current_id):
shad = shadow.Shadow()

#load the background
surf_bg = pygame.image.load("bg.png").convert()

#Add the occluders.  Occluders are objects which block light.
#This code adds a single occluder for each black pixel.
occluders = []
#   Example 1
for y in range(surf_bg.get_height()):
    for x in range(surf_bg.get_height()):
        color = surf_bg.get_at((x, y))
        if color == (0, 0, 0, 255):
            occluders.append(
                occluder.Occluder([[x * 16, y * 16], [x * 16, y * 16 + 16],
                                   [x * 16 + 16, y * 16 + 16],
                                   [x * 16 + 16, y * 16]]))
#   Example 2
##occluders.append(occluder.Occluder([[256,256],[256,300],[300,300]]))
#   Example 3
##occluders.append(occluder.Occluder([[256,260],[300,260],[256,256]]))
shad.set_occluders(occluders)
shad.set_radius(100.0)

#Scale the background to the screen's size, and convert it for speed
surf_bg = pygame.transform.scale(surf_bg, screen_size)
surf_bg.convert()

#Falloff multiplier
surf_falloff = pygame.image.load("light_falloff100.png").convert()
Exemple #6
0
#Our shadowing object
shad = shadow.Shadow()

#load the background
surf_bg = pygame.image.load("bg.png").convert()

#Add the occluders.  Occluders are objects which block light.
#This code adds a single occluder for each black pixel.
occluders = []
#   Example 1
for y in range(surf_bg.get_height()):
    for x in range(surf_bg.get_height()):
        color = surf_bg.get_at((x,y))
        if color == (0,0,0,255):
            occluders.append(occluder.Occluder([[x*16,y*16],[x*16,y*16+16],[x*16+16,y*16+16],[x*16+16,y*16]]))
#   Example 2
##occluders.append(occluder.Occluder([[256,256],[256,300],[300,300]]))
#   Example 3
##occluders.append(occluder.Occluder([[256,260],[300,260],[256,256]]))
shad.set_occluders(occluders)
shad.set_radius(100.0)

#Scale the background to the screen's size, and convert it for speed
surf_bg = pygame.transform.scale(surf_bg,screen_size)
surf_bg.convert()

#Falloff multiplier
surf_falloff = pygame.image.load("light_falloff100.png").convert()

with_background = True