print(sys.stdout.encoding) import vgame vgame.DEBUG = True path = '../test_data/fjdz/image' vgame.Initer(size=(240, 480)) main = vgame.Theater(path + '/background.png', (640, 480)) print(main.size) player_imgs = [ path + '/hero1.png', path + '/hero2.png', ] player = vgame.Player(player_imgs, rate=200, showsize=(50, 62)).local(main, (120, 400)).follow(main, .05) player.direction = lambda self, d: self.mover.move(d.get('p1'), 6) def control(self, c): if self.delay(c and c.get('p1')[0], time=50, repeat=True): create_bullet() if self.delay(c and c.get('p1')[1], time=50, repeat=True): for idx, i in enumerate(main.Bullet): print(idx, i) i.rect[:2] = 100, 100 player.control = control bullet_player = vgame.Music('../test_data/fjdz/music/bullet.wav', .2)
# 增加环境变量,仅测试使用 import os import sys p = os.path.split(os.getcwd())[0] sys.path = [p] + sys.path import sys print(sys.stdout.encoding) import vgame vgame.DEBUG = True vgame.Camera.DEBUG = True vgame.Initer() main = vgame.Theater(size=(1024, 640)) player = vgame.Player().local(main, (80, 600)).follow(main, .05) # 在没有超过边界时,窗口会平滑居中移动 wall = vgame.Wall(showsize=(500, 10)).local(main, (400, 300)) player.direction = lambda self, d: self.mover.move(d.get('p1'), 10) player.mouse = lambda self, m: self.clicker.dnd(m) # 设置a对象可以被鼠标左键拖动 player.bound = lambda self, b: print(self, b) player.click = lambda self: print(123) player.mouseover = lambda self: print('over') player.mouseout = lambda self: print('out')
map.local(main) print(map.gridsize) gy = '../test_data/fc吞食天地素材/行走图/关羽.png' vgame.Image(gy) imake = vgame.ImageMaker(gy) s = imake.gridcut((32, 32)) playerimg_u = vgame.Image(s[12:16], rate=200, showsize=(32,32)) playerimg_d = vgame.Image(s[ 0: 4], rate=200, showsize=(32,32)) playerimg_r = vgame.Image(s[ 8:12], rate=200, showsize=(32,32)) playerimg_l = vgame.Image(s[ 4: 8], rate=200, showsize=(32,32)) player = vgame.Player(playerimg_d, rectsize=(32, 32)).map.local(map, (1,1), 10) player.status['direction']['up'] = playerimg_u player.status['direction']['down'] = playerimg_d player.status['direction']['right'] = playerimg_r player.status['direction']['left'] = playerimg_l atk = '../test_data/fc吞食天地素材/战斗_头像图/攻击图1.png' imake = vgame.ImageMaker(atk) s = imake.gridcut((192, 192)) playerimg_a_right = vgame.Image(s[8:10], rate=200, showsize=(192,192), offsets=(-80,80)) playerimg_a_left = vgame.Image(s[8:10], rate=200, showsize=(192,192), offsets=(80,80), flip='x') player.status['direction']['atkr'] = playerimg_a_right player.status['direction']['atkl'] = playerimg_a_left def ctl(self, c): if self.delay(c and c.get('p1')[0]):
bg0 = '../test_data/sea.jpg' ims = '../test_data/e1' fsd = '../test_data/fish/down' fsu = '../test_data/fish/up' fsr = '../test_data/fish/right' fra = '../test_data/fish/right_attck1' Initer() vgame.DEBUG = True # 调试模式 # vgame.Theater.Map.DEBUG = True # 打开地图栅格调试 # vgame.Theater.Camera.DEBUG = True # 资源加载 i_bg0 = Image(bg0) i_ims = Image(ims, showsize=(40, 40), rate=80) i_fsd = Image(fsd, showsize=(40, 40), rate=60) i_fsu = Image(fsu, showsize=(40, 40), rate=60) i_fsr = Image(fsr, showsize=(40, 40), rate=60) i_fsl = Image(fsr, showsize=(40, 40), rate=60, flip='x') i_fra = Image(fra, showsize=(40, 40), rate=60) main = Theater(i_bg0) player = vgame.Player(i_fsd) player.status['direction'] = { 'up': i_fsu, 'down': i_fsd, 'right': i_fsr, 'left': i_fsl, } player.local(main) player.direction = lambda self, d: self.mover.move(d.get('p1'))
Run = vgame.ImageMaker(pathA + '/spr_ArcherRun_strip_NoBkg.png') Run = Run.gridcut((Run.size[0]/8, 128)) vgame.Initer() main = vgame.Theater(size=(980,640)) show_Attack = vgame.Anime(Attack, rectsize=(30,40), rate=60, offsets=(-30,-5)).local(main, offsets=(100,-200)) show_Dash = vgame.Anime(Dash, rectsize=(30,40), rate=60, offsets=(0,-5)).local(main, offsets=(100,-150)) show_Death = vgame.Anime(Death, rectsize=(30,40), rate=60, offsets=(0,-5)).local(main, offsets=(100,-100)) show_Idle = vgame.Anime(Idle, rectsize=(30,40), rate=60, offsets=(0,-5)).local(main, offsets=(100,-50)) show_JumpAndFall = vgame.Anime(JumpAndFall,rectsize=(30,40), rate=60, offsets=(0,-5)).local(main, offsets=(100,0)) show_Melee = vgame.Anime(Melee, rectsize=(30,40), rate=60, offsets=(0,-5)).local(main, offsets=(100,50)) show_Run = vgame.Anime(Run, rectsize=(30,40), rate=60, offsets=(0,-5)).local(main, offsets=(100,100)) Idle_r = vgame.Image(Idle, rate=60, offsets=(0,-5)) Idle_l = vgame.Image(Idle, rate=60, offsets=(0,-5), flip='x') player = vgame.Player(Idle_r, rectsize=(30,40)).local(main).follow(main, .1) player.status['direction']['right'] = Idle_r player.status['direction']['left'] = Idle_l def direct(self, d): self.mover.move(d.get('p1'), 10) def ctl(self, c): if self.delay(c and c.get('p1')[0], time=100): self.aload_image(show_Attack.imager) if self.delay(c and c.get('p1')[1], time=100): self.aload_image(show_Melee.imager) player.direction = direct player.control = ctl player.mouse = lambda self,m: self.clicker.dnd(m)
import sys p = os.path.split(os.getcwd())[0] sys.path = [p] + sys.path import sys print(sys.stdout.encoding) import random import vgame # vgame.DEBUG = True # vgame.Map.DEBUG = True init = vgame.Initer() main = vgame.Theater() player = vgame.Player(showsize=(80, 100)).local(main, offsets=(0, 180)) score = 0 txt = vgame.Text(str(score), textcolor=(255, 0, 0), textscale=2) label = vgame.Enemy(txt).local( main, (100, 100), ) bullets = [] def enemycreater(self): if self.delay(True, time=100, repeat=True): x = random.randint(40, 600) e = vgame.Enemy((0, 255, 5), showsize=(32, 32), in_bounds=False).local(main, (x, 0))
import sys p = os.path.split(os.getcwd())[0] sys.path = [p] + sys.path import sys print(sys.stdout.encoding) import vgame vgame.DEBUG = True # vgame.Map.DEBUG = True vgame.Initer() main = vgame.Theater(size=(960, 720)) maps = vgame.Map(grid=(20, 15), showsize=main.size).local(main) label = vgame.Anime(vgame.Text('wasd控制,j跳跃k冲刺')).local(main) player = vgame.Player((255, 0, 0), showsize=maps.gridsize).map.local(maps, (0, 14)) # 窗口大小由 Initer 配置 # 游戏内窗大小由 Theater 配置(如不配置默认随窗口大小) # 这里让 player 作为main窗口的跟随移动进行处理,这样可以让某些动作类的游戏窗口的移动更加平滑。 player.follow(main, .05) def direct(self, d): d = d.get('p1') if self.status['dash_toggle']: pass else: if d and 6 in d: self.status['speedx'] = 10 if d and 4 in d: self.status['speedx'] = -10
import os import sys p = os.path.split(os.getcwd())[0] sys.path = [p] + sys.path import sys print(sys.stdout.encoding) import vgame # vgame.DEBUG = True # vgame.Map.DEBUG = True s = vgame.Initer() main = vgame.Theater() labeler = vgame.Player( vgame.Text('J键修改数字', (255, 0, 0), 2, textwidth=300, textside='r')).local(main, (100, 100)) player = vgame.Player( vgame.Text('0', (255, 0, 0), 2, textwidth=150, textside='r')).local(main, (200, 200)) nums = {'v': 0} def ctl(self, c): if self.delay(c and c.get('p1')[0]): nums['v'] += 1 player.text = nums['v'] labeler.text = '开始点击'
sys.path = [p] + sys.path import sys print(sys.stdout.encoding) import vgame # vgame.DEBUG = True vgame.Menu.DEBUG = True vgame.Map.DEBUG = True vgame.Initer() main = vgame.Theater((0, 0, 0)).draw.rect((255, 255, 255), 5, 3) menu = vgame.Menu(grid=(9, 9), showsize=(main.size[0] - 50, 200 - 50)).local(main, offsets=(0, 140)) player = vgame.Player(showsize=(40, 20)).menu.local(menu, (1, 1)) maps = vgame.Map(grid=(9, 9), showsize=(main.size[0] - 200, 200 - 50)).local(main, offsets=(0, -140)) vgame.Enemy(showsize=(30, 10)).map.local(maps, (3, 3), 2) vgame.Enemy(showsize=(30, 10)).map.local(maps, (3, 4), 2) vgame.Enemy(showsize=(30, 10)).map.local(maps, (3, 5), 2) enemy = vgame.Enemy(showsize=(30, 10)).map.local(maps, (8, 8), 2) player = vgame.Player(showsize=(30, 15)).map.local(maps, (4, 5), 1) def ctl(self, c): if self.delay(c and c.get('p1')[0]): print(maps) print(self.map.trace(enemy))
# 增加环境变量,仅测试使用 import os import sys p = os.path.split(os.getcwd())[0] sys.path = [p] + sys.path import sys print(sys.stdout.encoding) import vgame vgame.Initer() main = vgame.Theater() a = vgame.Player().local(main, (100, 100)) b = vgame.Wall(showsize=(300, 100)).local(main, (200, 200)) def move_d(self, d): # self 代表了被覆盖了 direction 函数的对象本身,即为 Player 实例。 # 这个实例有一个 mover 方法,可以将获取到的操作信息直接用 mover.move 函数接收 # 这样能直接移动,如果需要修改各个方向的加速度分量, # p1:WASD p2:上下左右键 # 这个 get('p1') 消息实际上是一个数字的列表 # 这个列表长度最大为2,从小键盘上看到的 8264 方向即作为方向表示,比英文更加直观 # 这里的消息 d 也是经过处理了的,同时按下超过三个方向键这里的消息就会返回空。 # 同时按下左右,或者同时按下上下均返回空消息。所以这些接收的消息必然是八方向其中的一个。 # 放心使用即可。 self.mover.move(d.get('p1'), 13) # 实际上 Player 实例本身就是一个更加强大的 Sprite 类,所以自身也拥有 rect 属性