| Unuk 1.0

- Main Page
- Classes
- Files

- File List
- File Members

src/Unuk/Player.cpp
Go to the documentation of this file.

    00001 #include <GL/gl.h>
    00002 #include <SDL/SDL.h>
    00003 #include "../libUnuk/Sprite.h"
    00004 #include "../libUnuk/Debug.h"
    00005 #include "../libUnuk/Input.h"
    00006 #include "Player.h"
    00007
    00008 Player::Player(void) : m_posx(0), m_posy(0) {
    00009   //m_player = new Sprite("../Data/Media/test.bmp");
    00010 }
    00011
    00012 Player::~Player(void) {
    00013   CleanUp();
    00014 }
    00015
    00016 void Player::Prepare(void) {
    00017   // I borked up the image loader, so for now we will
    00018   // rotate the image 180 degrees.
    00019   m_player->Rotate(180);
    00020   m_player->SetScale(0.5f, 0.5f);
    00021   //Set our pivot to the top right.
    00022   m_player->SetPivot(1.0f, 1.0f);
    00023
    00024   CreateInput();
    00025   // Move the player.
    00026   if(KeyStillDown(SDLK_w) || KeyStillDown(SDLK_UP))     { SetVelocity(0, -5); }
    00027   if(KeyStillDown(SDLK_a) || KeyStillDown(SDLK_LEFT))   { SetVelocity(-5, 0); }
    00028   if(KeyStillDown(SDLK_s) || KeyStillDown(SDLK_DOWN))   { SetVelocity( 0, 5); }
    00029   if(KeyStillDown(SDLK_d) || KeyStillDown(SDLK_RIGHT))  { SetVelocity( 5, 0); }
    00030   UpdateInput();
    00031
    00032   SetPosition(m_posx, m_posy);
    00033 }
    00034
    00035 void Player::Render(void) {
    00036   // Only render calls should appear here.
    00037   m_player->Render();
    00038 }
    00039
    00040 void Player::SetSprite(void) {
    00041   m_player = new Sprite("../Data/Media/test.bmp");
    00042 }
    00043
    00044 void Player::SetPosition(GLdouble posx, GLdouble posy) {
    00045   // Set the position of the player sprite.
    00046   m_posx = posx;
    00047   m_posy = posy;
    00048
    00049   m_player->SetX(m_posx);
    00050   m_player->SetY(m_posy);
    00051 }
    00052
    00053 void Player::SetVelocity(GLdouble velx, GLdouble vely) {
    00054   m_velx = velx;
    00055   m_vely = vely;
    00056
    00057   m_posx += m_velx;
    00058   m_posy += m_vely;
    00059 }
    00060
    00061 void Player::CleanUp(void) {
    00062   delete m_player;
    00063 }

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines