Skip to content

Commit

Permalink
Revert "Added spritesheets, fixed animation system and added spritesh…
Browse files Browse the repository at this point in the history
…eet support to animation system"

This reverts commit d33b30d.
  • Loading branch information
dimkauzh committed Jan 28, 2024
1 parent d33b30d commit d216256
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 178 deletions.
28 changes: 3 additions & 25 deletions docs/changelog/v5.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
# Version 5 Todo/Changelog

## V5
- [x] Docs cleanup
- [x] New color system
- [x] Optimised font drawing
- [x] OpenGL rendering

## V5
- [ ] New Window features
- [ ] Full Screen
- [ ] is_fullscreen
- [ ] toggle_fullscreen
- [ ] Screen Safer
- [ ] get_screensafer_allowed
- [ ] set_screensafer_allowed
- [ ] get_vsync_enabled
- [ ] get_screen_refresh_rate
- [ ] get_display_amount
- [ ] get_active

- [ ] SpriteSheet class
- [ ] __init__(Image, width, height)
- [ ] frames (variable with all your extracted frames)
- [ ] draw(speed) (gets a argument speed that specifies the speed of drawing in frames)

- Image system updates
- [ ] Added crop() function
- [ ] Docs cleanup
- [ ] New color system
- [ ] Optimised font drawing
10 changes: 5 additions & 5 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ nav:


- Changelog:
- V5: 'changelog/v5.md'
- V4: 'changelog/v4.md'
- V3: 'changelog/v3.md'
- v5: 'changelog/v5.md'
- v4: 'changelog/v4.md'
- v3: 'changelog/v3.md'

- Legacy:
- Start: 'legacy/index.md'
- V3:
- v3:
- Wiki:
- Main page: 'legacy/v3/wiki/wiki.md'
- Keys page: 'legacy/v3/wiki/keys.md'
Expand All @@ -59,7 +59,7 @@ nav:
- Setup: 'legacy/v3/tutorials/setup.md'
- Basics: 'legacy/v3/tutorials/basics.md'

- V4:
- v4:
- Wiki:
- Window with fusion: 'legacy/v4/wiki/window.md'
- Rendering with fusion: 'legacy/v4/wiki/rendering.md'
Expand Down
1 change: 0 additions & 1 deletion src/fusionengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

# Animation
from fusionengine.engine.animation import *
from fusionengine.engine.spritesheets import *


import pygame as pg
Expand Down
31 changes: 13 additions & 18 deletions src/fusionengine/engine/animation.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
from fusionengine.engine.window import Window
from fusionengine.engine.spritesheets import SpriteSheet


class Animation:
def __init__(self, window: Window, images: tuple | SpriteSheet) -> None:
def __init__(self, window: Window, images: tuple, speed: int) -> None:
"""
The class to create a Animation.
Args:
window: Window
image (Tuple | Spritesheets): Tuple of Images or a SpriteSheet
image: tuple of Images
Speed: Int (FPS)
"""
self.frame = 0
if isinstance(images, SpriteSheet):
self.frames = images.frames
elif isinstance(images, tuple):
self.frames = images
else:
ValueError("Images must be a tuple of Images or a SpriteSheet")
self.anim = images

self.speed = speed
self.window = window

def play(self, speed: float) -> None:
def draw(self) -> None:
"""
Draw the animation you made before
"""
if isinstance(self.frame, int) or (
isinstance(self.frame, float) and self.frame.is_integer()
):
if 0 <= int(self.frame) < len(self.frames):
self.frames[int(self.frame)].draw()
self.window.set_fps(self.speed)

self.frame += speed

if self.frame >= len(self.frames):
if self.frame >= len(self.anim):
self.frame = 0

image = self.anim[self.frame]

image.draw()

self.frame += 1
35 changes: 4 additions & 31 deletions src/fusionengine/engine/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
class Image:
def __init__(
self,
image_path: str | Imager.Image,
image_path: str,
x: int,
y: int,
width: int,
height: int,
) -> None:
"""
Opens an image. Can be later rendered with draw method.
Opens an image. Can be later rendered with draw_image.
Args:
image_path (str or Pillow Image): The path to the image | Pillow Image
image_path (str): The path to the image
x (int): X coordinate of the image
y (int): Y coordinate of the image
width (int): Width of the image (scaling allowed)
Expand All @@ -31,13 +31,7 @@ def __init__(
self.width = width
self.height = height

if isinstance(image_path, str):
self.image = Imager.open(str(image_path))
elif isinstance(image_path, Imager.Image):
self.image = image_path
else:
raise ValueError("Invalid image_path type")

self.image = Imager.open(image_path)
image_data = self.image.tobytes("raw", "RGBA", 0, -1)

self.texture = gl.GenTextures(1)
Expand All @@ -59,27 +53,6 @@ def __init__(
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

def crop(self, left: int, right: int, top: int, bottom: int) -> "Image":
"""
Crop the image based on the specified boundaries.
Args:
left (int): The left boundary of the crop area.
right (int): The right boundary of the crop area.
top (int): The top boundary of the crop area.
bottom (int): The bottom boundary of the crop area.
Returns:
Image: A new Image object representing the cropped image.
"""
return Image(
self.image.crop((left, right, top, bottom)),
self.x,
self.y,
self.width,
self.height,
)

def draw(self) -> None:
"""
Draws your image on the screen.
Expand Down
81 changes: 0 additions & 81 deletions src/fusionengine/engine/spritesheets.py

This file was deleted.

17 changes: 0 additions & 17 deletions tests/spritesheet.py

This file was deleted.

0 comments on commit d216256

Please sign in to comment.