Adding ship and settings
This commit is contained in:
@ -3,6 +3,7 @@ import sys
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
from ship import Ship
|
||||||
|
|
||||||
class AlienInvasion:
|
class AlienInvasion:
|
||||||
"""Overall class to manage game assets and behaviour."""
|
"""Overall class to manage game assets and behaviour."""
|
||||||
@ -15,6 +16,8 @@ class AlienInvasion:
|
|||||||
self.screen = pygame.display.set_mode((self.settings.screen_witdh, self.settings.screen_heigh))
|
self.screen = pygame.display.set_mode((self.settings.screen_witdh, self.settings.screen_heigh))
|
||||||
pygame.display.set.caption("Alien Invasion")
|
pygame.display.set.caption("Alien Invasion")
|
||||||
|
|
||||||
|
self.ship = Ship(self)
|
||||||
|
|
||||||
# Set the background color.
|
# Set the background color.
|
||||||
self.bg_color = (230, 230, 230)
|
self.bg_color = (230, 230, 230)
|
||||||
|
|
||||||
@ -28,6 +31,7 @@ class AlienInvasion:
|
|||||||
|
|
||||||
# Redraw the screen during each pass through the loop.
|
# Redraw the screen during each pass through the loop.
|
||||||
self.screen.fill(self.settings.bg_color)
|
self.screen.fill(self.settings.bg_color)
|
||||||
|
self.ship.blitme()
|
||||||
|
|
||||||
# Make the most recently drawn screen visible.
|
# Make the most recently drawn screen visible.
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|||||||
21
ship.py
Normal file
21
ship.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class Ship:
|
||||||
|
"""A class to manage the ship"""
|
||||||
|
|
||||||
|
def __init__(self, ai_game):
|
||||||
|
"""Initialize the ship and set its starting position"""
|
||||||
|
self.screen = ai_game.screen
|
||||||
|
self.screen_rect = ai_game.screen.get_rect()
|
||||||
|
|
||||||
|
# Load the ship image and get its rect.
|
||||||
|
self.image = pygame.image.load('images/ship.bmp')
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
|
||||||
|
# Start each new ship at the bottom center of the screen.
|
||||||
|
self.rect.midbottom = self.screen_rect.midbottom
|
||||||
|
|
||||||
|
def blitme(self):
|
||||||
|
"""Draw the ship at its current location"""
|
||||||
|
self.screen.blit(self.image, self.rect)
|
||||||
|
|
||||||
Reference in New Issue
Block a user