Lập Trình Linux

Pygame Tutorial – 8 – Creating the Enemy – Space Invader




In this we will video we will create an enemy for our lonely spaceship. In this process learning about re-spawning and randomization of location of the enemy

Next video – Movement of the Enemy

Full playlist –

Subscribe –
Website – www.buildwithpython.com
Instagram –

#python #pygame

Nguồn:https://ftlinuxcourse.com/

Xem Thêm Bài Viết Khác:https://ftlinuxcourse.com/lap-trinh-linux

Tin HOT
TUYỆT PHẨM PHẠM DUY: LIVE SHOW NGÀY TRỞ VỀ (PHẦN 1)
Phần Mềm
Hướng dẫn cập nhật hệ điều hành iOS 11 cho iPhone
Máy Tính
Mổ bụng siêu phẩm Casio 580 VNX
  • I just realized that following a project step by step like this, is my preferred method for learning programming! Don't have the patience for long books. Thanks a lot!


  • this sir deserves lots of subs


  • You made the tutorial very easy to understand and interesting.


  • can someone point out the mistakes in my code?

    import pygame

    # intialize the pygame
    pygame.init()

    # create the screen
    screen = pygame.display.set_mode((800, 600))

    # Title and Icon
    pygame.display.set_caption('Space Invaders')

    icon = pygame.image.load('ufo.png')
    pygame.display.set_icon(icon)

    # Player
    playerImg = pygame.image.load('spaceShip.png')
    playerX = 30
    playerY = 480
    playerX_change = 0

    def player(x,y):
    screen.blit(playerImg, (x,y))

    # Game Loop
    running = True
    while running:
    screen.fill((0,0,0))

    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    running = False

    # if keystroke is pressed check whether its right or left
    if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_LEFT:
    playerX_change = -0.7

    if event.type == pygame.K_RIGHT:
    playerX_change = 0.7

    if event.type == pygame.KEYUP:
    if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
    playerX_change = 0

    playerX += playerX_change

    if playerX <= 0:
    playerX = 0
    elif playerX >= 736:
    playerX = 736

    player(playerX, playerY)
    pygame.display.update()

    pygame.quit()