diff --git a/data/images/entities/player.png b/data/images/entities/player.png new file mode 100644 index 0000000..74d17fd Binary files /dev/null and b/data/images/entities/player.png differ diff --git a/data/images/tiles/grass/0.png b/data/images/tiles/grass/0.png new file mode 100644 index 0000000..19d23b1 Binary files /dev/null and b/data/images/tiles/grass/0.png differ diff --git a/data/images/tiles/grass/1.png b/data/images/tiles/grass/1.png new file mode 100644 index 0000000..f4d69f5 Binary files /dev/null and b/data/images/tiles/grass/1.png differ diff --git a/data/images/tiles/grass/2.png b/data/images/tiles/grass/2.png new file mode 100644 index 0000000..9474b87 Binary files /dev/null and b/data/images/tiles/grass/2.png differ diff --git a/data/images/tiles/stone/0.png b/data/images/tiles/stone/0.png new file mode 100644 index 0000000..8248aee Binary files /dev/null and b/data/images/tiles/stone/0.png differ diff --git a/data/images/tiles/stone/1.png b/data/images/tiles/stone/1.png new file mode 100644 index 0000000..159980e Binary files /dev/null and b/data/images/tiles/stone/1.png differ diff --git a/data/images/tiles/stone/2.png b/data/images/tiles/stone/2.png new file mode 100644 index 0000000..57a068d Binary files /dev/null and b/data/images/tiles/stone/2.png differ diff --git a/data/maps/map_1.csv b/data/maps/map_1.csv new file mode 100644 index 0000000..666a9f7 --- /dev/null +++ b/data/maps/map_1.csv @@ -0,0 +1,21 @@ +3,1,1,1,1,1,1,1,1,1,1,1,1,1,4 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +1,2,2,2,2,2,2,2,2,2,2,2,2,2,1 +5,1,1,1,1,1,1,1,1,1,1,1,1,1,6 diff --git a/game.py b/game.py new file mode 100644 index 0000000..4dd226a --- /dev/null +++ b/game.py @@ -0,0 +1,53 @@ +import pygame +import numpy as np +from scripts.tiles import Tilemap +from scripts.entities import Entity +from scripts.utils import load_image, load_images + +# SETTINGS +WIDTH = 1280 +HEIGHT = 720 +TITLE = 'YuGiOh Tag Force Clone' + +class Game: + def __init__(self): + pygame.init() + self.screen = pygame.display.set_mode((WIDTH, HEIGHT)) + self.display = pygame.Surface((WIDTH//2, HEIGHT//2)) + + pygame.display.set_caption(TITLE) + self.clock = pygame.time.Clock() + + self.player = Entity(self, 'player', (50.0,200.0), (8, 15)) + self.assets = { + 'player' : load_image('entities/player.png'), + 'grass' : load_images('tiles/grass/'), + 'stone' : load_images('tiles/stone/') + } + self.tilemap = Tilemap(self, (32,32), 'map_1.csv') + def run(self): + self.status = True + while self.status: + self.display.fill('white') + delta = np.array([0.0,0.0]) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + self.status = False + keys = pygame.key.get_pressed() + if keys[pygame.K_LEFT]: + delta[0] -= 1 + if keys[pygame.K_RIGHT]: + delta[0] += 1 + if keys[pygame.K_UP]: + delta[1] -= 1 + if keys[pygame.K_DOWN]: + delta[1] += 1 + self.player.update(delta) + self.tilemap.render(self.display) + self.player.render(self.display) + self.screen.blit(pygame.transform.scale_by(self.display,2), (0,0)) + pygame.display.update() + self.clock.tick(60) + pygame.quit() + +Game().run() diff --git a/scripts/__pycache__/entities.cpython-311.pyc b/scripts/__pycache__/entities.cpython-311.pyc new file mode 100644 index 0000000..9d4b957 Binary files /dev/null and b/scripts/__pycache__/entities.cpython-311.pyc differ diff --git a/scripts/__pycache__/tiles.cpython-311.pyc b/scripts/__pycache__/tiles.cpython-311.pyc new file mode 100644 index 0000000..4fb0084 Binary files /dev/null and b/scripts/__pycache__/tiles.cpython-311.pyc differ diff --git a/scripts/__pycache__/utils.cpython-311.pyc b/scripts/__pycache__/utils.cpython-311.pyc new file mode 100644 index 0000000..979f7c7 Binary files /dev/null and b/scripts/__pycache__/utils.cpython-311.pyc differ diff --git a/scripts/entities.py b/scripts/entities.py new file mode 100644 index 0000000..634761d --- /dev/null +++ b/scripts/entities.py @@ -0,0 +1,15 @@ +import pygame +import numpy as np + +class Entity: + def __init__(self, game, e_type, pos, size): + self.game = game + self.type = e_type + self.pos = np.array(pos) + self.size = size + self.velocity = np.array([0,0], dtype=np.float32) + def update(self, movement = np.array([0,0])): + frame_movement = self.velocity + movement + self.pos += frame_movement + def render(self, surface): + surface.blit(self.game.assets[self.type], self.pos) diff --git a/scripts/tiles.py b/scripts/tiles.py new file mode 100644 index 0000000..6741f1c --- /dev/null +++ b/scripts/tiles.py @@ -0,0 +1,27 @@ +import pygame +import numpy as np +from scripts.utils import TILE_DICT + +BASE_MAP_PATH = 'data/maps/' + +class Tilemap: + def __init__(self, game, tile_size, map_path): + self.game = game + self.tile_size = np.array(tile_size) + self.offgrid_tiles = [] + self.load_map(map_path) + def load_map(self, map_path): + print(map_path) + tile_arr = np.transpose(np.loadtxt(BASE_MAP_PATH + map_path, delimiter=',', dtype=np.int8)) + self.tilemap = np.empty_like(tile_arr, dtype = object) + for row in range(tile_arr.shape[0]): + for col in range(tile_arr.shape[1]): + type_var = TILE_DICT[tile_arr[row,col]] + self.tilemap[row,col] = {'type' : type_var[0], 'variant' : type_var[1], 'pos': np.array([row,col])} + def render(self, surface): + for x in range(self.tilemap.shape[0]): + for y in range(self.tilemap.shape[1]): + tile = self.tilemap[x,y] + surface.blit(self.game.assets[tile['type']][tile['variant']],tile['pos'] * self.tile_size) + for tile in self.offgrid_tiles: + surface.blit(self.game.assets[tile['type']][tile['variant']],tile.pos) #this tile is written offgrid so no mult by tile_size diff --git a/scripts/utils.py b/scripts/utils.py new file mode 100644 index 0000000..4b03df1 --- /dev/null +++ b/scripts/utils.py @@ -0,0 +1,21 @@ +import pygame +import os +TILE_DICT = { + 1 : ('grass',0), + 2 : ('stone',0), + 3 : ('grass',1), + 4 : ('stone',1), + 5 : ('grass',2), + 6 : ('stone',2) +} +BASE_IMG_PATH = 'data/images/' +def load_image(path): + img = pygame.image.load(BASE_IMG_PATH + path).convert() + img.set_colorkey((0,0,0)) + return img + +def load_images(path): + images = [] + for img_name in sorted(os.listdir(BASE_IMG_PATH + path)): + images.append(load_image(path + '/' + img_name)) + return images diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..334a14b --- /dev/null +++ b/shell.nix @@ -0,0 +1,12 @@ +{ pkgs ? import {config = { allowUnfree = false; cudaSupport = false;}; }}: + +pkgs.mkShell { + buildInputs = with pkgs; [ + (python311.withPackages(ps: with ps; [ pip numpy notebook tkinter pygame-ce ])) + ]; +#cudaPackages.cudatoolkit + shellHook = '' + echo "You are now using a NIX environment" + idle3.11 + ''; +}