Starsector API
Loading...
Searching...
No Matches
Actor.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.eventide;
2
3import java.awt.Color;
4import java.util.LinkedHashMap;
5import java.util.Map;
6
7import org.lwjgl.util.vector.Vector2f;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.graphics.SpriteAPI;
11
12public class Actor {
13
16 public float facing = 1f;
17 public Vector2f loc = new Vector2f();
18
19 public int maxHealth;
20 public int health;
21
22 public String texId;
23
24 public Map<String, String> actionRemap1 = new LinkedHashMap<String, String>();
25 public Map<String, String> actionRemap2 = new LinkedHashMap<String, String>();
26 public Map<String, Float> actionSpeedMult = new LinkedHashMap<String, Float>();
27
28
29 public Actor() {
30 this(null);
31 }
32 public Actor(String texId) {
33 this.texId = texId;
34 }
35
36 public String getActionId() {
37 if (currAction == null) return "";
38 return currAction.anim.action;
39 }
40
41 public void endCurrentAnimation() {
42 if (currAction != null) {
43 currAction.makeCurrentFrameLast = true;
44 }
45 }
46
47 protected float freeze = 0f;
48 public void freeze(float sec) {
49 freeze = sec;
50 }
51 public void advance(float amount) {
52 freeze -= amount;
53 if (freeze > 0) return;
54
55 //amount *= 0.25f;
56 if (currAction != null) {
57 Float mult = actionSpeedMult.get(currAction.anim.action);
58 if (mult == null) mult = 1f;
59 currAction.advance(amount * mult);
60 if (currAction.isDone()) {
61 currAction = null;
62 }
63 }
64 if (currAction == null) {
65 if (nextAction != null) {
67 nextAction = null;
68 } else {
69 //currAction = new AnimAction(this, Actions.IDLE);
70 doAction(Actions.IDLE, true);
71 }
73 }
74 }
75
77 if (currAction == null) return null;
78 return currAction.curr;
79 }
80
81 public void doAction(String action, boolean forceInterruptCurrent) {
82 if (action == Actions.ATTACK &&
84 action = Actions.RIPOSTE;
85 forceInterruptCurrent = true;
86 } else if (currAction != null && currAction.anim != null && currAction.anim.interruptableBy.contains(action)) {
87 forceInterruptCurrent = true;
88 }
89
90 if (actionRemap1.containsKey(action)) {
91 action = actionRemap1.get(action);
92 }
93 if (actionRemap2.containsKey(action)) {
94 action = actionRemap2.get(action);
95 }
96
97 if (forceInterruptCurrent) {
98 nextAction = null;
99 currAction = new AnimAction(this, action, getCurrentFrame());
100 if (currAction.anim == null) {
101 currAction = null;
102 } else {
104 }
105 } else {
106 if (nextAction == null || nextAction.anim == null) {
107 nextAction = null;
108 }
109 nextAction = new AnimAction(this, action, getCurrentFrame());
110 }
111 }
112
113 public void render(float alphaMult) {
114 boolean renderShadow = true;
115 renderShadow = false;
116 if (renderShadow && currAction != null && currAction.anim != null && currAction.curr != null &&
117 !currAction.curr.hittableArea.isEmpty()) {
118 HitArea area = currAction.curr.hittableArea.get(0);
119 area = area.getAdjustedForAction(currAction);
120 SpriteAPI shadow = Global.getSettings().getSprite("graphics/fx/hit_glow.png");
121 shadow.setNormalBlend();
122 shadow.setColor(Color.black);
123
124 float sw = currAction.curr.width * 1.25f;
125 if (sw > 200) {
126 sw = 200 + (sw - 200) * 0.33f;
127 }
128 shadow.setSize(sw, 40f);
129
130 shadow.setAlphaMult(0.5f);
131 shadow.renderAtCenter(area.x + area.w/2f, loc.y - currAction.anim.frameHeight / 2f + 5f);
132 }
133
134 currAction.render(alphaMult);
135 }
136}
137
138
139
140
141
static SettingsAPI getSettings()
Definition Global.java:51
void doAction(String action, boolean forceInterruptCurrent)
Definition Actor.java:81
HitArea getAdjustedForAction(AnimAction action)
Definition HitArea.java:15
SpriteAPI getSprite(String filename)