-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
217 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,8 @@ def run(): | |
forges.run() | ||
|
||
def get(): | ||
return forges | ||
return forges | ||
|
||
def import_sdl2(): | ||
global sdl2 | ||
import sdl2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters