Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Full paths rewrite and more
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkauzh committed Dec 8, 2023
1 parent 7c85118 commit 2e07607
Show file tree
Hide file tree
Showing 29 changed files with 358 additions and 116 deletions.
8 changes: 7 additions & 1 deletion docs/changelog/v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ hide:
- [x] Scene manager
- [x] Scenes classes
- [x] Main scene class (SceneManager)
- [x] Inheritance based
- [ ] New way of a applcation (Application class)
- [ ] Inheritance based
- [ ] Build in loop
- [ ] Make this optional and not the main way
- [ ] Paths Rewrite


7 changes: 3 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Wiki is made if you need to know what a function does.
Api is made if you need to know if a function exist and what arguments it takes,
and in tutorials we made some tutorials for you to better understand fusion!

## Todo list and changelog
- [v4](changelog/v4.md)
- [v3](changelog/v3.md)

## v4

Expand Down Expand Up @@ -40,10 +43,6 @@ and in tutorials we made some tutorials for you to better understand fusion!

### Tutorials
- [Tutorials](v3/tutorials/index.md)

### Todo list and changelog
- [v3](changelog/v3.md)
- [v4](changelog/v4.md)


## 💻 Setting up
Expand Down
1 change: 1 addition & 0 deletions examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
def loop():
window.set_fps(60)
image.draw()

57 changes: 40 additions & 17 deletions src/fusionengine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
__author__ = "Dimkauzh"
__version__ = "4.0.6"
__version__ = "4.1.0"

import sys
import os

os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide"

from fusionengine.files.window import *
from fusionengine.files.image import *
from fusionengine.files.debug import *
from fusionengine.files.color import *
from fusionengine.files.event import *
from fusionengine.files.draw import *
from fusionengine.files.shape import *
from fusionengine.files.body import *
from fusionengine.files.systems import *
from fusionengine.files.storage import *
from fusionengine.files.ui import *
from fusionengine.files.fonts import *
from fusionengine.files.vector import *
from fusionengine.files.math import *
from fusionengine.files.sound import *
from fusionengine.files.scene import *
# Core
from fusionengine.core.window import *
from fusionengine.core.image import *
from fusionengine.core.draw import *
from fusionengine.core.shape import *

# Events
from fusionengine.events.event import *
from fusionengine.events.keys import *

# Colors
from fusionengine.colors.color import *
from fusionengine.colors.colortools import *

# Physics
from fusionengine.physics.body import *

# Storage
from fusionengine.storage.storage import *

# UI
from fusionengine.ui.ui import *

# Fonts
from fusionengine.fonts.fonts import *

# Math
from fusionengine.math.vector import *
from fusionengine.math.math import *

# Sound
from fusionengine.sound.sound import *

# Scene
from fusionengine.scene.scene import *

# Tools
from fusionengine.tools.systems import *
from fusionengine.tools.debug import *


import pygame as pg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,58 +140,4 @@
YELLOWGREEN = (154, 205, 50, 255)


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
55 changes: 55 additions & 0 deletions src/fusionengine/colors/colortools.py
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
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


Expand Down
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


Expand Down
21 changes: 21 additions & 0 deletions src/fusionengine/core/shape.py
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)
105 changes: 105 additions & 0 deletions src/fusionengine/core/window.py
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))
22 changes: 22 additions & 0 deletions src/fusionengine/events/event.py
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



Loading

0 comments on commit 2e07607

Please sign in to comment.