This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
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
29 changed files
with
358 additions
and
116 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
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
def loop(): | ||
window.set_fps(60) | ||
image.draw() | ||
|
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
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,55 @@ | ||
def hex_to_rgba(hex): | ||
"""Converts (#)RRGGBB to [R, G, B, 255].""" | ||
hex6 = hex.replace("#", "") | ||
return int(hex6[:2], 16), int(hex6[2:4], 16), int(hex6[4:6], 16), 255 | ||
|
||
|
||
def hsv_to_rgb(hue, sat, val, alpha: int) -> tuple[int, int, int, int]: | ||
"""Takes in HSV values and ouputs red, green and blue values. | ||
Hue is from 0 to 360 (float). | ||
Saturation and value are from 0 to 1 (float). | ||
Alpha is from 0 to 255 (int).""" | ||
if hue <= 60: | ||
hue_red = 255 | ||
|
||
elif 60 <= hue <= 120: | ||
hue_red = 255 * ((-hue / 60) + 2) | ||
|
||
elif 120 <= hue <= 240: | ||
hue_red = 0 | ||
|
||
elif 240 <= hue <= 300: | ||
hue_red = (hue / 60) - 4 | ||
|
||
elif 300 <= hue <= 360: | ||
hue_red = 255 | ||
|
||
if hue <= 60: | ||
hue_green = 255 * (hue / 60) | ||
|
||
elif 60 <= hue <= 180: | ||
hue_green = 255 | ||
|
||
elif 180 <= hue <= 240: | ||
hue_green = 255 * ((-hue / 60) + 4) | ||
|
||
elif 240 <= hue <= 360: | ||
hue_green = 0 | ||
|
||
if hue <= 120: | ||
hue_blue = 0 | ||
|
||
elif 120 <= hue <= 180: | ||
hue_blue = 255 * ((hue / 60) - 2) | ||
|
||
elif 180 <= hue <= 300: | ||
hue_blue = 255 | ||
|
||
elif 300 <= hue <= 360: | ||
hue_blue = 255 * ((-hue / 60) + 6) | ||
|
||
red = val * (sat * hue_red + (255 - 255 * sat)) | ||
green = val * (sat * hue_green + (255 - 255 * sat)) | ||
blue = val * (sat * hue_blue + (255 - 255 * sat)) | ||
|
||
return int(red), int(green), int(blue), alpha |
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,4 +1,4 @@ | ||
import fusionengine.files.window as window | ||
import fusionengine.core.window as window | ||
import pygame as pg | ||
|
||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/fusionengine/files/image.py → src/fusionengine/core/image.py
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,4 +1,4 @@ | ||
import fusionengine.files.window as window | ||
import fusionengine.core.window as window | ||
import pygame as pg | ||
|
||
|
||
|
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,21 @@ | ||
import pygame as pg | ||
|
||
import fusionengine.core.window as fe_window | ||
|
||
|
||
class Rect: | ||
def __init__( | ||
self, window: fe_window.Window, x: int, y: int, width: int, height: int, color: tuple | ||
) -> None: | ||
"""A class that creates a new custom shape. (Not for the user)""" | ||
self.x = x | ||
self.y = y | ||
self.width = width | ||
self.height = height | ||
self.color = color | ||
self.rect = pg.Rect(x, y, width, height) | ||
self.window = window | ||
|
||
def draw(self) -> None: | ||
"""Creates a new rectangle. Can be later rendered with draw_own_rect.""" | ||
pg.draw.rect(self.window.window, self.color, self.rect) |
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,105 @@ | ||
import fusionengine.tools.debug as fe_debug | ||
import pygame as pg | ||
import pygame_gui as gui | ||
from pygame.locals import DOUBLEBUF | ||
|
||
|
||
class Window: | ||
def __init__(self, title: str, width: int, height: int) -> None: | ||
self._running = False | ||
self._fps = 60 | ||
self._quittable = True | ||
self.clock = pg.time.Clock() | ||
|
||
self.title = title | ||
self.width = width | ||
self.height = height | ||
|
||
try: | ||
self.window = pg.display.set_mode((width, height), DOUBLEBUF, 16) | ||
pg.display.set_caption(title) | ||
|
||
self.manager = gui.UIManager((width, height)) | ||
|
||
program_icon = pg.image.load(fe_debug.DEBUGIMAGE) | ||
pg.display.set_icon(program_icon) | ||
|
||
self._running = True | ||
|
||
except Exception: | ||
print("Error: Can't create a window.") | ||
|
||
def change_icon(self, image_path): | ||
"""Changes icon | ||
Args: | ||
Icon_Path (str): Path to your icon | ||
""" | ||
|
||
programIcon = pg.image.load(image_path) | ||
pg.display.set_icon(programIcon) | ||
|
||
def loop(self, your_loop) -> None: | ||
"""A while loop decorator function. | ||
Args: | ||
your_loop (callable): Your main loop function | ||
""" | ||
while self.running(): | ||
your_loop() | ||
|
||
def running(self) -> bool: | ||
"""Returns if the window is running. Used for the main loop. | ||
Args: | ||
window: Your window | ||
Returns: | ||
bool: returns true if the window is running else false | ||
""" | ||
self._refresh() | ||
return self._running | ||
|
||
def set_fps(self, fps: int) -> None: | ||
"""Sets the desired frames per second for the game loop. | ||
Args: | ||
fps (int): The desired frames per second | ||
""" | ||
self._fps = fps | ||
|
||
def force_quit(self) -> None: | ||
"""Force quits the window. | ||
Specifically, stops and deletes window. | ||
Args: | ||
window: Your window | ||
""" | ||
self._running = False | ||
del self.window | ||
|
||
def toggle_quittable(self) -> None: | ||
"""Toggles whether the window is quittable.""" | ||
self._quittable = not self._quittable | ||
|
||
def _refresh(self) -> None: | ||
"""Does all things for refreshing window. (Not for the user) | ||
Args: | ||
window: Your window | ||
""" | ||
|
||
self.DELTATIME = self.clock.tick(self._fps) | ||
|
||
for event in pg.event.get(): | ||
if event.type == pg.QUIT and self._quittable: | ||
self._running = False | ||
|
||
self.manager.process_events(event) | ||
|
||
self.manager.update(self.DELTATIME) | ||
self.manager.draw_ui(self.window) | ||
|
||
pg.display.update() | ||
|
||
self.window.fill((0, 0, 0)) |
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,22 @@ | ||
import pygame as pg | ||
|
||
|
||
clicked = False | ||
|
||
|
||
def key_down(key): | ||
keys = pg.key.get_pressed() | ||
return keys[key] | ||
|
||
|
||
def key_down_once(key): | ||
global clicked | ||
if key_down(key) and not clicked: | ||
clicked = True | ||
return True | ||
elif not key_down(key): | ||
clicked = False | ||
return False | ||
|
||
|
||
|
Oops, something went wrong.