Camera class ready for rendering implimentation
This commit is contained in:
@@ -26,6 +26,11 @@ void Camera::SetCenter(Vec2* point) {
|
||||
m_view->y = (point->y - m_view->CenterY());
|
||||
}
|
||||
|
||||
Rect Camera::GetRect() {
|
||||
Rect rect(m_view->x, m_view->y, m_view->w, m_view->h);
|
||||
return rect;
|
||||
}
|
||||
|
||||
int Camera::GetX() {
|
||||
return m_view->x;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
|
||||
void SetCenter(Vec2* point);
|
||||
|
||||
Rect GetRect();
|
||||
int GetX();
|
||||
int GetY();
|
||||
int GetW();
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
int main(int argc, char** argv) {
|
||||
Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1000 / 60); // 1000 / 60);
|
||||
Camera camera(SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
game.AddCamera("follow", &camera);
|
||||
game.UseCamera("follow");
|
||||
game.AddCamera("free", &camera);
|
||||
game.UseCamera("free");
|
||||
Timer timer;
|
||||
|
||||
Sprite sans("sans", game.renderer, SpriteType::SPRITE_ANIMATED);
|
||||
@@ -38,6 +38,23 @@ int main(int argc, char** argv) {
|
||||
sans.Pos->x -= 10;
|
||||
} else sans.Spritestate = SpriteState::STATE_FRONT;
|
||||
|
||||
if (state[SDL_SCANCODE_UP]) {
|
||||
camera.TranslateViewY(-10);
|
||||
std::cout << camera.GetRect().ToString() << std::endl;
|
||||
}
|
||||
if (state[SDL_SCANCODE_RIGHT]) {
|
||||
camera.TranslateViewX(10);
|
||||
std::cout << camera.GetRect().ToString() << std::endl;
|
||||
}
|
||||
if (state[SDL_SCANCODE_DOWN]) {
|
||||
camera.TranslateViewY(10);
|
||||
std::cout << camera.GetRect().ToString() << std::endl;
|
||||
}
|
||||
if (state[SDL_SCANCODE_LEFT]) {
|
||||
camera.TranslateViewX(-10);
|
||||
std::cout << camera.GetRect().ToString() << std::endl;
|
||||
}
|
||||
|
||||
if (timer.ticks % 5 == 0) {
|
||||
sans.TickAninmation();
|
||||
explosion.TickAninmation();
|
||||
|
||||
@@ -24,9 +24,7 @@ SDL_Rect* Rect::ToSDLRect() {
|
||||
}
|
||||
|
||||
std::string Rect::ToString() {
|
||||
std::string res = "";
|
||||
|
||||
res += "( ";
|
||||
std::string res = "(";
|
||||
res += std::to_string(x);
|
||||
res += ", ";
|
||||
res += std::to_string(y);
|
||||
|
||||
Reference in New Issue
Block a user