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

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

not working ...

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