/minild29

To get this branch, use:
bzr branch http://9ix.org/bzr/minild29
1 by Josh C
initial commit
1
#include "Dark.h"
2
3
namespace Dark
4
{
5
  Player::Player() : Entity(),
6
		     VELOCITY(150.0f)
7
  {
8
    sprite = new SpriteAnimation("player.png", FILTER_NONE, 64, 64);
9
    sprite->Add("idle", 0, 0, 0.35f);
10
    sprite->Play("idle");
11
    SetGraphic(sprite);
12
13
    AddTag("player");
14
    
15
    SetCollider(new RectangleCollider(32, 32));
16
  }
17
18
  void Player::Update()
19
  {
20
    Entity::Update();
21
22
    //Scene::GetCamera()->position = position;
23
24
    //...
25
  }
26
27
  // Scene
28
29
  DarkScene::DarkScene() : Scene()
30
  {
31
  }
32
  
33
  void DarkScene::Begin()
34
  {
35
    Scene::Begin();
36
37
    Graphics::Set2D(1024, 768);
38
39
    Text *inst2 = new Text("Press ESC to quit");
40
    inst2->position = Vector2(-492, -354); // 20px h, 30px v from U-L corner
41
    Add(inst2);
42
43
    Input::DefineMaskKey("left", KEY_LEFT);
44
    Input::DefineMaskKey("right", KEY_RIGHT);
45
    Input::DefineMaskKey("up", KEY_UP);
46
    Input::DefineMaskKey("down", KEY_DOWN);
47
48
    Input::DefineMaskKey("up", KEY_W);
49
    Input::DefineMaskKey("left", KEY_A);
50
    Input::DefineMaskKey("down", KEY_S);
51
    Input::DefineMaskKey("right", KEY_D);
52
53
    // level editor
54
    Add( levelEditor = new LevelEditor() );
55
    levelEditor->Disable();
56
57
    // load level from files
58
    Level::LoadProject("project.xml");
59
    Level::Load("level.xml", this);
60
   
61
    Player *player = new Player;
62
    player->position = Graphics::GetScreenCenter();
63
    Add(player);
64
65
    Graphics::SetBackgroundColor(Color::green * 0.2f);
66
67
  }
68
69
  void DarkScene::Update()
70
  {
71
    Scene::Update();
72
73
    if (Input::IsKeyPressed(KEY_ESCAPE))
74
      Game::Quit();
75
76
    if (isPaused)
77
      {
78
	if (Input::IsKeyPressed(KEY_S) && Input::IsKeyHeld(KEY_LCTRL))
79
	  Level::Save();
80
81
	if (Input::IsKeyPressed(KEY_A))
82
	  Scene::GetCamera()->position.x -= 600;
83
84
	if (Input::IsKeyPressed(KEY_D))
85
	  Scene::GetCamera()->position.x += 600;
86
      }
87
88
    if (Input::IsKeyPressed(KEY_TAB))
89
      {
90
        // if we're not doing anything in the levelEditor...
91
        if (levelEditor->GetState() == FTES_NONE)
92
          {
93
            isPaused = !isPaused;
94
            
95
            if (isPaused)
96
	      levelEditor->Enable();
97
            else
98
	      levelEditor->Disable();
99
          }
100
      }
101
102
  }// DarkScene::Update
103
104
  Text::Text(const std::string& text, FontAsset* font)
105
    : Entity(), text(text)
106
  {
107
    if (font == NULL)
108
      this->font = Assets::RequestFont("LiberationSans-Regular.ttf", 18.0f);
109
    else
110
      this->font = font;
111
  }
112
113
  void Text::Render()
114
  {
115
    Graphics::PushMatrix();
116
117
    // place text directly relative to camera
118
    Graphics::Translate(scene->GetCamera()->position + position);
119
120
    Graphics::SetBlend(BLEND_ALPHA);
121
    Graphics::SetColor(Color::white);
122
    Graphics::BindFont(font);
123
    
124
    Graphics::RenderText(*font, text, 0, 0);
125
    Graphics::PopMatrix();
126
  }
127
128
}