Skip to content

Commit f6aea38

Browse files
committed
first commit 1.0
0 parents  commit f6aea38

4 files changed

Lines changed: 197 additions & 0 deletions

File tree

Example.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<canvas id="myCanvas" width="200" height="100">
10+
Your browser does not support the HTML canvas element.
11+
</canvas>
12+
<script src="choppy.js"></script>
13+
<script>
14+
var choppy = new Choppy("myCanvas");
15+
16+
// Scene 0: Forest
17+
choppy.sceneCreate(`
18+
// Define drawings once (or update them dynamically)
19+
escenaActual.layers[0] = "ctx.fillStyle = 'green'; ctx.fillRect(0,0,200,100);"; // Floor
20+
escenaActual.layers[2] = "ctx.fillStyle = 'white'; ctx.fillText('Level: Forest', 10, 20);"; // UI
21+
`, "Forest");
22+
23+
// Scene 1: Cave
24+
choppy.sceneCreate(`
25+
escenaActual.layers[0] = "ctx.fillStyle = 'black'; ctx.fillRect(0,0,200,100);"; // Dark background
26+
escenaActual.layers[1] = "ctx.fillStyle = 'gray'; ctx.fillRect(50,50,20,20);"; // A rock
27+
`, "Cave");
28+
29+
choppy.play(); // Launch the game loop
30+
31+
// Example of scene transition after 2 seconds
32+
setTimeout(() => {
33+
choppy.setScene(1);
34+
}, 2000);
35+
</script>
36+
</body>
37+
</html>

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 B4uti4Dev / B4uti4GD / B4uti4github
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 🌊 Choppy Engine v1.0
2+
**The ultra-lightweight game orchestration layer for Canvas API.**
3+
4+
Choppy is not a heavy framework; it's a high-speed abstraction script for developers who love the **Canvas API** but hate managing scenes in visual engines, Z-orders, and game loops from scratch. It's designed for **speed-running game development** and rapid prototyping.
5+
6+
---
7+
8+
## 🔥 Why Choppy?
9+
10+
* **Pure Canvas API**: If you know `ctx.fillRect()` and CanvasAPI, you already know Choppy.
11+
* **Zero Overhead**: A single, tiny JS file. No dependencies. No bloat.
12+
* **Dynamic Scripting**: Use the power of string-based logic (`eval`) for instant prototyping.
13+
* **Scene-Based Z-Order**: Each scene manages its own independent rendering layers (Background, Game, UI).
14+
* **Semi-Recursive Flow**: Change scenes and modify the engine state directly from within your scene scripts.
15+
16+
---
17+
18+
## 🚀 Quick Start (Speed-run style)
19+
20+
### 1. Setup your HTML
21+
1. In the body tag:
22+
```html
23+
<canvas id="myCanvas" width="200" height="100"></canvas>
24+
<script src="choppy.js"></script>
25+
```
26+
27+
2. Create your Game Logic
28+
```html
29+
<script>
30+
var choppy = new Choppy("myCanvas");
31+
32+
// Scene 0: Forest
33+
choppy.sceneCreate(`
34+
// Define drawings once (or update them dynamically)
35+
escenaActual.layers[0] = "ctx.fillStyle = 'green'; ctx.fillRect(0,0,200,100);"; // Floor
36+
escenaActual.layers[2] = "ctx.fillStyle = 'white'; ctx.fillText('Level: Forest', 10, 20);"; // UI
37+
`, "Forest");
38+
39+
// Scene 1: Cave
40+
choppy.sceneCreate(`
41+
escenaActual.layers[0] = "ctx.fillStyle = 'black'; ctx.fillRect(0,0,200,100);"; // Dark background
42+
escenaActual.layers[1] = "ctx.fillStyle = 'gray'; ctx.fillRect(50,50,20,20);"; // A rock
43+
`, "Cave");
44+
45+
choppy.play(); // Launch the game loop
46+
47+
// Example of scene transition after 2 seconds
48+
setTimeout(() => {
49+
choppy.setScene(1);
50+
}, 2000);
51+
</script>
52+
```
53+
💡 Important Tips 🔥
54+
Scene Management: Choppy provides a lightweight display list. You can switch scenes instantly without memory leaks.
55+
Extensibility: You can extend the Choppy class easily to add physics or sound systems.
56+
Security Disclaimer: This script uses eval() for extreme flexibility and speed. Be careful when copying scripts from untrusted sites; malicious code could be hidden in strings. Always know what your eval strings are doing.
57+
58+
## Usage & Credits
59+
60+
### 📦 Local Installation Only
61+
For security reasons (due to the use of `eval()`), **ChoppyJS must be hosted locally**. Do not link to this script via a CDN. Download the `choppy.js` file and include it directly in your project's ZIP or repository.
62+
63+
### 📜 Attribution
64+
This project is licensed under the MIT License. This means you **must** keep the copyright notice in the code. Additionally, we highly recommend and appreciate it if you credit **ChoppyJS** in:
65+
* Your project's `README.md`.
66+
* Your game's "Credits" screen.
67+
* The "Tools Used" section of your game's page.
68+
69+
Example: "Built with ChoppyJS by B4uti4GD"
70+
71+
72+
Made by me with a little help from AI 😉. Go build something fast!

choppy.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// ChoppyJS - A simple JavaScript game abstraction script for 2D games
2+
3+
// Disclaimer: This is a basic framework for building 2D games using JavaScript and HTML5 Canvas.
4+
// It provides scene management and layer drawing capabilities.
5+
// You can extend it further based on your game requirements.
6+
// But, This is an simple script for game making; consider security implications of using eval() and remember to be careful when copying scripts from untrusted sites; they could install malware without your knowledge.
7+
8+
// Tips:
9+
// 1. Use eval() to run scene scripts and layer drawing code.
10+
// 2. Each scene can have multiple layers (1, 2, 3) for drawing order.
11+
// 3. Use setScene(index) to switch between scenes, and use sceneCreate(evalScene, name) for creating scenes.
12+
// 4. Use deltaTime for frame-independent movement.
13+
// 5. Access the current scene with 'escenaActual' in eval scripts.
14+
// 6. Each layers of the current scene is a string to be evaled and runnned in order.
15+
// 7. This is a basic framework, extend it as needed for your game with "this." + some var name for states.
16+
// 8. Remember to handle user input and game states within the eval scripts.
17+
// 9. Enjoy building your 2D games with ChoppyJS!
18+
19+
class Choppy {
20+
constructor(canvasId) {
21+
this.canvas = document.getElementById(canvasId);
22+
this.ctx = this.canvas.getContext("2d");
23+
this.scenes = [];
24+
this.currentScene = 0;
25+
this.lastTime = 0;
26+
}
27+
28+
sceneCreate(evalScene, name) {
29+
// Save the scene like an object
30+
this.scenes.push({ script: evalScene, name: name, layers: {
31+
1: "",
32+
2: "",
33+
3: "",
34+
} });
35+
}
36+
37+
// Método para cambiar de escena (interrumpir la actual)
38+
setScene(index) {
39+
if (index >= 0 && index < this.scenes.length) {
40+
this.currentScene = index;
41+
}
42+
}
43+
44+
play() {
45+
const loop = (timestamp) => {
46+
this.deltaTime = timestamp - this.lastTime;
47+
this.lastTime = timestamp;
48+
var ctx = this.ctx;
49+
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
50+
51+
// Use this in the eval scripts to access the current scene
52+
const escenaActual = this.scenes[this.currentScene];
53+
54+
// 1. Run Logic from the current scene
55+
eval(escenaActual.script);
56+
57+
// 2. Draw Layers in order
58+
Object.keys(escenaActual.layers).sort().forEach(z => {
59+
eval(escenaActual.layers[z]);
60+
});
61+
62+
requestAnimationFrame(loop);
63+
};
64+
requestAnimationFrame(loop);
65+
}
66+
67+
}

0 commit comments

Comments
 (0)