def __init__(self): self.foot = screen.create_sprite('tank_foot', self, './pics/tank_foot.png', (300, 300)) self.body = screen.create_sprite('tank_body', self, './pics/tank_body.png', self.foot.pos) self.head = screen.create_sprite('tank_head', self, './pics/tank_head.png', self.foot.pos) self.speed = 1 self._fire_colddown = False pass
def __init__(self, x, y): name = 'block_%d_%d' % (x, y) posx = x * 64 + 32 posy = y * 64 + 32 images = [ './pics/0.png', './pics/1.png', './pics/2.png', './pics/3.png', './pics/4.png', './pics/5.png', './pics/6.png', './pics/7.png', './pics/8.png', './pics/mine2.png', './pics/flag.png', './pics/unknown.png', # 11 './pics/mine.png', # 12 './pics/mine3.png' # 13 ] self.body = screen.create_sprite(name, self, images, posx, posy) self.body.switch_costume(11) self.mine = False self.x = x self.y = y self.opened = False self.flaged = False
def create_blocks(row, column): """create blocks""" image_files = [ './pics/0.png', './pics/1.png', './pics/2.png', './pics/3.png', './pics/4.png', './pics/5.png', './pics/6.png', './pics/7.png', './pics/8.png', './pics/mine2.png', './pics/flag.png', './pics/unknown.png', # 11 './pics/mine.png' # 12 ] # create blocks for y in range(0, row): for x in range(0, column): b = screen.create_sprite('block_%d_%d' % (x, y)) b.add_costume(image_files) b.switch_costume(11) b.move_to(x * 64 + 32, y * 64 + 32) # add user-define variables b.mine = False b.open = False b.flag = False # put mine put_mines(row, column, 10)
def fire(self, btn_press): if btn_press: if not self._fire_colddown or screen.now_time( ) - self._fire_colddown > 200: mdir = self.head.dir obj = screen.create_sprite('bullet_XXXXXX', self, './pics/bullet1.png', self.foot.pos) obj.set_auto_move(5, mdir) obj = screen.create_sprite('bullet_XXXXXX', self, './pics/bullet1.png', self.foot.pos) obj.set_auto_move(5, mdir - 5) obj = screen.create_sprite('bullet_XXXXXX', self, './pics/bullet1.png', self.foot.pos) obj.set_auto_move(5, mdir + 5) self._fire_colddown = screen.now_time() else: self._fire_colddown = 0
def _create(self): self.body = screen.create_sprite('target_XXXXXX', self, './pics/1.png', screen.random_pos()) # self.bar = screen.draw_box(64, 12, 'red', (0, 0, 0), 0) # self.bar.move_to(self.body.pos_x, self.body.pos_y+38) self.hp = 20 self.bar2 = screen.SpriteBar(value=20, max=20, width=64) self.bar2.move_to(self.body.pos_x, self.body.pos_y + 38) self.bar2.value = self.hp
import screen def on_mouse_down(pos, button): pass if __name__ == '__main__': # init screen.set_backdrop('./pics/grass.jpg') screen.set_event('MouseButtonDown', on_mouse_down) # screen.set_event('KEYDOWN', on_key_down) tank = screen.create_sprite('tank') tank.set_costume('./pics/tank12.png') tank.move_to(300, 300) # main-loop speed = 2 while not screen.closed: tick = screen.run() if screen.key_pressed('up'): tank.point_dir(0, rotate=True) tank.move(speed) elif screen.key_pressed('down'): tank.point_dir(180, rotate=True) tank.move(speed) elif screen.key_pressed('left'): tank.point_dir(270, rotate=True)