Pygame Shmup Part 9: Shields

preview_player
Показать описание
In this installment, we'll add shields to our player ship and show how to draw a bar to visually display how much shield energy we have.

In each video in this series, we'll add another feature to the Shmup game until we have a full game experience with graphics, animations, sound, and much more!

Helpful links:
Рекомендации по теме
Комментарии
Автор

Slowly working through all the tutorials. Great work, great explanation and great pace! On this one, I added changing shield bar to YELLOW at 50% and RED at 10% all by myself! :D Thanks to your mentorship!

Jason-xglw
Автор

Can't get enough of the serie, thank you so much, this is so well done !

TheDannybrain
Автор

Best Python tutorial series on YouTube! Thank you for great vids!

Vitalezzz
Автор

this is the BEST pygame series EVER! thank you so much!

p.s. i am learning this under a age of 10

truepal
Автор

To clarify a bit: a big reason to not "repeat yourself" is to minimize the chance of mistakes.
If you right out one bit of code and then refer to it, you'll make sure you don't get subtle mistakes or differences between the two (or more) instances if you had all written them out again.
It also makes it easier to chance something in the process, not having to search and chance every single instance of it.

omikronweapon
Автор

Made my own ammo system, Glad im learning. Thank you

cjdabj
Автор

Hello! Loving the tutorial so far. Quick question/comment. When I ran the code for the shield bar, the bar would go all the way down after one hit from any sized mob. I knew player.shield was okay because it would take a couple hits for the game to stop running. I was able to fix this by changing
fill = (pct / 100) * BAR_LENGTH
to
fill = player.shield
Do you know why the former was not working for me, and will I run into any problems later by using the later. Thanks so much!

kylervin
Автор

I added my own part in which I play the shield down sound from the space shooter redux every time a meteor hits me

tahaahmed
Автор

The background music starts very loud and after shooting, music volume gets lower, but louder when game starts. How do I could fix it? Thank you for classes

RomeuMello
Автор

Hey man, great tutorial so far still enjoying it. Just a question though, you see the fill = (pct / 100) * BAR_LENGTH line, does this variable only limit the player shield to being 100? Because say the player shield was a maximum of 30, would that not only fill the bar in 30 pixels? Also, if that is the case how could I change that slightly so the fill will account for the maximum player shield changing? Apologies for all the questions I'm just very new to pygame and might be complicating things a bit too much for myself, but appreciate any feedback, cheers.

gangstaliam
Автор

Can we create a android app with python? If it is possible, then please explain me ? Thanks!

ashutoshtiwari
Автор

Great tutorial, I just have one question.

Is there any way to change the hit damage so that it multiplies the speed of the object and not the size?

ryanoat
Автор

fill = (pct /100) * BAR_LENGTH

with this equation I get an integer division. When pct < 100 fill = 0. Why do you divide by 100 then multiply 100 within the same equation.

I removed the variable fill and changed the following line:

fill_rect = pygame.Rect(x, y, pct, BAR_HEIGHT)

since pct is already a percentage

vermiman
Автор

I love your tutorials, and I often add extra code onto them to make the game more fun. I've run into a problem that I can't seem to fix, however:
How would you make the meteors have health? I tried to add a health variable to the mob class called 'self.health = 100' but when I try to run the collision detection code it doesn't work:

# collision detection
hits = pygame.sprite.groupcollide(mobs, playerShoot, False, True)
for hit in hits:
mob.health -= 20
if mob.health <= 0:
score += 500
mobExplode.play()
mob.kill()
explosion = Explosion(hit.rect.center, 'lg')
allSprites.add(explosion)

the problem is that if I name the variable 'mob' (the sprite object) only the first meteor takes damage, and if I name it 'mobs' (the sprite group) there's an "Unresolved attribute reference 'health' for class 'Group'" which crashes the game when I shoot it, as the sprite group has no health property. What should I do in this scenario? Thanks in advance!

florix
Автор

I want to add a screen for the player to choose a ship ? How can I do it ? Please explain me!

ashutoshtiwari
Автор

Python is throwing an error when I try the shield bar thing. It's telling me 'ValueError: size needs to be (int width, int height)' an I have tried everything I can think of to fix the issue, but it persists until I disable the bar

samspence
Автор

draw_shield_bar(screen, 5, 5, player.shield)
AttributeError: 'Player' object has no attribute 'shield'

eee-oldl
Автор

thats bad, The correct calculation is "fill = (actual_shield * BAR_LENGTH) / base_shield"

MyWebhack
Автор

I am trying to make it so that when my player can't go through any of the walls using sprite collide but i dont know how to make i so you can't go through any side of the wall since in my collision walls is a groups and I don't think I can do walls.rect.top do you know how to make my walls completely unpassable:
my wall and player class is:
class Player(pygame.sprite.Sprite):
def __init__(self):

self.image = pygame.Surface((30, 30))
self.image.fill(GREEN)
self.rect = self.image.get_rect()
self.rect.topleft = (30, 30)
self.vel = 8

def update(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
self.rect.x -= self.vel
if keys[pygame.K_d]:
self.rect.x += self.vel
if keys[pygame.K_w]:
self.rect.y -= self.vel
if keys[pygame.K_s]:
self.rect.y += self.vel


class Wall(pygame.sprite.Sprite):
def __init__(self, x, y, w, h):

self.image = pygame.Surface((w, h))
self.image.fill(BLUE)
self.rect = self.image.get_rect()
self.rect.topleft = (x, y)

and my collision is currently:
blocks = pygame.sprite.spritecollide(player, walls, False)
for block in blocks:
pass

Liam-pfih
Автор

it is not working
TypeError: draw_shield_bar() takes exactly 3 arguments (4 given)

SalmanAhmed