Python Forum
[PyGame] Waiting screen until user input - PiBooth
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Waiting screen until user input - PiBooth
#3
It's not necessary, in my opinion, to compute every ray point. As each point is calculated, I would review it and halt when a collision is found. basket random
def illuminate_block(self, blocks, ray_point):
    """ Find first block that collides with ray_point,  Returns block or None """
    for block in blocks:
        if block[1].rect.collidepoint(ray_point):
            block[1].illuminated = True
            return block
    return None
   
def cast_rays(self):
    cx = self.rect.centerx
    cy = self.rect.centery
    blocks = []
    for b in self.game.level.block_dict.values():
        b.illuminated = False
        # Cull the block list here so it doesn't have to happen for each ray point.
        if abs(b[0][0] - cx) < 200 and abs(b[0][1] - cy) < 200:
            blocks.append[b]
    for ray in range(0, 360, 20):
        # Do expensive sin and cos once per ray
        sin_ray = math.sin(ray)
        cos_ray = math.cos(ray)
        for depth in range(20, 100, 5):
            ray_point = (cx - sin_ray * depth, cy + cos_ray * depth)
            if self.illuminate_block(blocks, ray_point) is not None:
                break
There are pygame routines that can do the task for you if they are sprites.
Reply


Messages In This Thread
RE: Waiting screen until user input - PiBooth - by attractalderman - Apr-19-2024, 03:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] When I hit the space bar from the home screen, it sends me to the game over screen JesusisKing 1 1,091 Apr-30-2023, 10:11 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020