Skip to content

Commit

Permalink
it might work pls
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilhenry committed Aug 29, 2024
1 parent 38ac474 commit d4d3baa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 90 deletions.
50 changes: 0 additions & 50 deletions constants-pygbag.py

This file was deleted.

16 changes: 4 additions & 12 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,13 @@
# Sprites
SCALE_FACTOR = 3
SPRT_MARBLE = pygame.image.load(PATH_SPRITES / "marble.png") # 18x18
SPRT_MARBLE = pygame.transform.scale(
SPRT_MARBLE, (18 * SCALE_FACTOR, 18 * SCALE_FACTOR)
) # Scaling factor 3
SPRT_MARBLE = pygame.transform.scale(SPRT_MARBLE, (18 * SCALE_FACTOR, 18 * SCALE_FACTOR)) # Scaling factor 3
SPRT_BOARD = pygame.image.load(PATH_SPRITES / "board.png") # 198x198
SPRT_BOARD = pygame.transform.scale(
SPRT_BOARD, (198 * SCALE_FACTOR, 198 * SCALE_FACTOR)
) # Scaling factor 3
SPRT_BOARD = pygame.transform.scale(SPRT_BOARD, (198 * SCALE_FACTOR, 198 * SCALE_FACTOR)) # Scaling factor 3
SPRT_POSSIBLE_MOVE = pygame.image.load(PATH_SPRITES / "possible_ring.png")
SPRT_POSSIBLE_MOVE = pygame.transform.scale(
SPRT_POSSIBLE_MOVE, (18 * SCALE_FACTOR, 18 * SCALE_FACTOR)
) # Scaling factor 3
SPRT_POSSIBLE_MOVE = pygame.transform.scale(SPRT_POSSIBLE_MOVE, (18 * SCALE_FACTOR, 18 * SCALE_FACTOR)) # Scaling factor 3
SPRT_SELECTED_MARBLE = pygame.image.load(PATH_SPRITES / "select_ring.png")
SPRT_SELECTED_MARBLE = pygame.transform.scale(
SPRT_SELECTED_MARBLE, (18 * SCALE_FACTOR, 18 * SCALE_FACTOR)
) # scaling factor 3
SPRT_SELECTED_MARBLE = pygame.transform.scale(SPRT_SELECTED_MARBLE, (18 * SCALE_FACTOR, 18 * SCALE_FACTOR)) # scaling factor 3

# Sounds
SND_BG = pygame.mixer.Sound(str(PATH_AUDIO / "soundtrack.ogg"))
Expand Down
36 changes: 8 additions & 28 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@
for j in range(7):
# 198x198 board, 18x18 marbles, 36x36 is the padding before grid starts, no padding in between marbles
POS2COORD[Position(i, j)] = Coordinate(
((c.D_WIDTH // 2) - (198 * c.SCALE_FACTOR // 2))
+ (36 * c.SCALE_FACTOR)
+ (j * 18 * c.SCALE_FACTOR),
((c.D_HEIGHT // 2) - (198 * c.SCALE_FACTOR // 2))
+ (36 * c.SCALE_FACTOR)
+ (i * 18 * c.SCALE_FACTOR),
((c.D_WIDTH // 2) - (198 * c.SCALE_FACTOR // 2)) + (36 * c.SCALE_FACTOR) + (j * 18 * c.SCALE_FACTOR),
((c.D_HEIGHT // 2) - (198 * c.SCALE_FACTOR // 2)) + (36 * c.SCALE_FACTOR) + (i * 18 * c.SCALE_FACTOR),
)

# initialize pygame
Expand Down Expand Up @@ -101,20 +97,10 @@ def process_events(self) -> None:

# get which possible move is clicked (if any)
for move in self.possible_positions:
if (
POS2COORD[move].x
< event.pos[0]
< POS2COORD[move].x + 18 * c.SCALE_FACTOR
):
if (
POS2COORD[move].y
< event.pos[1]
< POS2COORD[move].y + 18 * c.SCALE_FACTOR
):
if POS2COORD[move].x < event.pos[0] < POS2COORD[move].x + 18 * c.SCALE_FACTOR:
if POS2COORD[move].y < event.pos[1] < POS2COORD[move].y + 18 * c.SCALE_FACTOR:
# move the marble
new_board = self.board.make_move(
Move(self.selected_marble.pos, move)
)
new_board = self.board.make_move(Move(self.selected_marble.pos, move))
if new_board:
self.musician.play_move_sound()
self.board = new_board
Expand All @@ -136,9 +122,7 @@ def main_loop(self):
"""

if self.selected_marble:
move_locations = self.board.get_possible_move_locations(
self.selected_marble.pos
)
move_locations = self.board.get_possible_move_locations(self.selected_marble.pos)
self.possible_positions = move_locations

def display(self):
Expand All @@ -159,13 +143,9 @@ def display(self):

rendered_text = c.FONT_MAIN.render("Brainvita", False, (0, 0, 0))
c.ROOT_DISPLAY.blit(rendered_text, (20, 50))
rendered_text = c.FONT_UI.render(
f"Moves: {self.move_count}", False, (0, 0, 0)
)
rendered_text = c.FONT_UI.render(f"Moves: {self.move_count}", False, (0, 0, 0))
c.ROOT_DISPLAY.blit(rendered_text, (20, 120))
rendered_text = c.FONT_UI.render(
f"Marbles: {self.board.num_marbles}", False, (0, 0, 0)
)
rendered_text = c.FONT_UI.render(f"Marbles: {self.board.num_marbles}", False, (0, 0, 0))
c.ROOT_DISPLAY.blit(rendered_text, (20, 150))

self.marble_list.draw(c.ROOT_DISPLAY)
Expand Down

0 comments on commit d4d3baa

Please sign in to comment.