Skip to content

Commit

Permalink
Added animations to entities, and more
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkauzh committed Dec 30, 2023
1 parent 72b2c51 commit 71f9c57
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 17 deletions.
12 changes: 6 additions & 6 deletions docs/changelog/v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
47 changes: 46 additions & 1 deletion docs/v4/wiki/wiki.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
54 changes: 50 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 10 additions & 5 deletions src/fusionengine/entity/entity.py
Original file line number Diff line number Diff line change
@@ -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__(
Expand All @@ -20,6 +18,7 @@ def __init__(
self.height = height
self.window = window
self.gravity = 0
self.frame = 0

def load_image(
self,
Expand All @@ -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)
Expand Down

0 comments on commit 71f9c57

Please sign in to comment.