{"id":31836696,"url":"https://github.com/phialsbasement/whgame-when-language-game-engine","last_synced_at":"2026-02-15T21:02:51.092Z","repository":{"id":316527662,"uuid":"1063753237","full_name":"PhialsBasement/whGame-WHEN-Language-Game-Engine","owner":"PhialsBasement","description":"whGame is a lightweight 2D game engine written entirely in WHEN language. It showcases how WHEN's unique conditional paradigm and implicit looping can elegantly handle game development without traditional control flow structures.","archived":false,"fork":false,"pushed_at":"2025-09-25T04:38:22.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-25T06:21:16.159Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PhialsBasement.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-25T04:31:33.000Z","updated_at":"2025-09-25T04:38:26.000Z","dependencies_parsed_at":"2025-09-25T06:21:20.209Z","dependency_job_id":null,"html_url":"https://github.com/PhialsBasement/whGame-WHEN-Language-Game-Engine","commit_stats":null,"previous_names":["phialsbasement/whgame-when-language-game-engine"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/PhialsBasement/whGame-WHEN-Language-Game-Engine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhialsBasement%2FwhGame-WHEN-Language-Game-Engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhialsBasement%2FwhGame-WHEN-Language-Game-Engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhialsBasement%2FwhGame-WHEN-Language-Game-Engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhialsBasement%2FwhGame-WHEN-Language-Game-Engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PhialsBasement","download_url":"https://codeload.github.com/PhialsBasement/whGame-WHEN-Language-Game-Engine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhialsBasement%2FwhGame-WHEN-Language-Game-Engine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009799,"owners_count":26084648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-12T01:53:55.794Z","updated_at":"2025-10-12T01:53:56.624Z","avatar_url":"https://github.com/PhialsBasement.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# whGame Engine 🎮\r\n\r\nA lightweight game engine written entirely in WHEN language, demonstrating the power and elegance of WHEN's conditional paradigm for game development.\r\n\r\n## 🌟 Features\r\n\r\n- **Pure WHEN Implementation** - No Python game code, just WHEN!\r\n- **Sprite Management** - Create, move, and delete game sprites\r\n- **Collision Detection** - Built-in AABB collision system\r\n- **Keyboard Input** - Real-time keyboard event handling\r\n- **Implicit Game Loop** - Leverages WHEN's main loop paradigm\r\n- **Color Support** - Hex and named color support\r\n- **Window Management** - Easy window creation and configuration\r\n\r\n## 🚀 Quick Start\r\n\r\n### Prerequisites\r\n\r\n- [WHEN Language](https://github.com/PhialsBasement/WHEN-Language) interpreter installed\r\n- Python 3.8+ (for the WHEN interpreter)\r\n- tkinter (usually comes with Python)\r\n\r\n### Installation\r\n\r\n1. Clone this repository:\r\n```bash\r\ngit clone https://github.com/PhialsBasement/whGame-WHEN-Language-Game-Engine.git\r\ncd whGame-Engine\r\n```\r\n\r\n2. Copy `whGame.when` to your WHEN project directory or ensure it's in the same directory as your game file.\r\n\r\n### Your First Game\r\n\r\nCreate a file `my_game.when`:\r\n\r\n```when\r\nimport whGame\r\n\r\nplayer = None\r\nplayer_x = 300\r\nplayer_y = 300\r\n\r\nmain:\r\n    # Initialize once\r\n    when not whGame.initialized:\r\n        whGame.init_engine(600, 400, \"My First Game\", \"#000033\")\r\n        player = whGame.create_sprite(player_x, player_y, 40, 40, \"#00FF00\", \"player\")\r\n\r\n    # Game loop\r\n    when whGame.initialized and whGame.running:\r\n        # Handle input\r\n        when whGame.is_key_pressed(\"left\"):\r\n            player_x = player_x - 5\r\n            whGame.move_sprite(player, -5, 0)\r\n\r\n        when whGame.is_key_pressed(\"right\"):\r\n            player_x = player_x + 5\r\n            whGame.move_sprite(player, 5, 0)\r\n\r\n        # Update display\r\n        whGame.update_display()\r\n        sleep(0.016)  # 60 FPS\r\n\r\n    # Exit on ESC\r\n    when whGame.is_key_pressed(\"escape\"):\r\n        whGame.stop_game()\r\n        exit()\r\n```\r\n\r\nRun your game:\r\n```bash\r\npython when.py my_game.when\r\n```\r\n\r\n## 📚 API Reference\r\n\r\n### Initialization\r\n\r\n#### `init_engine(width, height, title, bg_color)`\r\nInitialize the game engine and create a window.\r\n- `width`: Window width in pixels\r\n- `height`: Window height in pixels\r\n- `title`: Window title string\r\n- `bg_color`: Background color (hex string or color name)\r\n\r\n### Sprites\r\n\r\n#### `create_sprite(x, y, width, height, color, tag)`\r\nCreate a new sprite.\r\n- Returns: Sprite object with properties `x`, `y`, `width`, `height`, `color`, `tag`\r\n\r\n#### `move_sprite(sprite, dx, dy)`\r\nMove a sprite by delta values.\r\n\r\n#### `set_sprite_position(sprite, x, y)`\r\nSet absolute position of a sprite.\r\n\r\n#### `delete_sprite(sprite)`\r\nRemove a sprite from the game.\r\n\r\n### Input\r\n\r\n#### `is_key_pressed(key)`\r\nCheck if a key is currently pressed.\r\n- Common keys: `\"left\"`, `\"right\"`, `\"up\"`, `\"down\"`, `\"space\"`, `\"escape\"`, `\"a\"`-`\"z\"`, `\"0\"`-`\"9\"`\r\n\r\n### Collision\r\n\r\n#### `check_collision(sprite1, sprite2)`\r\nCheck if two sprites are colliding using AABB detection.\r\n- Returns: `True` if colliding, `False` otherwise\r\n\r\n#### `on_collision(tag1, tag2, handler_function)`\r\nRegister a collision handler for sprites with specific tags.\r\n- `handler_function`: Called with `(sprite1, sprite2)` when collision occurs\r\n\r\n### Display\r\n\r\n#### `update_display()`\r\nRefresh the game display. Call this each frame.\r\n\r\n#### `draw_text(x, y, text, color, font)`\r\nDraw text on screen.\r\n- `font`: Optional tuple like `(\"Arial\", 20)`\r\n\r\n#### `clear_canvas()`\r\nClear all sprites from the display.\r\n\r\n### Game Control\r\n\r\n#### `stop_game()`\r\nStop the game loop and close the window.\r\n\r\n#### Properties\r\n- `whGame.initialized`: Boolean, true after init_engine\r\n- `whGame.running`: Boolean, true while game is active\r\n- `whGame.window_width`: Current window width\r\n- `whGame.window_height`: Current window height\r\n\r\n## 🎮 Example Games\r\n\r\n### Asteroid Blaster\r\nA classic space shooter where you defend against falling asteroids.\r\n```bash\r\npython when.py examples_asteroid.when\r\n```\r\n\r\n**Controls:**\r\n- Arrow Keys: Move left/right\r\n- Space: Fire bullets\r\n- ESC: Exit\r\n\r\n### Space Shooter\r\nA vertical scrolling shooter with enemy waves.\r\n```bash\r\npython when.py examples_space.when\r\n```\r\n\r\n**Controls:**\r\n- Arrow Keys: Move left/right\r\n- Space: Shoot\r\n- ESC: Exit\r\n\r\n## 🏗️ Architecture\r\n\r\nwhGame leverages WHEN language's unique features:\r\n\r\n### Implicit Game Loop\r\n```when\r\nmain:\r\n    when whGame.initialized and whGame.running:\r\n        # This runs every frame automatically!\r\n        update_game()\r\n        whGame.update_display()\r\n```\r\n\r\n### Conditional Game Logic\r\n```when\r\n# No if/else needed!\r\nwhen player.health \u003c= 0:\r\n    game_over = True\r\n\r\nwhen game_over:\r\n    display_game_over_screen()\r\n\r\nwhen not game_over:\r\n    continue_gameplay()\r\n```\r\n\r\n### Error-Free Collision Handling\r\n```when\r\n# Using WHEN's safe_call for robust collision detection\r\ncollision_result = safe_call(whGame.check_collision, player, enemy)\r\n\r\nwhen is_success(collision_result) and get_result(collision_result):\r\n    handle_player_hit()\r\n```\r\n\r\n## 🔧 Advanced Features\r\n\r\n### Custom Collision Handlers\r\n```when\r\ndef on_bullet_hits_enemy(bullet, enemy):\r\n    score = score + 10\r\n    whGame.delete_sprite(bullet)\r\n    whGame.delete_sprite(enemy)\r\n\r\nwhGame.on_collision(\"bullet\", \"enemy\", on_bullet_hits_enemy)\r\n```\r\n\r\n### Sprite Velocity System\r\n```when\r\n# Set sprite velocity\r\nwhGame.set_sprite_velocity(enemy, 0, 2)  # Move down at 2 pixels/frame\r\n\r\n# Update all sprites with velocity\r\nwhGame.update_all_sprites_physics()\r\n```\r\n\r\n### Game State Management\r\n```when\r\ngame_state = \"menu\"\r\n\r\nmain:\r\n    when game_state == \"menu\":\r\n        show_menu()\r\n        when whGame.is_key_pressed(\"space\"):\r\n            game_state = \"playing\"\r\n\r\n    when game_state == \"playing\":\r\n        run_game()\r\n        when player_lives == 0:\r\n            game_state = \"game_over\"\r\n\r\n    when game_state == \"game_over\":\r\n        show_game_over()\r\n        when whGame.is_key_pressed(\"r\"):\r\n            reset_game()\r\n            game_state = \"menu\"\r\n```\r\n\r\n## 🤝 Contributing\r\n\r\nWe welcome contributions! whGame is a demonstration of WHEN language capabilities, and we'd love to see what you can build with it.\r\n\r\n### Ideas for Contributions:\r\n- New example games\r\n- Additional sprite shapes (circles, polygons)\r\n- Particle systems\r\n- Sound support (if WHEN adds audio capabilities)\r\n- Animation system\r\n- Tilemap support\r\n\r\n## 📝 License\r\n\r\nMIT License - feel free to use whGame in your own projects!\r\n\r\n## 🙏 Acknowledgments\r\n\r\n- Built for the [WHEN Language](https://github.com/YourUsername/WHEN-Language)\r\n- Inspired by classic game engines but reimagined in WHEN's unique paradigm\r\n- Thanks to the WHEN community for testing and feedback\r\n\r\n## 🐛 Known Limitations\r\n\r\n- No audio support (WHEN language limitation)\r\n- Basic shapes only (rectangles)\r\n- No image/sprite sheet support (WHEN uses colored rectangles)\r\n- Single window only\r\n- No fullscreen mode\r\n\r\n## 🚦 Roadmap\r\n\r\n- [ ] Sprite rotation\r\n- [ ] Particle effects system\r\n- [ ] Multiple collision shapes\r\n- [ ] Scene management\r\n- [ ] Save/Load game state\r\n- [ ] Networking support for multiplayer\r\n- [ ] Performance optimizations\r\n- [ ] Mobile touch input support\r\n\r\n---\r\n\r\n**Made with ❤️ in WHEN Language**\r\n\r\n\r\n*Remember: In WHEN, everything is a condition, even your game loop!*\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphialsbasement%2Fwhgame-when-language-game-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphialsbasement%2Fwhgame-when-language-game-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphialsbasement%2Fwhgame-when-language-game-engine/lists"}