source: trunk/orbital/tank.h @ 1434

Last change on this file since 1434 was 1434, checked in by sam, 11 years ago

orbital: enhance the language with [] contexts.

File size: 1.9 KB
Line 
1//
2// Orbital
3//
4// Copyright: (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
5//            (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
6//            (c) 2012 Sam Hocevar <sam@hocevar.net>
7//
8
9/* FIXME: this file is pure crap; it's only a test. */
10
11#if !defined __TANK_H__
12#define __TANK_H__
13
14class Tank : public WorldEntity
15{
16public:
17    Tank()
18      : m_turret_angle(0.f),
19        m_ready(false)
20    {
21        m_body.SendCommand("[sc#110 ab6 6 15 ty-2"
22                           " sc#aca afcb4 5 16 0.4 tx4 ty5 mx]"
23                           "[sc#3a0 afcb8 7 10 0.4 tz-4 ty5]");
24        m_turret.SendCommand("[sc#3a0 afcb3 6 10 0.4 tx-8 afcb3 6 10 0.4 tx4 ty13]"
25                             "[sc#aca afcb3 6 10 0.4 rx-30 ty13]");
26
27        m_rotation = quat::rotate(RandF(0.f, 360.f), vec3(0, 1, 0));
28    }
29
30    ~Tank()
31    {
32    }
33
34    char const *GetName() { return "<tank>"; }
35
36    /* Set a target for the tank */
37    void SetTarget(vec3 const &position)
38    {
39        m_target = position;
40    }
41
42protected:
43    virtual void TickGame(float seconds)
44    {
45        WorldEntity::TickGame(seconds);
46
47        float test = RandF(40.f, 70.f);
48        m_rotation *= quat::rotate(seconds * test, vec3(0, 1, 0));
49        m_velocity = m_rotation.transform(vec3(0, 0, 1));
50        m_position += seconds * 80.f * m_velocity;
51
52        m_turret_angle += seconds * 50.f;
53    }
54
55    virtual void TickDraw(float seconds)
56    {
57        WorldEntity::TickDraw(seconds);
58
59        if (!m_ready)
60        {
61            m_body.SendCommand("irb");
62            m_turret.SendCommand("irb");
63            m_ready = true;
64        }
65
66        mat4 model = mat4::translate(m_position) * mat4(m_rotation);
67        m_body.Render(model);
68
69        model = model * mat4::rotate(m_turret_angle, vec3(0, 1, 0));
70        m_turret.Render(model);
71    }
72
73private:
74    Mesh m_body, m_turret;
75    vec3 m_target;
76    float m_turret_angle;
77    bool m_ready;
78};
79
80#endif /* __TANK_H__ */
81
Note: See TracBrowser for help on using the repository browser.