Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created September 18, 2021 06:21
Show Gist options
  • Save shinysu/15a38f532842b8ee133b2f272cae88d6 to your computer and use it in GitHub Desktop.
Save shinysu/15a38f532842b8ee133b2f272cae88d6 to your computer and use it in GitHub Desktop.
space shooter - Creating bullets
import pgzrun
WIDTH = 1000
HEIGHT = 700
player = Actor('playership')
player.x = WIDTH / 2
player.y = HEIGHT - 50
def draw():
screen.blit('skyb', (0, 0))
player.draw()
pgzrun.go()
import pgzrun
WIDTH = 1000
HEIGHT = 700
player = Actor('playership')
player.x = WIDTH / 2
player.y = HEIGHT - 50
def draw():
screen.blit('skyb', (0, 0))
player.draw()
def update():
move_player()
def move_player():
if keyboard.left:
player.x -= 5
if keyboard.right:
player.x += 5
pgzrun.go()
import pgzrun
WIDTH = 1000
HEIGHT = 700
player = Actor('playership')
player.x = WIDTH / 2
player.y = HEIGHT - 50
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 -= 5
if keyboard.right:
player.x += 5
def create_new_bullet():
bullet = Actor('bullet')
bullet.pos = player.pos
bullets.append(bullet)
pgzrun.go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment