Skip to content

Commit

Permalink
Created Game Structure - Part 22 - Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
karpo27 committed May 15, 2023
1 parent d8944a4 commit 662e289
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 126 deletions.
46 changes: 0 additions & 46 deletions controls.py

This file was deleted.

37 changes: 0 additions & 37 deletions credits.py

This file was deleted.

6 changes: 1 addition & 5 deletions main_menu.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Scripts:
import constants
from base_state import BaseState
from submenus import Options
from audio import Audio
from controls import Controls
from credits import Credits
from submenus import Options, Controls, Credits
from pointer import Pointer
from background_creator import *
from text_creator import *
Expand Down Expand Up @@ -32,7 +29,6 @@ def __init__(self):
(WIDTH/2, HEIGHT/3), "GAME PROJECT", 70)
# Initialize Classes:
self.options = Options()
self.audio = Audio()
self.controls = Controls()
self.credits = Credits()
self.pointer = Pointer()
Expand Down
7 changes: 3 additions & 4 deletions pause.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Scripts:
from constants import *
from base_state import BaseState
from submenus import Options
from audio import Audio
from controls import Controls
from submenus import Options, Controls
from pointer import Pointer
from background_creator import *

Expand Down Expand Up @@ -33,7 +31,6 @@ def __init__(self):

# Initialize Classes:
self.options = Options()
self.audio = Audio()
self.controls = Controls()
self.pointer = Pointer()

Expand All @@ -55,12 +52,14 @@ def handle_action(self):
elif self.index == 1:
self.screen = "CONTROLS"
self.index = 0
self.options_qty = 0
elif self.index == 2:
self.index = 1
self.screen = "PAUSE"
elif self.screen == "CONTROLS":
self.index = 1
self.screen = "OPTIONS"
self.options_qty = 2

def get_event(self, event):
# Pause Menu Movement:
Expand Down
55 changes: 21 additions & 34 deletions submenus.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ class Controls(BaseState):
def __init__(self):
# Screen Text and Options:
super().__init__()
# self.font_size = 26
# self.margin = 40
self.pos_left = self.left_x, self.left_y = WIDTH / 3, HEIGHT / 3 - 80
self.pos_right = self.left_x + 300, self.left_y
self.text_left = ["Forward", "Back", "Left", "Right", "Fire", "Switch Weapon"]
self.text_right = ["W / ARROW UP", "S / ARROW DOWN", "A / ARROW LEFT", "D / ARROW RIGHT", "SPACE", "ENTER"]
self.controls = []
self.controls.append(TextCreator(self.index, "BACK", 'freesansbold.ttf', 48, 48, (255, 255, 255), (193, 225, 193),
self.controls.append(TextCreator(self.index, "BACK", self.font_type, 48, 48, self.base_color, self.hover_color,
(WIDTH / 2, 5 / 6 * HEIGHT), "", 50), )
for index, text in enumerate(self.text_left):
self.controls.append(
Expand All @@ -40,34 +38,23 @@ def __init__(self):
TextCreator(index + 1, text, self.font_type, 26, 52, self.base_color, self.hover_color, self.pos_right,
self.text_right[0], 40))

'''
self.controls = [
TextCreator(0, "BACK",
'freesansbold.ttf', 48, 48, (255, 255, 255), (193, 225, 193),
(WIDTH / 2, 5 / 6 * HEIGHT), "", 50),
TextCreator(1, "Forward", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.left_x, self.left_y), "Forward", self.margin),
TextCreator(2, "Back", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.left_x, self.left_y), "Forward", self.margin),
TextCreator(3, "Left", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.left_x, self.left_y), "Forward", self.margin),
TextCreator(4, "Right", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.left_x, self.left_y), "Forward", self.margin),
TextCreator(5, "Fire", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.left_x, self.left_y), "Forward", self.margin),
TextCreator(6, "Switch Weapon", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.left_x, self.left_y), "Forward", self.margin),
TextCreator(1, "W / ARROW UP", 'freesansbold.ttf', self.font_size, 48, (255, 255, 255), (193, 225, 193),
(self.right_x, self.left_y), "W / ARROW UP", self.margin),
TextCreator(2, "S / ARROW DOWN", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.right_x, self.left_y), "W / ARROW UP", self.margin),
TextCreator(3, "A / ARROW LEFT", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.right_x, self.left_y), "W / ARROW UP", self.margin),
TextCreator(4, "D / ARROW RIGHT", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.right_x, self.left_y), "W / ARROW UP", self.margin),
TextCreator(5, "SPACE", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.right_x, self.left_y), "W / ARROW UP", self.margin),
TextCreator(6, "ENTER", 'freesansbold.ttf', self.font_size, 94, (255, 255, 255), (193, 225, 193),
(self.right_x, self.left_y), "W / ARROW UP", self.margin),
]
'''

class Credits(BaseState):
def __init__(self):
# Screen Text and Options:
super().__init__()
self.pos = self.pos_x, self.pos_y = WIDTH / 2, HEIGHT / 3
self.text = ["May 2023", "Game Project is a Python game developed by me: Julian Giudice (github.com/karpo27).",
"It's my first game since I started learning Python 6 months ago.",
"I want to thank Pygame for allowing me to use this module,",
"and allow so many users to code their games.",
"I'll keep coding and trying myself harder to incorporate to the IT world."]
self.credits = []
self.credits.append(TextCreator(self.index, "BACK", self.font_type, 48, 48, self.base_color, self.hover_color,
(WIDTH / 2, 5 / 6 * HEIGHT), "", 50))
for index, text in enumerate(self.text):
self.credits.append(
TextCreator(index + 1, text, self.font_type, 22, 52, self.base_color, self.hover_color, self.pos,
"", 40))


0 comments on commit 662e289

Please sign in to comment.