editor and game improvements

- (editor) entities can be rotated
- (editor) asteroids get a random angular velocity
- (editor) level title and author can be specified
- (editor) editor can only be quit when clicking the 'X' button
- (game) smaller asteroids have similar velocities as the previous bigger ones
This commit is contained in:
2011-02-12 15:43:06 +01:00
parent 42d40befcd
commit 57ea0596b8
13 changed files with 192 additions and 17 deletions
+1
View File
@@ -37,6 +37,7 @@ SET ( ENGINE_SRCS
Engine.cc
Logging.cc
EnumStrings.cc
Utils.cc
)
INCLUDE_DIRECTORIES (
+7
View File
@@ -188,6 +188,13 @@ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) {
/** \brief Keyboard processing */
bool ControllerBase::OnKeyUp (const SDL_keysym &keysym) {
SetButtonState (keysym.sym, false);
if (keysym.sym == SDLK_F12) {
if (mView->GetIsFullscreen())
mView->SetFullscreen(false);
else
mView->SetFullscreen(true);
}
uistate.keypressed_set.insert (keysym.sym);
+1
View File
@@ -20,6 +20,7 @@
#include "Module.h"
#include "EngineEnums.h"
#include "Utils.h"
// Some ugly #defines
+19
View File
@@ -257,6 +257,12 @@ bool Button (int id, const char* caption, int x, int y, int w, int h) {
controller->uistate.hotitem = controller->uistate.lastwidget;
controller->uistate.last_keysym = SDLK_CLEAR;
break;
case SDLK_TAB:
controller->uistate.last_keysym = SDLK_CLEAR;
controller->uistate.last_unicode = 0;
controller->uistate.hotitem = 0;
controller->uistate.kbditem = 0;
break;
case SDLK_RETURN:
controller->uistate.last_keysym = SDLK_CLEAR;
// As we (probably) exit the current set of widgets, we have to clear
@@ -372,6 +378,12 @@ bool CheckButton (int id, const char* caption, bool checked, int x, int y, int w
controller->uistate.hotitem = controller->uistate.lastwidget;
controller->uistate.last_keysym = SDLK_CLEAR;
break;
case SDLK_TAB:
controller->uistate.last_keysym = SDLK_CLEAR;
controller->uistate.last_unicode = 0;
controller->uistate.hotitem = 0;
controller->uistate.kbditem = 0;
break;
case SDLK_RETURN:
controller->uistate.last_keysym = SDLK_CLEAR;
// As we (probably) exit the current set of widgets, we have to clear
@@ -478,6 +490,13 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
controller->uistate.kbditem = 0;
return false;
break;
case SDLK_TAB:
controller->uistate.last_keysym = SDLK_CLEAR;
controller->uistate.last_unicode = 0;
controller->uistate.hotitem = 0;
controller->uistate.kbditem = 0;
return false;
break;
case SDLK_RETURN:
controller->uistate.last_keysym = SDLK_CLEAR;
controller->uistate.last_unicode = 0;
+1 -1
View File
@@ -99,11 +99,11 @@ int PhysicsBase::Simulate (float msec, ModelBase* model) {
// if the timestep is too small we simply resolve the collision and
// do not move beforehang
LogDebug ("Time step too small ==> Resolving Step immediately");
ResolveCollision (0., entity_a_id, entity_b_id, info);
// Send the collision event to the Model (if we have one)
if (model) {
model->SendEntityCollisionEvent (entity_a_id, entity_b_id, info.time, info.point, info.normal);
}
ResolveCollision (0., entity_a_id, entity_b_id, info);
// collision_remaining_step -= 1.0e-4;
} else {
Move (info.time * (1 - alpha));
+37 -2
View File
@@ -43,13 +43,21 @@ int ViewBase::OnInit (int argc, char* argv[]) {
mWindowHeight = VIEW_DEFAULT_HEIGHT;
mWindowWidth = VIEW_DEFAULT_WIDTH;
// get and save the screen resolution
mScreenHeight = SDL_GetVideoInfo()->current_h;
mScreenWidth = SDL_GetVideoInfo()->current_w;
mDrawFullscreen = false;
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if( SDL_SetVideoMode( mWindowWidth, mWindowHeight, 16, SDL_OPENGL | SDL_RESIZABLE ) == 0 ) {
if( SDL_SetVideoMode( mWindowWidth, mWindowHeight, 16, SDL_OPENGL ) == 0 ) {
LogError ("Video mode set failed: %s", SDL_GetError ());
exit (-1);
}
LogMessage ("Resolution is %dx%d", SDL_GetVideoInfo()->current_w, SDL_GetVideoInfo()->current_h);
InitGL ();
Resize (mWindowWidth, mWindowHeight);
@@ -187,6 +195,28 @@ void ViewBase::PostDraw() {
SDL_GL_SwapBuffers ();
}
void ViewBase::SetFullscreen (bool fullscreen) {
if (fullscreen && mDrawFullscreen)
return;
if (!fullscreen && !mDrawFullscreen)
return;
if (mDrawFullscreen) {
mWindowHeight = VIEW_DEFAULT_HEIGHT;
mWindowWidth = VIEW_DEFAULT_WIDTH;
mDrawFullscreen = false;
} else {
mWindowWidth = mScreenWidth;
mWindowHeight = mScreenHeight;
mDrawFullscreen = true;
}
Resize (mWindowWidth, mWindowHeight);
}
/* Fonts */
/** \brief Parses font specifications strings into its values
@@ -401,7 +431,12 @@ void ViewBase::Resize (int width, int height) {
* workaround, however since I do not yet run SDL 1.3 I hold on to this.
* See http://lists.libsdl.org/pipermail/sdl-libsdl.org/2008-November/067306.html
*/
if( SDL_SetVideoMode( mWindowWidth, mWindowHeight, 16, SDL_OPENGL | SDL_RESIZABLE ) == 0 ) {
Uint32 video_flags = SDL_OPENGL;
if (mDrawFullscreen)
video_flags = video_flags | SDL_FULLSCREEN;
if( SDL_SetVideoMode( mWindowWidth, mWindowHeight, 16, video_flags) == 0 ) {
LogError ("Video mode set failed: %s", SDL_GetError ());
exit (-1);
}
+12
View File
@@ -26,6 +26,9 @@ class ViewBase : public Module{
/** \brief Resizes the View */
void Resize (int width, int height);
/** \brief Switches to fullscreen */
void SetFullscreen (bool fullscreen);
bool GetIsFullscreen () { return mDrawFullscreen; };
/** \brief Performs actions before drawing (e.g. timer stuff) */
void PreDraw();
@@ -96,6 +99,8 @@ class ViewBase : public Module{
/** \brief Draws orthographic overlay*/
void DrawOverlay2D ();
bool mDrawFullscreen;
/** \brief Draws a grid of 16 x 16 tiles */
void DrawGrid ();
bool mDrawGrid;
@@ -114,6 +119,13 @@ class ViewBase : public Module{
unsigned int mWindowHeight;
/** \brief The width of the canvas we're drawing on */
unsigned int mWindowWidth;
/** \brief The height of the screen in pixels */
unsigned int mScreenHeight;
/** \brief The width of the screen in pixels */
unsigned int mScreenWidth;
/** \brief Stores the current frame rate */
int mFrameRate;