Skip to content

Commit

Permalink
Merge pull request #55 from dimkauzh/dev
Browse files Browse the repository at this point in the history
Version 4.2
  • Loading branch information
dimkauzh authored Dec 31, 2023
2 parents 101fa21 + 71f9c57 commit a2c7b4a
Show file tree
Hide file tree
Showing 23 changed files with 315 additions and 295 deletions.
4 changes: 2 additions & 2 deletions docs/changelog/v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ hide:
- navigation
---

## 3.0.0 Todo/Changelog
## V3 Todo/Changelog

- [x] Engine
- [x] Window
Expand All @@ -28,4 +28,4 @@ hide:
- [x] Sound system
- [x] Sound player
- [x] File support
- [x] And more...
- [x] And more...
30 changes: 17 additions & 13 deletions docs/changelog/v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@
hide:
- navigation
---
# Version 4 Todo/Changelog

## 4.0.0 Todo/Changelog

## V4
- [x] Rewrite codebase
- [x] Cleaner api
- [x] Rewrite documentation
- [x] Better documentation
- [x] Easier usage

## 4.1.0 Todo/Changelog

## V4.1
- [x] Scenes managment
- [x] Creating different scenes
- [x] Scene manager
- [x] Scenes classes
- [x] Main scene class (SceneManager)
- [ ] Docs for it
- [x] Docs for it
- [x] Paths Rewrite


## 4.2.0 Todo/Changelog
- [ ] New way of a applcation (Application class)
- [ ] Inheritance based
- [ ] Build in loop
- [ ] Make this optional and not the main way
- [ ] Animation system
- [ ] Load images
- [ ] Play animation
## V4.2
- [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
- [ ] Box2D
- [ ] Static Body
- [ ] Rigid Body
- [ ] Integration with entities


19 changes: 12 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ And your done!
- [Wiki](v4/wiki/index.md)


### Api
- [Setting up](#setting-up)
- [API](v4/api/api.md)

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

Expand All @@ -71,13 +67,22 @@ The wiki, api and tutorials to the old v3 version of fusion, which is not being
- [Wiki](v3/wiki/index.md)


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


## Api
There pages aren't maintained anymore and won't be. Please head over to the Wiki pages, tutorials or examples.
### Api
- [Setting up](#setting-up)
- [API](v4/api/api.md)


### V3 Api
- [Setting up](#setting-up-v3)
- [API](v3/api/api.md)

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



## 💻 Setting up v3

Expand Down
51 changes: 48 additions & 3 deletions 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 Expand Up @@ -291,7 +336,7 @@ The code shows how to save the modified data back to the storage file on disk.
if you need keyboard input, then use this if statement with your own key (see key tab for all key names):

```python
if fusion.key_down(fusion.KEY_a):
if fusion.Key(fusion.KEY_a).key_down():
print("Key A pressed")
```

Expand All @@ -300,7 +345,7 @@ if you need keyboard input, then use this if statement with your own key (see ke
If you need keydown to be only once, then you use this:

```python
if fusion.key_down_once(fusion.KEY_a):
if fusion.Key(fusion.KEY_a).key_down_once():
print("Key A pressed")
```

Expand Down
2 changes: 1 addition & 1 deletion examples/example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def loop():
fusion.set_background_color(window, fusion.VIOLET)
fusion.draw_rect(window, 100, 100, 400, 400, fusion.BLUE)

if fusion.key_down_once(fusion.KEY_a):
if fusion.Key(fusion.KEY_a).key_down():
print("Key A pressed")
8 changes: 4 additions & 4 deletions examples/example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def loop():

player.load_rect(fusion.AQUA)

if fusion.key_down(fusion.KEY_UP):
if fusion.Key(fusion.KEY_UP).key_down():
player.y = int(player.y - speed)

elif fusion.key_down(fusion.KEY_DOWN):
elif fusion.Key(fusion.KEY_DOWN).key_down():
player.y = int(player.y + speed)

elif fusion.key_down(fusion.KEY_RIGHT):
elif fusion.Key(fusion.KEY_RIGHT).key_down():
player.x = int(player.x + speed)

elif fusion.key_down(fusion.KEY_LEFT):
elif fusion.Key(fusion.KEY_LEFT).key_down():
player.x = int(player.x - speed)

player.draw_rect()
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
10 changes: 9 additions & 1 deletion src/fusionengine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "Dimkauzh"
__version__ = "4.1.0"
__version__ = "4.2.0"

import sys
import os
Expand All @@ -20,6 +20,9 @@
from fusionengine.colors.color import *
from fusionengine.colors.colortools import *

# Entity
from fusionengine.entity.entity import *

# Physics
from fusionengine.physics.body import *

Expand All @@ -38,14 +41,19 @@

# Sound
from fusionengine.sound.sound import *
from fusionengine.sound.background import *

# Scene
from fusionengine.scene.scene import *
from fusionengine.scene.manager import *

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

# Animation
from fusionengine.animation.animation import *


import pygame as pg
import pygame_gui as gui
Expand Down
27 changes: 27 additions & 0 deletions src/fusionengine/animation/animation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from fusionengine.core.window import Window

class Animation:
def __init__(self, window: Window, images: tuple, speed: int) -> None:
"""
"""
self.frame = 0
self.anim = images

self.speed = speed
self.window = window

def draw(self):
#default_fps = self.window.get_fps()
self.window.set_fps(self.speed)

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

image = self.anim[self.frame]

image.draw()

self.frame += 1
#self.window.set_fps(default_fps)

6 changes: 3 additions & 3 deletions src/fusionengine/core/image.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fusionengine.core.window as window
from fusionengine.core.window import Window
import pygame as pg


class Image:
def __init__(
self,
window: window.Window,
window: Window,
image_path,
x: int,
y: int,
Expand All @@ -27,7 +27,7 @@ def draw(self) -> None:


def draw_image_file(
window: window.Window, path: str, x: int, y: int, width: int, height: int
window: Window, path: str, x: int, y: int, width: int, height: int
):
"""Draw image directly from provided path."""
texture = pg.image.load(path)
Expand Down
7 changes: 5 additions & 2 deletions src/fusionengine/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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._clock = pg.time.Clock()

self.title = title
self.width = width
Expand Down Expand Up @@ -69,6 +69,9 @@ def set_fps(self, fps: int) -> None:
"""
self._fps = fps

def get_fps(self) -> int:
return self._fps

def force_quit(self) -> None:
"""Force quits the window.
Specifically, stops and deletes window.
Expand All @@ -89,7 +92,7 @@ def _refresh(self) -> None:
window: Your window
"""

self.DELTATIME = self.clock.tick(self._fps)
self.DELTATIME = self._clock.tick(self._fps)

for event in pg.event.get():
if event.type == pg.QUIT and self._quittable:
Expand Down
Loading

0 comments on commit a2c7b4a

Please sign in to comment.