Ajout d'un zoom de camera

This commit is contained in:
theo@manjaro 2021-07-02 21:06:34 +02:00
parent facdf19e6e
commit 69c591aaae
5 changed files with 27 additions and 6 deletions

View File

@ -9,7 +9,8 @@ class Game():
self.datadir = lib.get_save_dir("slime")
self.DISPLAY_WIDTH, self.DISPLAY_HEIGHT = 1280, 720
self.window = pygame.display.set_mode(((self.DISPLAY_WIDTH,self.DISPLAY_HEIGHT)))
self.window = pygame.Surface((self.DISPLAY_WIDTH,self.DISPLAY_HEIGHT))
self.realwindow = pygame.display.set_mode((self.DISPLAY_WIDTH,self.DISPLAY_HEIGHT))
pygame.display.set_caption("kfr 2 ???")
pygame.init()
pygame.mixer.init()
@ -75,6 +76,7 @@ class Game():
self.globals["cameray"] = 0
self.globals["scamerax"] = 3
self.globals["scameray"] = 0
self.scaleCamera()
settings = {"sfx":1,"bgm":1}
self.globals["bgmvolume"] = settings["bgm"]
@ -246,8 +248,12 @@ class Game():
p = Particle(self,sprites,posx,posy,velx,vely,modvelx,modvely,flipx,flipy,fps)
self.gameloop.summon(p)
def perror(self,msg):
print("ERROR: "+str(msg))
def scaleCamera(self,neww=None,newh=None):
if not neww:
neww=self.DISPLAY_WIDTH
if not newh:
newh=self.DISPLAY_HEIGHT
self.globals["cameraw"] = neww
self.globals["camerah"] = newh
def pinfo(self,msg):
print("INFO : "+str(msg))
self.globals["tempsubsurface"] = pygame.Surface((neww,newh))

View File

@ -53,6 +53,9 @@ class Player(BaseObject):
else:
self.move(hor*self.speed*self.game.dt,self.vertical*self.game.dt)
self.game.globals["camerax"] = self.rect.center[0]-self.game.globals["cameraw"]/2
self.game.globals["cameray"] = self.rect.center[1]-self.game.globals["camerah"]/2
def move(self,movex,movey):
hstoped = False
hor = int(movex+self.hrest)
@ -108,3 +111,6 @@ class Player(BaseObject):
result = rect
break
return result
def draw(self):
self.game.window.blit(self.sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])

View File

@ -14,7 +14,7 @@ class TilesetRenderer(BaseObject):
def draw(self):
for layer in self.layers:
self.game.window.blit(layer["surface"],(layer["offsets"]))
self.game.window.blit(layer["surface"],(layer["offsets"][0]-self.game.globals["camerax"],layer["offsets"][1]-self.game.globals["cameray"]))
def reinit(self,level):
json = level["data"]

View File

@ -59,3 +59,10 @@ class GameLoop():
# Je stabilise la caméra
game.globals["camerax"]-=rx
game.globals["cameray"]-=ry
# Get the right ratio
widthratio = game.DISPLAY_WIDTH/game.globals["cameraw"]
heightratio = game.DISPLAY_HEIGHT/game.globals["camerah"]
game.globals["tempsubsurface"].blit(game.window,[0,0])
temp = game.pygame.transform.scale(game.globals["tempsubsurface"],(game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT))
game.realwindow.blit(temp,[0,0])

View File

@ -8,6 +8,7 @@ from gamedata.objects.combat.player import Player
from gamedata.objects.combat.tileset import TilesetRenderer
def main(game):
game.scaleCamera()
game.gameloop.reinit() # Je réinitialis la boucle
bg = MenuBackground(game)
menu = MainMenu(game.DISPLAY_WIDTH/4,round(game.DISPLAY_HEIGHT*3/8),game,game.DISPLAY_WIDTH//2,game.DISPLAY_HEIGHT//2)
@ -15,6 +16,7 @@ def main(game):
game.gameloop.summon(menu)
def fight(game):
game.scaleCamera(416,234)
game.gameloop.reinit()
mapname = game.lib.choice(list(game.levels_lib.keys()))
tileset = TilesetRenderer(0,0,game,mapname)