]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Even smoother combat animations.
authoroskar.wiksten@gmail.com <oskar.wiksten@gmail.com@08aca716-68be-ccc6-4d58-36f5abd142ac>
Tue, 18 Oct 2011 20:56:08 +0000 (20:56 +0000)
committeroskar.wiksten@gmail.com <oskar.wiksten@gmail.com@08aca716-68be-ccc6-4d58-36f5abd142ac>
Tue, 18 Oct 2011 20:56:08 +0000 (20:56 +0000)
Allow multiple animations to run concurrently.

git-svn-id: https://andors-trail.googlecode.com/svn/trunk@187 08aca716-68be-ccc6-4d58-36f5abd142ac

AndorsTrail/res/values/loadresources_debug.xml
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DebugInterface.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/CombatController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/VisualEffectController.java

index bd8484b76c9382a363e97d25d287cabad1c770f3..5eaba9b60a5539fc741d040cd7dfffe01d04d51e 100644 (file)
@@ -11,6 +11,7 @@
 [id|iconID|name|category|displaytype|hasManualPrice|baseMarketCost|hasEquipEffect|equip_boostMaxHP|equip_boostMaxAP|equip_moveCostPenalty|equip_attackCost|equip_attackChance|equip_criticalChance|equip_criticalMultiplier|equip_attackDamage_Min|equip_attackDamage_Max|equip_blockChance|equip_damageResistance|equip_conditions[condition|magnitude|]|hasUseEffect|use_boostHP_Min|use_boostHP_Max|use_boostAP_Min|use_boostAP_Max|use_conditionsSource[condition|magnitude|duration|chance|]|hasHitEffect|hit_boostHP_Min|hit_boostHP_Max|hit_boostAP_Min|hit_boostAP_Max|hit_conditionsSource[condition|magnitude|duration|chance|]|hit_conditionsTarget[condition|magnitude|duration|chance|]|hasKillEffect|kill_boostHP_Min|kill_boostHP_Max|kill_boostAP_Min|kill_boostAP_Max|kill_conditionsSource[condition|magnitude|duration|chance|]|];
 {debug_dagger1|items_weapons:20|Black heart dagger|0|3|1|6|1||||2|100|30|3|5|10|||||||||||||||||||||||};
 {debug_ring1|items_jewelry:4|Black heart ring|7|1|1|3|1|||||50|||10|10|||||||||||||||||||||||};
+{shadow_slayer|items_weapons:60|Shadow of the slayer|0|3|1|0|1||2||7|25|10|2|5|9|||||||||||||||||1|1|1||||};
        </string>
 
 
@@ -31,6 +32,7 @@
        {dagger0|1|1|100|}
        {debug_dagger1|1|1|100|}
        {debug_ring1|1|1|100|}
+       {shadow_slayer|1|1|100|}
        }|};
        </string>
 
index a2497868d115a4f646be8085cee24503959f2e1f..86f8f399d78d2d010763e6bca06106fd5fc4339c 100644 (file)
@@ -124,14 +124,6 @@ public final class DebugInterface {
                                mainActivity.showToast("DEBUG: hp set to max", Toast.LENGTH_SHORT);
                                }
                        })
-                       ,new DebugButton("exp", new OnClickListener() {
-                       @Override
-                               public void onClick(View arg0) {
-                               world.model.player.addExperience(10000);
-                               mainActivity.updateStatus();
-                               mainActivity.showToast("DEBUG: added 10k exp", Toast.LENGTH_SHORT);
-                               }
-                       })
                        /*
                        ,new DebugButton("cg", new OnClickListener() {
                        @Override
index 6a76c8b1a1c466635fff8cd5a2b33af978514506..bb79f1e0005098c557db7eb3caf5fe9047686552 100644 (file)
@@ -195,10 +195,10 @@ public final class CombatController implements VisualEffectCompletedCallback {
                        }
                        message(msg);
                        
+                       context.mainActivity.updateStatus();
                        if (lastAttackResult.targetDied) {
                                playerKilledMonster(currentlyAttackedMonster);
                        }
-                       context.mainActivity.updateStatus();
                        
                        startAttackEffect(attack, model.uiSelections.selectedPosition, this, CALLBACK_PLAYERATTACK);
                } else {
index 2b0a47390fab278e4427bb044f70e65c13e3a9f0..506d6a191d68c45897ac1e7c1d2e1dc0efd6c29c 100644 (file)
@@ -3,7 +3,7 @@ package com.gpl.rpg.AndorsTrail.controller;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.Paint.Align;
-import android.os.AsyncTask;
+import android.os.Handler;
 
 import com.gpl.rpg.AndorsTrail.VisualEffectCollection;
 import com.gpl.rpg.AndorsTrail.VisualEffectCollection.VisualEffect;
@@ -14,7 +14,7 @@ import com.gpl.rpg.AndorsTrail.util.Size;
 import com.gpl.rpg.AndorsTrail.view.MainView;
 
 public final class VisualEffectController {
-       private VisualEffectAnimation currentEffect;
+       private int effectCount = 0;
 
        private final VisualEffectCollection effectTypes;
        public VisualEffectController(WorldContext world) {
@@ -22,64 +22,28 @@ public final class VisualEffectController {
        }
 
        public void startEffect(MainView mainview, Coord position, int effectID, int displayValue, VisualEffectCompletedCallback callback, int callbackValue) {
-               VisualEffectAnimation e = currentEffect;
-               if (e != null) {
-                       e.killjoin();
-               }
-               currentEffect = new VisualEffectAnimation(effectTypes.effects[effectID], position, mainview, displayValue, callback, callbackValue);
-               currentEffect.execute();
+               ++effectCount;
+               (new VisualEffectAnimation(effectTypes.effects[effectID], position, mainview, displayValue, callback, callbackValue))
+               .start();
        }
        
-       public final class VisualEffectAnimation extends AsyncTask<Void, Integer, Void> {
-                 
-           @Override
-               protected Void doInBackground(Void... arg0) {
-               final int sleepInterval = effect.millisecondPerFrame / 2;
-               try {
-                       while (isAlive) {
-                                       update();
-                               Thread.sleep(sleepInterval);
-                               if (isCancelled()) return null;
-                               }
-                       Thread.sleep(effect.millisecondPerFrame);
-               } catch (InterruptedException e) { }
-               
-               return null;
-        }
-           
-           @Override
-           protected void onCancelled() {
-               isAlive = false;
-           }
-             
-           public void killjoin() { this.cancel(true); }
+       public final class VisualEffectAnimation extends Handler implements Runnable {
 
-           private void update() {
-               int elapsed = (int)(System.currentTimeMillis() - startTime);
-               if (elapsed > effect.duration) {
-                       isAlive = false;
-                       return;
-               }
-               
-               int currentFrame = (int) Math.floor(elapsed / effect.millisecondPerFrame);
-               
-               if (currentFrame > effect.lastFrame) currentFrame = effect.lastFrame;
-                       if (currentFrame < 0) currentFrame = 0;
-                       final boolean changed = currentFrame != this.lastFrame;
-                       if (!changed) return;
-                       
-                       this.lastFrame = currentFrame;
-                       this.publishProgress(currentFrame);
-               }
-           
-           
                @Override
-               protected void onProgressUpdate(Integer... progress) {
-                       super.onProgressUpdate(progress);
-                       redrawFrame(progress[0]);
+               public void run() {
+                       update();
+                       if (currentFrame == effect.lastFrame) {
+                               onCompleted();
+                       } else {
+                               postDelayed(this, effect.millisecondPerFrame);
+                       }
                }
-               private void redrawFrame(int frame) {
-               int tileID = effect.frameIconIDs[frame];
+             
+           private void update() {
+               ++currentFrame;
+               int frame = currentFrame;
+               
+               int tileID = effect.frameIconIDs[frame];
                        int textYOffset = -2 * (frame);
                        if (frame >= beginFadeAtFrame && displayText != null) {
                                this.textPaint.setAlpha(255 * (effect.lastFrame - frame) / (effect.lastFrame - beginFadeAtFrame)); 
@@ -87,26 +51,19 @@ public final class VisualEffectController {
                        view.redrawAreaWithEffect(area, this, tileID, textYOffset, this.textPaint);
                }
 
-               @Override
-               protected void onPostExecute(Void result) {
-                       super.onPostExecute(result);
-                       VisualEffectController.this.currentEffect = null;
+               protected void onCompleted() {
+               --effectCount;
                        view.redrawArea(area, MainView.REDRAW_AREA_EFFECT_COMPLETED);
                        if (callback != null) callback.onVisualEffectCompleted(callbackValue);
                }
-
-               @Override
-               protected void onPreExecute() {
-                       super.onPreExecute();
-                       this.isAlive = true;
-                       redrawFrame(0);
+               
+               public void start() {
+                       postDelayed(this, 0);
                }
 
-               private boolean isAlive = false;
-               private int lastFrame = 0;
+               private int currentFrame = 0;
                
                private final VisualEffect effect;
-               private final long startTime;
                private final MainView view;
                
                public final Coord position;
@@ -129,25 +86,16 @@ public final class VisualEffectController {
                        this.textPaint.setTextSize(view.scaledTileSize * 0.5f); // 32dp.
                        this.textPaint.setAlpha(255);
                        this.textPaint.setTextAlign(Align.CENTER);
-                       this.startTime = System.currentTimeMillis();
                        this.view = view;
                        this.beginFadeAtFrame = effect.lastFrame / 2;
                }
        }
        
-       
        public static interface VisualEffectCompletedCallback {
                public void onVisualEffectCompleted(int callbackValue);
        }
 
-       public void killCurrentEffect() {
-               VisualEffectAnimation e = currentEffect;
-               if (e != null) {
-                       e.killjoin();
-               }
-       }
-
        public boolean isRunningVisualEffect() {
-               return currentEffect != null;
+               return effectCount > 0;
        }
 }