https://github.com/passiomatic/sunny-land Skip to content Sign up Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Project management - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up Sign up {{ message }} passiomatic / sunny-land * Notifications * Star 22 * Fork 0 A WebGL Playground platformer. BSD-3-Clause License 22 stars 0 forks Star Notifications * Code * Issues 2 * Pull requests 0 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights main Switch branches/tags [ ] Branches Tags Nothing to show {{ refName }} default View all branches Nothing to show {{ refName }} default View all tags 1 branch 0 tags Go to file Code Clone HTTPS GitHub CLI [https://github.com/p] Use Git or checkout with SVN using the web URL. [gh repo clone passio] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio If nothing happens, download the GitHub extension for Visual Studio and try again. Go back Latest commit @passiomatic passiomatic Add project files ... dddc662 Apr 19, 2021 Add project files dddc662 Git stats * 2 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time assets Add project files Apr 19, 2021 src Add project files Apr 19, 2021 .gitignore Add project files Apr 19, 2021 LICENSE Initial commit Mar 17, 2021 README.md Add project files Apr 19, 2021 SunnyLand.code-workspace Add project files Apr 19, 2021 elm.json Add project files Apr 19, 2021 View code Sunny Land -- A WebGL Playground platformer Goals Run locally How this thing works Initialisation Game loop Physics engine Game logic handling Level design Credits README.md Sunny Land -- A WebGL Playground platformer Sunny Land is both a learning experiment and ongoing project to showcase Elm's WebGL Playground package potential. PLAY ONLINE Sunny Land level Goals It aims to have a farly complete feature set found in typical 80's platformers: * A simple 2d physics engine * Different game entities: player, enemies and bonus items * Whole screen graphic FX * Multiple levels (to-do) * Respawn logic (to-do) Run locally Clone the repo and on the command line run Elm's reactor command: elm reactor And the point your browser to http://localhost:8000/src/Main.elm How this thing works Initialisation Depending on Memory.status value an intro screen or a game level is shown. After the intro screen and before playing (and for every level change) entities are spawned using information found in Level.spawns and assigned to Memory.entities. When entities are ready the game loop can run. Game loop At each frame the Main.update function is executed the following steps are performed: 1. All the game entities are updated. In particular, during this step user input is captured and accelaration for the NPC's (non-player characters) is set. 2. The physics simulation is run to figure out the next positions for all the entities taking any contacts into account. 3. The list of contacts resulting from step (2) is finally used to perform any game logic. Physics engine The physics code has been adapted from the particle engine found in Game Physics Engine Development book by Ian Millington. It handles contact detection and resolution between circles and circles against line segments. To handle contacts each physics body (game entity) has an associated circle shape (defined by radius), while ground and walls are defined by line segments. The Physics module knows very little about the game itself, so it can be easily extracted and used on another project. Strictly speaking a physics body needs only a subset of Entity fields, hence it is defined as an extensible record: type alias PhysicsBody a = { a | id : Int , p : Vec2 , v : Vec2 , a : Vec2 , radius : Float , restitution : Float , contact : Vec2 , contactTestBitMask : Int , categoryBitMask : Int , affectedByGravity : Bool , affectedByContact : Bool } The entry point of the physics engine is the Physics.step function. At each frame the step function is called accepting the current level walls and physics bodies and it takes care of: 1. Apply forces (gravity and ground friction) to each body, and update velocity accordingly. 2. For each physics body figure out contacts with walls and other bodies. 3. Resolve contacts one after another, applying impulses to separate affected bodies and fixing interpenetrations. 4. Returns to caller the updated bodies and a list of generated contacts. Game logic handling Each Contact is defined as a custom type: type Contact a = BetweenBodies Int Int ContactData | WithWall Int ContactData While looping through the contact list, WithWall values are discared while BetweenBodies are passed to Entity.respond function. This function figures out what to do next, i.e. when player hits an enemy the game needs to decide if the former stomped the latter or got hit. Level design Game levels are designed using Tiled, saved to JSON files and then converted into Elm code via a Python script (see Levels.elm). You can open assets/level1.json with Tiled and see how the various level layers are used to define the terrain, the obstacles and spawn points for the game entities. Credits Game art by Ansimuz https://ansimuz.itch.io/sunny-land-pixel-game-art About A WebGL Playground platformer. Resources Readme License BSD-3-Clause License Languages * Elm 79.3% * PLSQL 20.7% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.