Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created September 21, 2021 09:19
Show Gist options
  • Save shinysu/ba8a016bfe9b48b4b96d99e9443b8bd9 to your computer and use it in GitHub Desktop.
Save shinysu/ba8a016bfe9b48b4b96d99e9443b8bd9 to your computer and use it in GitHub Desktop.
battle_city
import pgzrun
WIDTH = 800
HEIGHT = 600
tank = Actor('tank_blue')
tank.bottom = HEIGHT
tank.x = WIDTH / 2
tank.angle = 90
def draw():
screen.blit('grass', (0, 0))
tank.draw()
pgzrun.go()
'''
moving the tank
'''
import pgzrun
WIDTH = 800
HEIGHT = 600
tank = Actor('tank_blue')
tank.bottom = HEIGHT
tank.x = WIDTH / 2
tank.angle = 90
def draw():
screen.blit('grass', (0, 0))
tank.draw()
def update():
move_tank()
def move_tank():
if keyboard.left:
tank.angle = 180
tank.x -= 5
elif keyboard.right:
tank.angle = 0
tank.x += 5
elif keyboard.up:
tank.angle = 90
tank.y -= 5
elif keyboard.down:
tank.angle = 270
tank.y += 5
pgzrun.go()
'''
build the wall
'''
import pgzrun
WIDTH = 800
HEIGHT = 600
tank = Actor('tank_blue')
tank.bottom = HEIGHT
tank.x = WIDTH / 2
tank.angle = 90
walls = []
def draw():
screen.blit('grass', (0, 0))
tank.draw()
for wall in walls:
wall.draw()
def update():
move_tank()
def move_tank():
if keyboard.left:
tank.angle = 180
tank.x -= 5
elif keyboard.right:
tank.angle = 0
tank.x += 5
elif keyboard.up:
tank.angle = 90
tank.y -= 5
elif keyboard.down:
tank.angle = 270
tank.y += 5
def create_new_wall():
for i in range(16):
for j in range(12):
wall = Actor('wall')
wall.topleft = (i * 50, j * 50)
walls.append(wall)
create_new_wall()
pgzrun.go()
'''
build the wall
'''
import pgzrun
from random import randint
WIDTH = 800
HEIGHT = 600
tank = Actor('tank_blue')
tank.bottom = HEIGHT
tank.x = WIDTH / 2
tank.angle = 90
walls = []
def draw():
screen.blit('grass', (0, 0))
tank.draw()
for wall in walls:
wall.draw()
def update():
move_tank()
def move_tank():
if keyboard.left:
tank.angle = 180
tank.x -= 5
elif keyboard.right:
tank.angle = 0
tank.x += 5
elif keyboard.up:
tank.angle = 90
tank.y -= 5
elif keyboard.down:
tank.angle = 270
tank.y += 5
def create_new_wall():
for i in range(16):
for j in range(10):
if randint(0, 100) > 50:
wall = Actor('wall')
wall.topleft = (i * 50, 50 + j * 50)
walls.append(wall)
create_new_wall()
pgzrun.go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment