Metadata-Version: 2.4
Name: prism2d
Version: 1.0.8
Summary: A lightweight 2D game engine built with Tkinter.
Author: Jay
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Pillow>=10.0.0
Dynamic: license-file

## Update Log ##
version 1.0.8
-full reupload due to file corruption
-bug fixes

# Prism2D

A lightweight 2D game engine built on Python's built-in `tkinter` — no pygame, no external rendering dependencies beyond Pillow.

```bash
pip install prism2d
```

## Quick Start

```python
import prism2d as P2D

engine = P2D.Engine(title="My Game")

player = P2D.Sprite(engine.canvas, "player.png", 100, 100,
    movable=True, keymap="arrows", speedx=5, speedy=5)

engine.players = [player]
engine.sprites = [player]
engine.run()
```

## Features

### Engine
- Window creation with configurable width, height, and title
- Fixed-tick game loop (`root.after` based)
- Global key tracking (`keys_held`) for smooth, simultaneous multi-directional input
- `Engine.current` — auto-accessible from anywhere once created

### Sprite
Created from an image file, with position, movement, and optional player controls.

| Method | What it does |
|---|---|
| `.move(dx, dy)` | Move relative to current position |
| `.move_to(x, y)` | Move to an absolute position |
| `.get_position()` | Returns `(x, y)` |
| `.hide()` / `.show()` | Toggle visibility |
| `.change(image_path)` | Swap the sprite's image |
| `.rotate(degrees)` | Rotate relative to current angle |
| `.scale(factor)` | Resize relative to current scale |
| `.collides_with(other)` | Bounding-box collision check |

**Creation parameters:**
- `solid` — participates in collision
- `movable` + `keymap` (`"arrows"` or `"wasd"`) + `speedx`/`speedy` — enables keyboard-controlled movement
- `weight` + `pushable` — controls collision response (see below)
- `.actions` — dict of `{key: function}` for custom key-triggered behavior, assigned after creation

### Multi-Player Input
Any number of sprites can be player-controlled simultaneously, each with independent keymaps:

```python
player1 = P2D.Sprite(engine.canvas, "p1.png", 100, 100, movable=True, keymap="arrows", speedx=5, speedy=5)
player2 = P2D.Sprite(engine.canvas, "p2.png", 300, 300, movable=True, keymap="wasd", speedx=5, speedy=5)

engine.players = [player1, player2]
```

### Collision
Add sprites to `engine.sprites` to have them checked for collisions each frame. Two response modes, controlled per-sprite:

- **`pushable=True`** (default) — colliding sprites push each other apart, weighted by `weight`. Heavier sprites resist being pushed more, and push lighter sprites further.
- **`pushable=False`** — acts as a solid wall; blocks movement into it without being displaced itself.

### Custom Key Actions
Attach arbitrary functions to any key, separate from movement:

```python
player.actions = {
    "h": player.hide,
    "s": player.show,
    "r": lambda: player.rotate(15),
}
```

Use `lambda: func(args)` when the action needs to pass arguments.

### Label
Simple text display on the canvas.

```python
label = P2D.Label(engine.canvas, "Score: 0", x=50, y=20)
label.set_text("Score: 10")
label.move_to(x, y)
label.hide() / label.show()
```

### Button
Clickable rectangular button with a text label.

```python
def on_click():
    print("clicked!")

button = P2D.Button(engine.canvas, x=100, y=100, width=150, height=50,
                     text="Start", command=on_click)
```

## Notes

- Images should have a transparent background (RGBA PNG) for correct rendering during rotation and scaling — sprites are internally converted to RGBA on load.
- `rotate()` and `scale()` always transform from the original image, so repeated calls don't degrade quality.
- Only one `Engine` instance is supported at a time (`Engine.current` is overwritten on each new instance).

## License

MIT
