//collide and animation internal Projectile(Moveable owner, Vector2f start, Moveable d, Func<Moveable, bool> doA, Animation animation, float scale, bool collide) : this(owner, start, d, doA, null, new IntRect(0, 0, animation.FrameWidth, animation.FrameHeight), scale) { this.collide = collide; animationPlayer = new AnimationPlayer(); animationPlayer.PlayAnimation(animation); }
internal FishObject(Vector2f position) : base(fishText, position, new IntRect(0, 0, 24, 20), true) { flutter = new Cooldown(5.0f); flutterAni = new Animation(fishText, new Vector2f(0,0), 2, new Vector2f(24, 20), .3f, Animation.Type.fronttobacktofrontend, "flutter"); }
//TODO make load contenting thru bossfight library?, so we can unload content quickly too internal static new void LoadContent() { ursiBaseTexture = GameBox.loadTexture(SimpleModel.BOSS_PATH + "ursidor/ursidorbase");//images\characters\bosses\ursidor Texture t = GameBox.loadTexture(SimpleModel.BOSS_PATH + "ursidor/ursidoranim"); fishEatAnimation = new Animation(t, new Vector2f(0, 4 * ANIMATION_FRAME_SIZE.Y), 3, ANIMATION_FRAME_SIZE, .25f, Animation.Type.normal, "fisheat"); attackAnimation = new Animation(t, new Vector2f(0,0), 3, ANIMATION_FRAME_SIZE, .175f, Animation.Type.normal, "attack"); attackAnimation.setDirectional(true); hungeredwarningTexture = GameBox.loadTexture("images/UI/warning"); chargedwarningTexture = GameBox.loadTexture("images/UI/chargewarning"); }
/// <summary> /// Advances the time position and draws the current frame of the animation. /// position is bottom middle of the image /// Returns if it drew? /// </summary> public bool Draw(double gameTime, RenderWindow window, Vector2f position, float rot, float scale, Direction direction) { if (animation == null || state == State.Idle)//idk how this happens return false; position = new Vector2f(position.X - animation.FrameWidth / 2.0f * scale, position.Y - animation.FrameHeight * scale); // Calculate the source rectangle of the current frame. FloatRect source = new FloatRect(FrameIndex * animation.Texture.Size.X, 0, animation.Texture.Size.Y, animation.Texture.Size.Y); int x = FrameIndex * animation.FrameWidth + (int)animation.startPostition.X, y; if (!animation.isDirectional()) y = (int)animation.startPostition.Y; else y = (int)direction * animation.FrameHeight + (int)animation.startPostition.Y; IntRect source2 = new IntRect(x, y, animation.FrameWidth, animation.FrameHeight); // Draw the current frame. /*if (rot != 0) { spriteBatch.Draw(animation.Texture, position, source2, Color.White, rot, Origin, scale, flip, 0.0f); } else spriteBatch.Draw(animation.Texture, position, source2, Color.White); */ {//TODO drawing is bad atm Sprite s = new Sprite(animation.Texture,source2); s.Position = position; s.Rotation = rot; s.Color = Color.White; //s.Origin = Origin; s.Scale = new Vector2f(flip == SpriteEffects.FlipHorizontally ? -scale : scale, flip == SpriteEffects.FlipHorizontally ? -scale : scale); window.Draw(s); } // Process passing time. (elapsed time since last update time += (float)(gameTime - GameBox.getInstance().getLastUpdateTime()) / 1000; while (time > animation.FrameTime) { time -= animation.FrameTime; // Advance the frame index; looping or clamping as appropriate. switch (animation.animationType) { case Animation.Type.fronttobacktofront:// 1 2 3 4 5 4 3 2 1 repeat if (frameIndex <= 0) { counter = 1; } else if (frameIndex >= animation.FrameCount - 1) { counter = -1; }//else do nothing and still increase frameIndex += counter; break; case Animation.Type.fronttobacktofrontend:// 1 2 3 4 5 4 3 2 1 END frameIndex += counter; if (frameIndex < 0) { animation = null; state = State.Idle; return false; } else if (frameIndex >= animation.FrameCount - 1) { counter = -1; }//else do nothing and still increase break; case Animation.Type.looping: //1 2 3 4 5 1 2 3 4 5 frameIndex = (frameIndex + 1) % animation.FrameCount; break; case Animation.Type.normal: // 1 2 3 4 5 done to idle frameIndex++; break; case Animation.Type.keepLast: // 1 2 3 4 5 5 5 5 5... if (frameIndex + 1 >= animation.FrameCount - 1) { frameIndex = animation.FrameCount - 1; //animation = null; } else { frameIndex++; } if (frameIndex == 2) return true; break; case Animation.Type.customorder://an array will be inputed when the animation is created, [1,3,4,2] counter++; frameIndex = animation.CustomFrames[counter]; break; } } //for normal, reset to normal if (animation.animationType == Animation.Type.normal && frameIndex >= animation.FrameCount) { animation = null; state = State.Idle; callEndFunction(); } return true; }
internal override void Update(double gameTime) { base.Update(gameTime); if (currentHp <= 0) return; if (!isMoving() && (fireballRepeat) && target != null && !target.isDead()) { //game stuff then if (checkCircleRangeAndMove(target, FIREBALL_RANGE, gameTime)) { //do nothing because you are running } else if (a1.use(gameTime)) { weaponPlayer.doAnimation1(); Animation fireballAnim = new Animation(fireballProjAnimTexture, new Vector2f(0,0), 3, new Vector2f(24, 20), .2f, Animation.Type.looping, "fireballproj"); InGame.getInstance().addProjectile(new Projectile(this, getMid(), target, doFireball, fireballAnim, FIREBALL_GFX_SCALE, false)); } } if (!isMoving() && (bigFireballRepeat) && target != null && !target.isDead()) { //game stuff then if (checkCircleRangeAndMove(target, BIGFIREBALL_RANGE, gameTime)) { } else if (sb1.use()) { weaponPlayer.doAnimation1(); Animation bigFireballAnim = new Animation(fireballProjAnimTexture, new Vector2f(3*24,0), 3, new Vector2f(24, 20), .2f, Animation.Type.looping, "bigfireballproj"); Projectile proj = new Projectile(this, getMid(), target, doBigFireball, bigFireballAnim, BIGFIREBALL_GFX_SCALE, false); InGame.getInstance().addProjectile(proj); } } //update abilitys effected by cdReduc a1.setCDReduc(buffs.getValue(BuffType.CDreduc)); }
public void PlayAnimation(Animation animation) { PlayAnimation(animation, null); }
/// <summary> /// Begins or continues playback of an animation. /// </summary> public void PlayAnimation(Animation animation, Func<bool> endFunction) { if (animation == null) { state = State.Idle; return; } // Start the new animation. this.animation = animation; this.frameIndex = 0; this.time = 0.0f; state = State.Animation; if (animation.animationType == Animation.Type.fronttobacktofrontend) counter = 1; else counter = 0; if (animation.animationType == Animation.Type.customorder) frameIndex = animation.CustomFrames[counter]; this.endFunction = endFunction; }
internal void setAnimation(Animation ani, Func<bool> function) { animationPlayer.PlayAnimation(ani,function); }
internal void setAnimation(Animation ani) { animationPlayer.PlayAnimation(ani,null); }
public static Animation createAnimation(string image_file, float secondsPerFrame, int numOfFrame, Vector2f frameSize, Vector2f coord, Animation.Type aniType, string name) { return new Animation(GameBox.loadTexture(image_file), new Vector2f(frameSize.X * coord.X, frameSize.Y * coord.Y), numOfFrame, frameSize, secondsPerFrame, aniType, name); }