diff options
| author | aleksav013 <aleksav013@gmail.com> | 2021-06-01 21:03:32 +0200 |
|---|---|---|
| committer | aleksav013 <aleksav013@gmail.com> | 2021-06-01 21:03:32 +0200 |
| commit | dbe41a2f77774ee716d3ff45db766d6400970f57 (patch) | |
| tree | ec86f7305bcb2d3eec37bf8e123cb901f80a5a5d /src/Enemy2.cpp | |
| parent | 82d49a6825af009d950b3a6c18d609da2ef8486c (diff) | |
Splitting code; Creating Makefile
Diffstat (limited to 'src/Enemy2.cpp')
| -rw-r--r-- | src/Enemy2.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Enemy2.cpp b/src/Enemy2.cpp new file mode 100644 index 0000000..fc65942 --- /dev/null +++ b/src/Enemy2.cpp @@ -0,0 +1,30 @@ +#include"includes/Global.hpp" +#include"includes/Enemy2.hpp" +float Enemy2::time=14; +Enemy2::Enemy2(sf::Vector2f pozicija,sf::Vector2f velicina,sf::Color boja):Entity(pozicija,velicina,boja) +{ + vx=vy=0; +} +void Enemy2::izracunajbrzinu(float igracx,float igracy,float dt) +{ + float k=(igracy-y)/(igracx-x); + float r=200.0*dt; + float dx=r/std::sqrt(1+k*k); + if(igracx-x<0) dx=-dx; + float dy=k*dx; + vx+=dx; + vy+=dy; +} +void Enemy2::izracunajpoz(float igracx,float igracy,float dt) +{ + if((x+vx-igracx)*(x+vx-igracx)+(y+vy-igracy)*(y+vy-igracy)<(x-igracx)*(x-igracx)+(y-igracy)*(y-igracy)) + { + x+=vx*dt*3; + y+=vy*dt*3; + } + else + { + x+=vx*dt; + y+=vy*dt; + } +} |
