More animation work
[potpourri.git] / include / core / Actor.h
blobd3236ae14c0acbb6fadb5e0139100e994e94be52
1 // Copyright 2008 Brian Caine
3 // This file is part of Potpourri.
5 // Potpourri is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Potpourri is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Potpourri. If not, see <http://www.gnu.org/licenses/>.
19 // NOTES:
21 // This is the Actor class.
23 #ifndef __ACTOR_H
24 #define __ACTOR_H
26 #include "MediaLoader.h"
27 #include "ScriptedClass.h"
28 #include "EventReceiver.h"
29 #include "Level.h"
31 #include "Game.h"
33 #include "../Global.h"
35 #include "../plugins/graphics/Graphics.h"
36 #include "../plugins/audio/Audio.h"
37 #include "../plugins/input/InputManager.h"
39 #include <string>
40 #include <map>
41 #include <vector>
43 namespace fragrant
45 typedef Pair<float> ActorPair;
46 typedef Pair<int> LevelPair;
48 ActorPair makePair(float, float);
50 const int INV_Y = 0;
51 // so, we need to invert y for graphics/physics stuff
52 // 500 is an arbitrary point, and shouldn't really matter
54 // well what about static lines, eh?
56 // yeah, so, fixed it to zero
58 struct ActorGraphics // fixme
60 std::string sauce;
61 ActorPair pos;
62 float angle;
65 // a line fills the first two pairs in PhysicsShape's data member with
66 // the first and second point. The radius of the line is set as the x
67 // member for a third
69 // Circles have x of one member of data set to the radius
71 enum Shape
73 S_Line,
74 S_Circle,
75 S_Poly
78 struct PhysicsShape
80 Shape shape;
81 std::vector<ActorPair> data;
82 ActorPair offset;
84 float elasticity;
85 float friction;
88 struct ActorPhysics
90 float mass;
91 float inertia;
92 bool fixed;
94 LevelPair base_position; // it is really only relevant for lines
96 std::vector<PhysicsShape> shapes; // oh god, no!
99 struct ActorGraphic // fixme: poor choice of naming here
101 LevelPair position;
102 float angle;
103 Drawable* graphic;
106 class Game;
107 class PhysicsObject;
108 class PhysicsSimulation;
109 struct ActorData
111 std::string name;
113 std::vector<ActorGraphics> graphics; // fixme: per other fixmes
114 ActorPhysics physics;
115 std::map<std::string, std::string> scripts;
116 LevelPair position;
118 Audio audio;
119 ScriptVM* script_vm;
120 InputManager* input_manager;
121 PhysicsSimulation* simulation;
122 MediaLoader* media_loader;
124 Game* game;
127 class Actor : public ScriptedClass, public EventReceiver
129 public:
130 Actor(ActorData data);
131 ~Actor();
133 void draw(Target* target, LevelPair offset);
134 void setAngle(float);
135 float getAngle();
137 // event stuff
138 void raiseEvent(Event event);
140 // script stuff
142 func getConstructor();
143 void destroy();
145 std::string getClassName();
146 std::vector<std::string> getClassFunctions();
147 Variant* callFunction(std::string funcname,
148 std::vector<Variant*> params, ScriptVM* script_vm);
150 // xml parsing stuff
152 static ActorData parseXML(std::string source,
153 MediaLoader& media_loader);
155 private:
156 std::vector<ActorGraphic> sprites;
158 std::map<std::string, std::string> ldata;
159 bool persistent;
161 ActorData initial_params;
163 Event cur_event;
164 LevelPair position;
165 PhysicsObject* physics_object;
169 #endif