37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
# This is a sample Python script.
|
|
|
|
# Press Shift+F10 to execute it or replace it with your code.
|
|
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
|
|
|
|
|
def print_hi(name):
|
|
# Use a breakpoint in the code line below to debug your script.
|
|
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
|
|
|
|
|
# Press the green button in the gutter to run the script.
|
|
if __name__ == '__main__':
|
|
print_hi('PyCharm')
|
|
|
|
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
|
import sys
|
|
import pygame
|
|
from bullet import Bullet
|
|
from alien import Alien
|
|
from time import sleep
|
|
|
|
|
|
def check_keydown_events(event, ai_settings, screen, ship, bullets):
|
|
if event.key == pygame.K_RIGHT:
|
|
ship.moving_right = True
|
|
elif event.key == pygame.K_LEFT:
|
|
ship.moving_left = True
|
|
elif event.key == pygame.K_SPACE:
|
|
fire_bullet(ai_settings, screen, ship, bullets)
|
|
elif event.key == pygame.K_q:
|
|
sys.exit()
|
|
|
|
|
|
def fire_bullet(ai_settings, screen, ship, bullets):
|
|
if len(bullets) < ai_settings.bullets_allowed
|
|
bullets.add(new_bullet) |