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

Last change on this file since 1740 was 1740, checked in by Jnat, 8 years ago
File size: 2.2 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                //m_bo.m_position = m_position + vec3(100.0f,100.0f,100.0f);
18                m_bo = new Bo();
19                Ticker::Ref(m_bo);
20    }
21
22    ~Player()
23    {
24        if (m_stick)
25            Input::UntrackStick(m_stick);
26                               
27                Ticker::Unref(m_bo);
28    }
29
30    char const *GetName() { return "<player>"; }
31
32protected:
33    virtual void TickGame(float seconds)
34    {
35        WorldEntity::TickGame(seconds);
36
37        float updown = (float)(Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/));
38        float rightleft = (float)(Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/));
39               
40                //float StickAngle = (float)m_stick->GetAxis(2);
41
42                if (!m_stick)
43            m_stick = Input::TrackStick(0);
44        if (!m_stick)
45            m_stick = Input::TrackStick(0);
46        if (m_stick && m_stick->GetAxisCount() >= 4)
47        {
48            rightleft += 1.f * m_stick->GetAxis(0);
49            updown += -1.f * m_stick->GetAxis(1);
50        }
51
52                //Rotate
53                /*
54        float test = lol::sin(0.5f) * 200.f + 60.f;
55        m_rotation *= quat::rotate(seconds * test, vec3(0, 1, 0));
56
57        m_velocity = 120.f * m_rotation.transform(vec3(0, 0, 1));
58        vec3 deltapos = seconds * m_velocity;
59                */
60
61                //Player control
62                //vec3 deltapos;
63                if (rightleft * rightleft + updown * updown > 0.2f){
64                        m_velocity = vec3(rightleft,0,0);//120.f * m_rotation.transform(vec3(0, 0, 1));
65                        vec3 deltapos = 200.f* seconds * m_velocity;
66
67                        m_position += deltapos;
68                }
69                m_bo->m_position = (m_position + vec3(0.0f,0.0f,10.0f) );
70                m_bo->m_rotation = lol::atan2(updown,rightleft);
71                //m_position += deltapos;
72
73    }
74
75    virtual void TickDraw(float seconds)
76    {
77        WorldEntity::TickDraw(seconds);
78
79        if (!m_ready)
80        {
81            m_bodymesh.MeshConvert();
82            m_ready = true;
83        }
84
85        mat4 model = mat4::translate(m_position) * mat4(m_rotation);
86
87        m_bodymesh.Render(model);
88    }
89
90private:
91    EasyMesh m_bodymesh;
92    Stick *m_stick;
93        Bo *m_bo;
94       
95    bool m_ready;
96};
97
98#endif /* __PLAYER_H__ */
99
Note: See TracBrowser for help on using the repository browser.