-- [Add] Player movement is now running smoothly.

-- [Remove] Killed a few files that I am not using any longer.
This commit is contained in:
Rtch90 2011-10-25 22:17:33 +01:00
parent b99de4354e
commit d913ab8e10
11 changed files with 21 additions and 249 deletions

View File

@ -22,4 +22,4 @@ static:
clean: clean:
$(MAKE) -C ../src/libUnuk clean $(MAKE) -C ../src/libUnuk clean
$(MAKE) -C ../src/Unuk clean $(MAKE) -C ../src/Unuk clean
rm -f Unuk Debug.log ../Data/Debug.log rm -f Unuk Debug.log ../Data/Debug.log ../Unuk-QT/Unuk-QT

View File

@ -1,6 +1,6 @@
############################################################################# #############################################################################
# Makefile for building: Unuk-QT # Makefile for building: Unuk-QT
# Generated by qmake (2.01a) (Qt 4.7.3) on: Sun Oct 23 18:21:18 2011 # Generated by qmake (2.01a) (Qt 4.7.3) on: Tue Oct 25 22:14:31 2011
# Project: Unuk-QT.pro # Project: Unuk-QT.pro
# Template: app # Template: app
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro # Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
@ -43,8 +43,7 @@ OBJECTS_DIR = ./
####### Files ####### Files
SOURCES = ../src/libUnuk/Vec2.cpp \ SOURCES = ../src/libUnuk/Sprite.cpp \
../src/libUnuk/Sprite.cpp \
../src/libUnuk/ImageLoader.cpp \ ../src/libUnuk/ImageLoader.cpp \
../src/libUnuk/Debug.cpp \ ../src/libUnuk/Debug.cpp \
../src/Unuk/Player.cpp \ ../src/Unuk/Player.cpp \
@ -52,8 +51,7 @@ SOURCES = ../src/libUnuk/Vec2.cpp \
../src/Unuk/Game.cpp \ ../src/Unuk/Game.cpp \
../src/libUnuk/Entity.cpp \ ../src/libUnuk/Entity.cpp \
../src/libUnuk/Input.cpp ../src/libUnuk/Input.cpp
OBJECTS = Vec2.o \ OBJECTS = Sprite.o \
Sprite.o \
ImageLoader.o \ ImageLoader.o \
Debug.o \ Debug.o \
Player.o \ Player.o \
@ -160,7 +158,7 @@ qmake: FORCE
dist: dist:
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0 @$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.h ../src/libUnuk/ImageLoader.h ../src/libUnuk/Sprite.h ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/Unuk/Game.h ../src/Unuk/Player.h ../src/libUnuk/KeyboardInterface.h ../src/libUnuk/XKeyboardInterface.h ../src/libUnuk/Static.h ../src/libUnuk/UnukWindow.h ../src/libUnuk/Geometry.h ../src/libUnuk/Entity.h ../src/libUnuk/EntityType.h ../src/libUnuk/Input.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Vec2.cpp ../src/libUnuk/Sprite.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/Debug.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp ../src/libUnuk/Input.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0 $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/ImageLoader.h ../src/libUnuk/Sprite.h ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/Unuk/Game.h ../src/Unuk/Player.h ../src/libUnuk/Static.h ../src/libUnuk/Geometry.h ../src/libUnuk/Entity.h ../src/libUnuk/EntityType.h ../src/libUnuk/Input.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Sprite.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/Debug.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp ../src/libUnuk/Input.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
clean:compiler_clean clean:compiler_clean
@ -202,9 +200,6 @@ compiler_clean:
####### Compile ####### Compile
Vec2.o: ../src/libUnuk/Vec2.cpp ../src/libUnuk/Vec2.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Vec2.o ../src/libUnuk/Vec2.cpp
Sprite.o: ../src/libUnuk/Sprite.cpp ../src/libUnuk/Sprite.h \ Sprite.o: ../src/libUnuk/Sprite.cpp ../src/libUnuk/Sprite.h \
../src/libUnuk/ImageLoader.h \ ../src/libUnuk/ImageLoader.h \
../src/libUnuk/Debug.h ../src/libUnuk/Debug.h
@ -220,7 +215,7 @@ Debug.o: ../src/libUnuk/Debug.cpp ../src/libUnuk/Debug.h
Player.o: ../src/Unuk/Player.cpp ../src/libUnuk/Sprite.h \ Player.o: ../src/Unuk/Player.cpp ../src/libUnuk/Sprite.h \
../src/libUnuk/ImageLoader.h \ ../src/libUnuk/ImageLoader.h \
../src/libUnuk/Debug.h \ ../src/libUnuk/Debug.h \
../src/libUnuk/KeyboardInterface.h \ ../src/libUnuk/Input.h \
../src/Unuk/Player.h ../src/Unuk/Player.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp
@ -228,6 +223,7 @@ main.o: ../src/Unuk/main.cpp ../src/Unuk/Game.h \
../src/Unuk/Player.h \ ../src/Unuk/Player.h \
../src/libUnuk/Sprite.h \ ../src/libUnuk/Sprite.h \
../src/libUnuk/ImageLoader.h \ ../src/libUnuk/ImageLoader.h \
../src/libUnuk/Input.h \
../src/libUnuk/Debug.h ../src/libUnuk/Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../src/Unuk/main.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../src/Unuk/main.cpp
@ -235,6 +231,7 @@ Game.o: ../src/Unuk/Game.cpp ../src/Unuk/Game.h \
../src/Unuk/Player.h \ ../src/Unuk/Player.h \
../src/libUnuk/Sprite.h \ ../src/libUnuk/Sprite.h \
../src/libUnuk/ImageLoader.h \ ../src/libUnuk/ImageLoader.h \
../src/libUnuk/Input.h \
../src/libUnuk/Debug.h ../src/libUnuk/Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Game.o ../src/Unuk/Game.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Game.o ../src/Unuk/Game.cpp

View File

@ -7,24 +7,19 @@ OTHER_FILES += ../src/libUnuk/Vec2.o \
../src/libUnuk/GlxWindow.o \ ../src/libUnuk/GlxWindow.o \
../src/libUnuk/Sprite.o \ ../src/libUnuk/Sprite.o \
../src/libUnuk/Debug.o ../src/libUnuk/Debug.o
HEADERS += ../src/libUnuk/Vec2.h \ HEADERS += ../src/libUnuk/ImageLoader.h \
../src/libUnuk/ImageLoader.h \
../src/libUnuk/Sprite.h \ ../src/libUnuk/Sprite.h \
../src/libUnuk/Debug.h \ ../src/libUnuk/Debug.h \
../src/Libs/wglext.h \ ../src/Libs/wglext.h \
../src/Libs/glxext.h \ ../src/Libs/glxext.h \
../src/Unuk/Game.h \ ../src/Unuk/Game.h \
../src/Unuk/Player.h \ ../src/Unuk/Player.h \
../src/libUnuk/KeyboardInterface.h \
../src/libUnuk/XKeyboardInterface.h \
../src/libUnuk/Static.h \ ../src/libUnuk/Static.h \
../src/libUnuk/UnukWindow.h \
../src/libUnuk/Geometry.h \ ../src/libUnuk/Geometry.h \
../src/libUnuk/Entity.h \ ../src/libUnuk/Entity.h \
../src/libUnuk/EntityType.h \ ../src/libUnuk/EntityType.h \
../src/libUnuk/Input.h ../src/libUnuk/Input.h
SOURCES += ../src/libUnuk/Vec2.cpp \ SOURCES += ../src/libUnuk/Sprite.cpp \
../src/libUnuk/Sprite.cpp \
../src/libUnuk/ImageLoader.cpp \ ../src/libUnuk/ImageLoader.cpp \
../src/libUnuk/Debug.cpp \ ../src/libUnuk/Debug.cpp \
../src/Unuk/Player.cpp \ ../src/Unuk/Player.cpp \

View File

@ -63,8 +63,6 @@ void Game::Render(void) {
//glutSwapBuffers(); //glutSwapBuffers();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
if(KeyStillDown(SDLK_w)) {Debug::logger->message("Werks"); }
// Get frames per second. // Get frames per second.
frames++; frames++;
{ {

View File

@ -2,7 +2,7 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "../libUnuk/Sprite.h" #include "../libUnuk/Sprite.h"
#include "../libUnuk/Debug.h" #include "../libUnuk/Debug.h"
#include "../libUnuk/KeyboardInterface.h" #include "../libUnuk/Input.h"
#include "Player.h" #include "Player.h"
Player::Player(void) : Player::Player(void) :
@ -18,13 +18,16 @@ void Player::Prepare(void) {
// I borked up the image loader, so for now we will // I borked up the image loader, so for now we will
// rotate the image 180 degrees. // rotate the image 180 degrees.
m_player->Rotate(180); m_player->Rotate(180);
m_player->SetScale(0.5f, 0.5f);
// Set our pivot to the top right. // Set our pivot to the top right.
m_player->SetPivot(1.0f, 1.0f); m_player->SetPivot(1.0f, 1.0f);
if(m_velx && m_vely > 0) { // Move the player.
m_posx += m_velx; if(KeyStillDown(SDLK_w) || KeyStillDown(SDLK_UP)) { SetVelocity(0, -5); }
m_posy += m_vely; if(KeyStillDown(SDLK_a) || KeyStillDown(SDLK_LEFT)) { SetVelocity(-5, 0); }
} if(KeyStillDown(SDLK_s) || KeyStillDown(SDLK_DOWN)) { SetVelocity( 0, 5); }
if(KeyStillDown(SDLK_d) || KeyStillDown(SDLK_RIGHT)) { SetVelocity( 5, 0); }
SetPosition(m_posx, m_posy); SetPosition(m_posx, m_posy);
} }
@ -45,6 +48,9 @@ void Player::SetPosition(GLdouble posx, GLdouble posy) {
void Player::SetVelocity(GLdouble velx, GLdouble vely) { void Player::SetVelocity(GLdouble velx, GLdouble vely) {
m_velx = velx; m_velx = velx;
m_vely = vely; m_vely = vely;
m_posx += m_velx;
m_posy += m_vely;
} }
void Player::CleanUp(void) { void Player::CleanUp(void) {

View File

@ -26,8 +26,6 @@ private:
GLdouble m_posy; GLdouble m_posy;
// Velocity variables. // Velocity variables.
int m_tempvelx;
int m_tempvely;
int m_velx; int m_velx;
int m_vely; int m_vely;
}; };

View File

@ -1,31 +0,0 @@
#ifndef _KEYBOARDINTERFACE_H_
#define _KEYBOARDINTERFACE_H_
enum UnukKeyCode {
U_INVALID,
U_UP,
U_DOWN,
U_LEFT,
U_RIGHT,
U_SPACE,
U_w,
U_a,
U_s,
U_d,
U_MAX_KEYS
};
class KeyboardInterface {
public:
virtual ~KeyboardInterface(void) {}
virtual bool IsKeyPressed(UnukKeyCode code) = 0;
virtual bool IsKeyHeldDown(UnukKeyCode code) = 0;
virtual void HandleKeyDown(UnukKeyCode code) = 0;
virtual void HandleKeyUp(UnukKeyCode code) = 0;
// Translate The operating systems key, to a keycode.
virtual UnukKeyCode TranslateKey(unsigned int code) = 0;
virtual void Update(void) = 0;
};
#endif

View File

@ -1,22 +0,0 @@
#ifndef _UNUKWINDOW_H_
#define _UNUKWINDOW_H_
#include "Static.h"
class KeyboardInterface;
class Game;
class Static : private Static {
public:
virtual ~UnukWindow(void) {}
virtual bool Create(int width, int height, int bpp, bool fullscreen) = 0;
virtual void Destroy(void) = 0;
virtual void processEvents(void) = 0;
virtual void AttachGame(Game* game) = 0;
virtual bool IsRunning(void) = 0;
virtual void SwapBuffers(void) = 0;
virtual float GetElapsedSeconds(void) = 0;
virtual KeyboardInterface* GetKeyboard(void) const = 0;
};
#endif

View File

@ -1,55 +0,0 @@
#include "Vec2.h"
/// Get a 0.0 vector.
Vec2 Vec2::Zero() { return Vec2(0.0f, 0.0f); }
Vec2::Vec2(void) {
x = 0;
y = 0;
}
Vec2::Vec2(float xValue, float yValue) {
x = xValue;
y = yValue;
}
Vec2::Vec2(const Vec2 &v) {
x = v.x;
y = v.y;
}
Vec2::~Vec2(void) {
x = 0;
y = 0;
}
Vec2& Vec2::operator =(const Vec2 &v) {
x = v.x;
y = v.y;
return *this;
}
Vec2& Vec2::operator+=(const Vec2 &v) {
x += v.x;
y += v.y;
return *this;
}
Vec2& Vec2::operator-=(const Vec2 &v) {
x -= v.x;
y -= v.y;
return *this;
}
Vec2& Vec2::operator*=(float c) {
x *= c;
y *= c;
return *this;
}
/// Multiply by a vector2.
Vec2& Vec2::operator*=(const Vec2 &v) {
x *= v.x;
y *= v.y;
return *this;
}

View File

@ -1,33 +0,0 @@
#ifndef _VEC2_H_
#define _VEC2_H_
class Vec2
{
public:
static Vec2 Zero();
Vec2(void);
Vec2(float xValue, float yValue);
Vec2(const Vec2 &v);
~Vec2(void);
// the operators are required to allow the system to understand how to compute mathematical problems
// Copy operator
Vec2& operator=(const Vec2 &v);
// Addition operator
Vec2& operator+=(const Vec2 &v);
// Subtraction operator
Vec2& operator-=(const Vec2 &v);
// Multiply by a scalar
Vec2& operator*=(float c);
// Multiply by a vector2.
Vec2& operator*=(const Vec2 &v);
float x;
float y;
};
#endif

View File

@ -1,81 +0,0 @@
#ifndef XKEYBOARDINTERFACE_H
#define XKEYBOARDINTERFACE_H
#ifdef __unix__
#include <cstring>
#include "KeyboardInterface.h"
#include "Debug.h"
class XKeyboardInterface : public KeyboardInterface {
public:
XKeyboardInterface(void) {
for(int i = 0; i < U_MAX_KEYS; ++i) {
m_keyState[i] = 0;
m_lastKeyState[i] = 0;
}
}
virtual bool IsKeyPressed(UnukKeyCode code) {
return(m_lastKeyState[code] && m_keyState[code] == 1);
}
virtual bool IsKeyHeldDown(UnukKeyCode code) {
return(m_lastKeyState[code] && m_keyState[code]);
}
virtual void HandleKeyDown(UnukKeyCode code) {
m_keyState[code] = 1;
}
virtual void HandleKeyUp(UnukKeyCode code) {
m_keyState[code] =0;
}
UnukKeyCode TranslateKey(unsigned int code) {
switch(code) {
case XK_Up:
return U_UP;
break;
case XK_Down:
return U_DOWN;
break;
case XK_Left:
return U_LEFT;
break;
case XK_Right:
return U_RIGHT;
break;
case XK_space:
return U_SPACE;
break;
case XK_w:
return U_w;
break;
case XK_a:
return U_a;
break;
case XK_s:
return U_s;
break;
case XK_d:
return U_d;
break;
default:
Debug::logger->message("Warning: Can not translate this key");
return U_INVALID;
}
}
void Update(void) {
// Copy the current key to the last key state.
memcpy(m_lastKeyState, m_keyState, sizeof(short) * U_MAX_KEYS);
}
private:
short m_keyState[U_MAX_KEYS];
short m_lastKeyState[U_MAX_KEYS];
};
// __unix__
#endif
// XKEYBOARDINTERFACE_H
#endif