source: trunk/orbital/player.h @ 1344

Last change on this file since 1344 was 1344, checked in by sam, 9 years ago

orbital: create a Player class with joystick support.

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1//
2// Orbital
3//
4// Copyright: (c) 2012 Various People
5//
6
7/* FIXME: this file is pure crap; it's only a test. */
8
9#if !defined __PLAYER_H__
10#define __PLAYER_H__
11
12class Player : public WorldEntity
13{
14public:
15    Player()
16      : m_stick(0),
17        m_ready(false)
18    {
19        /* FIXME: this is the orange ship; add code for the other one later */
20        m_ship_mesh.SendCommand("sc1,.5,0,1");
21        m_ship_mesh.SendCommand("afcb5,1,3,0.6,fl,sc1,1,1,1,afcb1,5,3,0.6,tz-1,irb");
22        m_ship_mesh.SendCommand("sc1,.5,0,1");
23        m_ship_mesh.SendCommand("afcb3,6,7,.4,t0,0,7,sc1,1,1,1,afcb3,4,4,.4,t4,0,-4,mx,fl");
24        m_ship_mesh.SendCommand("sc1,.5,0,1");
25        m_ship_mesh.SendCommand("afcb3,6,5,.4,sc1,1,1,1,afcb2,3,9,.4,fl");
26        m_ship_mesh.SendCommand("scb1,1,1,1,ac4,15,.2,.6,1,1,tz-2,ac4,15,.2,.6,1,1,rx90,t0,-2,-7,fl");
27
28        m_exhaust_mesh.SendCommand("sc0,1,1,scb0,0,0,1,ac5,15,0,1.5,0,1,ac7,35,1.1,4,0,1,rx90,t-3,0,27,mx,fl");
29
30        m_drone_mesh.SendCommand("sc0.2,0.7,0,1,afcb3,6,10,0.4,tx-8,afcb3,6,10,0.4,tx4,ty13,fl,sc1,1,1,1,afcb3,6,10,0.4,rx-30,ty13,fl");
31    }
32
33    ~Player()
34    {
35        if (m_stick)
36            Ticker::Unref(m_stick);
37    }
38
39    char const *GetName() { return "<ship>"; }
40
41protected:
42    virtual void TickGame(float seconds)
43    {
44        WorldEntity::TickGame(seconds);
45
46        float rightleft = 0.f, updown = 0.f;
47
48        if (!m_stick)
49            m_stick = Input::TrackStick();
50        if (m_stick && m_stick->GetAxisCount() >= 4)
51        {
52            rightleft += 1.f * m_stick->GetAxis(2);
53            updown += -1.f * m_stick->GetAxis(3);
54        }
55
56        m_position += vec3(rightleft, 0.f, -updown) * 200.f * seconds;
57    }
58
59    virtual void TickDraw(float seconds)
60    {
61        WorldEntity::TickDraw(seconds);
62
63        if (!m_ready)
64        {
65            m_ship_mesh.SendCommand("irb");
66            m_exhaust_mesh.SendCommand("irb");
67            m_drone_mesh.SendCommand("irb");
68            m_ready = true;
69        }
70
71        mat4 model = mat4::translate(m_position) * mat4(m_rotation);
72        m_ship_mesh.Render(model);
73        m_exhaust_mesh.Render(model);
74
75        for (int i = 0; i < m_drones.Count(); i++)
76        {
77            m_drone_mesh.Render(model * mat4::translate(m_drones[i]));
78        }
79    }
80
81private:
82    Mesh m_ship_mesh, m_drone_mesh, m_exhaust_mesh;
83    Stick *m_stick;
84
85    Array<vec3> m_drones;
86    bool m_ready;
87};
88
89#endif /* __PLAYER_H__ */
90
Note: See TracBrowser for help on using the repository browser.