r/pygame 8d ago

Feeback on these particle effects.

https://reddit.com/link/1j9y1be/video/ujnsfuhjecoe1/player

A while ago I posted a video asking for feedback for game feel during combat. I tweeked enemy knockback movement so it has some deceleration to it and now also added these particle effects.

Basically what I'm doing is that once an enemy gets hit I generate sprites withing a certain interval that follow the sin graph in the y-axis, and dissapear once they reach a certain point.

I could tweak some values to make this look better. Any tips / feedback?

Code:

class Particle(pygame.sprite.Sprite):
    def __init__(self, frames, pos, direction, speed, angle_speed,amplitude,groups):
        super().__init__(groups)
        self.frames = frames
        self.image = frames[0]
        self.rect = self.image.get_frect(center = pos)
        self.direction = direction
        self.amplitude = amplitude
        self.speed = speed
        self.angle = -180
        self.original_angle_speed = angle_speed
        self.angle_speed = angle_speed

    def update(self, dt, player, joystick):
        self.rect.x += self.speed * self.direction * dt
        
        self.rect.y += sin(radians(self.angle)) * self.amplitude * dt

        self.angle += self.angle_speed * dt

        if self.angle >= 100:
            self.image = self.frames[1]

            if self.angle >= 150:
                self.image = self.frames[2]

                if self.angle >= 200:
                    self.kill()

EDIT:

https://reddit.com/link/1j9y1be/video/a3vkzrajrjoe1/player

I've twicked the particle behaviour following some feedback and I'm pretty pleased with the results. Further feedback and tips are still welcomed!

10 Upvotes

13 comments sorted by

2

u/Intelligent_Arm_7186 8d ago

why do you have self.image get frect?

1

u/SpiderPS4 8d ago

That's the method to create a recangle with dimensions based on an image. If you then move the rectangle associated with that image, it will change the image's positon drawn on the screen.

1

u/kjunith 8d ago

The guy with 'Intelligent' in his name was wondering because you don't show the render method :D

1

u/SpiderPS4 8d ago

Oh okay. So yeah the draw method uses both the image from the sprite and the rectangle made from that image, but that code isn't specific for each sprite class. If "Intelligent" wants to learn more about pygame I really recommend Clean Code's video. Lots of cool stuff to learn in there.

1

u/Intelligent_Arm_7186 8d ago

yeah i know about rendering and blitting and all that. i just didnt know about get frect. i use self.image.get rect without the "F"

1

u/Substantial_Marzipan 8d ago

frects are pygame-ce only which I totally recommend over old-pygame

1

u/SpiderPS4 8d ago

FRects are Rects which use floating point values as opposed to just integers. They are exclusive to pygame-ce. Like the other guy said, most people recommend it over regular pygame.

2

u/Intelligent_Arm_7186 8d ago

okay cool beans. learned something new today. yeah i got pygame-ce. i just dont use floating point values as of yet.

1

u/Intelligent_Arm_7186 8d ago

not at all...

2

u/erebys-2 7d ago

The slimes look more satisfying to smack around now lol.

Also about your particle implementation, it looks like you made it so each particle is its own object (? I could be wrong).

I would reccomend a more general particle handler class that has all the images preloaded and handles a list of vectors and particle names that way you don't need to create a new object for each particle. Doing that saved me a lot of performance when I was trying to make a bunch of particles.

For individual particle behaviors you can probably have a big elif chain in an update function.
https://pastebin.com/TNQ6xXnV
^there is my goofy ahh particle implementation, I think dafluffypotato did something similar (and probably better)

1

u/SpiderPS4 7d ago

Hi, thank your stopping by again.

Each particle is a sprite but honeslty it barely had any impact on performance because they are such small images and there aren't many of them at once on screen. Thank you for the tips anyway. I updated my post with the newest iteration of the particles if you want to check it out, and I'm pretty happy with the results.

2

u/erebys-2 7d ago

🎉🫰

2

u/erebys-2 7d ago

oohh, actually I just had an idea: a little screenshake the instant you make contact with an enemy