-
Notifications
You must be signed in to change notification settings - Fork 3
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
Kostia Kotliarov
committed
Aug 30, 2017
1 parent
552bdcc
commit bfb5702
Showing
6 changed files
with
118 additions
and
128 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
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
Binary file modified
BIN
+4.06 KB
(110%)
...codeproj/project.xcworkspace/xcuserdata/kostia.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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,109 @@ | ||
#include "pacman.h" | ||
|
||
void putGhost(t_pacman *pacman, t_ghost *ghost) | ||
{ | ||
|
||
extern int map[H][W]; | ||
int lenCurrent; | ||
int lenClosest = INT_MAX; | ||
int lenFarest = 0; | ||
int mapValue; | ||
|
||
ghost->ghostMove = (t_pos){0, 0}; | ||
map[ghost->ghostPos.y][ghost->ghostPos.x] = ghost->ghostMapPreviousValue; | ||
|
||
//check move down | ||
mapValue = map[ghost->ghostPos.y + 1][ghost->ghostPos.x]; | ||
if (mapValue == 0 || mapValue == 1 || mapValue == 3 || mapValue == 4) | ||
{ | ||
if (pacman->eat == 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x - pacman->pac.x,2) + pow(ghost->ghostPos.y + 1 - pacman->pac.y,2))) < lenClosest) | ||
{ | ||
lenClosest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {0, 1}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y + 1][ghost->ghostPos.x + 0]; | ||
} | ||
else if (pacman->eat != 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x - pacman->pac.x,2) + pow(ghost->ghostPos.y + 1 - pacman->pac.y,2))) > lenFarest) | ||
{ | ||
lenFarest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {0, 1}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y + 1][ghost->ghostPos.x + 0]; | ||
} | ||
} | ||
//check move up | ||
mapValue = map[ghost->ghostPos.y - 1][ghost->ghostPos.x]; | ||
if (mapValue == 0 || mapValue == 1 || mapValue == 3 || mapValue == 4) | ||
{ | ||
if (pacman->eat == 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x - pacman->pac.x,2) + pow(ghost->ghostPos.y - 1 - pacman->pac.y,2))) < lenClosest) | ||
{ | ||
lenClosest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {0, -1}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y - 1][ghost->ghostPos.x + 0]; | ||
} | ||
else if (pacman->eat != 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x - pacman->pac.x,2) + pow(ghost->ghostPos.y - 1 - pacman->pac.y,2))) > lenFarest) | ||
{ | ||
lenFarest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {0, -1}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y - 1][ghost->ghostPos.x + 0]; | ||
} | ||
} | ||
//check move left | ||
mapValue = map[ghost->ghostPos.y][ghost->ghostPos.x + 1]; | ||
if (mapValue == 0 || mapValue == 1 || mapValue == 3 || mapValue == 4) | ||
{ | ||
if (pacman->eat == 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x + 1 - pacman->pac.x,2) + pow(ghost->ghostPos.y - pacman->pac.y,2))) < lenClosest) | ||
{ | ||
lenClosest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {1, 0}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y + 0][ghost->ghostPos.x + 1]; | ||
} | ||
else if (pacman->eat != 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x + 1 - pacman->pac.x,2) + pow(ghost->ghostPos.y - pacman->pac.y,2))) > lenFarest) | ||
{ | ||
lenFarest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {1, 0}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y + 0][ghost->ghostPos.x + 1]; | ||
} | ||
} | ||
//check move right | ||
mapValue = map[ghost->ghostPos.y][ghost->ghostPos.x - 1]; | ||
if (mapValue == 0 || mapValue == 1 || mapValue == 3 || mapValue == 4) | ||
{ | ||
if (pacman->eat == 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x - 1 - pacman->pac.x,2) + pow(ghost->ghostPos.y - pacman->pac.y,2))) < lenClosest) | ||
{ | ||
lenClosest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {-1, 0}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y + 0][ghost->ghostPos.x - 1]; | ||
} | ||
else if (pacman->eat != 0 && (lenCurrent = sqrt(pow(ghost->ghostPos.x - 1 - pacman->pac.x,2) + pow(ghost->ghostPos.y - pacman->pac.y,2))) > lenFarest) | ||
{ | ||
lenFarest = lenCurrent; | ||
ghost->ghostMove = (t_pos) {-1, 0}; | ||
ghost->ghostMapPreviousValue = map[ghost->ghostPos.y + 0][ghost->ghostPos.x - 1]; | ||
} | ||
} | ||
|
||
if (ghost->ghostMapPreviousValue == 3) | ||
{ | ||
//if U eated by ghost | ||
pacman->pacmanLives--; | ||
if (pacman->pacmanLives == 0) | ||
{ | ||
putTextMessage(pacman, "You lose"); | ||
SDL_Delay(1500); | ||
exit(0); | ||
} | ||
map[pacman->pac.y][pacman->pac.x] = 0; | ||
setDefaultPosition(pacman); | ||
pacman->pacMove = (t_pos){-1, 0}; | ||
putTextMessage(pacman, "GET READY"); | ||
sdlRenderClear(pacman); | ||
SDL_Delay(1500); | ||
ghost->ghostMapPreviousValue = 0; | ||
return ; | ||
} | ||
ghost->ghostPos.x += ghost->ghostMove.x; | ||
ghost->ghostPos.y += ghost->ghostMove.y; | ||
map[ghost->ghostPos.y][ghost->ghostPos.x] = ghost->id; | ||
ghost->ghostRect = (SDL_Rect){ghost->ghostPos.x * 30, ghost->ghostPos.y * 30, 30, 30}; | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.