forked from TarunTomar122/Automating-Pacman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pacman.py
113 lines (88 loc) · 2.91 KB
/
pacman.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'''
Refrences -
1. https://www.gamasutra.com/view/feature/132330/the_pacman_dossier.php?page=1
2. https://gameinternals.com/understanding-pac-man-ghost-behavior
This is an attempt to recreate pacman in pygame.
AUTHORS -
1. Rohan Singh
2. Maruf Hussain
3. Tarun Singh Tomar
This version of pacman will be used to implement
a genetic algorithm which will be able to play
pacman.
A project by Robotics Club IIT Jodhpur.
'''
__version__ = '0.23'
import pygame
import time
from utils import *
from entities import *
# Game Loop
running = True
while running:
for entity in entities[1:]:
if pacman.coordinate == entity.coordinate:
running = False
for ghost in entities[1:]:
if ghost.target == ghost.coordinate:
ghost.choose_target_tile()
for entity in entities:
if entity.coordinate == (23, 13):
entity.coordinate = (4, 13)
elif entity.coordinate == (3, 13):
entity.coordinate = (22, 13)
# RGB = Red, Green, Blue
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
i, j = pacman.coordinate
i += 1
if maze[j][i] == 0:
pacman.direction = (1, 0)
else:
pacman.tmpdirection = (1, 0)
if event.key == pygame.K_LEFT:
i, j = pacman.coordinate
i -= 1
if maze[j][i] == 0:
pacman.direction = (-1, 0)
else:
pacman.tmpdirection = (-1, 0)
if event.key == pygame.K_UP:
i, j = pacman.coordinate
j -= 1
if maze[j][i] == 0:
pacman.direction = (0, -1)
else:
pacman.tmpdirection = (0, -1)
if event.key == pygame.K_DOWN:
i, j = pacman.coordinate
j += 1
if maze[j][i] == 0:
pacman.direction = (0, 1)
else:
pacman.tmpdirection = (0, 1)
if event.type == pygame.KEYUP:
playerMove = 0
#print(pacman.coordinate)
create_maze()
if pac_upd == 30:
for entity in entities:
entity.update()
for entity in entities[1:]:
if pacman.coordinate == entity.coordinate:
running = False
pac_upd = 0
pac_upd += 1
for entity in entities:
entity.draw()
# print("Pinky", pinky.target, pacman.coordinate)
# print("Blinky",blinky.target,pacman.coordinate)
# print("inky",inky.target,pacman.coordinate)
# print("Clyde",clyde.target,pacman.coordinate)
# print( pacman.direction, pacman.tmpdirection)
pygame.display.update()
# time.sleep(0.01)