Starsector API
Loading...
Searching...
No Matches
AnimAction.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.eventide;
2
3import java.awt.Color;
4import java.util.LinkedHashSet;
5import java.util.Set;
6
7import org.lwjgl.opengl.GL11;
8import org.lwjgl.util.vector.Vector2f;
9
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.graphics.SpriteAPI;
12import com.fs.starfarer.api.util.Misc;
13
14public class AnimAction {
15 public CharAnim anim;
17 public float progress;
18 public Actor actor;
19 public boolean done = false;
20
21 public boolean performedBlock = false;
22 public boolean wasBlocked = false;
23 public boolean scoredHit = false;
24
25 public boolean makeCurrentFrameLast = false;
26
27 public SpriteAPI sprite;
29 public float returnToIdleXCorrection = 0f;
30
31 public Set<CharAnimFrame> playedSoundsFor = new LinkedHashSet<CharAnimFrame>();
32
33 public AnimAction(Actor actor, Object animKey, CharAnimFrame preFrame) {
34 this.actor = actor;
35 this.preFrame = preFrame;
36 this.anim = Actions.ANIMATIONS.get(animKey);
37 this.sprite = Global.getSettings().getSprite(anim.textureId);
38 if (actor.texId != null) {
39 this.sprite = Global.getSettings().getSprite(actor.texId);
40 }
41 }
42
43// public AnimAction(Actor actor, CharAnim anim) {
44// this.actor = actor;
45// this.anim = anim;
46// }
48 int index = 0;
49 for (CharAnimFrame frame : anim.frames) {
50 if (!frame.attackArea.isEmpty()) {
51 index = anim.frames.indexOf(frame);
52 }
53 }
54 int currIndex = anim.frames.indexOf(curr);
55
56 return index - currIndex;
57 }
58
59 public void undoLastMove() {
60 if (curr != null) {
61 actor.loc.x -= curr.move.x * anim.scale * actor.facing;
62 actor.loc.y -= curr.move.y * anim.scale * actor.facing;
63 }
64 }
65
66 public void advance(float amount) {
67 progress += amount;
68 float total = 0f;
69 for (CharAnimFrame f : anim.frames) {
70 total += f.dur;
71 if (total > progress) {
72 if (curr != f) {
75 } else {
76 curr = f;
77 actor.loc.x += curr.move.x * anim.scale * actor.facing;
78 actor.loc.y += curr.move.y * anim.scale * actor.facing;
79
80 if (!playedSoundsFor.contains(curr)) {
82 for (String soundId : curr.soundIds) {
83 if (soundId == null || soundId.isEmpty()) continue;
84 //Global.getSoundPlayer().playUISound(soundId, 1f, 1f);
85 Vector2f soundLoc = new Vector2f(actor.loc);
86 soundLoc.x *= DuelPanel.SOUND_LOC_MULT;
87 Global.getSoundPlayer().playSound(soundId, 1f, 1f, soundLoc, new Vector2f());
88 }
89 }
90
91 if (curr == anim.frames.get(0) && preFrame != null && anim.initialRelativeOffset != null) {
92 float preW = preFrame.width * anim.scale;
93 float w = curr.width * anim.scale;
95 actor.loc.x -= returnToIdleXCorrection;
97 }
98 }
99 }
100 break;
101 }
102 }
103 if (progress >= anim.getTotalTime()) {
104 actor.loc.x += anim.moveToIdle.x * anim.scale * actor.facing + returnToIdleXCorrection;
105 actor.loc.y += anim.moveToIdle.y * anim.scale * actor.facing;
106 done = true;
107 }
108 }
109
110 public void render(float alphaMult) {
111 if (curr == null) return;
112
113// if (actor.facing > 0 && curr != null && curr == anim.frames.get(0)) {
114// System.out.println("Progress: " + progress);
115// }
116
117 float x = actor.loc.x;
118 float y = actor.loc.y;
119 sprite.setAlphaMult(alphaMult);
121
122 //sprite.setBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR);
123
124 if (actor.facing > 0) {
125 sprite.setTexX(curr.tx);
126 sprite.setTexY(curr.ty);
127 sprite.setTexWidth(curr.tw);
128 sprite.setTexHeight(curr.th);
129 } else {
130 sprite.setTexX(curr.tx + curr.tw);
131 sprite.setTexY(curr.ty);
132 sprite.setTexWidth(-curr.tw);
133 sprite.setTexHeight(curr.th);
134 }
135 sprite.renderAtCenter(x, y);
136
137// GL11.glDisable(GL11.GL_TEXTURE_2D);
138// GL11.glEnable(GL11.GL_BLEND);
139// GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
140// Misc.renderQuad(x - curr.width / 2f, y - curr.height / 2f, curr.width, curr.height, Color.red, 0.5f);
141
142 if (DuelPanel.DEBUG) {
143 GL11.glDisable(GL11.GL_TEXTURE_2D);
144 GL11.glEnable(GL11.GL_BLEND);
145 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
146 for (HitArea area : curr.hittableArea) {
147 area = area.getAdjustedForAction(this);
148 Misc.renderQuad(area.x, area.y, area.w, area.h, new Color(120,120,120,127), alphaMult);
149 }
150 for (HitArea area : curr.attackArea) {
151 area = area.getAdjustedForAction(this);
152 Misc.renderQuad(area.x, area.y, area.w, area.h, new Color(200,60,60,127), alphaMult);
153 }
154 for (HitArea area : curr.blockArea) {
155 area = area.getAdjustedForAction(this);
156 Misc.renderQuad(area.x, area.y, area.w, area.h, new Color(60,200,60,127), alphaMult);
157 }
158 }
159 }
160
161 public boolean isDone() {
162 return done;
163 }
164
165}
166
167
168
169
170
static SettingsAPI getSettings()
Definition Global.java:51
static SoundPlayerAPI getSoundPlayer()
Definition Global.java:43
static Map< String, CharAnim > ANIMATIONS
Definition Actions.java:39
AnimAction(Actor actor, Object animKey, CharAnimFrame preFrame)
SpriteAPI getSprite(String filename)
SoundAPI playSound(String id, float pitch, float volume, Vector2f loc, Vector2f vel)