Commit 231c011b authored by anthrax's avatar anthrax
Browse files

Bring everything to template

parent 0aab6b81
[flake8]
ignore = E501,W503,E221,E302
max-complexity = 14
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
*.pyc
*.log
venv/
config.py
config.ini
.python-version
*cache*
# ci-cd pipeline
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: check-yaml
stages: [commit]
- id: end-of-file-fixer
stages: [commit]
- id: trailing-whitespace
stages: [commit]
- id: pretty-format-json
stages: [commit]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
stages: [commit]
- repo: ssh://gitlab@git.lynxcore.org:29876/tools/pre-commit.git
rev: afd9c12f0f0c529432f64aa3cd3815e02c7693fa
hooks:
- id: black-on-post-commit
stages: [post-commit]
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
# Contributing
all:
@echo "make build -------------------- Build the test server image"
@echo "make run ---------------------- Run the current build"
@echo "make kill --------------------- Stop the currently running build"
@echo "make clean -------------------- Delete the current build"
build:
@echo "No build step defined yet"
run:
@echo "No run step defined yet"
kill:
@echo "No kill step defined yet"
clean:
@echo "No clean step defined yet"
......@@ -3,109 +3,135 @@
import pygame
import os
class Actor(pygame.sprite.Sprite):
def __init__(self, charID, fps, zoom):
pygame.sprite.Sprite.__init__(self)
self.charID = charID
self.spritePath = "sprites"
self.spriteFile = "transSprite.png"
self.sprite = ""
self.currentLayer = 0
self.width = 24
self.height = 32
self.fps = fps
self.dirX = 0
self.dirY = 0
self.posX = 180
self.posY = 350
self.stepSize = 2.0 + (float(zoom) / float(5))
self._images = self.loadSpriteFile()
self._start = pygame.time.get_ticks()
self._delay = 1000 / self.fps
self._lastUpdate = 0
self._frame = 0
self._angle = 0
self._scale = zoom
self.sprite = pygame.transform.rotozoom(self._images[0], self._angle, self._scale)
self.collMask = pygame.mask.from_surface(self._images[0], 127)
self.update(pygame.time.get_ticks())
def move(self, direction, collMasks):
for mask in collMasks:
dxpos = mask.overlap_area(self.collMask, (int(self.posX+self.stepSize+1),int(self.posY)))
dypos = mask.overlap_area(self.collMask, (int(self.posX),int(self.posY+self.stepSize+1)))
dxneg = mask.overlap_area(self.collMask, (int(self.posX-self.stepSize-2),int(self.posY)))
dyneg = mask.overlap_area(self.collMask, (int(self.posX),int(self.posY-self.stepSize-1)))
if dxpos != 0 or dypos != 0 or dxneg != 0 or dyneg != 0:
break
if direction == "up" and dyneg == 0:
self.dirY = 1
self.posY = self.posY - self.stepSize
elif direction == "down" and dypos == 0:
self.dirY = 0
self.posY = self.posY + self.stepSize
elif direction == "left" and dxneg == 0:
self.dirX = 1
self.posX = self.posX - self.stepSize
elif direction == "right" and dxpos == 0:
self.dirX = 0
self.posX = self.posX + self.stepSize
self.update(pygame.time.get_ticks())
def update(self, time):
if time - self._lastUpdate > self._delay:
self._frame += 1
if self._frame >= len(self._images): self._frame = 0
if self.dirX == 0:
self.sprite = pygame.transform.rotozoom(self._images[self._frame], self._angle, self._scale)
elif self.dirX == 1:
self.sprite = pygame.transform.flip(pygame.transform.rotozoom(self._images[self._frame], self._angle, self._scale),True,False)
self._lastUpdate = time
self.collMask = pygame.mask.from_surface(self._images[self._frame], 127)
def horizFlip(self):
if self.dirX == 0:
self.dirX = 1
elif self.dirX == 1:
self.dirX = 0
def vertFlip(self):
if self.dirY == 0:
self.dirY = 1
elif self.dirY == 1:
self.dirY = 0
def loadSpriteFile(self):
images = []
masterImage = pygame.image.load(os.path.join(self.spritePath, self.spriteFile)).convert_alpha()
masterWidth, masterHeight = masterImage.get_size()
for i in xrange(int(masterWidth)/self.width):
images.append(masterImage.subsurface((i*self.width, 0, self.width, self.height)))
return images
def loadDataFromConfigFile(self):
print "loading character data from file"
def __init__(self, charID, fps, zoom):
pygame.sprite.Sprite.__init__(self)
self.charID = charID
self.spritePath = "sprites"
self.spriteFile = "transSprite.png"
self.sprite = ""
self.currentLayer = 0
self.width = 24
self.height = 32
self.fps = fps
self.dirX = 0
self.dirY = 0
self.posX = 180
self.posY = 350
self.stepSize = 2.0 + (float(zoom) / float(5))
self._images = self.loadSpriteFile()
self._start = pygame.time.get_ticks()
self._delay = 1000 / self.fps
self._lastUpdate = 0
self._frame = 0
self._angle = 0
self._scale = zoom
self.sprite = pygame.transform.rotozoom(
self._images[0], self._angle, self._scale
)
self.collMask = pygame.mask.from_surface(self._images[0], 127)
self.update(pygame.time.get_ticks())
def move(self, direction, collMasks):
for mask in collMasks:
dxpos = mask.overlap_area(
self.collMask, (int(self.posX + self.stepSize + 1), int(self.posY))
)
dypos = mask.overlap_area(
self.collMask, (int(self.posX), int(self.posY + self.stepSize + 1))
)
dxneg = mask.overlap_area(
self.collMask, (int(self.posX - self.stepSize - 2), int(self.posY))
)
dyneg = mask.overlap_area(
self.collMask, (int(self.posX), int(self.posY - self.stepSize - 1))
)
if dxpos != 0 or dypos != 0 or dxneg != 0 or dyneg != 0:
break
if direction == "up" and dyneg == 0:
self.dirY = 1
self.posY = self.posY - self.stepSize
elif direction == "down" and dypos == 0:
self.dirY = 0
self.posY = self.posY + self.stepSize
elif direction == "left" and dxneg == 0:
self.dirX = 1
self.posX = self.posX - self.stepSize
elif direction == "right" and dxpos == 0:
self.dirX = 0
self.posX = self.posX + self.stepSize
self.update(pygame.time.get_ticks())
def update(self, time):
if time - self._lastUpdate > self._delay:
self._frame += 1
if self._frame >= len(self._images):
self._frame = 0
if self.dirX == 0:
self.sprite = pygame.transform.rotozoom(
self._images[self._frame], self._angle, self._scale
)
elif self.dirX == 1:
self.sprite = pygame.transform.flip(
pygame.transform.rotozoom(
self._images[self._frame], self._angle, self._scale
),
True,
False,
)
self._lastUpdate = time
self.collMask = pygame.mask.from_surface(self._images[self._frame], 127)
def horizFlip(self):
if self.dirX == 0:
self.dirX = 1
elif self.dirX == 1:
self.dirX = 0
def vertFlip(self):
if self.dirY == 0:
self.dirY = 1
elif self.dirY == 1:
self.dirY = 0
def loadSpriteFile(self):
images = []
masterImage = pygame.image.load(
os.path.join(self.spritePath, self.spriteFile)
).convert_alpha()
masterWidth, masterHeight = masterImage.get_size()
for i in xrange(int(masterWidth) / self.width):
images.append(
masterImage.subsurface((i * self.width, 0, self.width, self.height))
)
return images
def loadDataFromConfigFile(self):
print "loading character data from file"
class Enemy(Actor):
def whoAreYou(self):
print "Hi, I'm also an Enemy!\n"
def whoAreYou(self):
print "Hi, I'm also an Enemy!\n"
class Player(Actor):
def whoAreYou(self):
print "Hi, I'm also a Player!\n"
def attack(self):
print "Attacking the air! Wooohoooo!"
def whoAreYou(self):
print "Hi, I'm also a Player!\n"
def attack(self):
print "Attacking the air! Wooohoooo!"
......@@ -2,6 +2,7 @@
from . import Object
class Animate(Object.Object):
def whoAreYou(self):
print "Hi, I'm an Animate Object!"
\ No newline at end of file
def whoAreYou(self):
print "Hi, I'm an Animate Object!"
#!/usr/bin/env python2
class Effect:
def __init__(self):
print "Hi, I'm an Effect!"
def __init__(self):
print "Hi, I'm an Effect!"
class Magic(Effect):
def whoAreYou(self):
print "Hi, I'm a Magic effect!"
def whoAreYou(self):
print "Hi, I'm a Magic effect!"
......@@ -2,6 +2,7 @@
from . import Actor
class Enemy(Actor.Actor):
def whoAreYou(self):
print "Hi, I'm also an Enemy!\n"
\ No newline at end of file
def whoAreYou(self):
print "Hi, I'm also an Enemy!\n"
#!/usr/bin/env python2
class FileHandler:
def __init__(self, path):
self.path = path
def openFile(self):
try:
file = open(self.path)
return file
except:
return false
def readFile(self):
try:
self.file.read()
return file
except:
return false
def writeFile(self, data):
try:
print "writing to file here"
return true
except:
return false
def __init__(self, path):
self.path = path
def openFile(self):
try:
file = open(self.path)
return file
except:
return false
def readFile(self):
try:
self.file.read()
return file
except:
return false
def writeFile(self, data):
try:
print "writing to file here"
return true
except:
return false
class ConfigFile(FileHandler):
def readConfigValues(self):
print "Reading config file for file " + str(self.path)
def readConfigValues(self):
print "Reading config file for file " + str(self.path)
class MapFile(FileHandler):
def __init__(self, path):
FileHandler.__init__(FileHandler(path), path)
print "Reading a map now..."
def __init__(self, path):
FileHandler.__init__(FileHandler(path), path)
print "Reading a map now..."
def readMap(self):
print "Reading a map now..."
def readMap(self):
print "Reading a map now..."
class ScriptFile(FileHandler):
def readScript(self):
print "Reading a script file now..."
def readScript(self):
print "Reading a script file now..."
......@@ -2,12 +2,15 @@
import pygame
class Hud:
def __init__(self):
self.framePosition = (540,900)
self.pcImgPosition = (548,912) # Versatz ist: x + 12, y + 18
self.frames = pygame.image.load("sprites/hud/frame.png").convert_alpha()
self.pcImg = pygame.transform.rotozoom(pygame.image.load("sprites/hud/pcimg.png").convert_alpha(),0,1.5)
#self.hpBar = pygame.image.load("sprites/hud/hpbar.png").convert_alpha()
#self.mpBar = pygame.image.load("sprites/hud/mpbar.png").convert_alpha()
#self.strBar = pygame.image.load("sprites/hud/strbar.png").convert_alpha()
def __init__(self):
self.framePosition = (540, 900)
self.pcImgPosition = (548, 912) # Versatz ist: x + 12, y + 18
self.frames = pygame.image.load("sprites/hud/frame.png").convert_alpha()
self.pcImg = pygame.transform.rotozoom(
pygame.image.load("sprites/hud/pcimg.png").convert_alpha(), 0, 1.5
)
# self.hpBar = pygame.image.load("sprites/hud/hpbar.png").convert_alpha()
# self.mpBar = pygame.image.load("sprites/hud/mpbar.png").convert_alpha()
# self.strBar = pygame.image.load("sprites/hud/strbar.png").convert_alpha()
......@@ -2,6 +2,7 @@
from . import Object
class Inanimate(Object.Object):
def whoAreYou(self):
print "Hi, I'm an Inanimate Object!"
\ No newline at end of file
def whoAreYou(self):
print "Hi, I'm an Inanimate Object!"
......@@ -2,6 +2,7 @@
from . import Effect
class Magic(Effect.Effect):
def whoAreYou(self):
print "Hi, I'm a Magic effect!"
\ No newline at end of file
def whoAreYou(self):
print "Hi, I'm a Magic effect!"
#!/usr/bin/env python2
class Object:
def __init__(self):
print "Hi, I'm an Object!"
def __init__(self):
print "Hi, I'm an Object!"
class Animate(Object):
def whoAreYou(self):
print "Hi, I'm an Animate Object!"
def whoAreYou(self):
print "Hi, I'm an Animate Object!"
class Inanimate(Object):
def whoAreYou(self):
print "Hi, I'm an Inanimate Object!"
def whoAreYou(self):
print "Hi, I'm an Inanimate Object!"
......@@ -2,6 +2,7 @@
from . import Actor
class Player(Actor.Actor):
def whoAreYou(self):
print "Hi, I'm also a Player!\n"
\ No newline at end of file
def whoAreYou(self):
print "Hi, I'm also a Player!\n"
......@@ -2,18 +2,20 @@
import pygame
def load_sound(name):
class No_Sound:
def play(self): pass
class No_Sound:
def play(self):
pass
if not pygame.mixer or not pygame.mixer.get_init():
return No_Sound()
if not pygame.mixer or not pygame.mixer.get_init():
return No_Sound()
fullname = os.path.join('data', name)
if os.path.exists(full_name) == False:
sound = pygame.mixer.Sound(fullname)
else:
print 'File does not exist:', fullname
return No_Sound
fullname = os.path.join("data", name)
if os.path.exists(full_name) == False:
sound = pygame.mixer.Sound(fullname)
else:
print "File does not exist:", fullname
return No_Sound
return sound
return sound
......@@ -2,77 +2,88 @@
import pygame, os
class World:
def __init__(self, zoom, filename):
self._scale = zoom
self._angle = 0
self.posX = 0
self.posY = 0
self.filename = filename
self.img ="map001.png"
self.retData = []
self.layerLow = []
self.layerColl = []
self.layerHigh = []
self.mapLow = []
self.mapColl = []
self.mapHigh = []
self.mapData = self.readMapFile()
self.loadedLayers = self.loadLayer(self.mapData[2])
def readMapFile(self):
file = open("maps/" + str(self.filename),'r')
sep = "="
def __init__(self, zoom, filename):
self._scale = zoom
self._angle = 0
self.posX = 0
self.posY = 0
self.filename = filename
self.img = "map001.png"
self.retData = []
self.layerLow = []
self.layerColl = []
self.layerHigh = []
self.mapLow = []
self.mapColl = []
self.mapHigh = []
self.mapData = self.readMapFile()
self.loadedLayers = self.loadLayer(self.mapData[2])
def readMapFile(self):
file = open("maps/" + str(self.filename), "r")
sep = "="
# load general settings for the map here
for line in file:
if line.rpartition(sep)[0] == "name":
self.name = line.rpartition(sep)[2].strip("\n")
if line.rpartition(sep)[0] == "script":
self.script = line.rpartition(sep)[2].strip("\n")
if line.rpartition(sep)[0] == "width":
self.width = line.rpartition(sep)[2].strip("\n")
if line.rpartition(sep)[0] == "height":
self.height = line.rpartition(sep)[2].strip("\n")
if line.rpartition(sep)[0] == "layers":
self.layers = line.rpartition(sep)[2].strip("\n")
if line.rpartition(sep)[0] == "tilesize":
self.tilesize = line.rpartition(sep)[2].strip("\n")
# load general settings for the map here