aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoisis <moisis.george@yahoo.com>2023-05-17 17:22:32 +0300
committerMoisis <moisis.george@yahoo.com>2023-05-17 17:22:32 +0300
commit55efbb61eb7dfb7b8f1faf5de55b239e270d12e4 (patch)
treeea0c008b80e1c7ad5772cfba9643e9b798281916
parent3d7e3d1eba26cc57b31337b0708fce3747f8a988 (diff)
downloadMacpan-55efbb61eb7dfb7b8f1faf5de55b239e270d12e4.tar.xz
Macpan-55efbb61eb7dfb7b8f1faf5de55b239e270d12e4.zip
Added SCORE
-rw-r--r--src/GUIbutton.py136
-rw-r--r--src/MacPan.py68
-rw-r--r--src/game_state.py2
3 files changed, 101 insertions, 105 deletions
diff --git a/src/GUIbutton.py b/src/GUIbutton.py
index 2c75a9c..32303a2 100644
--- a/src/GUIbutton.py
+++ b/src/GUIbutton.py
@@ -1,68 +1,82 @@
+import pygame.display
class Button():
- def __init__(self, image, pos, text_input, font, base_color, hovering_color):
- self.image = image
- self.x_pos = pos[0]
- self.y_pos = pos[1]
- self.font = font
- self.base_color, self.hovering_color = base_color, hovering_color
- self.text_input = text_input
- self.text = self.font.render(self.text_input, True, self.base_color)
- if self.image is None:
- self.image = self.text
- self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
- self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
-
- def update(self, screen):
- if self.image is not None:
- screen.blit(self.image, self.rect)
- screen.blit(self.text, self.text_rect)
-
- def checkForInput(self, position):
- if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
- return True
- return False
-
- def changeColor(self, position):
- if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
- self.text = self.font.render(self.text_input, True, self.hovering_color)
- else:
- self.text = self.font.render(self.text_input, True, self.base_color)
+ def __init__(self, image, pos, text_input, font, base_color, hovering_color):
+ self.image = image
+ self.x_pos = pos[0]
+ self.y_pos = pos[1]
+ self.font = font
+ self.base_color, self.hovering_color = base_color, hovering_color
+ self.text_input = text_input
+ self.text = self.font.render(self.text_input, True, self.base_color)
+ if self.image is None:
+ self.image = self.text
+ self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
+ self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
+
+ def update(self, screen):
+ if self.image is not None:
+ screen.blit(self.image, self.rect)
+ screen.blit(self.text, self.text_rect)
+
+ def checkForInput(self, position):
+ if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
+ self.rect.bottom):
+ return True
+ return False
+
+ def changeColor(self, position):
+ if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
+ self.rect.bottom):
+ self.text = self.font.render(self.text_input, True, self.hovering_color)
+ else:
+ self.text = self.font.render(self.text_input, True, self.base_color)
+
class ToggleSwitch():
- def __init__(self, image, pos, text_input, font, base_color, hovering_color):
- self.image = image
- self.x_pos = pos[0]
- self.y_pos = pos[1]
- self.font = font
- self.base_color, self.hovering_color = base_color, hovering_color
- self.text_input = text_input
- self.text = self.font.render(self.text_input, True, self.base_color)
- if self.image is None:
- self.image = self.text
- self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
- self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
-
- def update(self, screen):
- if self.image is not None:
- screen.blit(self.image, self.rect)
- screen.blit(self.text, self.text_rect)
-
- def checkForInput(self, position):
- if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
- self.rect.bottom):
- return True
- return False
-
- def changeColor(self, position):
- if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
- self.rect.bottom):
- self.text = self.font.render(self.text_input, True, self.hovering_color)
- else:
- self.text = self.font.render(self.text_input, True, self.base_color)
-
- def changeimage(self, image):
- self.image = image
+
+ def __init__(self, image, pos, text_input, font, base_color, hovering_color):
+ super(ToggleSwitch, self).__init__()
+ self.image = image
+ self.x_pos = pos[0]
+ self.y_pos = pos[1]
+ self.font = font
+ self.base_color, self.hovering_color = base_color, hovering_color
+ self.text_input = text_input
+ self.text = self.font.render(self.text_input, True, self.base_color)
+ if self.image is None:
+ self.image = self.text
+ self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
+ self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))
+
+ def update(self, screen):
+ if self.image is not None:
+ screen.blit(self.image, self.rect)
+ screen.blit(self.text, self.text_rect)
+
+ def checkForInput(self, position):
+ if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
+ self.rect.bottom):
+ return True
+ return False
+
+ # def changeColor(self, position):
+ # if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,
+ # self.rect.bottom):
+ # self.text = self.font.render(self.text_input, True, self.hovering_color)
+ # else:
+ # self.text = self.font.render(self.text_input, True, self.base_color)
+
+ def changetext1(self):
+ # if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top,self.rect.bottom) :
+ self.text = self.font.render("Debug Mode is ON", True, self.hovering_color)
+ # else:
+ def changetext2(self):
+ self.text = self.font.render("Debug Mode is OFF", True, self.base_color)
+
+
+
+
diff --git a/src/MacPan.py b/src/MacPan.py
index f23b752..d6297c6 100644
--- a/src/MacPan.py
+++ b/src/MacPan.py
@@ -2,10 +2,10 @@ import pygame
import sys
from GUIbutton import Button, ToggleSwitch
-from src.game import Game
+from game import Game
import ctypes
-from src.settings import Settings, settings
+from settings import Settings, settings
# icon on taskbar
@@ -32,33 +32,6 @@ def get_font(size, number): # Returns Press-Start-2P in the desired size
return pygame.font.Font("../assets/PAC-FONT.TTF", size)
-# def play():
-# while True:
-# PLAY_MOUSE_POS = pygame.mouse.get_pos()
-#
-# SCREEN.fill("black")
-#
-# PLAY_TEXT = get_font(45).render("This is the PLAY screen.", True, "White")
-# PLAY_RECT = PLAY_TEXT.get_rect(center=(640, 260))
-# SCREEN.blit(PLAY_TEXT, PLAY_RECT)
-#
-# PLAY_BACK = Button(image=None, pos=(640, 460),
-# text_input="BACK", font=get_font(75), base_color="White", hovering_color="Green")
-#
-# PLAY_BACK.changeColor(PLAY_MOUSE_POS)
-# PLAY_BACK.update(SCREEN)
-#
-# for event in pygame.event.get():
-# if event.type == pygame.QUIT:
-# pygame.quit()
-# sys.exit()
-# if event.type == pygame.MOUSEBUTTONDOWN:
-# if PLAY_BACK.checkForInput(PLAY_MOUSE_POS):
-# main_menu()
-#
-# pygame.display.update()
-
-## Todo options sound options here ??
def options():
while True:
OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
@@ -73,21 +46,22 @@ def options():
text_input="BACK", font=get_font(75, 1), base_color="white", hovering_color="yellow")
Debug_Mode = ToggleSwitch(image=pygame.image.load('../assets/Quit Rect.png'), pos=(300, 300),
- text_input="Debug Mode", font=get_font(20, 1), base_color="Black",
+ text_input="Debug Mode is OFF", font=get_font(20, 1), base_color="Black",
hovering_color="cyan")
Sound_Mode = ToggleSwitch(image=pygame.image.load('../assets/Quit Rect.png'), pos=(900, 300),
text_input="Sound ", font=get_font(20, 1), base_color="Black",
hovering_color="cyan")
- # Debug_Mode_RECT = Debug_Mode.get_rect(center=(640, 150))
- # SCREEN.blit(Debug_Mode_RECT,Debug_Mode)
+ # Debug_Mode_RECT = Debug_Mode.text.get_rect(center=(640, 150))
OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
OPTIONS_BACK.update(SCREEN)
- Debug_Mode.changeColor(OPTIONS_MOUSE_POS)
+ # Debug_Mode.changetext(OPTIONS_MOUSE_POS)
+ # Debug_Mode.changeColor(OPTIONS_MOUSE_POS)
Debug_Mode.update(SCREEN)
- Sound_Mode.changeColor(OPTIONS_MOUSE_POS)
+ #
+ # #Sound_Mode.changeColor(OPTIONS_MOUSE_POS)
Sound_Mode.update(SCREEN)
for event in pygame.event.get():
@@ -97,24 +71,33 @@ def options():
if event.type == pygame.MOUSEBUTTONDOWN:
if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
main_menu()
+ pygame.display.update()
elif Debug_Mode.checkForInput(OPTIONS_MOUSE_POS):
- if lolsettings.debug :
+ if lolsettings.debug:
lolsettings.debug = False
- Debug_Mode.image = (pygame.image.load('../assets/Quit Rect.png'))
+ # Debug_Mode.update_image2(pygame.image.load('../assets/Quit Rect.png'))
+ # pygame.display.update()
+ Debug_Mode.changetext1()
Debug_Mode.update(SCREEN)
- options()
+ print(Debug_Mode.text_input)
+ print("Debug State :")
+ print(lolsettings.debug)
else:
lolsettings.debug = True
- Debug_Mode.image = (pygame.image.load('../assets/greenboxz.png'))
+ Debug_Mode.changetext2()
Debug_Mode.update(SCREEN)
+ pygame.display.update()
+ print("Debug State :")
+ print(lolsettings.debug)
+
elif Sound_Mode.checkForInput(OPTIONS_MOUSE_POS):
- if lolsettings.sound :
- lolsettings.sound=False
+ if lolsettings.sound:
+ lolsettings.sound = False
+ print(lolsettings.sound)
else:
lolsettings.sound = True
-
-
+ print(lolsettings.sound)
pygame.display.update()
@@ -149,7 +132,6 @@ def main_menu():
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
- # play()
game = Game(lolsettings)
game.run()
if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
diff --git a/src/game_state.py b/src/game_state.py
index 41e7985..d942ae1 100644
--- a/src/game_state.py
+++ b/src/game_state.py
@@ -32,7 +32,7 @@ class GameState():
self.is_pacman_alive = True
def reset(self, sprites ,settings):
- self.pacman = Player(sprites[0])
+ self.pacman = Player(sprites[0],settings)
self.blinky = Blinky(sprites[1], 12 * TILE_WIDTH +
15, 12 * TILE_HEIGHT + 15,settings)
self.pinky = Pinky(sprites[2], 11 * TILE_WIDTH +