making the aliens move
This commit is contained in:
parent
cfd4c1bf86
commit
90b736f955
|
@ -12,6 +12,10 @@ HEIGHT = 800
|
|||
WINDOW_SIZE = (WIDTH, HEIGHT)
|
||||
FPS = 60
|
||||
|
||||
|
||||
ROWS = 5
|
||||
COLS = 5
|
||||
|
||||
# load background image
|
||||
bg = pygame.image.load("img/bg.png") # FUCK THIS IN THE ASS FIXXED IT FUCK YEA
|
||||
def draw_bg():
|
||||
|
@ -29,7 +33,7 @@ class Spaceship(pygame.sprite.Sprite):
|
|||
self.last_shot = pygame.time.get_ticks()
|
||||
def update(self):
|
||||
speed = 8
|
||||
cooldown = 500 # millisconds
|
||||
cooldown = 400 # millisconds
|
||||
key = pygame.key.get_pressed()
|
||||
if key[pygame.K_a] and self.rect.left > 0: # Why zero not width tried width would not move
|
||||
self.rect.x -= speed # why speed not pixal + or - like others??
|
||||
|
@ -57,8 +61,24 @@ class Bullets(pygame.sprite.Sprite):
|
|||
self.rect.center = [x, y]
|
||||
def update(self):
|
||||
self.rect.y -= 5
|
||||
|
||||
|
||||
if self.rect.bottom < 0:
|
||||
self.kill()
|
||||
# video for this https://www.youtube.com/watch?v=mqz1_wRSMwo
|
||||
class Aliens(pygame.sprite.Sprite):
|
||||
def __init__(self,x ,y):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
self.image = pygame.image.load("img/alien" + str(random.randint(1, 5)) + ".png") # List this will call 1-5 but thought it would be 0-4 or is that place holders
|
||||
self.rect = self.image.get_rect()
|
||||
self.rect.center = [x, y]
|
||||
self.move_counter = 0
|
||||
self.move_direction = 1
|
||||
# WONT MOVE TO THE RIGHT ONLY TO THE LEFT AND STOP
|
||||
def update(self):
|
||||
self.rect.x += self.move_direction
|
||||
self.move_counter += 1
|
||||
if abs(self.move_counter) > 75:
|
||||
self.move_direction *= -1
|
||||
self.move_counter += self.move_direction
|
||||
|
||||
# create sprite groups
|
||||
spaceship_group = pygame.sprite.Group()
|
||||
|
@ -67,6 +87,17 @@ bullet_group = pygame.sprite.Group()
|
|||
# create player
|
||||
spaceship = Spaceship(int(WIDTH / 2), HEIGHT - 100, 3)
|
||||
spaceship_group.add(spaceship)
|
||||
alien_group = pygame.sprite.Group()
|
||||
|
||||
def create_aliens():
|
||||
for row in range(ROWS):
|
||||
for item in range(COLS):
|
||||
alien = Aliens(100 + item * 100, 100 + row * 70)
|
||||
alien_group.add(alien)
|
||||
|
||||
create_aliens()
|
||||
|
||||
|
||||
|
||||
|
||||
WHITE = (255, 255, 255)
|
||||
|
@ -83,7 +114,7 @@ clock = pygame.time.Clock()
|
|||
|
||||
|
||||
|
||||
running = True
|
||||
running = True # IF RUNNING USING THE BUTTON NOT CONSOLE IT CRASHES WHY??????
|
||||
while running:
|
||||
clock.tick(FPS)
|
||||
|
||||
|
@ -96,11 +127,12 @@ while running:
|
|||
running = False
|
||||
|
||||
spaceship.update()
|
||||
|
||||
bullet_group.update()
|
||||
alien_group.update()
|
||||
# draw sprite groups on screen
|
||||
spaceship_group.draw(screen)
|
||||
bullet_group.draw(screen)
|
||||
alien_group.draw(screen)
|
||||
pygame.display.update() # Go over it again FLIP vs UPDATE Which to use When
|
||||
|
||||
|
||||
|
|
BIN
PyGame/practice/gameprac/img/alien1.png
Normal file
BIN
PyGame/practice/gameprac/img/alien1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 731 B |
BIN
PyGame/practice/gameprac/img/alien2.png
Normal file
BIN
PyGame/practice/gameprac/img/alien2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
PyGame/practice/gameprac/img/alien3.png
Normal file
BIN
PyGame/practice/gameprac/img/alien3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
PyGame/practice/gameprac/img/alien4.png
Normal file
BIN
PyGame/practice/gameprac/img/alien4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
BIN
PyGame/practice/gameprac/img/alien5.png
Normal file
BIN
PyGame/practice/gameprac/img/alien5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Loading…
Reference in New Issue
Block a user