Skip to content

Commit

Permalink
updated UI_elements movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Adria-F committed Apr 24, 2018
1 parent e4e1be7 commit 69d688e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Motor2D/Motor2D.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<Xml Include="..\Game\config.xml">
<SubType>Designer</SubType>
</Xml>
<Xml Include="..\Game\cutscenes.xml" />
<Xml Include="..\Game\cutscenes\attack.xml" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
7 changes: 5 additions & 2 deletions Motor2D/Motor2D.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,16 @@
<Filter Include="Desenvolupament ========\UI_elements">
<UniqueIdentifier>{83496dbf-2d02-443e-998b-5863bb549010}</UniqueIdentifier>
</Filter>
<Filter Include="Desenvolupament ========\Files\Cutscenes">
<UniqueIdentifier>{313c73b4-91c8-4d01-84e6-bff9adf41428}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Xml Include="..\Game\config.xml">
<Filter>Desenvolupament ========\Files</Filter>
</Xml>
<Xml Include="..\Game\cutscenes.xml">
<Filter>Desenvolupament ========\Files</Filter>
<Xml Include="..\Game\cutscenes\attack.xml">
<Filter>Desenvolupament ========\Files\Cutscenes</Filter>
</Xml>
</ItemGroup>
</Project>
25 changes: 20 additions & 5 deletions Motor2D/j1Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,34 @@ void j1Gui::manageCutsceneEvents(float dt)
UI_Element* element = getElement((*it_s)->id);
if (element != nullptr)
{
fPoint stepMovement;
float time_percentage = dt / (float)((*it_s)->duration / 1000.0f);
float step_speed = DEFAULT_UI_SPEED*dt;
switch ((*it_s)->type)
{
case MOVE_TO:
if ((*it_s)->movement.x == 0 && (*it_s)->movement.y == 0)
if ((*it_s)->movement.x == 0 && (*it_s)->movement.y == 0) //In this case, you have defined a destiny
{
//So you calculate the needed movement to reach that position
(*it_s)->movement.x = (*it_s)->destiny.x - element->local_position.x;
(*it_s)->movement.y = (*it_s)->destiny.y - element->local_position.y;
if ((*it_s)->movement.x == 0 && (*it_s)->movement.y == 0)
{
App->cutscenemanager->activeCutscene->forceStepFinish((*it_s)); //If after that movement still is 0 it means that already is in that position so you finish step
break;
}
}
//And then do as in the normal MOVE case
case MOVE:
stepMovement = { (*it_s)->movement.x * time_percentage, (*it_s)->movement.y * time_percentage };
element->local_position += stepMovement;
if ((*it_s)->duration == -1) //At the beginning the duration is set to infinite (-1)
{
float distance = sqrt(pow((*it_s)->movement.x, 2.0) + pow((*it_s)->movement.y, 2.0));
float time = distance / DEFAULT_UI_SPEED;
(*it_s)->duration = time * 1000; //So you calculate the duration that it will take to perform the desired movement
//Now calculate the director vector of the movement
(*it_s)->movement_vector.x = (*it_s)->movement.x / distance;
(*it_s)->movement_vector.y = (*it_s)->movement.y / distance;
}
element->local_position.x += (*it_s)->movement_vector.x*step_speed;
element->local_position.y += (*it_s)->movement_vector.y*step_speed;
break;
case ACTIVATE_AT:
element->local_position.x = (*it_s)->destiny.x;
Expand Down
2 changes: 2 additions & 0 deletions Motor2D/j1Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "j1Module.h"
#include <list>

#define DEFAULT_UI_SPEED 150

class UI_Element;
class TextBox;

Expand Down

0 comments on commit 69d688e

Please sign in to comment.