source: trunk/games/demo-jnat/player.h @ 1723

Last change on this file since 1723 was 1723, checked in by Jnat, 8 years ago

omg

File size: 2.0 KB
Line 
1//
2// demo-jnat
3//
4
5
6#if !defined __PLAYER_H__
7#define __PLAYER_H__
8
9class Player : public WorldEntity
10{
11public:
12    Player()
13      : m_stick(0),
14        m_ready(false)
15    {
16                m_bodymesh.Compile("[sc#3a0 afcb5 10 5 0.4 ty5]""[sc#a30 afcb8 7 10 0.4]");
17    }
18
19    ~Player()
20    {
21        if (m_stick)
22            Input::UntrackStick(m_stick);
23    }
24
25    char const *GetName() { return "<player>"; }
26
27protected:
28    virtual void TickGame(float seconds)
29    {
30        WorldEntity::TickGame(seconds);
31
32        float updown = (float)(Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/));
33        float rightleft = (float)(Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/));
34                if (!m_stick)
35            m_stick = Input::TrackStick(0);
36        if (!m_stick)
37            m_stick = Input::TrackStick(0);
38        if (m_stick && m_stick->GetAxisCount() >= 4)
39        {
40            rightleft += 1.f * m_stick->GetAxis(0);
41            //updown += -1.f * m_stick->GetAxis(1);
42        }
43
44                //Rotate
45                /*
46        float test = lol::sin(0.5f) * 200.f + 60.f;
47        m_rotation *= quat::rotate(seconds * test, vec3(0, 1, 0));
48
49        m_velocity = 120.f * m_rotation.transform(vec3(0, 0, 1));
50        vec3 deltapos = seconds * m_velocity;
51                */
52
53                //Player control
54                //vec3 deltapos;
55                if (rightleft * rightleft + updown * updown > 0.2f){
56                        m_velocity = vec3(rightleft,0,0);//120.f * m_rotation.transform(vec3(0, 0, 1));
57                        vec3 deltapos = 200.f* seconds * m_velocity;
58
59                        m_position += deltapos;
60                }
61               
62                //m_position += deltapos;
63
64    }
65
66    virtual void TickDraw(float seconds)
67    {
68        WorldEntity::TickDraw(seconds);
69
70        if (!m_ready)
71        {
72            m_bodymesh.MeshConvert();
73            m_ready = true;
74        }
75
76        mat4 model = mat4::translate(m_position) * mat4(m_rotation);
77
78        m_bodymesh.Render(model);
79    }
80
81private:
82    EasyMesh m_bodymesh;
83    Stick *m_stick;
84       
85    bool m_ready;
86};
87
88#endif /* __PLAYER_H__ */
89
Note: See TracBrowser for help on using the repository browser.