Python Forum
[PyGame] sound effect delay and program laggy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] sound effect delay and program laggy
#15
(Sep-28-2019, 04:56 AM)xBlackHeartx Wrote: if anything, that class-based example you linked to looks like spaghetti to me.
Using nested loops to make states is what makes it spaghetti the worst. For example when you are looking for draw methods, you have to look in every loop. Same for logic. So code is all over the entire source file instead of being contained in one area. It makes it hard to find related code.
(Sep-28-2019, 04:56 AM)xBlackHeartx Wrote: And I'm not planning on becoming a professional programmer, so why does it matter if my code doesn't follow standard?
One reason is because it makes it that much hard to help. Aside from being organized
for your own sake.

(Sep-28-2019, 04:56 AM)xBlackHeartx Wrote: Besides, my professor claimed its common for free-lance programmers to intentionally make spaghetti code to make sure that their employers won't hire a rival programmer if they need more work done on it.
Python strives to make code readable. Making spaghetti code is not ideal in any situation because you yourself might not understand it if your are making it hard for someone else to. Especially if you come back to the code at a later date. Why make everything spaghetti then? If your boss instructs you to make it spaghetti, then whatever...its their code. But why make your code a constant spaghetti mess?
(Sep-28-2019, 04:56 AM)xBlackHeartx Wrote: And other than my lag issue, my program runs fine and I do play it regularly.
Spaghetti code can run perfectly fine. But it also can easily hide hard to diagnose bugs and bottlenecks.

(Sep-28-2019, 04:56 AM)xBlackHeartx Wrote: And why would using classes speed it up anyway?
I didnt use classes to speed up your game. I used pygame time ticks on your existing code without creating classes.

(Sep-28-2019, 04:56 AM)xBlackHeartx Wrote: And I can't even begin to imagine how to make this game using classes. Now, I have made custom classes and used them (even if they are rather ineptly designed, such as requiring over a dozen parameters)
If you need a dozen parameters for a class, then you are most likely building it wrong. That is one benefit to using classes is the reduction of parameters all over the code.

A Space Invaders is a good example that would use classes. Each invader would be the result of a single class creating numerous objects. A modified invader can be made by inheriting from that class to make a new class with a slight variation of logic or data. Since classes are a collection of logic and data, anytime you want to view your code of anything relating to the invaders, you simply look in the class. My eureka moment in OOP was when i was forced to use classes. Before that i thought the same, that classes made it more complex. In reality they simplify it.
Recommended Tutorials:


Messages In This Thread
RE: sound effect delay and program laggy - by metulburr - Sep-28-2019, 11:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Laggy Game Movement game_slayer_99 12 4,793 Oct-05-2022, 11:34 AM
Last Post: metulburr
Music [PyGame] Chopper wash effect efficiency questions. michael1789 9 4,634 Jan-19-2021, 07:12 PM
Last Post: michael1789
  Appropriately delay this PyGame code kleynah22 2 4,516 Nov-09-2017, 02:00 PM
Last Post: Windspar
  [PyGame] My program is very laggy GamePlanet 6 7,255 Aug-15-2017, 03:00 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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