May-24-2020, 04:41 PM
(This post was last modified: May-24-2020, 05:12 PM by lolloiltizio.)
Hey boys, I've successfully created a space invaders clone with pygame thanks to you!
I've used the "list method" and if you want to use a Rect instead an Img with windows.blit, you have to write the for loop after the pygame.draw(things) like this (note I've used some variables like colors that are not declared!):
This is the code for the bullets, but with enemies is the same.
To CONTROL the bullet shoot, you can simply append a Rect to the list in the while loop like this:
(Tell me if you'd like to see the project ;))
*really
I've used the "list method" and if you want to use a Rect instead an Img with windows.blit, you have to write the for loop after the pygame.draw(things) like this (note I've used some variables like colors that are not declared!):
screen.fill(bgcolor) pygame.draw.rect(screen, color, ship) for bullet in bullets: bullet.y -= 5 if bullet.y < 0: bullet_remover.append(bullet) else: pygame.draw.rect(screen, color, bullet pygame.display.flip() clock.tick(60)Put this after the whole thing
This is the code for the bullets, but with enemies is the same.
To CONTROL the bullet shoot, you can simply append a Rect to the list in the while loop like this:
while True: ticks = pygame.time.get_ticks() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.mixer.music.stop() pygame.quit() print('Thanks for playing Space invaders! \nclosing...') sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: if ticks > bullet_next_tick: bullet_next_tick = ticks + bullet_interval bullets.append(pygame.Rect(ship.x, ship.y, 5, 20)) if event.key == pygame.K_RIGHT: x_spid += 5 if event.key == pygame.K_LEFT: x_spid -= 5 if event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: x_spid -= 5 if event.key == pygame.K_LEFT: x_spid += 5Obviously you still need to remove bullets
for bullet in bullet_remover: bullets.remove(bullet) bullet_remover = []I'm really happy and proud of that. Thank you. Relly, thank you.
(Tell me if you'd like to see the project ;))
(May-24-2020, 04:41 PM)lolloiltizio Wrote: Hey boys, I've successfully created a space invaders clone with pygame thanks to you!
I've used the "list method" and if you want to use a Rect instead an Img with windows.blit, you have to write the for loop after the pygame.draw(things) like this (note I've used some variables like colors that are not declared!):
screen.fill(bgcolor) pygame.draw.rect(screen, color, ship) for bullet in bullets: bullet.y -= 5 if bullet.y < 0: bullet_remover.append(bullet) else: pygame.draw.rect(screen, color, bullet pygame.display.flip() clock.tick(60)Put this after the whole thing
This is the code for the bullets, but with enemies is the same.
To CONTROL the bullet shoot, you can simply append a Rect to the list in the while loop like this:
while True: ticks = pygame.time.get_ticks() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.mixer.music.stop() pygame.quit() print('Thanks for playing Space invaders! \nclosing...') sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: if ticks > bullet_next_tick: bullet_next_tick = ticks + bullet_interval bullets.append(pygame.Rect(ship.x, ship.y, 5, 20)) if event.key == pygame.K_RIGHT: x_spid += 5 if event.key == pygame.K_LEFT: x_spid -= 5 if event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: x_spid -= 5 if event.key == pygame.K_LEFT: x_spid += 5Obviously you still need to remove bullets
for bullet in bullet_remover: bullets.remove(bullet) bullet_remover = []I'm really happy and proud of that. Thank you. Relly, thank you.
(Tell me if you'd like to see the project ;))
*really