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 Mar 18, 2022
1 parent 2fd68a6 commit 48f75c0
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 9 deletions.
6 changes: 5 additions & 1 deletion forges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ def run():
forges.run()

def get():
return forges
return forges

def import_sdl2():
global sdl2
import sdl2
54 changes: 54 additions & 0 deletions forges/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os, shutil, sys

class Builder:
def __init__(self, file_name, noconsole = True, flags = []):
self.file_name = file_name
self.default_flags = []

if noconsole:
self.default_flags.append("--noconsole")

else:
self.default_flags.append("--console")

self.flags = self.default_flags + flags
self.flags_string = ""

space = 0

for i in self.flags:
if space != 0:
space -= 1
self.flags_string += " "

self.flags_string += i
space += 1

for i in sys.path:
if "site-packages" in i:
files = os.listdir(i)

state = 0

for j in files:
if "forges" == j:
state += 1
self.forges_path = i + "\\" + j

if "sdl2" == j:
state += 1
self.sdl2_path = i + "\\" + j

if "sdl2dll" == j:
state += 1
self.sdl2dll_path = i + "\\" + j

if state == 3:
self.site_packages_path = i

def build(self):
os.system(f"pyinstaller {self.file_name} {self.flags_string} --noconfirm --onefile --clean --icon={self.forges_path}/assets/icon/icon_ico.ico --add-data \"{self.sdl2dll_path};sdl2dll/\" --add-data \"{self.forges_path};forges/\"")
shutil.copy(f"dist/{os.path.splitext(os.path.basename(self.file_name))[0]}.exe", ".")
shutil.rmtree("build", ignore_errors = True)
shutil.rmtree("dist", ignore_errors = True)
os.remove(f"{os.path.splitext(os.path.basename(self.file_name))[0]}.spec")
4 changes: 3 additions & 1 deletion forges/prefabs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from forges.prefabs.top_view_controller import TopViewController
from forges.prefabs.top_view_controller import TopViewController
from forges.prefabs.platformer_controller import PlatformerController
from forges.prefabs.button import Button
64 changes: 64 additions & 0 deletions forges/prefabs/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import forges

class Button(forges.Entity):
def __init__(self, *args, **kwargs):
super().__init__()

self.width, self.height = 100, 40
self.normal_color, self.press_color, self.highlight_color = forges.color.Color(200, 200, 200), forges.color.Color(100, 100, 100), forges.color.Color(150, 150, 150)

self.color = forges.color.Color(self.normal_color.r, self.normal_color.g, self.normal_color.b, self.normal_color.a)

for i in kwargs:
setattr(self, i, kwargs[i])

self.window = forges.get().get_window()
self.functions = {}
self.target_color = forges.color.Color(self.color.r, self.color.g, self.color.b, self.color.a)

def update(self):
if self.hit(self.window.input.mouse_pos()):
if self.window.input.mouse_pressed(self.window.buttons["LEFT"]):
self.press()

else:
if self.pressed:
self.release()

self.highlight()

else:
self.natural()
self.pressed = False

self.color.r, self.color.g, self.color.b, self.color.a = int(self.target_color.r), int(self.target_color.g), int(self.target_color.b), int(self.target_color.a)

def natural(self):
self.target_color = forges.math.lerp(self.target_color, self.normal_color, 0.1)

def press(self):
self.pressed = True

self.target_color = forges.math.lerp(self.target_color, self.press_color, 0.3)

if "on_press" in self.functions:
self.functions["on_press"]()

def release(self):
self.pressed = False

self.target_color = forges.math.lerp(self.target_color, self.highlight_color, 0.1)

if "on_release" in self.functions:
self.functions["on_release"]()

def highlight(self):
self.pressed = False

self.target_color = forges.math.lerp(self.target_color, self.highlight_color, 0.2)

if "on_highlight" in self.functions:
self.functions["on_highlight"]()

def event(self, func):
self.functions[func.__name__] = func
38 changes: 38 additions & 0 deletions forges/prefabs/platformer_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import forges

class PlatformerController(forges.Entity):
def __init__(self, *args, **kwargs):
super().__init__()

self.window = forges.forges.get_window()

self.speed = 5
self.sprint_speed = 10
self.jumpforce = -13

for i in kwargs:
setattr(self, i, kwargs[i])

self.target_speed = self.speed
self.add_script(forges.scripts.Gravity())

def add_object(self, object):
self.get_script(0).add_object(object)

def update(self):
if self.window.input.key_pressed(self.window.keys["LSHIFT"]):
self.target_speed = self.sprint_speed

else:
self.target_speed = self.speed

if self.window.input.key_pressed(self.window.keys["D"]):
self.x += self.target_speed

if self.window.input.key_pressed(self.window.keys["A"]):
self.x -= self.target_speed

if self.window.input.key_pressed(self.window.keys["SPACE"]):
if self.get_script(0).grounded:
self.get_script(0).grounded = False
self.get_script(0).force(forges.math.Vector2(0, self.jumpforce))
13 changes: 8 additions & 5 deletions forges/prefabs/top_view_controller.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import forges

class TopViewController(forges.Entity):
def __init__(self, width = 50, height = 100, x = 0, y = 0, color = forges.color.Color(20, 20, 20), fill = True, layer = 1, speed = 3, sprint_speed = 6):
super().__init__(width = width, height = height, x = x, y = y, color = color, fill = fill, layer = layer)
def __init__(self, *args, **kwargs):
super().__init__()

self.window = forges.forges.get_window()

self.speed = speed
self.sprint_speed = sprint_speed
self.speed = 3
self.sprint_speed = 6

self.target_speed = speed
for i in kwargs:
setattr(self, i, kwargs[i])

self.target_speed = self.speed

def update(self):
if self.window.input.key_pressed(self.window.keys["LSHIFT"]):
Expand Down
3 changes: 2 additions & 1 deletion forges/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from forges.scripts.toggle_fullscreen import ToggleFullscreen
from forges.scripts.toggle_fullscreen import ToggleFullscreen
from forges.scripts.gravity import Gravity
36 changes: 36 additions & 0 deletions forges/scripts/gravity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import forges

class Gravity(forges.Script):
def __init__(self, *args, **kwargs):
super().__init__()

self.acceleration = forges.math.Vector2(0, 0.5)
self.velocity = forges.math.Vector2(0, 0)
self.friction = -0.01

self.objects = []

for i in kwargs:
setattr(self, i, kwargs[i])

def add_object(self, object):
self.objects.append(object)

def force(self, force):
self.velocity += force

def update(self, window, entity):
self.acceleration = forges.math.Vector2(0, 0.5)
self.grounded = False

for i in self.objects:
if i.hit(entity):
if entity.y < i.y:
entity.y = i.y - entity.height
self.velocity = forges.math.Vector2(0, 0)
self.grounded = True

if not self.grounded:
self.acceleration.x += self.velocity.x * self.friction
self.velocity += self.acceleration
entity.set_pos(entity.get_pos() + self.velocity + forges.math.Vector2(0, 0.5) + self.acceleration)
6 changes: 6 additions & 0 deletions forges/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def update_handler(self):
self.functions["update"]()

def draw_handler(self):
if "on_draw" in self.functions:
self.functions["on_draw"]()

for layer in dict(sorted(self.engine.objects.items(), reverse = True)):
for object in self.engine.objects[layer]:
if object.destroyed:
Expand All @@ -163,6 +166,9 @@ def draw_handler(self):
else:
if hasattr(object, "visible"):
if object.visible:
if hasattr(object, "on_draw"):
object.on_draw()

object.draw()

def set_fullscreen(self, fullscreen = True):
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.2",
version = "0.0.3",
description = "A game engine made with SDL 2.",
long_description = long_desc,
long_description_content_type = "text/markdown",
Expand Down

0 comments on commit 48f75c0

Please # to comment.