Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added core/__pycache__/defines.cpython-38.pyc
Binary file not shown.
Binary file added core/__pycache__/mapManager.cpython-38.pyc
Binary file not shown.
Binary file added core/__pycache__/playerManager.cpython-38.pyc
Binary file not shown.
149 changes: 149 additions & 0 deletions core/defines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import os, sys

try:
from xml.dom.minidom import parse
except ImportError:
print( "Error: xml.dom.minidom module not found. Verify your python installation.")
sys.exit(1)

try:
import random
except ImportError:
print( "Error: random module not found. Verify your python installation.")
sys.exit(1)

try:
import pygame
except ImportError:
print( "Error: pygame module not installed. Install pygame module.") #TODO add autoinstaller
sys.exit(1)

try:
from pygame.locals import *
except ImportError:
print ("Error: pygame.locals not found. Verify your pygame installation.")
sys.exit(1)

from core.mapManager import MAP
from core.playerManager import PlayerManager

# --------------------------------------------------------
# ------------------ D E F I N E S -----------------------
# --------------------------------------------------------

PYGAME_COLOR = ((0, 0, 0),
(0, 127, 255),
(99, 175, 255),
(51, 155, 0),
(255, 190, 255),
(230, 146, 150),
(255, 255, 255),
(252, 235, 95),
(0, 0, 0),
(0, 127, 255),
(99, 175, 255),
(51, 155, 0),
(255, 190, 255),
(230, 146, 150),
(255, 255, 255),
(252, 235, 95))

COLOR_BLACK = 0
COLOR_BLUE = 1
COLOR_CYAN = 2
COLOR_GREEN = 3
COLOR_MAGENTA = 4
COLOR_RED = 5
COLOR_WHITE = 6
COLOR_YELLOW = 7
COLOR_BOLD = 8

FONT_SIZE = 5
SCREEN_SIZE = (1050, 600)

class WindowManager(object):
def __init__(self, win):
self._win = win

def centrarItemX(self, item):
screenX = 800#self._win.get_width() #logo screen is not 1044 but 800
itemX = item.get_width()
return (screenX/2)-(itemX/2)

def centrarItemY(self, item):
screenY = self._win.get_width() #logo height is always 600
itemY = item.get_width()
return (screenY/2)-(itemY/2)

pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE)
window=WindowManager(screen)

background=pygame.image.load('data/images/background/fondoNoche.png')

font=pygame.font.SysFont('Courier New', 15)
font = font.render('Press Enter to continue or Esc to Exit.', 1, (255,255,255))

logo = [
pygame.image.load(
'data/logo/titleLessOne.png'
), pygame.image.load(
'data/logo/titleLessTwo.png'
), pygame.image.load(
'data/logo/titleLessThree.png'
),
]

panel = pygame.image.load(os.path.join("data", 'gui', "SidePanel.png"))
btfont = pygame.font.Font(os.path.join("data", 'gui',
"LiberationMono-Bold.ttf"),
FONT_SIZE+12)

screen.blit(panel, (1024-224, 0))

count=0
contsprite=0

def _blit_messages():
"""
Blits player messages to the screen
"""
global screen
nb = min((SCREEN_SIZE[1] - 320) / FONT_SIZE, len(player.message))
nb=int(nb)
for i in range(nb):
col_mess = player.message[nb-i-1][1]
if col_mess > 7:
shift = 2
else:
shift = 1
screen.blit(BorderText(btfont, player.message[nb-i-1][0],
PYGAME_COLOR[col_mess], shift),
(SCREEN_SIZE[0]-250+5, 290 + i * FONT_SIZE*3))

# define map and player (im calling map as "mappa" cuz map is a python built-in func :) )
tiles=open(os.path.join('data', 'maps', 'azulejos.xml'))
mapfile = open(os.path.join('data', 'maps', 'demo.xml'))
mappa = MAP(window, screen)
mappa.LoadTiles(tiles)
mappa.MakeMap(mapfile)
print('[*] Game successfully created!')
# make the player object
player=PlayerManager(mappa, 0, 0, 40, 40)

def BorderText(font, text, coul, shift=1):
"""
Return a surface of white text with black border
"""
coul_text = (0, 0, 0)
surf_name = font.render(text, True, coul_text)
surf = pygame.Surface((surf_name.get_width() + 2 * shift + 1,
surf_name.get_height() + 2 * shift + 1),
pygame.SRCALPHA, 32)
#if shift >= 0:
# for i in range(0, 2 * shift + 1):
# for j in range(0, 2 * shift + 1):
# surf.blit(surf_name, (i, j))

surf.blit(surf_name, (shift, shift))
return surf
53 changes: 53 additions & 0 deletions core/mapManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os, sys, random
import pygame
from pygame.locals import *
from xml.dom.minidom import parse

class MAP(object):
def __init__(self, WindowManager, screen):
self._screen = screen
self._tiles={}
self.map=[]

def LoadTiles(self, arch):
print('[*] Loading tiles...')
tilesArch = parse(arch)
tilesList = tilesArch.getElementsByTagName('azulejo')
for tile in tilesList:
self._tiles[tile.childNodes[0].nodeValue] = pygame.image.load(os.path.join('data', 'images', 'terrain', tile.childNodes[0].nodeValue+'.png'))
self._tiles[tile.childNodes[0].nodeValue].convert()

def MakeMap(self, arch, pos=0):
print('[*] Building the world...')
mapArch = parse(arch)
MapLines = mapArch.getElementsByTagName('fila')
for fila in MapLines:
MapColumns = fila.getElementsByTagName('columna')
filamapa=[]
for column in MapColumns:
filamapa.append(column.childNodes[0].nodeName)
self.map.append(filamapa)

def showMap(self, sprite=None):
x=20; y=10
startX = 0
startY = 0
posX = posY = 0
scrollMapX = 0
scrollMapY = 0
#drawedWin = pygame.Surface([self._screen.get_width(), self._screen.get_height()])
if sprite:
scrollMapX = sprite.scrollMapX
scrollMapY = sprite.scrollMapY
for line in self.map[scrollMapY:]:
posY += 1
posX = -1
if 380 - (posY*x)+(posX*x) < -20:
break
for tile in line[scrollMapX:]:
posX += 1
if not 380 - (posY * x) + (posX * x) > 760 - (posY * 19):
self._screen.blit(self._tiles[tile], (380 - (posY * x) + (posX * x), 180 + (posY * y) + (posX * y)))
if sprite:
if posX + scrollMapX == sprite.pos[0] and posY + scrollMapY == sprite.pos[1]:
self._screen.blit(sprite.spriteActual, (380 - (posY * x) + ((posX) * x), 180 + (posY * y) + ((posX) * y) - 20))
135 changes: 135 additions & 0 deletions core/playerManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import os, sys, random
import pygame
from pygame.locals import *

#FIXME spawn coordinates

COLOR_BLACK = 0
COLOR_BLUE = 1
COLOR_CYAN = 2
COLOR_GREEN = 3
COLOR_MAGENTA = 4
COLOR_RED = 5
COLOR_WHITE = 6
COLOR_YELLOW = 7
COLOR_BOLD = 8

class Player(pygame.sprite.Sprite):
def __init__(self, _map, x, y, ancho, alto, spriteArch):
super().__init__()
self.map=_map
self.spriteIndex = 0
self.spriteActual = pygame.Surface([ancho, alto])
self.initial = [x, y]
self.pos=[x, y]
self.hp=100
self.speed=10
self.acdist=10
self.walkingmen = []
sprites = pygame.image.load(os.path.join('data', 'images', 'character', 'body', spriteArch[0])).convert()
sprites.set_colorkey(sprites.get_at((0,0)), RLEACCEL)
spritesAncho, spritesAlto = sprites.get_size()
for i in range(int(spritesAlto/alto)):
self.walkingmen.append([])
for j in range(int(spritesAncho/ancho)):
self.walkingmen[i].append(sprites.subsurface(j*ancho, i*alto, ancho, alto))
sprites = pygame.image.load(os.path.join('data', 'images', 'character', 'body', spriteArch[1])).convert()
sprites.set_colorkey(sprites.get_at((0,0)), RLEACCEL)
spritesAncho, spritesAlto = sprites.get_size()
self.personajeGolpeando = []
for i in range(int(spritesAlto/alto)):
self.personajeGolpeando.append([])
for j in range(int(spritesAncho/ancho)):
self.personajeGolpeando[i].append(sprites.subsurface(j * ancho, i * alto, ancho, alto))
self.personaje = self.walkingmen
self.sprite=self.personaje[0][1]
self.spriteActual=self.sprite
self.rect = self.spriteActual.get_rect()
# TODO add moving sprites, so direction too

def mover(self, direction):
incX = incY = 1
if direction == 1:
#TODO use self.dir (or //.direction come te pare) to update self.spriteActual
if self.pos[1]>0:
incY = -1
incX = 0
elif direction == 2:
if self.pos[1]<len([fila[self.pos[0]] for fila in self.map.map])-1:
incY = 1
incX = 0
elif direction == 3:
if self.pos[0]>0:
incY = 0
incX = -1
elif direction == 4:
if self.pos[0] < len(self.map.map[self.pos[1]])-1:
incY = 0
incX = 1
if incX != 0 or incY != 0: variabilechenoncapisco=0
# TODO add: checka se puoi usare il prossimo tile
self.pos[0]+=incX
self.pos[1]+=incY

def action(self, k):
return k


class PlayerManager(Player):
def __init__(self, _map, x, y, ancho, alto):
super().__init__(_map, x-1, y, ancho, alto, ['drackoCaminar.bmp', 'drackoGolpear.bmp'])
self.scrollMapX=0
self.scrollMapY=0
self.message=[]

def mover(self, direction):
self.add_message('moving')
if direction == 1:
if self.pos[1]>0: #TODO add blocked tiles
if (len([fila[self.pos[0]] for fila in self.map.map]) - self.pos[1])-1>16 and self.scrollMapY>0:
self.scrollMapY -= 1
elif direction == 2:
if self.pos[1] < len([fila[self.pos[0]] for fila in self.map.map])-1:
if self.pos[1] > 15 and len([fila[self.pos[0]] for fila in self.map.map]) - self.pos[1] > 4 and len([fila[self.pos[0]] for fila in self.map.map][self.scrollMapY:]) > 20:
self.scrollMapY += 1
elif direction == 3:
if self.pos[0]>0:
if len(self.map.map[self.pos[1]]) - self.pos[0] > 16 and self.scrollMapX>0:
self.scrollMapX -= 1
elif direction == 4:
if self.pos[0] < len(self.map.map[self.pos[1]]) -1:
if self.pos[0] > 15 and len(self.map.map[self.pos[1]]) - self.pos[0] >= 4 and len(self.map.map[self.pos[1]][self.scrollMapX:]) > 20:
self.scrollMapX+=1
super(PlayerManager, self).mover(direction)

def action(self, k):
if self.acdist >= self.speed:
self.acdist = 0
else:
self.acdist += 1
return
if self != None: # TODO add life points check
if k[K_UP] or k[K_w]:
self.mover(3)
elif k[K_DOWN] or k[K_s]:
self.mover(4)
elif k[K_LEFT] or k[K_a]:
self.mover(2)
elif k[K_RIGHT] or k[K_d]:
self.mover(1)
# TODO add gameplay

def add_message(self, message, color=6):
l = []
elt = ""
for word in message.split(' '):
if len(elt) + len(word) < 30:
elt += " " + word
else:
l.append(elt[1:])
elt = " " + word
l.append(elt[1:])
for mess in l:
self.message.insert(0, (mess, color))
if len(self.message) > 100:
self.message.pop()
Binary file added data/gui/LiberationMono-Bold.ttf
Binary file not shown.
Binary file added data/gui/SidePanel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/background/Thumbs.db
Binary file not shown.
Binary file added data/images/background/fondoNoche.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/character/body/drackoCaminar.bmp
Binary file not shown.
Binary file added data/images/character/body/drackoGolpear.bmp
Binary file not shown.
Binary file added data/images/character/dos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/character/tres.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/character/uno.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/Thumbs.db
Binary file not shown.
Binary file added data/images/terrain/agua.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/aguaProfunda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/arena.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/baseTierra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/camino.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/flores.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/hielo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/montana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/pasto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/tierra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/terrain/vacio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/logo/Thumbs.db
Binary file not shown.
Binary file added data/logo/titleLessOne.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/logo/titleLessThree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/logo/titleLessTwo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions data/maps/azulejos.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<azulejos>
<azulejo>pasto</azulejo>
<azulejo>flores</azulejo>
<azulejo>arena</azulejo>
<azulejo>montana</azulejo>
<azulejo>camino</azulejo>
<azulejo>agua</azulejo>
<azulejo>aguaProfunda</azulejo>
<azulejo>baseTierra</azulejo>
<azulejo>hielo</azulejo>
<azulejo>tierra</azulejo>
<azulejo>vacio</azulejo>
</azulejos>
Loading