Skip to content

Commit

Permalink
Do a full pass on docs, compatibility, and content
Browse files Browse the repository at this point in the history
  • Loading branch information
kognise committed Mar 10, 2023
1 parent 8e9cfd8 commit 31e30e9
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 195 deletions.
8 changes: 5 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

## About your game

What is your game about?
**What is your game about?**

<!-- Example: Pushing boxes to the goal. (from [Sokoban Plus](https://sprig.hackclub.com/gallery/sokoban_plus)) -->

How to play your game?
**How do you play your game?**

<!-- Example : Press WASD to move, J to restart and K to toggle trails, Get A boxes (cyan) to A goals (green), Get B boxes (magenta) to B goals (red), Get normal boxes (gray) to either goal. (from [Sokoban plus](https://sprig.hackclub.com/gallery/sokoban_plus)) -->

## Code
Expand All @@ -22,4 +24,4 @@ Check off the items that are true. <!-- Put a `x` in the `[ ]`. Example: `[x] T
- [ ] The image is in the [`/games/img` directory](https://github.com/hackclub/sprig/tree/main/games/img).
- [ ] The name of the image matches the name of your file. <!-- Example: `sokoban_plus.js` -> `sokoban_plus.png`. -->

> Thanks for PR!
> Thanks for your PR!
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Welcome to Sprig!

The most straightforward way to contribute to Sprig is to [submit a game](https://sprig.hackclub.com/share) to the gallery.
The most straightforward way to contribute to Sprig is to [submit a game](https://sprig.hackclub.com/get) to the gallery.

You can also help out by fixing issues in the "Issues" tracker.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Hack Club

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ People learn best when they make things that they care about, which they can the

To get started you can follow [this challenge in the editor](https://sprig.hackclub.dev/gallery/getting_started), check out some [Sprig workshops](https://workshops.hackclub.com#sprig) or watch some short videos to get acquainted with Sprig:

[This video shows a quick overview of the editor.](https://youtu.be/GEbDRR_cqJI)
<!-- [This video shows a quick overview of the editor.](https://youtu.be/GEbDRR_cqJI)
[This video shows making a simple example "game".](https://youtu.be/1UTLS4aO9bQ)
[This video shows making a simple example "game".](https://youtu.be/1UTLS4aO9bQ) -->

## Development

Expand Down
6 changes: 6 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"./src/lib/engine/1-base/palette": "./src/lib/engine/1-base/palette.ts",
"./src/lib/engine/1-base/text": "./src/lib/engine/1-base/text.ts"
}
}
23 changes: 23 additions & 0 deletions deno.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2",
"remote": {
"https://deno.land/[email protected]/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74",
"https://deno.land/[email protected]/bytes/bytes_list.ts": "aba5e2369e77d426b10af1de0dcc4531acecec27f9b9056f4f7bfbf8ac147ab4",
"https://deno.land/[email protected]/bytes/equals.ts": "3c3558c3ae85526f84510aa2b48ab2ad7bdd899e2e0f5b7a8ffc85acb3a6043a",
"https://deno.land/[email protected]/bytes/mod.ts": "b2e342fd3669176a27a4e15061e9d588b89c1aaf5008ab71766e23669565d179",
"https://deno.land/[email protected]/io/buffer.ts": "fae02290f52301c4e0188670e730cd902f9307fb732d79c4aa14ebdc82497289",
"https://deno.land/[email protected]/io/types.d.ts": "107e1e64834c5ba917c783f446b407d33432c5d612c4b3430df64fc2b4ecf091",
"https://deno.land/[email protected]/streams/conversion.ts": "555c6c249f3acf85655f2d0af52d1cb3168e40b1c1fa26beefea501b333abe28",
"https://deno.land/[email protected]/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462",
"https://deno.land/[email protected]/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3",
"https://deno.land/[email protected]/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0",
"https://deno.land/[email protected]/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b",
"https://deno.land/[email protected]/path/_util.ts": "d7abb1e0dea065f427b89156e28cdeb32b045870acdf865833ba808a73b576d0",
"https://deno.land/[email protected]/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000",
"https://deno.land/[email protected]/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1",
"https://deno.land/[email protected]/path/mod.ts": "4b83694ac500d7d31b0cdafc927080a53dc0c3027eb2895790fb155082b0d232",
"https://deno.land/[email protected]/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d",
"https://deno.land/[email protected]/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1",
"https://deno.land/[email protected]/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba"
}
}
14 changes: 4 additions & 10 deletions docs/BACKBURNER.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
- Switch to dark version on hype page
- [animate growing sprig as you scroll](https://github.com/hackclub/sprig/issues/334)
- Redesign main menu
- adjust colors?
- Adjust color palette
- Adjust colors?
- Color map imported sprites
- Add whitenoise waveform
- Change default mobile game to playable one
- Add table of contents to docs
- Make a sprite gallery
- [x] Run games in strict mode
- will have to update any broken gallery games if we do this
- also have to adjust line number on error messages
- improve error logging
- [Make a sprite gallery](https://github.com/hackclub/sprig/issues/345)
- Improve error logging
- [Storage Abstraction for Games](https://github.com/hackclub/sprig/issues/362)
- [make a sprite gallery](https://github.com/hackclub/sprig/issues/345)
- [fix folding for ternary operator](https://github.com/hackclub/sprig/issues/360)
- [Fix folding for ternary operator](https://github.com/hackclub/sprig/issues/360)

149 changes: 2 additions & 147 deletions docs/BEGINNER_WORKSHOP.md
Original file line number Diff line number Diff line change
@@ -1,148 +1,3 @@
# Sprig Workshop - Beginner Level
# Build your first Sprig game!

## What is Sprig?
Sprig is a open-source handheld console developed by Hack Club. It uses a Raspberry Pi Pico and you can write games for it using Javascript. It is a tiny game engine that is embedded into the web and allows for you to quickly create tile-based games. Once you are done building your game, you can share it by making a PR, which if approved, will add it to the gallery.

## Getting Started
Go to the [Sprig editor](https://sprig.hackclub.com/editor) to start creating your own Sprig games. In this workshop we will build a simple game where you will control a player that pushes boxes into a goal.

### Creating and saving a game
When you open up sprig editor, you should be greeted by some code that is already there to serve as a little tutorial. In this workshop we won't need that code, so you can delete everything to get a clean file.
![](assets/default-window.png)
To save the game, you first need to name it by adding a multiline comment like this:
```
/*
@title: your_game
@author: your_name
*/
```
Next, you can save the game by going to `file` -> `save`, or by pressing ctrl + s. The game will be saved in the local storage in your browser, and it will not be accessible outside of your browser. To save it reliabily, download it as a `.js` file by going to `file` -> `share` -> `as file`.

### Sprite and bitmaps
All the interactable characters in your game will have to be sprites. To declare some sprites follow these steps:
First, declare the characters you will be using to identify your sprites.
```
const player = "p";
const box = "b";
const goal = "g";
```
Next, you will need to give them some textures.
```
setLegend(
[ player, bitmap`` ],
[ box, bitmap`` ],
[ goal, bitmap`` ]
);
```
Typing out the `bitmap` keyword should make it green and clickable. Clicking on it will open up the sprite editor, where you will be able to draw out what you want your sprites to look like.
![](assets/sprite-editor.png)

### Levels and maps
Now that you have the sprites, next thing you will need is a level for the sprites to move and play around in. Creating a level is very similar to creating a bitmap for a sprite.
```
let level = 0;
const levels = [
map``
];
let currentLevel = levels[level];
```
Like the `bitmap` keyword, the `map` is also clickable, and clicking it will open the map editor, where you can edit how you want your level to look like. You change the size the level, as well as adding sprites to the tiles.
![](assets/map-editor.png)
Once you are satisfied with your level, you can set that level as the one to be used.
```
setMap(currentLevel);
```

### Pushing Solids
Now we must add the mechanic of the player being able to push boxes. To first do this, we must set both the player and the box sprites as solids. Anything that is set as a solid cannot overlap with anything else that is solid.
```
setSolids([ player, box ]);
```
Next, we must make it so that the box sprite can be pushed around by the player sprite. This can be done by the `setPushables` function, which determines which sprites are allowed to push which sprites.
```
setPushables({
[ player ]: [ box ]
});
```
Now we are able to push around the box, but we can't do that yet as we can't move around!

### Taking Inputs
The Sprig console has 8 push buttons that it can take input from, which we can in the browser version represent as `WASD` and `IJKL`. To react to any presses of these keys, we can use the `onInput` function. Inside it, we can specify what we want to happen when that key is pressed. For our game, we want to move the player around using `WASD` keys. To move the player around, we can change the x and y components of the player sprite.
```
onInput("s", () => {
let playerSprite = getFirst(player); // Gets the sprite of the player
playerSprite.y++; // Moves the player one tile down
});
```
Try to replicate it for the W, A, and D keys to make the player move around in all four directions.

### Winning the game
Now that you are able to push the box around the level, we need to check if the box has been pushed onto the goal, and if so restart the game. We can check for this in the `afterInput` function. This function is executed after the inputs have been processed, and it works very similarly to the `onInput` funciton. To check that the box sprite is overlapping the goal sprite, we can check if their x and y positions are the same.
```
afterInput(() => {
let boxSprite = getFirst(box); // Gets the sprite of the box
let goalSprite = getFirst(goal); // Gets the sprite of the goal
// Check if they overlap
if (boxSprite.x == goalSprite.x && boxSprite.y == goalSprite.y) {
// You win
currentLevel = levels[level];
setMap(currentLevel);
}
});
```
We reset the game by setting the level back to what we set it in the beginning, which puts all the sprites back where they started.

### Adding Obstacles
We have a simple working game now, but there is no challenge and it is very boring. To remedy that, we are going to add obstacles, solid blocks that are scattered on the map that you cannot push around and are a barrier that player must go around. To do this we can create another sprite:
```
const obstacle = "o";
setLegend(
[ player, bitmap`` ],
[ box, bitmap`` ],
[ goal, bitmap`` ],
[ obstacle, bitmap`` ]
);
setSolids([player, box, obstacle]);
```
Since we don't want the obstacle to be pushed around, we will not add it the list of things that the player sprite can push around. Now you can open the map editor and scatter the obstacle block wherever you feel like, adding a bit of challenge into the game.

### Restart Mechanic
Sometimes, the box get stuck in a corner so that the player is unable to move it around. In this case, the user should have the option to restart the game. We add this mecahnic by setting the J key as the restart button, and then we use the code we did for player movement to check for key presses.
```
onInput("j", () => {
currentLevel = levels[level];
setMap(currentLevel);
});
```

### Adding more levels
One level may not just be enough, so to add more levels to the game, you can just add more maps to the levels list we created in the beginning. Make sure to edit it so that each map is different.
```
let level = 0;
const levels = [
map``,
map``,
map``,
map``,
];
let currentLevel = levels[level];
```
To make the user enter the next level when the player completes one level, we will have to modify the code we wrote when we added the win mechanic. Everytime the player completes one level, we increment the `level` variable so that they are on the next one. However the array of levels is finite and to avoid overflow, we will need to make sure that the value of `level` is not greater than the size of the `levels` array.
```
// Check if they overlap
if (boxSprite.x == goalSprite.x && boxSprite.y == goalSprite.y) {
// You win
level++; // Increment the level we are on
if (level >= levels.length) level = 0; // Go back to the first level if user finishes all levels
currentLevel = levels[level];
setMap(currentLevel);
}
```

### End, or the Beginning?
We have now finished building a very simple game, and now it's your time to hack and expand the game any way you want. You can change the sprites, add more game mechanics and maybe check out the advanced version that goes over more features of Sprig. There is a bustling online community in [#sprig](https://hackclub.slack.com/archives/C02UN35M7LG) channel on the [Hack Club Slack](https://hackclub.com/slack), where you can ask questions, share ideas and hang around with other Sprig makers.
Please see <https://workshops.hackclub.com/sprig_first_game/> for the latest version of this workshop.
4 changes: 2 additions & 2 deletions docs/GET_A_SPRIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

**Anyone can submit to the gallery, but read the details below if you want your very own Sprig.** If you have any questions, join #sprig on our [Slack](https://hackclub.com/slack)!

Sprig consoles are a limited run and will be ready for delivery end of 2022*.
Sprig consoles are a limited run and have been ready for delivery since end of 2022*.

Get on the waitlist now by [sharing your game](https://sprig.hackclub.com/share) and having it approved by one of our project maintainers. Once your GitHub pull request is approved, we'll collect your shipping details.
Get on the waitlist now by [sharing your game](https://sprig.hackclub.com/get) and having it approved by one of our project maintainers. Once your GitHub pull request is approved, we'll collect your shipping details.

There are only a few requirements to get a Sprig console:

Expand Down
4 changes: 2 additions & 2 deletions docs/UPLOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ cp -X ~/Downloads/pico-os.uf2 /Volumes/RPI-RP2

## Okay but how do I upload MY game?

![drop!](https://cloud-7fl999odl-hack-club-bot.vercel.app/0screenshot3.png)
![drop!](https://doggo.ninja/lRotxY.png)

Open up your game in the editor, click the upload button, and select the Sprig from the menu (again, like a USB device.)
Open up your game in the editor, click the "Run on Device" button in the top right, and select the Sprig from the menu (again, like a USB device.)

That's it! You're done :)
Binary file removed docs/assets/default-window.png
Binary file not shown.
Binary file removed docs/assets/map-editor.png
Binary file not shown.
Binary file removed docs/assets/sprite-editor.png
Binary file not shown.
Binary file removed docs/assets/upload_button.png
Binary file not shown.
13 changes: 4 additions & 9 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ Run games by hitting the `Run` button or pressing `Shift+Enter`.

## Getting Help

If this is your first time using Sprig, try playing through the [tutorial](https://sprig.hackclub.dev/gallery/getting_started).
If this is your first time using Sprig, try playing through the [tutorial](https://sprig.hackclub.dev/gallery/getting_started). From there, we suggest hacking on any of the [current games](https://sprig.hackclub.com/gallery) or starting from scratch.

You can also watch this [introduction to the editor](https://www.youtube.com/watch?v=GEbDRR_cqJI) or [walkthrough](https://www.youtube.com/watch?v=1UTLS4aO9bQ) on how to make a game. From there, we suggest hacking on any of the [current games](https://sprig.hackclub.com/gallery) or starting from scratch.
<!-- If this is your first time using Sprig, try playing through the [tutorial](https://sprig.hackclub.dev/gallery/getting_started).
You can also watch this [introduction to the editor](https://www.youtube.com/watch?v=GEbDRR_cqJI) or [walkthrough](https://www.youtube.com/watch?v=1UTLS4aO9bQ) on how to make a game. From there, we suggest hacking on any of the [current games](https://sprig.hackclub.com/gallery) or starting from scratch. -->

If you ever need help, have ideas, or want to meet other game-makers, join the community in the [#sprig](https://hackclub.slack.com/archives/C02UN35M7LG) channel on the [Hack Club Slack](https://hackclub.com/slack).

Expand Down Expand Up @@ -262,13 +264,6 @@ const playback = playTune(melody, Infinity)
playback.end()
```


## Debugging

Open up your browser console to debug.

You can look at game state by running `getState()` in the console. This will only work in the browser and not physical Sprigs; please avoid using this in your game. If you need the map size, use `width()` and `height()` instead.

<!--
## Idioms
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sprig-3",
"name": "sprig",
"version": "1.0.0",
"main": "index.js",
"type": "module",
Expand All @@ -8,7 +8,7 @@
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview"
"test": "deno run --allow-read ./tests/sprigfuzzy.js"
},
"dependencies": {
"@astrojs/preact": "^2.0.1",
Expand All @@ -29,8 +29,6 @@
"ms": "^2.1.3",
"nanoid": "^4.0.1",
"preact": "^10.6.5",
"react": "npm:@preact/compat",
"react-dom": "npm:@preact/compat",
"react-icons": "^4.7.1",
"sass": "^1.58.0",
"svelte": "^3.54.0",
Expand Down
Binary file added pico-os.uf2
Binary file not shown.
10 changes: 7 additions & 3 deletions src/components/popups-etc/help.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
box-shadow: 0 0 20px 0 #00000038;
}

.content strong {
color: #000000;
}

.content h1 {
text-align: center;
margin: 0;
Expand All @@ -51,7 +55,7 @@
}

.content h2 {
color: var(--pcb-base);
color: var(--accent-dark);
margin: 0;
font-size: 1.75em;
margin-top: 40px;
Expand All @@ -72,12 +76,12 @@

.content code, .content pre {
font-family: var(--font-code);
font-size: inherit;
font-size: 0.9rem;
background: #e9ecef;
color: #343a40;
}

.content code {
.content code {
padding: 0 4px;
}

Expand Down
7 changes: 7 additions & 0 deletions src/pages/editor.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { PersistenceState } from '../lib/state'
import { mobileUserAgent } from '../lib/utils/mobile'
import MobileUnsupported from '../components/popups-etc/mobile-unsupported'
// Redirects for legacy Sprig URLs
const galleryRegex = /^https:\/\/raw\.githubusercontent\.com\/hackclub\/sprig\/main\/games\/(.+)\.js$/
const galleryMatches = Astro.url.searchParams.get('file')?.match(galleryRegex) ?? null
if (galleryMatches) return Astro.redirect(`/gallery/${galleryMatches[1]}`, 302)
if (Astro.url.searchParams.has('id'))
return Astro.redirect(`/legacy-bucket/${Astro.url.searchParams.get('id')}`, 302)
const tempGame = Astro.cookies.get('sprigTempGame').value
if (tempGame) return Astro.redirect(`/~/${encodeURIComponent(tempGame)}`, 302)
Expand Down
Loading

0 comments on commit 31e30e9

Please sign in to comment.