class MainGameScene(Scene): def __init__(self): self.db = Database() self.db['points'] = 0 self.db['points_per_click'] = 1 self.db['speed'] = 10 super(MainGameScene, self).__init__() self.background = Background((0, 123, 228)) self.rails = MovingRail() self.label = TextLabel("Points: {}".format(self.db['points']), os.path.join("Resources", Database()['font']), 16, (50, 18)) self.train = Vehicle() self.train_rect = self.train.get_rect() self.button = Button(60, 200, 32, "Shop", (100, 100)) self.button_rect = self.button.get_rect() print(self.train_rect) def render(self, screen): self.background.render(screen) self.rails.render(screen) self.label.render(screen) self.train.render(screen) self.button.render(screen) def update(self, delta_time: float): self.rails.update(delta_time) self.label.update_text("Points: {}".format(self.db['points'])) def handle_event(self, event: pygame.event): if event.type == pygame.MOUSEBUTTONDOWN: if self.train_rect.collidepoint(event.pos): self.db['points'] += self.db['points_per_click'] elif self.button_rect.collidepoint(event.pos): Director().set_scene(ShopScene())
class ShopScene(Scene): def __init__(self): self.db = Database() super().__init__() self.background = Background((0, 123, 228)) self.button = Button(60, 200, 32, "Shop", (100, 100), color=(144, 191, 51)) self.button_rect = self.button.get_rect() self.label = TextLabel("Points: {}".format(self.db['points']), "Resources/F77-Minecraft.ttf", 16, (50, 18)) self.ten_km_up = Button(60, 350, 24, "+10km/h (50 pts)", (200, 370), color=(144, 191, 51)) self.hundred_km_up = Button(60, 350, 24, "+100km/h (300 pts)", (200, 280), color=(144, 191, 51)) self.five_hundred_km_up = Button(60, 350, 24, "+500km/h (1000 pts)", (200, 190), color=(144, 191, 51)) self.double_click_points = Button(60, 350, 24, "2X pts. (200 pts)", (600, 370), color=(144, 191, 51)) def render(self, screen: pygame.Surface): self.background.render(screen) self.button.render(screen) self.label.render(screen) self.ten_km_up.render(screen) self.hundred_km_up.render(screen) self.five_hundred_km_up.render(screen) self.double_click_points.render(screen) def update(self, delta_time: float): self.label.update_text("Points: {}".format(self.db['points'])) def handle_event(self, event: pygame.event): if event.type == pygame.MOUSEBUTTONDOWN: if self.button_rect.collidepoint(event.pos): Director().pop_scene() elif self.ten_km_up.get_rect().collidepoint(event.pos): if self.db['points'] >= 50: self.db['speed'] += 10 self.db['points'] -= 50 elif self.hundred_km_up.get_rect().collidepoint(event.pos): if self.db['points'] >= 300: self.db['speed'] += 100 self.db['points'] -= 300 elif self.five_hundred_km_up.get_rect().collidepoint(event.pos): if self.db['points'] >= 1000: self.db['speed'] += 500 self.db['points'] -= 1000 elif self.double_click_points.get_rect().collidepoint(event.pos): if self.db['points'] >= 200: self.db['points_per_click'] *= 2 self.db['points'] -= 200