first commit
BIN
data/images/entities/player.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
data/images/tiles/grass/0.png
Normal file
After Width: | Height: | Size: 121 B |
BIN
data/images/tiles/grass/1.png
Normal file
After Width: | Height: | Size: 121 B |
BIN
data/images/tiles/grass/2.png
Normal file
After Width: | Height: | Size: 121 B |
BIN
data/images/tiles/stone/0.png
Normal file
After Width: | Height: | Size: 122 B |
BIN
data/images/tiles/stone/1.png
Normal file
After Width: | Height: | Size: 122 B |
BIN
data/images/tiles/stone/2.png
Normal file
After Width: | Height: | Size: 121 B |
21
data/maps/map_1.csv
Normal file
@ -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
|
|
53
game.py
Normal file
@ -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()
|
BIN
scripts/__pycache__/entities.cpython-311.pyc
Normal file
BIN
scripts/__pycache__/tiles.cpython-311.pyc
Normal file
BIN
scripts/__pycache__/utils.cpython-311.pyc
Normal file
15
scripts/entities.py
Normal file
@ -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)
|
27
scripts/tiles.py
Normal file
@ -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
|
21
scripts/utils.py
Normal file
@ -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
|
12
shell.nix
Normal file
@ -0,0 +1,12 @@
|
||||
{ pkgs ? import <nixpkgs> {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
|
||||
'';
|
||||
}
|