Created
September 18, 2021 09:25
-
-
Save shinysu/a7dff86a325a6d685782ad01b685b68e to your computer and use it in GitHub Desktop.
space shoopter - Creating bullets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pgzrun | |
WIDTH = 1000 | |
HEIGHT = 700 | |
player = Actor('playership') | |
player.bottom = HEIGHT | |
player.x = WIDTH / 2 | |
def draw(): | |
screen.blit('skyb', (0,0)) | |
player.draw() | |
pgzrun.go() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
moving the player | |
''' | |
import pgzrun | |
WIDTH = 1000 | |
HEIGHT = 700 | |
player = Actor('playership') | |
player.bottom = HEIGHT | |
player.x = WIDTH / 2 | |
def draw(): | |
screen.blit('skyb', (0,0)) | |
player.draw() | |
def update(): | |
move_player() | |
def move_player(): | |
if keyboard.LEFT: | |
player.x -= 10 | |
if keyboard.RIGHT: | |
player.x += 10 | |
pgzrun.go() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
create bullets | |
''' | |
import pgzrun | |
WIDTH = 1000 | |
HEIGHT = 700 | |
player = Actor('playership') | |
player.bottom = HEIGHT | |
player.x = WIDTH / 2 | |
bullets = [] | |
def draw(): | |
screen.blit('skyb', (0,0)) | |
player.draw() | |
for bullet in bullets: | |
bullet.draw() | |
def update(): | |
move_player() | |
def on_key_down(key): | |
if key == keys.SPACE: | |
create_new_bullet() | |
def move_player(): | |
if keyboard.LEFT: | |
player.x -= 10 | |
if keyboard.RIGHT: | |
player.x += 10 | |
def create_new_bullet(): | |
bullet = Actor('bullet') | |
bullet.x = player.x | |
bullet.y = player.y | |
bullets.append(bullet) | |
pgzrun.go() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment