-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI.cpp
More file actions
32 lines (27 loc) · 656 Bytes
/
Copy pathAI.cpp
File metadata and controls
32 lines (27 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "AI.h"
AI::AI(Player *player, Ball *ball)
{
mTimer = Timer::Instance();
mplayer = player;
mBall = ball;
mSpeed = 500.0f;
}
void AI::HandleMovement()
{
if (mBall->mBall.y < mplayer->mPlayer.y + mplayer->mPlayer.w/2 )
{
mplayer->mPlayer.y -= 1.0f * mSpeed * mTimer->DeltaTime();
}
if (mBall->mBall.y > mplayer->mPlayer.y + mplayer->mPlayer.w / 2)
{
mplayer->mPlayer.y += 1.0f * mSpeed * mTimer->DeltaTime();
}
if (mplayer->mPlayer.y < mplayer->Upbounds)
mplayer->mPlayer.y = mplayer->Upbounds;
if (mplayer->mPlayer.y > mplayer->Downbounds)
mplayer->mPlayer.y = mplayer->Downbounds;
}
void AI::Update()
{
HandleMovement();
}