diff --git a/docs/changelog/v4.md b/docs/changelog/v4.md index 3b790b6..3368f75 100644 --- a/docs/changelog/v4.md +++ b/docs/changelog/v4.md @@ -17,16 +17,16 @@ hide: - [x] Scene manager - [x] Scenes classes - [x] Main scene class (SceneManager) - - [ ] Docs for it + - [x] Docs for it - [x] Paths Rewrite ## V4.2 -- [ ] Animation system - - [ ] Load images - - [ ] Play animation - - [ ] Entities have frames that you can manipulate -- [ ] New keys system +- [x] Animation system + - [x] Load images + - [x] Play animation + - [x] Entities have frames that you can manipulate +- [x] New keys system ## V4.3 - [ ] Physics engine diff --git a/docs/index.md b/docs/index.md index 7e1cf96..328ed4d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -78,7 +78,7 @@ There pages aren't maintained anymore and won't be. Please head over to the Wiki - [API](v4/api/api.md) -### Api +### V3 Api - [Setting up](#setting-up-v3) - [API](v3/api/api.md) diff --git a/docs/v4/wiki/wiki.md b/docs/v4/wiki/wiki.md index 92cbb8e..a4c7141 100644 --- a/docs/v4/wiki/wiki.md +++ b/docs/v4/wiki/wiki.md @@ -145,7 +145,7 @@ Then you need to render it (In the best situation this will happen in your loop) your_image.draw() ``` -## Create entity WARNING: PRE ALPHA (It's in really early stages) +## Entities If you want a player or an enemy or some moving object in your game, you can use an entity, thats an object that helps you manage things in your game: @@ -182,6 +182,51 @@ Then you can draw it with: your_entity.draw_image() ``` +### Custom animations with entities +Fusion has some build-in features into entity system to make animations more easy, here are some ways to use it + +#### Load frames +First of all, you need to load frames, and you can do this using this way: +```python +your_entity.load_animation(images: tuple) +``` + +#### Setting current frame +You can set the current frame with this function +```python +your_entity.set_frame(frame: int) +``` + +#### Getting current frame +To get the current frame, run: +```python +my_frame_var = your_entity.get_frame() +``` + +#### Drawing current frame +To draw current frame, use this function +```python +your_entity.draw_animation() +``` + +## Animation system (Early stages) +If you want to draw a animation, then you can do it this way + +### Loading the animations +To load the animation, run +```python +my_anim = fusion.Animation(your_window, your_images: tuple, fps: int) +``` + +### Drawing animation +To draw it then, run: +```python +my_anim.draw() +``` + +## Scene manager +See in [this example](https://github.com/dimkauzh/fusion-engine/blob/main/examples/example5.py) how to use the scene manager. + ## Sound ### Load sound diff --git a/mkdocs.yml b/mkdocs.yml index 56b226b..2d8391c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,16 +24,62 @@ theme: - toc.follow - navigation.expand + - content.code.copy + + palette: + - media: "(prefers-color-scheme)" + toggle: + icon: material/link + name: Switch to light mode - media: "(prefers-color-scheme: light)" scheme: default + primary: indigo + accent: indigo toggle: - icon: material/brightness-7 + icon: material/toggle-switch name: Switch to dark mode - - media: "(prefers-color-scheme: dark)" scheme: slate + primary: black + accent: indigo toggle: - icon: material/brightness-4 - name: Switch to light mode + icon: material/toggle-switch-off + name: Switch to system preference +markdown_extensions: + - abbr + - admonition + - attr_list + - def_list + - footnotes + - md_in_html + - toc: + permalink: true + - pymdownx.arithmatex: + generic: true + - pymdownx.betterem: + smart_enable: all + - pymdownx.caret + - pymdownx.details + - pymdownx.highlight: + anchor_linenums: true + line_spans: __span + pygments_lang_class: true + - pymdownx.inlinehilite + - pymdownx.keys + - pymdownx.magiclink: + normalize_issue_symbols: true + repo_url_shorthand: true + user: squidfunk + repo: mkdocs-material + - pymdownx.mark + - pymdownx.smartsymbols + - pymdownx.superfences: + custom_fences: + - name: mermaid + class: mermaid + format: !!python/name:pymdownx.superfences.fence_code_format + - pymdownx.tasklist: + custom_checkbox: true + - pymdownx.tilde diff --git a/src/fusionengine/entity/entity.py b/src/fusionengine/entity/entity.py index 3ed3857..915d301 100644 --- a/src/fusionengine/entity/entity.py +++ b/src/fusionengine/entity/entity.py @@ -1,8 +1,6 @@ from fusionengine.core.window import Window from fusionengine.core.image import Image from fusionengine.core.shape import Rect -from fusionengine.animation.animation import Animation - class Entity: def __init__( @@ -20,6 +18,7 @@ def __init__( self.height = height self.window = window self.gravity = 0 + self.frame = 0 def load_image( self, @@ -30,15 +29,21 @@ def load_image( self.window, image_path, self.x, self.y, self.width, self.height ) - def load_animation(self, window: Window, images: tuple, speed: int): - self.anim = Animation(window, images, speed) + def load_animation(self, images: tuple): + self.images = images def draw_animation(self): - self.anim.draw() + self.images[self.frame].draw() def draw_image(self) -> None: self.main_image.draw() + def set_frame(self, frame: int): + self.frame = frame + + def get_frame(self, frame: int) -> int: + return frame + def load_rect(self, color: tuple) -> None: """Gives the entity a rectangle and later draws it on the screen.""" self.main_rect = Rect(self.window, self.x, self.y, self.width, self.height, color)