python
1import pyxel 2import random 3 4IMG_NO = 0 5ENEMY_IMG_NO = 1 6 7class MyChara: 8 ani_no = 0 9 ani_max = 6 10 ani_interval = 2 11 ani_cnt = 0 12 ani_flg = False 13 14 def __init__(seif): 15 if pyxel.btn(pyxel.KEY_LEFT) or pyxel.btn(pyxel.GAMEPAD_1_LEFT): 16 self.my_x = max(self.my_x - 2, 0) 17 18 if pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn(pyxel.GAMEPAD_1_RIGHT): 19 self.my_x = min(self.my_x + 2, pyxel.width - 16) 20 21 if pyxel.btn(pyxel.KEY_UP) or pyxel.btn(pyxel.GAMEPAD_1_UP): 22 self.my_y = max(self.my_y - 2, 0) 23 24 if pyxel.btn(pyxel.KEY_DOWN) or pyxel.btn(pyxel.GAMEPAD_1_DOWN): 25 self.my_y = min(self.my_y + 2, pyxel.height - 16) 26 27 self.ani_flg = False 28 29 def startAnimation(self): 30 self.ani_cnt = -1 31 self.ani_no = 0 32 self.ani_flg = True 33 34 def drawImage(self,_my_x,_my_y): 35 if(self.ani_flg == True): 36 self.ani_cnt = (self.ani_cnt + 1)% self.ani_interval 37 if(self.ani_cnt == 0): 38 self.ani_no = self.ani_no + 1 39 if(self.ani_no >= self.ani_max): 40 self.ani_no = 0 41 self.ani_flg = False 42 else: 43 self.ani_no = 0 44 pyxel.blt( 45 _my_x,_my_y, 46 IMG_NO, 47 0 + (self.ani_no * 16),0, 48 16,16,1) 49 50 class Enemy: 51 ani_no = 0 52 ani_max = 6 53 ani_interval = 2 54 ani_cnt = 0 55 ani_flg = False 56 delete_flg = False 57 58 def __init__(self,_width,_height): 59 self.x = random.randint(0,_width) 60 self.y = random.randint(0,_height) 61 self.delete_flg = False 62 63 def startAnimation(self): 64 if(self.ani_flg == False): 65 self.ani_cnt = -1 66 self.ani_no = 0 67 self.ani_flg = True 68 69 def drawImage(self,_x,_y): 70 if(self.ani_flg == True): 71 self.ani_cnt = (self.ani_cnt + 1)% self.ani_interval 72 if(self.ani_cnt == 0): 73 self.ani_no = self.ani_no + 1 74 if(self.ani_no >= self.ani_max): 75 self.ani_no = self.ani_max - 1 76 self.ani_flg = False 77 self.delete_flg = True 78 else: 79 self.ani_no = 0 80 pyxel.blt( 81 _x,_y,ENEMY_IMG_NO, 82 0 + (self.ani_no * 16),0, 83 16,16,1) 84
pyxelでキャラクターのアニメーションを動かしたいのですが、動きません。
回答1件
あなたの回答
tips
プレビュー