You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
from ..components import info
|
|
import pygame
|
|
from .. import tools, setup
|
|
from .. import constants as C
|
|
from .. components import player
|
|
|
|
class Level:
|
|
def __init__(self):
|
|
self.finished = False
|
|
self.next = None
|
|
self.info = info.Info('level')
|
|
self.setup_background()
|
|
self.setup_player()
|
|
|
|
def setup_background(self):
|
|
self.background = setup.GRAPHICS['level_1']
|
|
rect = self.background.get_rect()
|
|
self.background = pygame.transform.scale(self.background,(int(rect.width * C.BG_MULTI),
|
|
int(rect.height * C.BG_MULTI)))
|
|
self.background_rect = self.background.get_rect()
|
|
|
|
def setup_player(self):
|
|
self.player = player.Player('mario')
|
|
self.player.rect.x = 300
|
|
self.player.rect.y = 490
|
|
|
|
|
|
def update(self, surface, keys):
|
|
self.player.update(keys)
|
|
self.update_player_position()
|
|
self.draw(surface)
|
|
|
|
|
|
def update_player_position(self):
|
|
self.player.rect.x += self.player.x_vel
|
|
if self.player.rect.x < 0:
|
|
self.player.rect.x = 0
|
|
if self.player.rect.x > C.SCREEN_W -16*C.PLAYER_MULTI:
|
|
self.player.rect.x = C.SCREEN_W -16*C.PLAYER_MULTI
|
|
self.player.rect.y += self.player.y_vel
|
|
|
|
def draw(self, surface):
|
|
surface.blit(self.background,(0,0))
|
|
surface.blit(self.player.image, self.player.rect)
|
|
self.info.draw(surface) |