前提・実現したいこと
プロセッシングでゲームを作成しています。
エンターキーを押してから、画面に表示する画像(スプライトシート)を3秒ごとに更新させたいのですが、上手く動かすことが出来ません。
どうすれば動きますか?
試行錯誤中のコードなのでよくわからないことになってます…
##ソースコード
processing
1class Menu extends BaseCharacter 2{ 3 //メニュー選択のフラグ 4 public boolean kougeki_f; 5 public boolean nigeru_f; 6 7 //「逃げる」を選択した場合の判定 8 public int escape_f; 9 10 //Pointの変数 11 PImage point; 12 public int posX, posY; 13 14 // 15 public int menu_state; 16 public int hyouji_time; 17 public boolean hyouji_f = false; 18 public static final int MENU_KOUGEKI = 0; 19 public static final int MENU_NIGERU = 1; 20 public static final int MENU_ENEMY_HP10 = 2; 21 public static final int MENU_ENEMY_HP0 = 3; 22 public static final int MENU_ENEMY_HP0_MS = 4; 23 public static final int MENU_PLAYER_HP10 = 5; 24 public static final int MENU_PLAYER_HP0 = 6; 25 public static final int MENU_NIGERU_Y = 7; 26 public static final int MENU_NIGERU_N = 8; 27 28 // 29 public Player_Battle player_b; 30 public Enemy_Battle enemy_b; 31 32 public Menu(MyGame parent) 33 { 34 super(parent, "MenuAll.png", 1, 9); 35 } 36 void initialize() 37 { 38 kougeki_f = true; 39 nigeru_f = false; 40 41 //Menuの設定 42 this.menu_state = MENU_KOUGEKI; 43 changeAnimation(this.menu_state); 44 this.position.set(width/2, 500); 45 //Pointの座標 46 this.posX = 200; 47 this.posY = 450; 48 49 //インスタンス化 50 this.player_b = new Player_Battle(); 51 this.enemy_b = new Enemy_Battle(); 52 53 frameRate(60); 54 } 55 56 void update(double deltaTime) 57 { 58 super.update(deltaTime); 59 this.draw(); 60 } 61 void draw() 62 { 63 this.select(); 64 /* 65 this.point = loadImage("MenuPoint.png"); 66 imageMode(CENTER); 67 image(this.point, posX,posY,20,20); 68 */ 69 70 hyouji_time++; 71 if (hyouji_time >= (60 * 3)) 72 { 73 hyouji_f = true; 74 hyouji_time = 0; 75 } 76 } 77 78 public void select() 79 { 80 if (keyPressed) 81 { 82 if (keyCode == LEFT) 83 { 84 //println("攻撃"); 85 this.menu_state = MENU_KOUGEKI; 86 changeAnimation(this.menu_state); 87 88 kougeki_f = true; 89 nigeru_f = false; 90 } 91 else if (keyCode == RIGHT) 92 { 93 //println("逃げる"); 94 this.menu_state = MENU_NIGERU; 95 changeAnimation(this.menu_state); 96 97 kougeki_f = false; 98 nigeru_f = true; 99 } 100 101 if ( key == ENTER) 102 { 103 if (kougeki_f == true) 104 { 105 println("プレイヤーの攻撃"); 106 attack(); 107 attack_enemy(); 108 kougeki_f = false; 109 } 110 else if (nigeru_f == true) 111 { 112 println("逃げる"); 113 escape(_parent.enemy); 114 nigeru_f = false; 115 } 116 } 117 } 118 } 119 120 public void attack() 121 { 122 //攻撃 123 BattleCharacter target = enemy_b; 124 player_b.attack(target); 125 //text(player_b._name + " が " + target.getName() + " を攻撃", 100,500); 126 if (enemy_b._hp > 0) 127 { 128 this.menu_state = MENU_ENEMY_HP10; 129 changeAnimation(this.menu_state); 130 } 131 else if (enemy_b._hp <= 0) 132 { 133 134 this.menu_state = MENU_ENEMY_HP0; 135 changeAnimation(this.menu_state); 136 137 138 this.menu_state = MENU_ENEMY_HP0_MS; 139 changeAnimation(this.menu_state); 140 141 _parent.enemy.position.set(0, 5000); 142 switch(_parent.map_c) 143 { 144 case 1: 145 _parent.state = _parent.STATE_MGAME1; 146 break; 147 case 2: 148 _parent.state = _parent.STATE_MGAME2; 149 break; 150 } 151 } 152 } 153 154 public void escape(Enemy enemy) 155 { 156 enemy.invincible = true; 157 escape_f = (int)random(0, 10); 158 if (escape_f % 2 == 0) 159 { 160 switch(_parent.map_c)//成功 161 { 162 case 1: 163 _parent.state = _parent.STATE_MGAME1; 164 break; 165 case 2: 166 _parent.state = _parent.STATE_MGAME2; 167 break; 168 } 169 } 170 else if ( escape_f % 2 == 1)//失敗 171 { 172 attack_enemy(); 173 if (player_b._hp == 0) _parent.state = _parent.STATE_OVER; 174 } 175 } 176 177 public void attack_enemy() 178 { 179 println(hyouji_f); 180 println(hyouji_time); 181 if (hyouji_f == true) 182 { 183 println("pp"); 184 BattleCharacter target = player_b; 185 enemy_b.attack(target); 186 187 188 if (player_b._hp > 0) 189 { 190 191 this.menu_state = MENU_PLAYER_HP10; 192 changeAnimation(this.menu_state); 193 hyouji_time = 0; 194 } 195 else 196 { 197 this.menu_state = MENU_PLAYER_HP10; 198 changeAnimation(this.menu_state); 199 200 _parent.state = _parent.STATE_OVER; 201 } 202 hyouji_f = false; 203 } 204 } 205} 206
補足情報(FW/ツールのバージョンなど)
processing-3.3.7
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。