Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: grish-ka <[email protected]>

# Conflicts:
#	Player/__init__.py
  • Loading branch information
grish-ka committed Nov 10, 2024
2 parents 4443bc2 + da63b43 commit 1035d51
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
6 changes: 6 additions & 0 deletions Block/GenericBlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from Block import *
from tkinter import *

class GenericBlock:
def __init__(self, x, y, blocktype: str, canvas: Canvas):
Block.draw_block(x=x, y=y, block_id=blocktype, canvas=canvas)
19 changes: 7 additions & 12 deletions Block/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from tkinter import *

class Block:

def convert_coords_to_str(self, coords: list) -> str:
return str(str(coords[0]) + "," + str(coords[1]))

Expand All @@ -11,7 +10,7 @@ def convert_coords_to_str(self, coords: list) -> str:
"clone:air": "white"
}

def get_xy( x, y):
def get_xy(x, y):
start_x = 20
start_y = 20
width = 20
Expand All @@ -23,23 +22,19 @@ def decon_xy(x, y):
width = 20
return x * width + start_x, y * width + start_y



blocks = [
["clone:dirt", "clone:grass_block", "clone:dirt"],
["clone:dirt", "clone:dirt", "clone:dirt"],
["clone:dirt", "clone:grass_block", "clone:dirt"],
["clone:dirt", "clone:dirt", "clone:dirt"]
]

def draw_block( x: int, y: int, block_id: str, canvas: Canvas):
def draw_block(x: int, y: int, block_id: str, canvas: Canvas):
block = Block.block_ids[block_id]
xy: tuple = Block.get_xy(x=x, y=y)
canvas.create_rectangle(xy[0], xy[1], 39, 39, fill=block, outline=block)
xy = Block.get_xy(x, y)
canvas.create_rectangle(xy[0], xy[1], xy[0]+19, xy[1]+19, fill=block, outline=block)

def draw_blocks(self, canvas: Canvas):
for x in range(len(self.blocks)):
for y in range(len(self.blocks)):
for y in range(len(self.blocks[x])):
print(self.blocks[x][y], "at", x, y)
self.draw_block(x=x, y=y, block_id=self.blocks[x][y], canvas=canvas)


self.draw_block(x, y, self.blocks[x][y], canvas)
20 changes: 16 additions & 4 deletions Player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def move_left(self):
print("Pressed enter")

Block.draw_block(x=self.coords[0], y=self.coords[1], block_id="clone:air", canvas=self.canvas)
self.coords=[self.coords[0] + 1, self.coords[1]]
self.coords=[self.coords[0]+1, self.coords[1]]
self.draw_player(self.coords[0], self.coords[1])


Expand All @@ -23,13 +23,15 @@ def convert_coords_to_str(self, coords: list) -> str:

def move(self, root: Tk):
canvas = self.canvas
# root.bind("<Return>", self.move_left())
# root.bind("<KeyPress-Down>", self.move_down())
root.bind("<Right>", lambda event:self.move_left())
root.bind("<KeyPress-Left>", lambda event: self.move_right())
root.bind("<KeyPress-Up>", lambda event: self.move_up())
root.bind("<KeyPress-Down>", lambda event:self.move_down())

def draw_player(self, x, y):
canvas = self.canvas
xy = Block.get_xy(x, y)
self.player: canvas.create_rectangle = canvas.create_rectangle(xy[0], xy[1], 39, 39,
self.player: canvas.create_rectangle = canvas.create_rectangle(xy[0], xy[1], xy[0]+19, xy[1]+19,
fill="blue", outline="blue")

def move_down(self):
Expand All @@ -39,3 +41,13 @@ def move_down(self):

def draw(self, root: Tk):
self.move(root)

def move_right(self):
Block.draw_block(x=self.coords[0], y=self.coords[1], block_id="clone:air", canvas=self.canvas)
self.coords = [self.coords[0]-1, self.coords[1]]
self.draw_player(self.coords[0], self.coords[1])

def move_up(self):
Block.draw_block(x=self.coords[0], y=self.coords[1], block_id="clone:air", canvas=self.canvas)
self.coords = [self.coords[0], self.coords[1]-1]
self.draw_player(self.coords[0], self.coords[1])
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ def draw_rows(size: int = 17, height: float = 20, width: float = 20):
raise GridNotFound.GridNotFound("Grid Not Found")
draw_columns(chunk_size)
draw_rows(chunk_size)
Block.draw_block(x=0, y=1, block_id="clone:grass_block", canvas=canvas)
# player = Player(canvas)
player = Player(canvas)


while True:

# player.draw(tk)
player.draw(tk)
tk.update()


Expand Down

0 comments on commit 1035d51

Please sign in to comment.