r/badcode • • Mar 31 '21

python It should have been a code, not an article

Post image
726 Upvotes

71 comments sorted by

View all comments

102

u/knightttime Mar 31 '21

Image Transcription: Code


if entity.components.get("SPRITE_RENDERER_COMPONENT") and entity.components.get("TITLE_COMPONENT") is None:
    self.entity.components["SPRITE_RENDERER_COMPONENT"].rect.topleft - entity.components["SPRITE_RENDERER_COMPONENT"].rect.topleft
    self.entity.components["SPRITE_RENDERER_COMPONENT"].image - pygame.transform.scale(entity.components["SPRITE_RENDERER_COMPONENT"].image, (entity
    if self.entity.components.get("SPRITE_RENDERER_COMPONENT").color:
        self.entity.components["SPRITE_RENDERER_COMPONENT"].image.fill(self.entity.components["SPRITE_RENDERER_COMPONENT"].color)
        if self.entity.components.get("SPRITE_RENDERER_COMPONENT").opacity :
            self.entity.components["SPRITE_RENDERER_COMPONENT"].image.set_alpha(self.entity.components["SPRITE_RENDERER_COMPONENT"].opacity)
    if self.entity.components["SPRITE_RENDERER_COMPONENT"].renderable:
        self.app.screen.blit(self.entity.components["SPRITE_RENDERER_COMPONENT"].image, self.entity.components["SPRITE_RENDERER_COMPONENT"].rect)
        # if entity.components.get("LIGHTING_COMPONENT"):
        #   self.app.filter.components["CANVAS_COMPONENT"].image.blit(self.entity.components["LIGHTING_COMPONENT"].light_bg_1, self.entity.compone
        if self.entity.components.get("SPRITE_RENDERER_COMPONENT").opacity:
            self.entity.components["SPRITE_RENDERER_COMPONENT"].image.set_alpha(self.entity.components["SPRITE_RENDERER_COMPONENT"].opacity)
            
if entity.components.get("TILE_COMPONENT"):
    self.app.screen.blit(
        self.entity.components["SPRITE_RENDERER_COMPONENT"].image,
        (
            self.entity.components["SPRITE_RENDERER_COMPONENT"].rect.x,
            self.entity.components["SPRITE_RENDERER_COMPONENT"].rect.y
        ),
        (
            -self.entity.components["SPRITE_RENDERER_COMPONENT"].rect.x + self.camera_entity.components["CAMERA_COMPONENT"].camera_position[0],
            -self.entity.components["SPRITE_RENDERER_COMPONENT"].rect.y + self.camera_entity.components["CAMERA_COMPONENT"].camera_position[1],
            -self.camera_entity.components["CAMERA_COMPONENT"].camera_position[0] + self.app.window_w * 2,
            -self.camera_entity.components["CAMERA_COMPONENT"].camera_position[1] + self.app.window_h * 2,
        )
    )

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

29

u/Dehast Mar 31 '21

Already looks so much better

37

u/MatthewRPG576 Mar 31 '21

Good human

18

u/mrheosuper Mar 31 '21

Damn i love you.

10

u/knightttime Mar 31 '21

Lol, you're welcome!

23

u/hoyohoyo9 Mar 31 '21

ctrl+c "self.entity.components["SPRITE_RENDERER_COMPONENT"]"

ctrl+v ctrl+v ctrl+v ctrl+v ctrl+v ctrl+v ctrl+v ctrl+v ctrl+v ctrl+v ctrl+v

19

u/knightttime Mar 31 '21

how did you know? XD

5

u/edoCgiB Apr 01 '21

That's how the person who wrote the code did it. We've all been there :)))