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
+68 -11
View File
@@ -149,7 +149,7 @@ bool View::OnReceiveEvent (const Engine::EventBasePtr &event) {
0.,
rel_velocity[2] * (rand()/float(RAND_MAX)) * 1.5
);
part_sprite_particle->mPhysicState->mVelocity = part_velocity;
part_sprite_particle->mPhysicState->mVelocity = part_velocity * -1.;
part_sprite_particle->mPhysicState->mAngleVelocity = (rand()/float(RAND_MAX) - 0.5 ) * 100.;
@@ -767,7 +767,7 @@ void View::DrawUiEnterPlayername() {
}
void View::DrawUiEditor() {
// DrawPageTitle ("Editor");
// DrawPageTitle ("Editor");
SelectFont ("console.ttf size=23");
// The close button
@@ -780,7 +780,7 @@ void View::DrawUiEditor() {
GetModel()->DoLoadLevel("level_edit_temp.txt");
GetModel()->SetGameState(GameStatePaused);
return;
} else {
} else if (!Engine::GUI::CheckKeyPressed(SDLK_ESCAPE)){
PopViewState();
}
}
@@ -804,19 +804,25 @@ void View::DrawUiEditor() {
return;
}
if (Engine::GUI::CheckButton (5, "Spd", mEditorState == EditorStateEntityVelocity, 210, 20, 50, button_height)) {
if (Engine::GUI::CheckButton (5, "Rot", mEditorState == EditorStateRotateEntity, 210, 20, 50, button_height)) {
mEditorState = EditorStateRotateEntity;
Engine::LogDebug ("Editor state now Move");
return;
}
if (Engine::GUI::CheckButton (6, "Spd", mEditorState == EditorStateEntityVelocity, 265, 20, 50, button_height)) {
mEditorState = EditorStateEntityVelocity;
Engine::LogDebug ("Editor state now Add");
return;
}
if (Engine::GUI::Button (6, "Save", 265, 20, 65, button_height)) {
if (Engine::GUI::Button (7, "Save", 325, 20, 65, button_height)) {
mEditorState = EditorStateSave;
Engine::LogDebug ("Editor state now Save");
return;
}
if (Engine::GUI::Button (7, "Load", 335, 20, 65, button_height)) {
if (Engine::GUI::Button (8, "Load", 400, 20, 65, button_height)) {
mEditorState = EditorStateLoad;
Engine::LogDebug ("Editor state now Load");
return;
@@ -826,7 +832,7 @@ void View::DrawUiEditor() {
// (i.e. a player entity and at least one asteroid)
if (GetModel()->GetPlayerEntityId() != 0
&& GetModel()->mAsteroids.size() > 0) {
if (Engine::GUI::Button (8, "Test", 405, 20, 64, button_height)) {
if (Engine::GUI::Button (9, "Test", 475, 20, 64, button_height)) {
mEditorState = EditorStateTest;
GetModel()->DoSaveLevel("level_edit_temp.txt");
@@ -854,6 +860,7 @@ void View::DrawUiEditor() {
if (GetModel()->GetPlayerEntityId() != Engine::NullEntityId) {
entity = Engine::CreateEntity(GameEntityTypeAsteroid);
entity->mPhysicState->SetVelocity (vector3d (0., 0., -1.));
entity->mPhysicState->SetAngleVelocity ( (rand()/float(RAND_MAX) - 0.5) * 120);
} else {
entity = Engine::CreateEntity(GameEntityTypeShip);
GetModel()->SetPlayerEntityId(entity->mId);
@@ -904,6 +911,41 @@ void View::DrawUiEditor() {
}
}
if (mEditorState == EditorStateRotateEntity) {
SelectFont ("console.ttf size=12");
// static vector3d mouse_start_rotate (0., 0., 0.);
static float start_angle = 0.;
if (mEditorEntityId == 0) {
if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
// Check if there is an entity near the given position
Engine::EntityBase* entity = Engine::GetEntityAt (mouse_world_pos);
if (entity) {
mEditorEntityId = entity->mId;
vector3d mouse_start_rotate = mouse_world_pos - entity->mPhysicState->GetPosition();
start_angle = atan2 (mouse_start_rotate[0], mouse_start_rotate[2]) * 180 / M_PI - entity->mPhysicState->mOrientation[1];
} else {
mEditorEntityId = 0;
}
}
}
if (mEditorEntityId != 0) {
Engine::EntityBase* entity = Engine::GetEntity (mEditorEntityId);
vector3d new_velocity = mouse_world_pos - entity->mPhysicState->GetPosition();
new_velocity[1] = 0.;
float angle = atan2 (new_velocity[0], new_velocity[2]) * 180. / M_PI;
entity->mPhysicState->SetOrientation (vector3d (0., angle - start_angle, 0.));
if (!Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
mEditorEntityId = 0;
}
}
}
if (mEditorState == EditorStateEntityVelocity) {
SelectFont ("console.ttf size=12");
// Engine::GUI::Label (9999, "Velocity", 128, 16);
@@ -935,7 +977,7 @@ void View::DrawUiEditor() {
if (mEditorState == EditorStateSave) {
glColor3f (0.2, 0.2, 0.2);
Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 200);
Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 280);
// Engine::GUI::Label (9999, "Saving", 128, 16);
SelectFont ("console.ttf size=23");
@@ -943,16 +985,26 @@ void View::DrawUiEditor() {
std::string level_name = GetModel()->GetLevelName();
glColor3f (1., 1., 1.);
if (Engine::GUI::LineEdit(52, 145, 210, level_name, 32))
if (Engine::GUI::LineEdit(52, 150, 200, level_name, 31))
GetModel()->SetLevelName(level_name);
if (Engine::GUI::Button (54, "Save", 145, 300, button_width, button_height)) {
Engine::GUI::Label(53, "Author: ", 145, 250);
std::string level_author = GetModel()->GetLevelAuthor();
if (Engine::GUI::LineEdit(531, 150, 270, level_author, 31))
GetModel()->SetLevelAuthor(level_author);
Engine::GUI::Label(54, "Level Title: ", 145, 320);
std::string level_title = GetModel()->GetLevelTitle();
if (Engine::GUI::LineEdit(541, 150, 340, level_title, 31))
GetModel()->SetLevelTitle(level_title);
if (Engine::GUI::Button (55, "Save", 145, 380, button_width, button_height)) {
GetModel()->DoSaveLevel((level_name + std::string(".txt")).c_str());
Engine::LogMessage ("Save");
mEditorState = EditorStateUnknown;
}
if (Engine::GUI::Button (55, "Cancel", screen_right - 140 - 5 - button_width, 300, button_width, button_height))
if (Engine::GUI::Button (56, "Cancel", screen_right - 140 - 5 - button_width, 380, button_width, button_height))
mEditorState = EditorStateUnknown;
}
@@ -981,6 +1033,11 @@ void View::DrawUiEditor() {
mEditorState = EditorStateUnknown;
}
if (Engine::GUI::CheckKeyPressed(SDLK_ESCAPE)) {
if (mEditorState != EditorStateUnknown)
mEditorState = EditorStateUnknown;
}
if (Engine::GUI::CheckKeyPressed(MouseButtonRight)
|| Engine::GUI::CheckKeyPressed(SDLK_ESCAPE) ) {
mEditorState = EditorStateUnknown;