Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sprig App] intro_to_sprig #2748

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 193 additions & 0 deletions games/intro_to_sprig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
@title: getting_started
@author: leo, edits
@tags: ['tutorial']
@addedOn: 2022-07-26

Check the tutorial in the bottom right, the run button is in the top right.
Make sure to remix this tutorial if you want to save your progress!
*/


const player = "p";
const box = "b";
const goal = "g";
const wall = "w";
const bob = "o";


setLegend(
[ player, bitmap`
................
................
................
................
.....00000......
....00...00.....
....0.....0.....
....0.....0.....
....00...00.....
.....00000......
......0.0.......
......0.00......
.....0...0......
....00....0.....
....0.....0.....
................`],
[ box, bitmap`
................
................
................
...88888888888..
...8....8....8..
...8....8....8..
...8....8....8..
...8....8....8..
...88888888888..
...8....8....8..
...8....8....8..
...8....8....8..
...8....8....8..
...88888888888..
................
................`],
[ goal, bitmap`
................
................
................
....444444......
...44....44.....
...4......4.....
...4.......4....
...4.......4....
...4.......4....
...44......4....
....4......4....
....44....44....
.....444444.....
................
................
................`],
[ wall, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
[bob, bitmap`
................
................
................
................
................
......HH........
......HH........
.......H........
.....HHHHHH.....
.......H........
......HHH.......
.....HH.HH......
................
................
................
................`]
);

// create game levels
let level = 0; // index starts at 0
const levels = [
map`
..p.
.b.g
....`,
map`
p..
.b.
..g`,
map`
p.wg
.bw.
....
....`,
map`
p...
.b..
...b
..bg`,
map`
...
.p.
...`,
map`
p.w.
.bwg
....
..bg`
];

// set the map displayed to the current level
const currentLevel = levels[level];
setMap(currentLevel);

setSolids([ player, box, wall ]); // other sprites cannot go inside of these sprites

// allow certain sprites to push certain other sprites
setPushables({
[player]: [box]
});


onInput("s", () => {
getFirst(player).y += 1; // positive y is downwards
});
onInput("d", () => {
getFirst(player).x += 1;
});
onInput("w", () => {
getFirst(player).y -= 1;
});
onInput("a", () => {
getFirst(player).x -= 1;
});

onInput("j", () => {
const currentLevel = levels[level]; // get the original map of the level

// make sure the level exists before we load it
if (currentLevel !== undefined) {
clearText("");
setMap(currentLevel);
}
});


// these get run after every input
afterInput(() => {

const targetNumber = tilesWith(goal).length;

const numberCovered = tilesWith(goal, box).length;

if (numberCovered === targetNumber) {
level = level + 1;

const currentLevel = levels[level];

if (currentLevel !== undefined) {
setMap(currentLevel);
} else {
addText("you win!", { y: 4, color: color`3` });
}
}
});
Loading