Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created September 18, 2021 09:41
Show Gist options
  • Select an option

  • Save shinysu/9ef9fe20bf963308e8ad34131b3970d4 to your computer and use it in GitHub Desktop.

Select an option

Save shinysu/9ef9fe20bf963308e8ad34131b3970d4 to your computer and use it in GitHub Desktop.
Creating new enemies
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()
'''
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()
'''
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()
'''
moving 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()
move_bullets()
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 move_bullets():
for bullet in bullets:
if bullet.bottom < 0:
bullets.remove(bullet)
else:
bullet.y -= 10
def create_new_bullet():
bullet = Actor('bullet')
bullet.x = player.x
bullet.y = player.y
bullets.append(bullet)
pgzrun.go()
'''
create enemies
'''
import pgzrun
from random import randint
WIDTH = 1000
HEIGHT = 700
player = Actor('playership')
player.bottom = HEIGHT
player.x = WIDTH / 2
bullets = []
enemies = []
def draw():
screen.blit('skyb', (0,0))
player.draw()
for bullet in bullets:
bullet.draw()
for enemy in enemies:
enemy.draw()
def update():
move_player()
move_bullets()
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 move_bullets():
for bullet in bullets:
if bullet.bottom < 0:
bullets.remove(bullet)
else:
bullet.y -= 10
def create_new_bullet():
bullet = Actor('bullet')
bullet.x = player.x
bullet.y = player.y
bullets.append(bullet)
def create_new_enemy():
enemy = Actor('enemygreen')
enemy.x = randint(100, WIDTH-100)
enemy.y = 10
enemies.append(enemy)
create_new_enemy()
pgzrun.go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment