-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89db8a1
commit 583b830
Showing
8 changed files
with
235 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#ifndef _AI_H_ | ||
#define _AI_H_ | ||
#include <list> | ||
#include "Ball.h" | ||
#include "Animation.h" | ||
|
||
class Snace { | ||
Sprite *sprite; | ||
}; | ||
|
||
|
||
class BallAnim { | ||
Ball* ball; | ||
MovingPathAnimation* BallAnimation; | ||
MovingPathAnimator* BallAnimator; | ||
|
||
public: | ||
Ball * GetBall() { | ||
return ball; | ||
} | ||
MovingPathAnimation* GetBallAnimation() { | ||
return BallAnimation; | ||
} | ||
MovingPathAnimator* GetBallAnimator() { | ||
return BallAnimator; | ||
} | ||
BallAnim(Ball* ball, MovingPathAnimation* BallAnimation, MovingPathAnimator* BallAnimator) { | ||
this->ball = ball; | ||
this->BallAnimation = BallAnimation; | ||
this->BallAnimator = BallAnimator; | ||
} | ||
}; | ||
|
||
class AI { | ||
list<BallAnim*> Balls; | ||
Snace *snace; | ||
unsigned delay = 3700; | ||
unsigned long lastTime; | ||
static int sum; | ||
|
||
public: | ||
void logic(unsigned long currTime) { | ||
srand(time(0)); | ||
while (currTime > lastTime && currTime - lastTime >= delay && (BallsWithState(ANIMATOR_RUNNING)+ BallsWithState(ANIMATOR_READY)) < 3 ){ | ||
int col = rand() % 2 + 1; | ||
BallAnim* ballAnim = nullptr; | ||
if (BallsWithState(ANIMATOR_FINISHED)) { // + BallsWithState(ANIMATOR_STOPPED) | ||
for (auto i = Balls.begin(); i != Balls.end(); ++i) { | ||
if ((*i)->GetBallAnimator()->GetState() == ANIMATOR_FINISHED) { | ||
ballAnim = (*i); | ||
ballAnim->GetBallAnimator()->SetState(ANIMATOR_READY); | ||
ballAnim->GetBall()->SetX(330 +((col - 1) * 100)); | ||
ballAnim->GetBall()->SetY(140); | ||
break; | ||
} | ||
} | ||
assert(ballAnim); | ||
} | ||
else { | ||
Ball* ball = new Ball("Ball" + to_string(sum), 330 + ((col - 1) * 100), 140); | ||
|
||
|
||
list<PathEntry> path; | ||
PathEntry *p; | ||
p = new PathEntry(0, 0, 1, 1000); // current position | ||
path.push_back(*p); | ||
for (int i = 0; i < 5; ++i) { | ||
if (rand() % 2) | ||
p = new PathEntry(-50, 74, 1, 1000); // x +/- 50, y + 74; | ||
else | ||
p = new PathEntry(50, 74, 1, 1000); | ||
|
||
// thelei kai endiamesa gia na kanei omala to jump | ||
|
||
path.push_back(*p); | ||
} | ||
|
||
for (int i = 0; i < 30; ++i) { | ||
p = new PathEntry(0, 10, 1, 70); | ||
path.push_back(*p); | ||
} | ||
MovingPathAnimation* BallAnimation = new MovingPathAnimation(path, "Ball" + to_string(sum)); | ||
MovingPathAnimator* BallAnimator = new MovingPathAnimator(ball->GetSprite(), BallAnimation); | ||
ballAnim = new BallAnim(ball, BallAnimation, BallAnimator); | ||
Balls.push_back(ballAnim); | ||
} | ||
ballAnim->GetBallAnimator()->Start(game->GetGameTime()); | ||
sum++; | ||
lastTime += delay; | ||
} | ||
} | ||
|
||
int BallsWithState(animatorstate_t state) { | ||
int count = 0; | ||
for (auto i = Balls.begin(); i != Balls.end(); ++i) { | ||
if ((*i)->GetBallAnimator()->GetState() == state) ++count; | ||
} | ||
return count; | ||
} | ||
|
||
AI(unsigned long t) { | ||
snace = nullptr; | ||
lastTime = t; | ||
} | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#ifndef _BALL_H_ | ||
#define _BALL_H_ | ||
#include "Sprites.h" | ||
#include <ctime> | ||
|
||
class Ball { | ||
Sprite *sprite; | ||
public: | ||
void Create(string id, int x, int y) { | ||
AnimationFilm* film = GetFilm(); | ||
sprite = new Sprite(id, film, x, y, 38, 43, 20); | ||
spriteList.Insert(sprite); | ||
} | ||
|
||
void SetFrame(unsigned FrameNo) { | ||
sprite->SetFrame(FrameNo); | ||
} | ||
void SetX(int x) { | ||
sprite->SetX(x); | ||
} | ||
void SetY(int y) { | ||
sprite->SetY(y); | ||
} | ||
Sprite* GetSprite() { | ||
return sprite; | ||
} | ||
|
||
void Destroy(){} //!!!!!!!!!!!! kathe fora pou feygei kapoio ball apo to window | ||
|
||
AnimationFilm* GetFilm() { | ||
AnimationFilm* film = AnimationFilmHolder::Get().GetFilm("balls"); | ||
if (film == nullptr) { | ||
SDL_Rect rect; | ||
rect.x = 0; | ||
rect.y = 0; | ||
rect.h = 13; | ||
rect.w = 13; | ||
vector<SDL_Rect> boxes; | ||
boxes.push_back(rect); | ||
rect.x = 13; | ||
rect.y = 0; | ||
rect.h = 13; | ||
rect.w = 13; | ||
boxes.push_back(rect); | ||
rect.x = 26; | ||
rect.y = 0; | ||
rect.h = 13; | ||
rect.w = 10; | ||
boxes.push_back(rect); | ||
rect.x = 36; | ||
rect.y = 0; | ||
rect.h = 13; | ||
rect.w = 10; | ||
boxes.push_back(rect); | ||
rect.x = 46; | ||
rect.y = 0; | ||
rect.h = 13; | ||
rect.w = 16; | ||
boxes.push_back(rect); | ||
rect.x = 62; | ||
rect.y = 0; | ||
rect.h = 13; | ||
rect.w = 18; | ||
boxes.push_back(rect); | ||
string id = "balls"; | ||
AnimationFilmHolder::Get().Load(id, "Sprites/BallsFilm.bmp", boxes); | ||
film = AnimationFilmHolder::Get().GetFilm("balls"); | ||
} | ||
return film; | ||
} | ||
|
||
Ball(char *id, int x, int y){ | ||
Create(id, x, y); | ||
SetFrame(1); | ||
} | ||
|
||
Ball(string id, int x, int y) { | ||
Create(id, x, y); | ||
SetFrame(1); | ||
} | ||
|
||
|
||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,8 +223,6 @@ bool compare(Sprite* s1, Sprite* s2); | |
|
||
class SpriteList final { | ||
list<Sprite *> list; | ||
|
||
|
||
public: | ||
|
||
|
||
|
Oops, something went wrong.