minor cleanups and added an icon

main
Martin Felis (berta) 2010-04-08 20:04:39 +02:00
parent 7c01aaf913
commit 60ee79152b
10 changed files with 28 additions and 100 deletions

View File

@ -14,13 +14,11 @@ namespace asteroids {
bool AsteroidEntity::CollisionEvent (Engine::EntityBase* entity_state) {
GameEntityType other_type = (GameEntityType) entity_state->mType;
Engine::LogDebug ("CONTACT OF AN ASTEROID");
if (other_type == GameEntityTypeRocket) {
// First remove the rocket
Engine::KillEntity (entity_state->mId);
Engine::LogMessage ("You killed an ASTEROID!");
Engine::LogMessage ("You killed an Asteroid!");
int i;
for (i = 0; i < mSubAsteroidsCount; i++) {

View File

@ -13,9 +13,6 @@ namespace asteroids {
*/
enum EntityControllerKeyState {
EntityKeyStateForward = 0,
EntityKeyStateBack,
EntityKeyStateLeft,
EntityKeyStateRight,
EntityKeyStateTurnLeft,
EntityKeyStateTurnRight,
EntityKeyStateLast

View File

@ -50,84 +50,6 @@ bool Cmd_ControllerForwardUp (std::vector<std::string> args) {
return false;
}
/* +back */
bool Cmd_ControllerBackDown (std::vector<std::string> args) {
assert (ControllerInstance);
Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId());
if (player_entity) {
player_entity->SetControllerKeyState (EntityKeyStateBack);
return true;
}
return false;
}
/* -back */
bool Cmd_ControllerBackUp (std::vector<std::string> args) {
assert (ControllerInstance);
Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId());
if (player_entity) {
player_entity->UnsetControllerKeyState (EntityKeyStateBack);
return true;
}
return false;
}
/* +left */
bool Cmd_ControllerLeftDown (std::vector<std::string> args) {
assert (ControllerInstance);
Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId());
if (player_entity) {
player_entity->SetControllerKeyState (EntityKeyStateLeft);
return true;
}
return false;
}
/* -left */
bool Cmd_ControllerLeftUp (std::vector<std::string> args) {
assert (ControllerInstance);
Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId());
if (player_entity) {
player_entity->UnsetControllerKeyState (EntityKeyStateLeft);
return true;
}
return false;
}
/* +right */
bool Cmd_ControllerRightDown (std::vector<std::string> args) {
assert (ControllerInstance);
Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId());
if (player_entity) {
player_entity->SetControllerKeyState (EntityKeyStateRight);
return true;
}
return false;
}
/* -right */
bool Cmd_ControllerRightUp (std::vector<std::string> args) {
assert (ControllerInstance);
Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId());
if (player_entity) {
player_entity->UnsetControllerKeyState (EntityKeyStateRight);
return true;
}
return false;
}
/* +turnleft */
bool Cmd_ControllerTurnLeftDown (std::vector<std::string> args) {
assert (ControllerInstance);
@ -198,13 +120,6 @@ void Controller::OnRegisterCommands () {
Engine::AddCommand ("+forward", Cmd_ControllerForwardDown);
Engine::AddCommand ("-forward", Cmd_ControllerForwardUp);
Engine::AddCommand ("+back", Cmd_ControllerBackDown);
Engine::AddCommand ("-back", Cmd_ControllerBackUp);
Engine::AddCommand ("+left", Cmd_ControllerLeftDown);
Engine::AddCommand ("-left", Cmd_ControllerLeftUp);
Engine::AddCommand ("+right", Cmd_ControllerRightDown);
Engine::AddCommand ("-right", Cmd_ControllerRightUp);
Engine::AddCommand ("+turnleft", Cmd_ControllerTurnLeftDown);
Engine::AddCommand ("-turnleft", Cmd_ControllerTurnLeftUp);

View File

@ -27,7 +27,6 @@ struct RocketEntity: public Engine::EntityBase {
virtual void Update (float delta_sec);
virtual bool CollisionEvent (Engine::EntityBase *entity) {
Engine::LogMessage ("Rocket BOOM");
return false;
}

View File

@ -125,7 +125,7 @@ void ShipEntity::Attack () {
rocket_physics->mPosition += entity_physic->mPosition;
rocket_physics->mOrientation = entity_physic->mOrientation;
rocket_physics->mVelocity = attack_dir.normalize();
rocket_physics->mVelocity *= ShipEntity::VarMaxSpeed.GetFloatValue() + 0.1;
rocket_physics->mVelocity *= ShipEntity::VarMaxSpeed.GetFloatValue() + 0.5;
}
}

View File

@ -22,15 +22,24 @@ int main (int argc, char* argv[]) {
engine.SetPhysics (new asteroids::Physics);
engine.SetView (new asteroids::View);
SetLogPrintLevel (Engine::LogLevelDebug);
SetLogPrintLevel (Engine::LogLevelMessage);
Engine::SetLogFilename ("game.log");
if (engine.Init (argc, argv) != 0) {
cout << "Could not start engine!" << endl;
exit (-1);
}
SDL_WM_SetCaption("Asteroids -TechDemo- 10.04","Asteroids");
// Load the icon
Uint32 colorkey;
SDL_Surface *image = NULL;
image = SDL_LoadBMP("./data/textures/icon.bmp");
if (!image)
Engine::LogWarning("Could not load icon: ./data/textures/icon.bmp");
else
SDL_WM_SetIcon(image,NULL);
SDL_WM_SetCaption("Asteroids -Leaked TechDemo-","Asteroids -Leaked TechDemo-");
engine.GetView()->SetGridSize (8,8);
dynamic_cast<asteroids::Physics*>(engine.GetPhysics())->SetWorldSize (28, 20);
@ -39,6 +48,9 @@ int main (int argc, char* argv[]) {
engine.MainLoop ();
SDL_WM_SetIcon(NULL,NULL);
SDL_FreeSurface (image);
engine.Destroy ();
cout << "Game Quit" << endl;

BIN
data/textures/icon.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -73,6 +73,7 @@ int Engine::OnInit (int argc, char* argv[]) {
LogError ("Error initializing SDL: %s", SDL_GetError ());
exit (-1);
}
SDL_WM_SetCaption("Engine Initializing","Engine Initializing");
/* Model */
if (mModel == NULL)

View File

@ -40,9 +40,6 @@ void Logging::OnDestroy () {
* Module specific functions
*/
void Logging::Log (LogLevel level, const char *str, ...) {
if (level < mPrintLevel)
return;
static char msg[LOG_MAX_MESSAGE_LENGTH];
static int last_length = LOG_MAX_MESSAGE_LENGTH;
static int i;
@ -58,12 +55,15 @@ void Logging::Log (LogLevel level, const char *str, ...) {
last_length = strlen (msg);
assert (last_length < LOG_MAX_MESSAGE_LENGTH);
std::cout << msg << std::endl;
if (level >= mPrintLevel)
std::cout << msg << std::endl;
LogEntry log_entry (level, msg);
mLogEntries.push_back (log_entry);
// write the logs to file
if (mLogFileOut) {
/// \TODO also write out the log level
time_t timer = time(NULL);
std::string timestr (asctime(localtime(&timer)));
mLogFileOut << timestr.substr(0, timestr.size() - 1) << ' ' << msg << std::endl;

View File

@ -7,6 +7,12 @@ namespace Engine {
class Module;
/** \brief All logging goes through this class
*
* Only log messages higher or equal that of mPrintLevel are printed out. When
* a log filename was specified by Logging::SetLogFilename() then all messages
* sent to the Logging class are written to the file.
*
* \TODO Add log level for files separately
*/
class Logging : public Module {
public: