Week 4: Jan 28 -1

Programming and system development - Shooting spaceship game (Part 1)

Learning objectives:

  • Create and run a text-based program
  • Output data and messages
  • Take text input from the user
  • Store data in variables
  • Use arithmetic operators.

Shooting a spaceship game:

Game Images:


Game Code:

# Set screen size

WIDTH=800

HEIGHT=450

# Set my variables

background=Actor("background")

alien=Actor("alien")

alien.x=50

alien.y=300

spaceship1=Actor("spaceship1")

spaceship1.x=780

spaceship1.y=50

# To display on the screen

def draw():

       background.draw()

       alien.draw()

       spaceship1.draw()

# Action function

def update():

       spaceship1.x=spaceship1.x-3

       if spaceship1.x<100:

                 spaceship1.x=780

     if keyboard.right:

                alien.x=alien.x+3

     if keyboard.left:

             alien.x=alien.x-3