from pygame.image import load

from lib.pgfw.pgfw.GameChild import GameChild

class Title(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.display_surface = self.get_display_surface()
        self.delegate = self.get_delegate()
        self.audio = self.get_audio()
        self.load_configuration()
        self.set_background()
        self.subscribe(self.respond)
        self.reset()

    def load_configuration(self):
        config = self.get_configuration("title")
        self.background_path = self.get_resource("title", "background")
        self.audio_path = self.get_resource("title", "audio")

    def set_background(self):
        self.background = load(self.background_path).convert()

    def respond(self, event):
        if self.active:
            if self.delegate.compare(event, "any"):
                self.deactivate()
                self.parent.home.activate()
        if self.activate_queued:
            self.activate()
            self.activate_queued = False

    def reset(self):
        self.activate_queued = False
        self.deactivate()

    def deactivate(self):
        self.active = False
        self.audio.stop_current_channel()

    def activate(self):
        self.active = True
        self.audio.play_bgm(self.audio_path)

    def queue_activation(self):
        self.activate_queued = True

    def update(self):
        if self.active:
            self.display_surface.blit(self.background, (0, 0))
from os.path import join

from pygame import Surface
from pygame.font import Font
from pygame.locals import *

from lib.pgfw.pgfw.Animation import Animation
from food_spring.level.land.Land import Land
from food_spring.level.platform.Platforms import Platforms
from food_spring.level.Food import Food
from food_spring.level.planet.Planet import Planet
from food_spring.level.stars.Stars import Stars
from food_spring.level.drop.Drops import Drops
from food_spring.level.door.Door import Door
from food_spring.level.ExitArrow import ExitArrow
from food_spring.level.obstacle.Obstacles import Obstacles
from food_spring.level.Window import Window

class Level(Animation):

    any_press_ignored = "left"
    transparent_color = 255, 0, 255

    def __init__(self, parent, index, horizontal_drop=False):
        Animation.__init__(self, parent)
        self.index = index
        self.display_surface = self.get_display_surface()
        self.input = self.get_input()
        self.compare = self.get_delegate().compare
        self.audio = self.get_audio()
        self.timer = self.get_game().timer
        self.siphon = self.get_game().siphon
        self.velocity = [0, 0]
        self.time = 0.0
        self.altitude = 0
        self.load_configuration()
        self.assign_defaults()
        self.set_background()
        self.land = Land(self)
        self.planet = Planet(self)
        self.stars = Stars(self)
        self.guns = self.parent.parent.gun_library[index]
        self.drops = Drops(self)
        self.platforms = Platforms(self)
        self.food = Food(self)
        self.door = Door(self)
        self.exit_arrow = ExitArrow(self)
        self.obstacles = Obstacles(self)
        self.window = Window(self)
        self.saved_food_surface = self.food.display_surface
        self.subscribe(self.respond)
        self.register(self.go, self.stall, self.enter, self.transition_to_go,
                      self.exit, self.fade_in_arrow)
        self.deactivate()

    def load_configuration(self):
        config = self.get_configuration("level")
        self.background_color = config["background-color"]
        self.gravity = config["gravity"]
        self.velocity_range = config["velocity"]
        self.stall_length = config["stall"]
        self.fall_pause = config["fall-pause"]
        self.entrance_offset = config["entrance-offset"]
        self.entrance_speed = config["entrance-speed"]
        self.audio_root = config["audio"]

    def assign_defaults(self):
        self.distance = 0.0
        self.velocity[0] = 0.0
        self.time = 0.0
        self.reset_queued = False

    def set_background(self):
        surface = Surface(self.display_surface.get_size())
        surface.fill(self.background_color)
        self.background = surface

    def deactivate(self):
        self.active = False
        self.halt()
        self.input.unregister_any_press_ignore(self.any_press_ignored)
        self.restore_food_surface()
        self.audio.stop_current_channel()

    def restore_food_surface(self):
        self.food.display_surface = self.saved_food_surface

    def respond(self, event):
        if self.compare(event, "reset-game"):
            self.deactivate()
        elif self.active and self.compare(event, "left") and \
                 self.exit_available and self.is_playing(check_all=True):
            self.halt()
            self.timer.stop()
            self.velocity[0] = 0.0
            food = self.food.location
            difference = self.platforms[0].location.right - food.right
            rect = self.get_entrance_mask()[1]
            food.bottomright = rect.w - difference, rect.h
            self.play(self.exit)

    def reset(self):
        self.assign_defaults()
        self.land.reset()
        self.drops.reset()
        self.platforms.reset()
        self.food.reset()
        self.door.reset()
        self.exit_arrow.reset()
        self.obstacles.reset()
        self.window.reset()

    def activate(self):
        self.active = True
        self.exit_available = False
        self.siphon.set_level(self.index)
        self.reset()
        self.input.register_any_press_ignore(self.any_press_ignored)
        mask, rect = self.get_entrance_mask()
        self.food.location.bottomleft = -self.entrance_offset, rect.h
        self.saved_food_surface = self.food.display_surface
        self.audio.play_bgm(self.get_resource(join(self.audio_root,
                                                   str(self.index) + ".ogg")))
        self.play(self.enter)

    def get_entrance_mask(self):
        base = self.door.foreground.location
        width = self.platforms[0].location.right - base.right
        mask = Surface((width, base.h), SRCALPHA)
        rect = mask.get_rect()
        rect.topleft = base.topright
        return mask, rect

    def enter(self):
        self.food.move(self.entrance_speed)
        mask, rect = self.get_entrance_mask()
        self.food.display_surface = mask
        self.clear_and_update_children()
        self.display_surface.blit(mask, rect)
        if self.food.location.left >= self.food.offset - rect.left:
            self.restore_food_surface()
            self.food.place_at_start()
            self.halt()
            self.play(self.stall)
            self.play(self.transition_to_go, delay=self.stall_length)

    def go(self):
        self.distance += self.velocity[0]
        self.clear_and_update_children()
        self.accelerate()
        self.time += 1
        if self.reset_queued:
            self.reset()
            self.halt()
            self.timer.stop()
            self.exit_available = True
            self.play(self.stall, delay=self.fall_pause)
            self.play(self.fade_in_arrow, delay=self.fall_pause)
            self.play(self.transition_to_go,
                      delay=self.stall_length + self.fall_pause)

    def stall(self):
        self.clear_and_update_children()

    def transition_to_go(self):
        self.halt()
        self.velocity[0] = self.velocity_range[0]
        self.timer.start()
        self.play(self.go)

    def fade_in_arrow(self):
        self.exit_arrow.fade(out=False)

    def exit(self):
        self.food.move(-self.entrance_speed)
        mask, rect = self.get_entrance_mask()
        self.food.display_surface = mask
        self.clear_and_update_children()
        self.display_surface.blit(mask, rect)
        if self.food.location.left <= -self.entrance_offset:
            self.restore_food_surface()
            self.halt()
            self.deactivate()
            self.get_game().home.activate()

    def queue_reset(self):
        self.reset_queued = True

    def is_going(self):
        return self.is_playing(self.go)

    def update(self):
        if self.active:
            Animation.update(self)

    def clear_and_update_children(self):
        self.clear()
        self.stars.update()
        self.planet.update()
        self.siphon.update()
        self.land.update()
        self.door.background.update()
        self.exit_arrow.update()
        self.guns.update()
        if not self.food.scope.active:
            self.food.update()
        self.door.foreground.update()
        self.drops.update()
        self.platforms.update()
        if self.food.scope.active:
            self.food.update()
        self.obstacles.update()
        self.window.update()

    def clear(self):
        self.display_surface.blit(self.background, (0, 0))

    def accelerate(self):
        time = self.time
        minimum, maximum = self.velocity_range
        self.velocity[0] =  minimum + time * maximum / (2000 + time)
        # self.print_velocity()

    def print_velocity(self):
        surface = Font(None, 24).render("%.2f" % self.velocity[0], False,
                                        (255, 255, 255))
        self.get_display_surface().blit(surface, (0, 0))
216.73.216.31
216.73.216.31
216.73.216.31
 
July 18, 2022


A new era ‼

Our infrastructure has recently upgraded ‼

Nugget Communications Bureau 👍

You've never emailed like this before ‼

Roundcube

Webmail software for reading and sending email from @nugget.fun and @shampoo.ooo addresses.

Mailman3

Email discussion lists, modernized with likes and emojis. It can be used for announcements and newsletters in addition to discussions. See lists for Picture Processing or Scrapeboard. Nowadays, people use Discord, but you really don't have to!

FreshRSS

With this hidden in plain sight, old technology, even regular people like you and me can start our own newspaper or social media feed.

Nugget Streaming Media 👍

The content you crave ‼

HLS

A live streaming, video format based on M3U playlists that can be played with HTML5.

RTMP

A plugin for Nginx can receive streaming video from ffmpeg or OBS and forward it as an RTMP stream to sites like Youtube and Twitch or directly to VLC.


Professional ‼

Nugget Productivity Suite 👍

Unleash your potential ‼

Kanboard

Virtual index cards you can use to gamify your daily grind.

Gitea

Grab whatever game code you want, share your edits, and report bugs.

Nugget Security 👍

The real Turing test ‼

Fail2ban

Banning is even more fun when it's automated.

Spamassassin

The documentation explains, "an email which mentions rolex watches, Viagra, porn, and debt all in one" will probably be considered spam.

GoAccess

Display HTTP requests in real time, so you can watch bots try to break into WordPress.

Nugget Entertainment Software 👍

The best in gaming entertainment ‼

Emoticon vs. Rainbow

With everything upgraded to the bleeding edge, this HTML4 game is running better than ever.


Zoom ‼

The game engine I've been working on, SPACE BOX, is now able to export to web, so I'm planning on turning nugget.fun into a games portal by releasing my games on it and adding an accounts system. The upgraded server and software will make it easier to create and maintain. I'm also thinking of using advertising and subscriptions to support the portal, so some of these services, like webmail or the RSS reader, may be offered to accounts that upgrade to a paid subscription.