1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
package ch.asynk.rustanddust.engine;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;
public abstract class HeadedPawn extends Pawn
{
private Sprite head;
protected Orientation orientation;
protected HeadedPawn()
{
super();
this.orientation = Orientation.KEEP;
}
public HeadedPawn(Faction faction, AtlasRegion body, AtlasRegion head, TextureAtlas overlays)
{
super(faction, body, overlays);
this.head = new Sprite(head);
this.orientation = Orientation.KEEP;
this.descr += " " + orientation;
}
@Override
public void dispose()
{
super.dispose();
}
@Override
public void setAlpha(float alpha)
{
super.setAlpha(alpha);
head.setAlpha(alpha);
}
@Override
public float getRotation()
{
return orientation.r();
}
@Override
public Orientation getOrientation()
{
return orientation;
}
@Override
public void setPosition(float x, float y)
{
super.setPosition(x, y);
float cx = x + (getWidth() / 2f);
float cy = y + (getHeight() / 2f);
head.setPosition((cx - (head.getWidth() / 2f)), (cy - (head.getHeight() / 2f)));
}
@Override
public void setRotation(float z)
{
getPosition().z = z;
head.setRotation(z);
this.orientation = Orientation.fromRotation(z);
}
@Override
public void setPosition(float x, float y, float z)
{
setPosition(x, y);
setRotation(z);
}
@Override
public void draw(Batch batch)
{
sprite.draw(batch);
head.draw(batch);
overlays.draw(batch);
}
@Override
public void drawDebug(ShapeRenderer debugShapes)
{
float w = sprite.getWidth();
float h = sprite.getHeight();
debugShapes.rect(sprite.getX(), sprite.getY(), (w / 2f), (h / 2f), w, h, sprite.getScaleX(), sprite.getScaleY(), sprite.getRotation());
w = head.getWidth();
h = head.getHeight();
debugShapes.rect(head.getX(), head.getY(), (w / 2f), (h / 2f), w, h, head.getScaleX(), head.getScaleY(), head.getRotation());
overlays.drawDebug(debugShapes);
}
}
|