From: Skullheadx <94652084+Skullheadx@users.noreply.github.com>
Date: Mon, 21 Nov 2022 20:41:24 +0000 (-0500)
Subject: tile, board, font, word making
X-Git-Url: http://git.skullheadx.com/sitemap.xml?a=commitdiff_plain;h=705df82a3366ad4f17198f95032a14170601e92e;p=word-hunt.git
tile, board, font, word making
---
diff --git a/.idea/misc.xml b/.idea/misc.xml
index a4652f3..d8a3dd8 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/.idea/word-hunt.iml b/.idea/word-hunt.iml
index 68d1b4d..bfd0b6b 100644
--- a/.idea/word-hunt.iml
+++ b/.idea/word-hunt.iml
@@ -3,8 +3,9 @@
+
-
+
\ No newline at end of file
diff --git a/Main/__pycache__/board.cpython-310.pyc b/Main/__pycache__/board.cpython-310.pyc
new file mode 100644
index 0000000..67a9d2c
Binary files /dev/null and b/Main/__pycache__/board.cpython-310.pyc differ
diff --git a/Main/__pycache__/game.cpython-310.pyc b/Main/__pycache__/game.cpython-310.pyc
new file mode 100644
index 0000000..2b5d001
Binary files /dev/null and b/Main/__pycache__/game.cpython-310.pyc differ
diff --git a/Main/__pycache__/setup.cpython-310.pyc b/Main/__pycache__/setup.cpython-310.pyc
index f71793c..68b6028 100644
Binary files a/Main/__pycache__/setup.cpython-310.pyc and b/Main/__pycache__/setup.cpython-310.pyc differ
diff --git a/Main/__pycache__/tile.cpython-310.pyc b/Main/__pycache__/tile.cpython-310.pyc
new file mode 100644
index 0000000..cb06862
Binary files /dev/null and b/Main/__pycache__/tile.cpython-310.pyc differ
diff --git a/Main/board.py b/Main/board.py
new file mode 100644
index 0000000..1c2c042
--- /dev/null
+++ b/Main/board.py
@@ -0,0 +1,49 @@
+import pygame
+
+from setup import *
+from tile import Tile
+
+
+class Board:
+
+ def __init__(self,position, length, width):
+ self.position = pygame.Vector2(position)
+ self.length = length
+ self.width = width
+ self.board = [[Tile((self.position.x + i * Tile.side_length,self.position.y + j * Tile.side_length)) for j in range(self.width)][:] for i in range(self.length)]
+
+ self.tiles = []
+ for i in range(self.length):
+ for j in range(self.width):
+ self.tiles.append(self.board[i][j])
+ self.last_selected = None
+
+ def update(self, delta):
+ letter = ""
+ for tile in self.tiles:
+ if self.last_selected is None:
+
+ l = tile.update(delta,tile.neighbors)
+ else:
+ l = tile.update(delta,self.last_selected.neighbors)
+ if l != "":
+ letter += l
+ self.last_selected = tile
+
+
+ if not pygame.mouse.get_pressed(3)[0]: # mouse not down
+ for tile in self.tiles:
+ tile.reset()
+ self.last_selected = None
+
+ return letter
+
+ def draw(self, surf):
+ pygame.draw.rect(surf,Colour.BLACK,pygame.Rect(self.position-pygame.Vector2(Tile.bezel/2), (self.length * Tile.side_length+Tile.bezel, self.width*Tile.side_length +Tile.bezel)))
+ for tile in self.tiles:
+ tile.draw(surf)
+ # debug
+ # if self.last_selected is not None:
+ # for i in self.last_selected.neighbors:
+ # pygame.draw.rect(surf,Colour.BLUE,pygame.Rect(i,(Tile.side_length,Tile.side_length)),3)
+
diff --git a/Main/font/Silkscreen-Regular.ttf b/Main/font/Silkscreen-Regular.ttf
new file mode 100644
index 0000000..e087e17
Binary files /dev/null and b/Main/font/Silkscreen-Regular.ttf differ
diff --git a/Main/game.py b/Main/game.py
new file mode 100644
index 0000000..2f3b535
--- /dev/null
+++ b/Main/game.py
@@ -0,0 +1,25 @@
+import pygame
+
+from setup import *
+from tile import Tile
+from board import Board
+
+class Game:
+ font = pygame.font.Font("font/Silkscreen-Regular.ttf", 40)
+
+ def __init__(self):
+ self.board = Board(center - pygame.Vector2(2 * Tile.side_length),4,4)
+ self.word = ""
+ self.word_display = self.font.render(self.word,True,Colour.BLACK,Colour.LIGHT_GRAY)
+
+ def update(self, delta):
+ self.word += self.board.update(delta)
+ if not pygame.mouse.get_pressed(3)[0]: # mouse not down
+ self.word = ""
+
+ self.word_display = self.font.render(self.word,True,Colour.BLACK,Colour.LIGHT_GRAY)
+
+
+ def draw(self, surf):
+ self.board.draw(surf)
+ surf.blit(self.word_display, self.word_display.get_rect(center=(center.x,SCREEN_HEIGHT/5)))
diff --git a/Main/main.py b/Main/main.py
index 8bc2939..beee3c6 100644
--- a/Main/main.py
+++ b/Main/main.py
@@ -1,13 +1,22 @@
+import pygame.time
+
from setup import *
+from game import Game
+
+scene = Game()
is_running = True
+delta = 1000/fps
while is_running:
screen.fill(Colour.WHITE)
-
if pygame.event.peek(pygame.QUIT):
is_running = False
+ scene.update(delta)
+ scene.draw(screen)
+
pygame.display.update()
+ delta = clock.tick(fps)
\ No newline at end of file
diff --git a/Main/setup.py b/Main/setup.py
index dc7b654..a04d5c7 100644
--- a/Main/setup.py
+++ b/Main/setup.py
@@ -1,4 +1,6 @@
import json
+import string
+
import pygame
import random
@@ -9,13 +11,22 @@ with open("pruned_words.json", 'r') as f:
pygame.init()
-# SCREEN_WIDTH, SCREEN_HEIGHT = 720, 720
-# dimensions = pygame.Vector2(SCREEN_WIDTH, SCREEN_HEIGHT)
-# center = pygame.Vector2(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)
-screen = pygame.display.set_mode((0,0), pygame.RESIZABLE)
+SCREEN_WIDTH, SCREEN_HEIGHT = 720, 720
+dimensions = pygame.Vector2(SCREEN_WIDTH, SCREEN_HEIGHT)
+center = pygame.Vector2(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)
+screen = pygame.display.set_mode(dimensions, pygame.RESIZABLE)
pygame.display.set_caption("Word Hunt")
+clock = pygame.time.Clock()
+fps = 60
+alphabet = string.ascii_lowercase
class Colour:
WHITE = (255,255,255)
+ GRAY = (255/2,255/2,255/2)
+ LIGHT_GRAY = (255*2/3,255*2/3,255*2/3)
+ BLACK = (0,0,0)
+ RED = (255, 0, 0)
+ GREEN = (0,255,0)
+ BLUE = (0,0,255)
diff --git a/Main/tile.py b/Main/tile.py
new file mode 100644
index 0000000..82cd3de
--- /dev/null
+++ b/Main/tile.py
@@ -0,0 +1,47 @@
+import pygame.mouse
+
+from setup import *
+
+class Tile:
+ side_length = 80
+ bezel = 5
+ cutoff = 7.5
+ font = pygame.font.Font("font/Silkscreen-Regular.ttf", 20)
+
+ def __init__(self, position):
+ self.position = pygame.Vector2(position)
+ self.selected = False
+ self.letter = random.choice(alphabet)
+ self.text = self.font.render(self.letter,True, Colour.BLACK)
+ self.neighbors = []
+ for i in range(-1,2):
+ for j in range(-1,2):
+ self.neighbors.append(self.position + pygame.Vector2(i * self.side_length, j * self.side_length))
+
+ def update(self, delta, neighbors):
+ if not self.selected and pygame.mouse.get_pressed()[0] and self.get_collision_rect().collidepoint(pygame.mouse.get_pos()) and self.position in neighbors:
+ self.selected = True
+ return self.letter
+ return ""
+
+ def reset(self):
+ self.selected = False
+
+ def get_rect(self):
+ return pygame.Rect(self.position,(self.side_length, self.side_length))
+
+ def get_collision_rect(self):
+ return pygame.Rect(self.position + pygame.Vector2(self.cutoff), pygame.Vector2(self.side_length) - pygame.Vector2(2 * self.cutoff))
+
+ def draw(self, surf):
+ if self.selected:
+ pygame.draw.rect(surf, Colour.LIGHT_GRAY, self.get_rect())
+ else:
+ pygame.draw.rect(surf, Colour.GRAY, self.get_rect())
+ pygame.draw.rect(surf,Colour.BLACK,self.get_rect(),self.bezel)
+
+ # debug
+ # pygame.draw.rect(surf, Colour.RED, self.get_collision_rect())
+
+ # letter
+ surf.blit(self.text,self.text.get_rect(center = (self.position.x + self.side_length/2, self.position.y + self.side_length/2)))