Skip to content

Commit

Permalink
Merge pull request #8 from avalsa/animation
Browse files Browse the repository at this point in the history
Animation
  • Loading branch information
treplen authored Jun 26, 2017
2 parents 978cf99 + c7e00c3 commit 18e2c32
Show file tree
Hide file tree
Showing 111 changed files with 3,583 additions and 470 deletions.
2 changes: 2 additions & 0 deletions AtomGame/.idea/AtomGame.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions AtomGame/.idea/dictionaries/sl.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions AtomGame/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions AtomGame/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,167 changes: 1,167 additions & 0 deletions AtomGame/.idea/workspace.xml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion AtomGame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ project(AtomGame)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS " -pthread")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_TYPE "Release")


add_subdirectory(objects)
add_subdirectory(model)
Expand Down Expand Up @@ -40,4 +42,6 @@ target_link_libraries(Rain log4cpp)
target_link_libraries(Rain Objects)
target_link_libraries(Rain Mechanics)
target_link_libraries(Rain Graphics)
target_link_libraries(Rain Plugin)
target_link_libraries(Rain Plugin)

build_command(TARGET Run)
Binary file added AtomGame/blocks/programs/leftRight.bit
Binary file not shown.
16 changes: 16 additions & 0 deletions AtomGame/blocks/programs/leftRight.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
push x7
push x6
cmp
jnz fin
push 0
pop x7
push -1
push x2
mul
pop x2
fin:
push 1
push x7
add
pop x7
end
Binary file added AtomGame/blocks/programs/patrol.bit
Binary file not shown.
55 changes: 55 additions & 0 deletions AtomGame/blocks/programs/patrol.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
push x2
push 0
cmp
jnz t
push x9
pop x2
t:
push x8
push x0
sub
push 0
cmp
pop
jb n
push -1
mul
n:
push 100
cmp
jb walk
push 0
push x2
cmp
jnb e
push -1
mul
pop x2
e:
push x8
push x0
cmp
jb en
push -1
push x2
mul
pop x2
jmp en
walk:
push x7
push x6
cmp
jnz fin
push 0
pop x7
push -1
push x2
mul
pop x2
fin:
push 1
push x7
add
pop x7
en:
end
Binary file modified AtomGame/blocks/programs/upDown.bit
Binary file not shown.
22 changes: 5 additions & 17 deletions AtomGame/blocks/programs/upDown.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
push x3
push 0
cmp
jnz main
push x7
pop x3
main:
push 50
push x6
cmp
jb skip
jnz fin
push 0
pop x6
revert:
push x3
pop x7
push -1
push x3
mul
pop x3
jmp end
skip:
push x6
fin:
push 1
push x7
add
pop x6
end:
push x3
pop x7
end
Binary file added AtomGame/blocks/programs/upDown_old.bit
Binary file not shown.
120 changes: 97 additions & 23 deletions AtomGame/controller/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,113 @@

log4cpp::Category &Controller::logger = log4cpp::Category::getInstance (typeid (Controller).name ());

void Controller::onRightKeyPress ()
void Controller::onRightKeyPress (float stregth)
{
model->movePlayer (Actor::Direction::Right);
model->movePlayer (Actor::Direction::Right,stregth);
}

void Controller::onLeftKeyPress ()
void Controller::onLeftKeyPress (float stregth)
{
model->movePlayer (Actor::Direction::Left);
model->movePlayer (Actor::Direction::Left,stregth);
}

void Controller::onUpKeyPress ()
{
model->movePlayer (Actor::Direction::Up);
model->movePlayer (Actor::Direction::Up,0);
}

void Controller::onDownKeyPress ()
void Controller::onDownKeyPress (float stregth)
{
model->movePlayer (Actor::Direction::Down);
model->movePlayer (Actor::Direction::Down,stregth);
}

void Controller::onNoMovementKeyPress ()
{
model->movePlayer (PhysicalObject::Direction::NoDirection);
model->movePlayer (PhysicalObject::Direction::NoDirection,0);
}

void Controller::onSpacePress()
{
model->shootPlayer();
}

void Controller::onRPress()
{
model->getPlayer ().respawn ();
}

Controller::Controller (Model *model, View *view) : model (model), view (view)
Controller::Controller (Model *model, View *view) : model (model), view (view), restartTicks(0)
{
logger.info ("Controller init");
}

void Controller::tick ()
{
//all presses we need
bool movementKeyPressed = false;
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Right))
if(sf::Joystick::isConnected (0))
{
onRightKeyPress ();
movementKeyPressed = true;
float axisRushPosition = sf::Joystick::getAxisPosition (0,sf::Joystick::Axis::R);
std::cout<<axisRushPosition<<'\n';
float axisXPosition = sf::Joystick::getAxisPosition (0,sf::Joystick::Axis::X);
if(axisXPosition<-10)
onLeftKeyPress (-axisXPosition*(axisRushPosition+500)/400);
else
if(axisXPosition>10)
onRightKeyPress (axisXPosition*(axisRushPosition+500)/400);
else
onNoMovementKeyPress ();
if(float axisYPosition = sf::Joystick::getAxisPosition (0,sf::Joystick::Axis::Y) > 0)
onDownKeyPress (axisYPosition);
if(sf::Joystick::isButtonPressed (0,0))
onUpKeyPress ();
if(sf::Joystick::isButtonPressed (0,1) && axisRushPosition == -100)
onSpacePress ();
if(sf::Joystick::isButtonPressed (0,6))
{
++restartTicks;
if(restartTicks == restartTicksReq)
{
restartTicks = 0;
onRPress ();
}
}
else
restartTicks = 0;
}
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Left))
else
{
onLeftKeyPress ();
movementKeyPressed = true;
//all presses we need
bool movementKeyPressed = false;
bool rush = sf::Keyboard::isKeyPressed (sf::Keyboard::LShift);
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Right))
{
onRightKeyPress (100 + (rush? 50 : 0));
movementKeyPressed = true;
}
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Left))
{
onLeftKeyPress (100 + (rush? 50 : 0));
movementKeyPressed = true;
}
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Up))
onUpKeyPress ();
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Down))
onDownKeyPress (100);
if (!movementKeyPressed)
onNoMovementKeyPress ();
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Space) && !rush)
onSpacePress ();
if(sf::Keyboard::isKeyPressed (sf::Keyboard::Key::R))
{
++restartTicks;
if (restartTicks == restartTicksReq)
{
restartTicks = 0;
onRPress ();
}
}
else
restartTicks = 0;
}
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Up))
onUpKeyPress ();
if (sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Down))
onDownKeyPress ();
if (!movementKeyPressed)
onNoMovementKeyPress ();
}

bool Controller::isPressed (sf::Keyboard::Key key)
Expand All @@ -68,3 +124,21 @@ bool Controller::isEnd ()
{
return sf::Keyboard::isKeyPressed (sf::Keyboard::Key::Escape);
}

void Controller::onMapChange(const char* mapName) {
view->changeMap(mapName);
}

void Controller::onCoinPicked() {
view->onCoinPick();
}

void Controller::onDieBot(Actor* obj)
{
view->onDieBot(obj);
}

void Controller::onShot()
{
view->onShot();
}
22 changes: 19 additions & 3 deletions AtomGame/controller/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@

class View;

class Model;

class Controller
{
public:

Controller (Model *, View *);

void onRightKeyPress ();
void onRightKeyPress (float stregth);

void onLeftKeyPress ();
void onLeftKeyPress (float stregth);

void onUpKeyPress ();

void onDownKeyPress ();
void onDownKeyPress (float stregth);

void onSpacePress();

void onRPress();

void onNoMovementKeyPress ();

Expand All @@ -33,10 +39,20 @@ class Controller

bool isEnd ();

void onMapChange(const char* mapName);

void onCoinPicked();

void onDieBot(Actor*);

void onShot();

private:
static log4cpp::Category &logger;
Model *model;
View *view;
const int restartTicksReq = 100;
int restartTicks;
};

#endif //ATOMGAME_ATOMGAME_H
Loading

0 comments on commit 18e2c32

Please sign in to comment.