Untitled
unknown
c_cpp
3 years ago
2.4 kB
5
Indexable
#include<iostream>
#include "function.h"
using namespace std;
// [TODO]
void Field::handleBallKicked(int dx, int dy){
bool isXbound = false;
bool isYbound = false;
if(dx == 0) isXbound = true;
if(dy == 0) isYbound = true;
while(true){
if(isXbound == false)
ball->SetX(ball->GetX() + dx);
if(isYbound == false)
ball->SetY(ball->GetY() + dy);
if(ball->GetX() < 0){
ball->SetX(0);
isXbound = true;
}
if(ball->GetX() > n-1){
ball->SetX(n-1);
isXbound = true;
}
if(ball->GetY() < 0){
ball->SetY(0);
isYbound = true;
}
if(ball->GetY() > m-1){
ball->SetY(m-1);
isYbound = true;
}
if(isYbound == true && isXbound == true){
break;
}
if(SomeoneIsHere(ball->GetX(), ball->GetY()) == true){
break;
}
}
}
// [TODO]
void Field::handleBallKickedRebounce(int dx, int dy){
bool bounced = false;
bool xbounced = false, ybounced = false;
while(true){
ball->SetX(ball->GetX() + dx);
ball->SetY(ball->GetY() + dy);
if(ball->GetX() <= 0){
ball->SetX(0);
if(bounced == false){
dx *= -1;
xbounced = true;
}
else dx = 0;
}
if(ball->GetX() >= n-1){
ball->SetX(n-1);
if(bounced == false){
dx *= -1;
xbounced = true;
}
else dx = 0;
}
if(ball->GetY() <= 0){
ball->SetY(0);
if(bounced == false){
dy *= -1;
ybounced = true;
}
else dy = 0;
}
if(ball->GetY() >= m-1){
ball->SetY(m-1);
if(bounced == false){
dy *= -1;
ybounced = true;
}
else dy = 0;
}
if(xbounced == true || ybounced == true)
bounced = true;
if(dx == 0 && dy == 0 && bounced == true){
break;
}
if(SomeoneIsHere(ball->GetX(), ball->GetY()) == true){
break;
}
}
}Editor is loading...