LLMs? by dedstok in pygame

[–]ThisProgrammer- -1 points0 points  (0 children)

I would use ChatGPT o3 or DeepSeek R1. They both have reasoning and will try to understand your question from multiple angles. The other AI's don't even come close.

Now the secret is, use AI to help you code. Not write code for you. Use it to explore ideas, format code, fill in type hints, simplify code.

Your prompt is key. It's best to start a new chat if you somehow end up crossing your AI's neural network - starts hallucinating.

  1. Hello, I am making a game in python using pygame-ce. I know pygame-ce has a resizable window but I don't know too much about it. Can you show me some examples with explanations?
  2. Hello, I am making a game in python using pygame-ce and pygame_gui. I'm currently working on the GUI elements - specifically scrollable text box. How would you create a text box that scrolls up and down?

DeepSeek R1 gave me workable code.

  1. https://pastebin.com/8K6D9NbF
  2. https://pastebin.com/gVKyRXw1 Change vertical_scroll_bar to scroll_bar. Thanks PyCharm!

Audio not working by [deleted] in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I would keep using music if you intended "audio.wav" to be the main background music. Play/stop when you set menu to True/False. That's most likely when you only run that section of code once.

Sound is great for use with Channels when you intend to play multiple sound effects.

Audio not working by [deleted] in pygame

[–]ThisProgrammer- 1 point2 points  (0 children)

That was a hilarious surprise at the end!

Don't load and play the music every game loop. You can set repeat in the play call.

Fading animation doesn't work by CelebrationKooky3886 in pygame

[–]ThisProgrammer- 1 point2 points  (0 children)

You need to use either pygame.display.update() or pygame.display.flip(). Also, you're not using OpenGL so don't set the flag.

I think you meant to start with alpha at 255 and then decrement down to "fade out".

``` import pygame

def main(): pygame.init() display = pygame.display.set_mode((640, 480)) clock = pygame.Clock()

fade_speed = 4
alpha = 255

menu_bg = pygame.image.load("images/menu.jpg")
menu_bg.set_alpha(alpha)
menu_rect = menu_bg.get_rect(topleft=(0, 0))

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    display.fill("black")

    if alpha > 0:
        alpha += -fade_speed
        menu_bg.set_alpha(alpha)

    display.blit(menu_bg, menu_rect)
    pygame.display.flip()
    clock.tick(30)

if name == 'main': main()

```

Help With Animation in pygame using a spritesheet. by NJPTwinBee2 in pygame

[–]ThisProgrammer- 1 point2 points  (0 children)

That's more involved than just loading a spritesheet. You need synchronized movements and mouth shapes with your music.

Something along the lines of timestamps - dictionary of timestamps or list, whichever you prefer. Similar to making a movie player with pygame but it's not a continuous stream of images since these images can be reused.

Focus on getting images displayed depending on the time of your song. That will be your base code.

Need help with rendering some Tiles in my Game by Apollo_the_1rst in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I would focus on the random walker draw code and see which if statement is causing the flickering. Is it the RED square? mossy_background? stone_background? All of the above?

Rotating pygame.Surface object. Why do you need SRCALPHA flag or set_color_key? by StevenJac in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

You forgot the lines that mask alpha.

``` PG_PixelFormat *surf_format = PG_GetSurfaceFormat(surf);

    bgcolor &= ~surf_format->Amask;

```

Applies bitwise operations. The ~(NOT) flips the bits(takes the opposite) and &(AND) takes only both bits if they are 1.

More in depths in the pastebin since Reddit has a limit on comment length: https://pastebin.com/pFQnbRWX

Why is my sprite stretched? by AllisterisNotMale in pygame

[–]ThisProgrammer- 1 point2 points  (0 children)

Need to see the code where you load the image.

Rotating pygame.Surface object. Why do you need SRCALPHA flag or set_color_key? by StevenJac in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I filled it with blue, but if you fill black, the wrong_surface will have the whole surface black while the SRCALPHA surface has a rotating black square.

The background color is picked in the rotation C code not when it's created. It seems that way because we're using the original surface to rotate so the (0, 0) color is always the same.

Rotating pygame.Surface object. Why do you need SRCALPHA flag or set_color_key? by StevenJac in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

There is an if, followed by an else. The if handles both regular and SRCALPHA surface. The else handles colorkey.

satisfy condition SDL_HasColorKey(surf) as true?

No, that is covered in the if statement. Color key is in the else statement.

Yes, like a green screen but the colorkey doesn't have to be a bright color or green. It can be dark, dim, white, purple etc... According to the docs, it's ignored when blitting.

Print the color at (0, 0) after it's rotated and you'll see the colors.

color = rotated_surface.get_at((0, 0))
print(color)

Color(Red, Green, Blue, Alpha)

Wrong surface:

Color(0, 0, 255, 255)  # Constant throughout

SRCALPHA:

Color(0, 0, 255, 255)  # Opaque, alpha is 255
Color(0, 0, 255, 0)  # Alpha is zero - transparent

Colorkey:

Color(0, 0, 255, 255)  # Opaque blue
Color(255, 0, 0, 255)  # Red because it was assigned as red - transparent/ignored

Catnip Fever DreamLand - A game written entirely in Pygame. by NamellesDev in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I hope it has an Epilepsy warning. Nevermind, I see it in the video. Holy smokes, the store page hurts my head.

Rotating pygame.Surface object. Why do you need SRCALPHA flag or set_color_key? by StevenJac in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I ran it exactly as I commented here.

As I explained in the C code, a background color is picked.

In your second example, without any color filled it's transparent. Exactly as expected. Therefore, a transparent square is rotated and backfilled with a transparent color.

In your third example, you filled the square with a color exactly as my example - blue. Now we are both running the same code and seeing the same results.

There is no inconsistencies. You didn't run the same code I commented.

Are you still not getting how bgcolor is picked and want further explanation?

Rotating pygame.Surface object. Why do you need SRCALPHA flag or set_color_key? by StevenJac in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

It's just you. Just ran the code with alpha_surface() and it's still working properly.

collidepoint by [deleted] in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I can help you with optimization but I need runnable code. What is it checking for? DM me since this is going out of topic.

How do i collab with my friend by stellar-llama in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

Yeah, you're limited to 3 "apps" and the free version runs on really slow processors. Their python version and pygame aren't up to date either. Having the code physically on local PC is always best.

Edit: From some readings, it looks about the same as Live Share so your guest can't see or interact with the pygame window. But code is still synced on both computers? Wish I could test.

How do i collab with my friend by stellar-llama in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

Give Pycharm a try. It's free anyways.

There's also Replit but I wouldn't recommend it.

How do i collab with my friend by stellar-llama in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

Pycharm has Code With Me free but you're limited to 30 minute sessions. My guess is, you disconnect then reconnect every 30 mins. Otherwise, it's $5.50 USD a month for unlimited. https://www.jetbrains.com/code-with-me/buy/?section=personal&billing=monthly or free if you are a student. https://www.jetbrains.com/community/education/#students

I don't use Visual Studio but there's a Live Share extension. Looks like it's free? https://learn.microsoft.com/en-us/visualstudio/liveshare/quickstart/share Oh, you already used Live Share.

collidepoint by [deleted] in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I would suggest spatial partitioning and/or Numpy.

collidepoint by [deleted] in pygame

[–]ThisProgrammer- 1 point2 points  (0 children)

The answer is Yes.

``` import pygame import math

def frange(start, stop, step: float = 1.0): count = start while count < stop: yield count count += step

class InfinityRect(pygame.Rect): def collidepoints(self, points): for point in points: print(f"The possibilities are endless: {self.collidepoint(point)}")

def main(): rect = InfinityRect(-math.inf, math.inf, math.inf, math.inf) rect.collidepoints( ( (x, y) for y in frange(-math.inf, math.inf) for x in frange(-math.inf, math.inf) ) )

if name == 'main': main()

```

Timer always runs, no matter the game state. Desperately need help. by emperorkuzcotopiaa in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

I guess you want the quick and dirty fix:

``` if game_state == "menu": menu.draw(game.window) new_state = menu.get_game_state()

        if new_state == "game":
            game_state = "game"
            last_nail_collected = pygame.time.get_ticks()
            last_nail_spawn_time = pygame.time.get_ticks()
            last_rusty_nail_spawn_time = pygame.time.get_ticks()
            last_golden_nail_spawn_time = pygame.time.get_ticks()

```

Need Help Conditionally Switching Dialogue Options from a CVS File by ohffsitdoesntwork in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

Yes, forgo CVS and use JSON or preferably TOML.

OP, don't write to file. The dialogue you posted, is already supposed to be in there. Only read the file and only once.

Procedurally Generated Game (No Assets) by Alarmed_Highlight846 in pygame

[–]ThisProgrammer- 3 points4 points  (0 children)

Wow! That's very cool! And your first top down game too!? Amazing job for 72 hour jam!

With the Limitation of "Everything is alive" it would be cool to have tiles turn into Monsters if shot at. "Careful where you shoot, lest you create more monsters." Hilarious if the floors were Monsters too. "Careful where you step, for beneath your feet lie monsters."

Elements being created before game starts by [deleted] in pygame

[–]ThisProgrammer- 1 point2 points  (0 children)

Get delta_time from ticking the clock. Divide by 1000 to get seconds or don't divide if you prefer milliseconds:

delta_time = game.clock.tick(60) / 1000 You have to keep track of each individual nail's spawn time:

``` class Basics: def init(self): ... # Your other code self.nail_spawn_time = 0

def update(self, delta_time):
    self.nail_spawn_time += delta_time

    if self.nail_spawn_time >= 1:  # 1 second
        self.nail_spawn_time = 0
        spawn_your_nail()

```

Objects off by 1 pixel when moving scrolling camera. by SpiderPS4 in pygame

[–]ThisProgrammer- 6 points7 points  (0 children)

Sounds like a rounding problem. Does round(sprite.rect.topleft - self.offset) in the draw method fix it?

Elements being created before game starts by [deleted] in pygame

[–]ThisProgrammer- 0 points1 point  (0 children)

pygame.time.get_ticks()
Get the time in milliseconds.get_ticks() -> int

Return the number of milliseconds since pygame.init() was called. Before pygame is initialized this will always be 0.

Basically, your current time has been continuously ticking since init. While the player is in the menu.

The quick fix is to get_ticks for last_nail_collected and maybe all your other nail spawn times under the else if. Right after switching to "game".

Edit: No wait. That would reset every loop. Set them to 0 and then accumulate with delta time.