Beispiel #1
0
	def move(self):
		self.pos[0] += math.sin(self.direction) * self.velocity
		self.pos[1] += math.cos(self.direction) * self.velocity

		GameCamera.set_pos((-self.pos[0], self.pos[1]))

		# Preventing movement below starting point
		self.pos[1] = max(0, self.pos[1])
Beispiel #2
0
	def drawbackground(self, surface):
		horizontalOffset = int(round(float(GameCamera.pos[0]) / self.window.get_width()))
		layer = int(round(float(GameCamera.pos[1]) / self.window.get_height()))

		self.layer = layer

		for i in range(-1, 2):
			for i2 in range(-1, 2):
				if layer == 0 and i2 != 0: continue
				if self.layers[layer-i2] == [0, 0]:
					self.layers[layer-i2] = terraingen.generateLayer(layer-i2, config.SCREEN_SIZE, 10)
					self.generatePowerUps((0, self.window.get_height() * (layer - 1)), (self.window.get_width(), self.window.get_height() * (layer + 0)))
				layersurf = self.layers[layer-i2][0]
				if i == -1 and i2 == -1:
					surface.fill(self.layers[layer][1])
				surface.blit(layersurf, GameCamera.adjust_pos(surface.get_width() * (i - horizontalOffset), -(self.window.get_height() * layer) + self.window.get_height() * i2))
Beispiel #3
0
	def checkCollide(self, rect):
		return rect.collidepoint(GameCamera.adjust_pos(self.pos))
Beispiel #4
0
	def draw(self, surface):
		surface.blit(self.image, GameCamera.adjust_pos(self.pos))
import parameters as PRAM
from setup import soundPlayerFactory, playerFactory, eventHandlerFactory
from render import Renderer
from game import Game
from input import InputHandler, ButtonMap
from camera import GameCamera
### SETUP ###
pygame.init()  # @UndefinedVariable
screen = pygame.display.set_mode((PRAM.DISPLAY_WIDTH, PRAM.DISPLAY_HEIGHT))
CLOCK = pygame.time.Clock()
DONE = False

### GAME ENGINE ###
musicPlayer, soundPlayer = soundPlayerFactory()
renderer = Renderer(screen)
gameCamera = GameCamera()
player = playerFactory()
game = Game(player, musicPlayer, soundPlayer, renderer, gameCamera)
inputHandler = InputHandler(game, player, ButtonMap())
eventHandler = eventHandlerFactory(game)
game.inputHandler = inputHandler

game.gameStartup()
while not DONE:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:  # @UndefinedVariable
            DONE = True  #TODO make this an input that creates a quit event?
        if event.type == pygame.KEYDOWN:  # @UndefinedVariable
            game.keydownEvents.append(event)
        #TODO can tell pygame to only check fro specific events
    game.keysPressed = pygame.key.get_pressed()