import pygame, mapgen, random
from pygame.locals import *
from settings import *

class Background():
	def __init__(self, path, speed = 0):
		self.image = pygame.image.load(path)
		self.image = self.image.convert_alpha()

		self.x = 0
		self.y = 0

		self.speed = speed

	def draw(self, surface):
		w, h = surface.get_size()
		iw, ih = self.image.get_size()

		pos = 0
		while pos - self.x < w:
			surface.blit(self.image, (pos - self.x, 0), (0, 0, iw, ih))
			pos += iw

		self.update(self.speed)

	def update(self, speed):
		self.x = (self.x + speed) % self.image.get_width()
