Week 4: Jan 28 -1 

Programming - Python - Shooting spaceship game (Part 1)

Learning objectives:

  • identify and describe data types in text-based programs, including Integer, Real and String
  • develop text-based programs that use:
    • input and output
    • data types including Integer, Real and String
    • variables
    • different arithmetic operators, including +, -, *, /
  • apply a test plan and test a program using a range of data
  • develop a program for a physical computing device to generate multiple outputs, based on multiple inputs

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