]> git.localhorst.tv Git - l2e.git/blob - src/graphics/SimpleAnimation.cpp
added capsule attack/animation handling
[l2e.git] / src / graphics / SimpleAnimation.cpp
1 #include "SimpleAnimation.h"
2
3 #include "../loader/Interpreter.h"
4 #include "../loader/TypeDescription.h"
5
6 using loader::FieldDescription;
7 using loader::Interpreter;
8 using loader::TypeDescription;
9
10 namespace graphics {
11
12 SimpleAnimation::SimpleAnimation()
13 : numFrames(0)
14 , col(0)
15 , row(0) {
16
17 }
18
19 SimpleAnimation::SimpleAnimation(
20                 const Sprite *sprite,
21                 int frameTime,
22                 int numFrames,
23                 int col,
24                 int row,
25                 bool repeat)
26 : Animation(sprite, frameTime, repeat)
27 , numFrames(numFrames)
28 , col(col)
29 , row(row) {
30
31 }
32
33
34 int SimpleAnimation::NumFrames() const {
35         return numFrames;
36 }
37
38 int SimpleAnimation::Col(int frame) const {
39         return col;
40 }
41
42 int SimpleAnimation::Row(int frame) const {
43         return row + frame;
44 }
45
46
47 void SimpleAnimation::CreateTypeDescription() {
48         SimpleAnimation sa;
49         Animation *a(&sa);
50
51         TypeDescription &td(TypeDescription::Create(TYPE_ID, "SimpleAnimation"));
52         td.SetDescription("An animation that uses a fixed column and increasing row of a sprite based on the frame number.");
53         td.SetConstructor(&Construct);
54         td.SetSize(sizeof(SimpleAnimation));
55         td.AddSupertype(Animation::TYPE_ID, ((char *)a) - ((char *)&sa));
56
57         Animation::AddFields(td, sa, ((char *)a) - ((char *)&sa));
58         td.AddField("framecount", FieldDescription(((char *)&sa.numFrames) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("number of frames of a single run"));
59         td.AddField("col", FieldDescription(((char *)&sa.col) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("the column of the sprite to draw from"));
60         td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("the row of the sprite of the first frame"));
61 }
62
63 void SimpleAnimation::Construct(void *data) {
64         new (data) SimpleAnimation;
65 }
66
67 }