forked from Akalay27/pythonRoguelike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (39 loc) · 1.52 KB
/
Copy pathmain.py
File metadata and controls
67 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pygame
import random
import sys
from map import *
from util import *
from animationController import *
from player import *
class Game:
CANVAS_WIDTH = 1000
CANVAS_HEIGHT = 600
def __init__(self):
self.screen = pygame.display.set_mode((self.CANVAS_WIDTH,self.CANVAS_HEIGHT),pygame.DOUBLEBUF | pygame.HWSURFACE)
self.player = Player(0,0)
self.map = Map()
self.player.pos.x = (self.map.rooms[0].bbox.x2-self.map.rooms[0].bbox.x1)/2*self.map.tileSize+self.map.tileSize*0.5
self.player.pos.y = (self.map.rooms[0].bbox.y2-self.map.rooms[0].bbox.y1)/2*self.map.tileSize+self.map.tileSize*0.5
self.cameraPos = Point(0,0)
self.clock = pygame.time.Clock()
self.gameLoop()
def gameLoop(self):
while 1:
self.clock.tick()
self.deltaTime = 60/(self.clock.get_fps()+0.0001)
self.screen.fill((0,0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.cameraPos.x,self.cameraPos.y = self.player.pos.x,self.player.pos.y
#self.cameraPos.x,self.cameraPos.y = lerp(self.cameraPos.x,self.player.pos.x,0.01), lerp(self.cameraPos.y,self.player.pos.y,0.01)
self.map.draw(self)
self.player.move(self)
self.player.draw(self)
self.map.draw(self,background=False)
#put player in center of start room
print(self.clock.get_fps())
pygame.display.flip()
def getCameraPoint(self,point):
return Point(self.CANVAS_WIDTH/2+point.x-int(self.cameraPos.x), self.CANVAS_HEIGHT/2+point.y-int(self.cameraPos.y)).int()
game = Game()