Created
September 18, 2021 06:46
-
-
Save shinysu/90d262a21520d229c461323c10e24fe5 to your computer and use it in GitHub Desktop.
create enemies
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.x = WIDTH / 2 | |
player.y = HEIGHT - 50 | |
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
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() |
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
''' | |
move bullets | |
''' | |
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() |
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
''' | |
move bullets | |
''' | |
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() | |
move_bullet() | |
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) | |
def move_bullet(): | |
for bullet in bullets: | |
if bullet.bottom < 0: | |
bullets.remove(bullet) | |
else: | |
bullet.y -= 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 enemies | |
''' | |
import pgzrun | |
from random import randint | |
WIDTH = 1000 | |
HEIGHT = 700 | |
player = Actor('playership') | |
player.x = WIDTH / 2 | |
player.y = HEIGHT - 50 | |
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_bullet() | |
move_enemy() | |
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) | |
def create_new_enemy(): | |
enemy = Actor('enemygreen') | |
enemy.x = randint(100, WIDTH-100) | |
enemy.y = 10 | |
enemies.append(enemy) | |
def move_bullet(): | |
for bullet in bullets: | |
if bullet.bottom < 0: | |
bullets.remove(bullet) | |
else: | |
bullet.y -= 10 | |
def move_enemy(): | |
for enemy in enemies: | |
enemy. y += 5 | |
create_new_enemy() | |
pgzrun.go() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment