Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored shouldChangeDirection function in class WallNutBowling in … #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/main.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/main.cpython-38.pyc
Binary file not shown.
Binary file added source/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added source/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added source/__pycache__/constants.cpython-37.pyc
Binary file not shown.
Binary file added source/__pycache__/constants.cpython-38.pyc
Binary file not shown.
Binary file added source/__pycache__/main.cpython-37.pyc
Binary file not shown.
Binary file added source/__pycache__/main.cpython-38.pyc
Binary file not shown.
Binary file added source/__pycache__/tool.cpython-37.pyc
Binary file not shown.
Binary file added source/__pycache__/tool.cpython-38.pyc
Binary file not shown.
Binary file added source/component/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added source/component/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added source/component/__pycache__/map.cpython-37.pyc
Binary file not shown.
Binary file added source/component/__pycache__/map.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added source/component/__pycache__/plant.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 1 addition & 3 deletions source/component/plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,7 @@ def handleMapYPosition(self):
self.map_y = map_y1

def shouldChangeDirection(self):
if self.init_rect.centery <= c.MAP_OFFSET_Y:
return True
elif self.init_rect.bottom + 20 >= c.SCREEN_HEIGHT:
if self.init_rect.centery <= c.MAP_OFFSET_Y or self.init_rect.bottom + 20 >= c.SCREEN_HEIGHT:
return True
return False

Expand Down
Binary file added source/state/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added source/state/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added source/state/__pycache__/level.cpython-37.pyc
Binary file not shown.
Binary file added source/state/__pycache__/level.cpython-38.pyc
Binary file not shown.
Binary file added source/state/__pycache__/mainmenu.cpython-37.pyc
Binary file not shown.
Binary file added source/state/__pycache__/mainmenu.cpython-38.pyc
Binary file not shown.
Binary file added source/state/__pycache__/screen.cpython-37.pyc
Binary file not shown.
Binary file added source/state/__pycache__/screen.cpython-38.pyc
Binary file not shown.
23 changes: 15 additions & 8 deletions source/state/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def choose(self, mouse_pos, mouse_click):
self.panel.checkCardClick(mouse_pos)
if self.panel.checkStartButtonClick(mouse_pos):
self.initPlay(self.panel.getSelectedCards())



#for when you're choosing your cards and setting up the beginning of the game
def initPlay(self, card_list):
self.state = c.PLAY
if self.bar_type == c.CHOOSEBAR_STATIC:
Expand All @@ -128,6 +130,8 @@ def initPlay(self, card_list):
self.setupZombies()
self.setupCars()


#contains logic for clicking and dragging plants onto the level map. Also handles spawning and killing of zombies
def play(self, mouse_pos, mouse_click):
if self.zombie_start_time == 0:
self.zombie_start_time = self.current_time
Expand Down Expand Up @@ -163,7 +167,7 @@ def play(self, mouse_pos, mouse_click):
self.addPlant()
elif mouse_pos is None:
self.setupHintImage()

#rendering and updating sun power-ups in-game
if self.produce_sun:
if(self.current_time - self.sun_timer) > c.PRODUCE_SUN_INTERVAL:
self.sun_timer = self.current_time
Expand All @@ -185,7 +189,7 @@ def play(self, mouse_pos, mouse_click):
self.checkPlants()
self.checkCarCollisions()
self.checkGameState()

#implementation of function that creates zombies
def createZombie(self, name, map_y):
x, y = self.map.getMapGridPos(0, map_y)
if name == c.NORMAL_ZOMBIE:
Expand All @@ -202,7 +206,7 @@ def createZombie(self, name, map_y):
def canSeedPlant(self):
x, y = pg.mouse.get_pos()
return self.map.showPlant(x, y)
#function for adding a plant to a square on the map.
def addPlant(self):
pos = self.canSeedPlant()
if pos is None:
Expand Down Expand Up @@ -266,7 +270,7 @@ def addPlant(self):
#print('addPlant map[%d,%d], grid pos[%d, %d] pos[%d, %d]' % (map_x, map_y, x, y, pos[0], pos[1]))

def setupHintImage(self):
pos = self.canSeedPlant()
pos = self.canSeedPlant() #check if a grid square is empty or occupied
if pos and self.mouse_image:
if (self.hint_image and pos[0] == self.hint_rect.x and
pos[1] == self.hint_rect.y):
Expand All @@ -283,7 +287,7 @@ def setupHintImage(self):
self.hint_plant = True
else:
self.hint_plant = False

#renders image of selected plant
def setupMouseImage(self, plant_name, select_plant):
frame_list = tool.GFX[plant_name]
if plant_name in tool.PLANT_RECT:
Expand Down Expand Up @@ -316,6 +320,7 @@ def removeMouseImage(self):
self.hint_image = None
self.hint_plant = False

#collision detection between plant bullets and zombies. bullets dont explode if they collide with a dead zombie
def checkBulletCollisions(self):
collided_func = pg.sprite.collide_circle_ratio(0.7)
for i in range(self.map_y_len):
Expand All @@ -337,6 +342,7 @@ def checkZombieCollisions(self):
for zombie in self.zombie_groups[i]:
if zombie.state != c.WALK:
continue
#check if the zombie collides with the bullet from the plant or the plant itself
plant = pg.sprite.spritecollideany(zombie, self.plant_groups[i], collided_func)
if plant:
if plant.name == c.WALLNUTBOWLING:
Expand All @@ -348,7 +354,8 @@ def checkZombieCollisions(self):
plant.setAttack()
elif plant.name != c.SPIKEWEED:
zombie.setAttack(plant)


#for when hypno zombies and zombies run into each other
for hypno_zombie in self.hypno_zombie_groups[i]:
if hypno_zombie.health <= 0:
continue
Expand Down Expand Up @@ -408,7 +415,7 @@ def killPlant(self, plant):
plant.kill()

def checkPlant(self, plant, i):
zombie_len = len(self.zombie_groups[i])
zombie_len = len(self.zombie_groups[i]) #i indexes to give number of zombies at y-co-ordinate i
if plant.name == c.THREEPEASHOOTER:
if plant.state == c.IDLE:
if zombie_len > 0:
Expand Down
2 changes: 1 addition & 1 deletion source/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def load_image_frames(directory, image_name, colorkey, accept):
tmp = {}
# image_name is "Peashooter", pic name is 'Peashooter_1', get the index 1
index_start = len(image_name) + 1
frame_num = 0;
frame_num = 0
for pic in os.listdir(directory):
name, ext = os.path.splitext(pic)
if ext.lower() in accept:
Expand Down