Home > other >  An alien invasion background color white, does not display the spacecraft
An alien invasion background color white, does not display the spacecraft

Time:09-24

The content of the alien_invasion. Py
# encoding: utf-8
The import sys
The import pygame
The from Settings import Settings
From the ship import ship

Def run_game () :
# initialize a game and create a screen object
Pygame. The init ()
Ai_settings=Settings ()
Screen=pygame. Display. Set_mode ((ai_settings. Screen_width, ai_settings. Screen_height))
Pygame. Display. Set_caption (" Alien night ")

# to create a spacecraft
The ship=ship (screen)


# start the game live cycle
While True:
# monitoring about the keyboard and mouse
For the event in pygame. Event. The get () :
If the event. The type==pygame. QUIT:
Sys. The exit ()
# every loop heavy send screen
Screen. The fill (ai_settings. Bg_color)

Ship. Blitme ()

# let's recent screen visible
Pygame. Display. Flip ()

Run_game ()

Settings. The content of the py
The class Settings () :
"" "storage "alien invasion" all set "" "
Def __init__ (self) :
"" "initialize game Settings "","
# screen Settings
Self. Screen_width=900
Self. Screen_height=600
Self. Bg_color=(230230230)
The content of the ship. Py
The import pygame

The class Ship () :
Def __init__ (self, screen) :
"" "initialize ship and set its initial position "" "
The self. The screen=screen

# to load the ship image and obtains its external rectangular
The self. The image=pygame. Image. The load (' images/ship. BMP)
The self. The rect=self. Image. Get_rect ()
Self. Screen_rect=screen. Get_rect ()

# put at the bottom of the screen every ship central
The self. The rect. Centerx=self. Screen_rect. Centerx
The self. The rect. Bottom=self. Screen_rect. Bottom

Def blitme (self) :
"" "draw the spacecraft in the location specified "","
The self. The screen. The blit (self image, self. The rect)
The import pygame

The class Ship () :
Def __init__ (self, screen) :
"" "initialize ship and set its initial position "" "
The self. The screen=screen

# to load the ship image and obtains its external rectangular
The self. The image=pygame. Image. The load (' images/ship. BMP)
The self. The rect=self. Image. Get_rect ()
Self. Screen_rect=screen. Get_rect ()

# put at the bottom of the screen every ship central
The self. The rect. Centerx=self. Screen_rect. Centerx
The self. The rect. Bottom=self. Screen_rect. Bottom

Def blitme (self) :
"" "draw the spacecraft in the location specified "","
The self. The screen. The blit (self image, self. The rect)
  • Related