Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Aermoss authored Apr 5, 2022
1 parent 90a4ccc commit 0388404
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 9 deletions.
1 change: 1 addition & 0 deletions forges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from forges.text import Text
from forges.mixer import Mixer
from forges.animation import Animation
from forges.intro import Intro

import forges.prefabs as prefabs
import forges.scripts as scripts
Expand Down
2 changes: 1 addition & 1 deletion forges/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def draw(self):

self.rect.x, self.rect.y, self.rect.w, self.rect.h = int(self.x), int(self.y), int(self.width), int(self.height)

sdl2.SDL_SetRenderDrawColor(self.engine.window.renderer, self.color.r, self.color.g, self.color.b, self.color.a)
sdl2.SDL_SetRenderDrawColor(self.engine.window.renderer, int(self.color.r), int(self.color.g), int(self.color.b), int(self.color.a))

if self.fill:
sdl2.SDL_RenderFillRect(self.engine.window.renderer, self.rect)
Expand Down
41 changes: 41 additions & 0 deletions forges/intro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from forges.entity import Entity
from forges.sprite import Sprite
from forges.color import Color
from forges.math import lerp

import time

class Intro(Entity):
def __init__(self):
super().__init__(color = Color(0, 0, 0, 255), layer = -1)

self.logo = Sprite(self.engine.path + "/assets/logo/logo.png", alpha = 0, width = 350, height = 80, layer = -1)
self.logo.update = self.update_logo

self.target_alpha = self.color.a
self.target_logo_alpha = self.logo.alpha

def update_logo(self):
self.logo.center()

if self.engine.window.start_time + 5 < time.time():
self.target_logo_alpha = lerp(self.target_logo_alpha, 0, 0.05)
self.logo.set_alpha(int(self.target_logo_alpha))

if self.logo.alpha == 0:
self.logo.destroy()

elif self.engine.window.start_time + 0.5 < time.time():
self.target_logo_alpha = lerp(self.target_logo_alpha, 255, 0.01)
self.logo.set_alpha(int(self.target_logo_alpha))

def update(self):
self.width = self.engine.window.width
self.height = self.engine.window.height

if self.engine.window.start_time + 7 < time.time():
self.target_alpha = lerp(self.target_alpha, 0, 0.1)
self.color.a = int(self.target_alpha)

if self.color.a == 0:
self.destroy()
3 changes: 2 additions & 1 deletion forges/prefabs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from forges.prefabs.top_view_controller import TopViewController
from forges.prefabs.platformer_controller import PlatformerController
from forges.prefabs.button import Button
from forges.prefabs.camera import Camera
from forges.prefabs.camera import Camera
from forges.prefabs.checkbox import CheckBox
11 changes: 6 additions & 5 deletions forges/prefabs/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def update(self):
self.shakes.clear()

for layer in dict(sorted(self.engine.objects.items(), reverse = True)):
for object in self.engine.objects[layer]:
if object not in self.static_objects:
if hasattr(object, "offset"):
object.offset.x = -self.x
object.offset.y = -self.y
if layer > 0:
for object in self.engine.objects[layer]:
if object not in self.static_objects:
if hasattr(object, "offset"):
object.offset.x = -self.x
object.offset.y = -self.y

def shake(self, force = 10, shake_wait = 0.01):
if self.last_shake + shake_wait < time.time():
Expand Down
20 changes: 20 additions & 0 deletions forges/prefabs/checkbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import forges

from forges.prefabs.button import Button

class CheckBox(Button):
def __init__(self, normal_color = forges.color.Color(200, 200, 200), press_color = forges.color.Color(100, 100, 100), highlight_color = forges.color.Color(150, 150, 150), width = 20, height = 20, x = 0, y = 0, color = forges.color.Color(6, 6, 8), fill = True, parent = None, layer = 1):
super().__init__(normal_color = normal_color, press_color = press_color, highlight_color = highlight_color, width = width, height = height, x = x, y = y, color = color, fill = fill, parent = parent, layer = layer)

self.functions["on_release"] = self.update_state
self.state = False

self.box = forges.Entity(width = self.width - 10, height = self.height - 10, x = 5, y = 5, parent = self)
self.box.visible = False

def update_state(self):
self.state = not self.state
self.box.visible = True if self.state else False

def get_state(self):
return self.state
13 changes: 12 additions & 1 deletion forges/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

from forges.input import Input
from forges.color import Color
from forges.intro import Intro

import __main__

class Window:
def __init__(self, width = 1200, height = 600, vsync = True, fullscreen = False, always_on_top = False, background_color = Color(255, 255, 255, 255)):
def __init__(self, width = 1200, height = 600, vsync = True, fullscreen = False, always_on_top = False, background_color = Color(255, 255, 255, 255), intro = True):
if hasattr(__main__.forges, "forges"):
self.engine = __main__.forges.forges

Expand Down Expand Up @@ -110,6 +111,12 @@ def __init__(self, width = 1200, height = 600, vsync = True, fullscreen = False,
"MIDDLE": sdl2.SDL_BUTTON_MIDDLE,
}

if intro:
self.intro = Intro()

else:
self.intro = None

def event_handler(self, event):
if event.type == sdl2.SDL_QUIT:
self.destroy()
Expand Down Expand Up @@ -186,6 +193,10 @@ def set_fullscreen(self, fullscreen = True):
if "on_fullscreen_change" in self.functions:
self.functions["on_fullscreen_change"](False)

def intro_finished(self):
if self.intro == None: return None
return True if self.intro.destroyed else False

def set_width(self, width):
self.width = width
sdl2.SDL_SetWindowSize(self.window, self.width, self.height)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name = "forges",
version = "0.0.5",
version = "0.0.6",
description = "A game engine made with SDL 2.",
long_description = long_desc,
long_description_content_type = "text/markdown",
Expand Down

0 comments on commit 0388404

Please # to comment.