From 2da23ea7be6dd20da8d7319da4db69ff9688b9e6 Mon Sep 17 00:00:00 2001 From: jonas Date: Mon, 10 Dec 2018 21:08:33 +0100 Subject: modified the demo to not trap object outside of screen, changed makefile --- AmpelJonas/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'AmpelJonas/main.cpp') diff --git a/AmpelJonas/main.cpp b/AmpelJonas/main.cpp index 343a688..d88ca9b 100644 --- a/AmpelJonas/main.cpp +++ b/AmpelJonas/main.cpp @@ -23,12 +23,23 @@ int main() b.write(); a.render(); - //usleep(10*1000); + usleep(10*1000); - if(x.getPosition().x <= 0 || x.getPosition().x >= a.getSize().x - 1) + if(x.getPosition().x <= 0) dir1 *= -1; - if(x.getPosition().y <= 0 || x.getPosition().y >= a.getSize().y) + else if(x.getPosition().x >= a.getSize().x) + { + dir1 *= -1; + x.setPosition({a.getSize().x, x.getPosition().y}); + } + + if(x.getPosition().y <= 0) + dir2 *= -1; + else if(x.getPosition().y >= a.getSize().y) + { dir2 *= -1; + x.setPosition({x.getPosition().x, a.getSize().y}); + } } a.render(); -- cgit v1.2.3