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
37
18
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
131
Mar 31 '21
I can’t get past that font tho
39
u/djpor2000 Mar 31 '21
Now imagine coding in Comic Sans...
8
u/SphericalMicrowave Mar 31 '21
3
Apr 01 '21
This is a million times worse than Comic Sans. Only the 'C' is serif! I am going to jump off a mountain.
0
Mar 31 '21
[deleted]
4
2
u/TheUnlocked Apr 01 '21
The demo only includes alphanumeric + period + comma. But the full paid version even includes ligatures.
19
Mar 31 '21
[removed] — view removed comment
14
u/konaya Mar 31 '21
It's more accurate to say that in the context of Windows default font selections, Comic Sans MS is marginally less crappy for certain kinds of dyslexia.
7
u/djpor2000 Apr 01 '21
Yes, one of the benefits of Comic Sans is that the letters "p", "q", "d" and "b" are not flipped versions of each other. The British Dyslexia Association also recommends "sans serif fonts, such as Arial and Comic Sans, as letters can appear less crowded."
But I cannot ever imagine coding in ANY font that isn't monospaced. 😅
5
36
u/Alberiman Mar 31 '21
For those that aren't sure -If you're looking up the same component that much just fricken import the component reference into a variable and be done with it . Looking up things using strings is already super inefficient but then take into account that you're repeatedly looking up the same variable and jesus.
To make it waaay faster and cheaper to repeatedly look up a string my advice is to have it pre-converted into the hash/integer(depending on how your code deals with it) and name it the same as the string you were reusing.
in this case just convert set
var = self.entity.components["SPRITE_RENDERER_COMPONENT"]
20
u/IrritableGourmet Mar 31 '21
OP walks into a library
OP: "Hello! I'm looking for the third word on the 4th page of the book with this name!"
Librarian: "Sure!" goes to card catalog, searches for book title, copies information to a post-it, walks to the shelf, climbs a ladder, grabs the book, walks back to the desk, and opens the book to the correct page
OP: "Thanks!" hands book back
Librarian: walks back to the shelf, climbs the ladder, puts the book back, throws away the note, and returns to the desk
OP: "Now, can you tell me the second word on the page?"
Librarian: "Sure!" walks to card catalog...
14
u/tangerinelion Mar 31 '21
There's a certain thrill to using bare strings though. You force people to be sharp and pay attention since a single typo anywhere will cause a hard to find bug. You also feel really smart because you can lookup data in these undocumented places and be a super elite hacker.
8
Apr 01 '21
I used to be the super elite hacker of my former workplace until they figured out my trick of searching the project for "Helen, insert bug here for job security."
22
u/Mr2-1782Man Mar 31 '21
If you hit Ctrl-V more than once you should think about what you're doing. If you're hitting it that many times just give up.
7
3
18
u/Cmgeodude Mar 31 '21 edited Mar 31 '21
It's the "I have to do everything in as few lines as possible!" syndrome. It's endemic in leetcode/codewars.
Run-on sentences work and can even be fun and/or impressive to either the listener/reader or the speaker, or maybe even both, but once you get going and have full repeated subordinate clauses that tie in tangential references that enrich but are not essential to your utterance, which I, a former foreign language teacher, define as any single speech act (or written, semantically coherent expression, question, exclamation, statement, imperative, or proposition), it may be time to pat yourself on the back for your amusing linguistic prowess - who doesn't love a language game? - and consider revising and separating your clauses for your audience, including readership, who risk getting lost in your conscious or unconscious, intellectually- stimulating verbosity.
Isn't it nicer to read statements when they're succinct and to the point?
Same thing with code. Each line should mean and do one and only one thing, please.
3
u/IrritableGourmet Mar 31 '21
I was gradually coming to have a mysterious and shuddery reverence for this girl; nowadays whenever she pulled out from the station and got her train fairly started on one of those horizonless transcontinental sentences of hers, it was borne in upon me that I was standing in the awful presence of the Mother of the German Language. I was so impressed with this, that sometimes when she began to empty one of these sentences on me I unconsciously took the very attitude of reverence, and stood uncovered; and if words had been water, I had been drowned, sure. She had exactly the German way; whatever was in her mind to be delivered, whether a mere remark, or a sermon, or a cyclopedia, or the history of a war, she would get it into a single sentence or die. Whenever the literary German dives into a sentence, that is the last you are going to see of him till he emerges on the other side of his Atlantic with his verb in his mouth.
28
7
3
u/khalidpro2 Mar 31 '21
which language is this?
5
Mar 31 '21
python
9
u/khalidpro2 Mar 31 '21
I know python, and the code was so unreadable that I didn't recognize it
6
Mar 31 '21
Most identifiable by the use of self and lack of curly braces.
2
u/khalidpro2 Mar 31 '21
there are other languages that has that
4
Mar 31 '21
Well if you want to go further there is the use of "None" and "and". Also the ":" after the if statements.
2
2
u/Nall-ohki Mar 31 '21
Code isn't countable
1
1
u/Architector4 Apr 01 '21
Code can be counted using measures such as the amount of characters, lines, functional lines (excluding empty spacer lines and comments), files or individual projects. Sure, not all of these ways to measure code count are effective or meaningful, but they nonetheless allow one to count code.
1
u/Nall-ohki Apr 01 '21
You don't understand the meaning of "countability" in English.
Likewise, "amount" is not used for countables like "characters". Use "number of" instead.
1
u/Architector4 Apr 01 '21
Looking at it again, I guess the reason you've stated that is to provide an underlying fact that should affect one's decision to put "a" before a word or not, i.e. trying to provide a hint to a grammar mistake, but without pointing out the grammar mistake itself. That wasn't obvious, and I thought you were trying to state that one can't measure "more code" or "less code" at all.
1
u/Nall-ohki Apr 01 '21
That's fair! I was specifically referring to the countability of the word rather than the measurability of the actual subject.
2
1
1
1
Apr 01 '21 edited Apr 01 '21
that's some inconsistencies in getting things, using both ["this"] and .get("this, the get function"). also forgot DRY (repeatedly getting stuff, that's how)
i'll be back later here when I finish copying the code and extract the functions to a variable to showcase variables with the thing
EDIT: I just did it. I did use some other software to extract the code, and isn't perfect. Thanks u/knightttime for the transcription
sprite_renderer = entity.components["SPRITE_RENDERER_COMPONENT"]
camera = self.camera_entity.components["CAMERA_COMPONENT"]
if sprite_renderer and entity.components["TITLE_COMPONENT"] is None:
self.sprite_renderer.rect.topleft - sprite_renderer.rect.topleft
self.sprite_renderer.image - pygame.transform.scale(sprite_renderer.image, (entity
if self.entity.components.get("SPRITE_RENDERER_COMPONENT").color:
self.sprite_renderer.image.fill(self.sprite_renderer.color)
if self.sprite_renderer.opacity :
self.sprite_renderer.image.set_alpha(self.sprite_renderer.opacity)
if self.sprite_renderer.renderable:
self.app.screen.blit(self.sprite_renderer.image, self.sprite_renderer.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.sprite_renderer.opacity:
self.sprite_renderer.image.set_alpha(self.sprite_renderer.opacity)
if entity.components.get("TILE_COMPONENT"):
self.app.screen.blit(
self.sprite_renderer.image,
(
self.sprite_renderer.rect.x,
self.sprite_renderer.rect.y
),
(
-self.sprite_renderer.rect.x + camera.camera_position[0],
-self.sprite_renderer.rect.y + camera.camera_position[1],
-camera.camera_position[0] + self.app.window_w * 2,
-camera.camera_position[1] + self.app.window_h * 2,
)
)1
u/AutoModerator Apr 01 '21
It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.
For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.
/u/JacksonChen666, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.
You can find some examples in the reddit help documentation.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
1
u/Oxey405 Apr 04 '21
Right click ; format ; wait for the microwave bell sound and then you have a beautiful code !
1
177
u/Pcb95 Mar 31 '21
Seems like a few extra variables could go a long way