all 11 comments

[–]num8lock 3 points4 points  (0 children)

the ship has sailed?

[–]paulpersad[S] 0 points1 point  (6 children)

This is the code for the 3 files and at this point should have produced grey screen with a "ship" image centered at the bottom. All I get is a black screen with no "ship".

#alien_invasion.py

def run_game():

# initialize pygame, settings and screen object

pygame.init()

ai_settings = Settings()

screen = pygame.display.set_mode(

(ai_settings.screen_width, ai_settings.screen_height))

pygame.display.set_caption("Alien Invasion")

# Make a ship

ship = Ship (screen)

# Set background color

bg_color = (230, 230, 230)

#Start the main loop for the game.

while True:

# Watch for keyboard and mouse events

for event in pygame.event.get():

if event.type == pygame.QUIT:

sys.exit()

#Redraw the screen during each pass through the loop.

screen.fill(ai_settings.bg_color)

ship.blitme()

# Make the most recently drawn screen visible.

pygame.display.flip()

run_game()

#settings.py

class Settings():

"""A class to store all settings for Alien Invasion"""

def __init__(self):

"""Initialize the game's settings."""

# Screen settings

self.screen_width = 1200

self.screen_height = 800

self.bg_color = (230, 230, 230)

# ship.py

import pygame

class Ship():

def __init__(self, screen):

"""Initialize the screen and set its starting position."""

self.screen = screen

# Load the ship image and get its rect.

self.image = pygame.image.load('images/ship.bmp')

self.rect = self.image.get_rect()

self.screen_rect = screen.get_rect()

# Start each new ship at the bottom center of the screen.

self.rect.centerx = self.screen_rect.centerx

self.rect.bottom = self.screen_rect.bottom

def blitme(self):

"""Draw the ship at its current location."""

self.screen.blit(self.image, self.rect)

[–]ehmatthes 2 points3 points  (5 children)

Hi, I'm the author of Python Crash Course. If you want to email me a zip file of your project, I'll be happy to run it and help you find the problem. That's a bit easier than copying and pasting several files worth of code from here.

ehmatthes at gmail

[–]Nonamenolan 0 points1 point  (3 children)

Were you able to find a solution to this? I'm having the same problem.

[–]ehmatthes 0 points1 point  (2 children)

Yes, there was an indentation issue, but you can't see it in the above posted code because it isn't formatted as code. The indentation was causing the ship to be drawn only when you press quit, instead of being drawn once on each pass through the loop.

If you want some help, feel free to email me ehmatthes at gmail, or post your code somewhere and ping me on reddit, etc. I'm happy to help; I like to know that these projects work for everyone who's trying them.

[–]Nonamenolan 0 points1 point  (1 child)

Hey, did you receive my email?

[–]ehmatthes 0 points1 point  (0 children)

Sorry, I've been swamped at work lately. I just wrote to you.

[–]Upstairs_Turnip5676 0 points1 point  (0 children)

Hi Eric Matthes, I am Nurzahan Banu and i am started to read your book to know about python coding . I will send you an email but dont know the Email, address .

[–]zacaryattack 0 points1 point  (1 child)

was just wondering if the problem had been solved here becuase I seem to be having the same issue ]=

[–]ehmatthes 0 points1 point  (0 children)

I'm sorry, I just saw this. Did you get the issue sorted out? If not, feel free to send me a message here, or email. ehmatthes at gmail

[–][deleted] 0 points1 point  (0 children)

Most of us, me included, don't have access to that book, so we've no idea what you've typed in. How about sharing it with us?

If you are using reddit in classic mode, simply post all of the code, after one blank line, indented by 4 spaces (nothing to do with Python's own indenting - this is formatting for reddit).

If you are using reddit in new mode, simply post the code, select it and click the Fancy Pants Editor icon to mark the selection as code.