Skip to content

Commit

Permalink
Created new forest map (#88)
Browse files Browse the repository at this point in the history
Part of #7
  • Loading branch information
r4pt0s authored Oct 5, 2024
2 parents 99c11d5 + b56417b commit 532eb72
Show file tree
Hide file tree
Showing 11 changed files with 977 additions and 1 deletion.
3 changes: 3 additions & 0 deletions asset_credits.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ https://marceles.itch.io/land-of-pixels-laboratory-tileset-pixel-art
https://pipoya.itch.io/charamel | Create awesome Characters

https://adriccustoms.itch.io/little-bits-office

https://opengameart.org/content/lpc-forest-tiles
By users Sharm, Hyptosis, Johann C, Beast, William. Thompsonj, & Reemax | Assets made by Lanea Zimmerman, Tuomo Untinen, Manuel Riecke
Binary file added public/exports/maps/map_forest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/forest_sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
870 changes: 870 additions & 0 deletions public/maps/map_forest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/maps/map_start.json
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.11.0",
"tileheight":16,
"tileheight":16,
"tilesets":[
{
"columns":19,
Expand Down
27 changes: 27 additions & 0 deletions src/gameObjects/map_forest/butterfly.gameObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { scaleFactor } from '../../constants';

export const butterfly = (k, map, spawnpoints) => {
k.loadSprite('butterfly', './forest_sprites.png', {
sliceX: 16,
sliceY: 16,
anims: {
'walk-side': { from: 89, to: 91, loop: true, speed: 4 },
'idle-side': 90,
},
});

return k.make([
k.sprite('butterfly', { anim: 'idle-side' }),
k.area({
shape: new k.Rect(k.vec2(0), 16,16),
}),
k.body({ isStatic: true }),
k.anchor('center'),
k.pos(
map.pos.x + spawnpoints.butterfly_a_1.x,
map.pos.y + spawnpoints.butterfly_a_1.y
),
k.scale(scaleFactor + 0.5),
'butterfly',
]);
};
18 changes: 18 additions & 0 deletions src/gameObjects/map_forest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { butterfly } from "./butterfly.gameObject";

const gameObjects = [butterfly];

export const addGameObjects = (k, map, spawnpoints) => {
return gameObjects.reduce((gameObjAcc, cb) => {
const temp = cb(k, map, spawnpoints);

if (Array.isArray(temp)) {
gameObjAcc.push(...temp);
return gameObjAcc;
}

gameObjAcc.push(temp);

return gameObjAcc;
}, []);
};
7 changes: 7 additions & 0 deletions src/interactions/map_city/enterMapForest.interactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const enterMapForestInteraction = (player, k, map) => {
player.onCollide('enter_map_top', () => {
import('../../scenes/forest').then((_) => {
k.go('forest', 'enter_forest');
});
});
};
2 changes: 2 additions & 0 deletions src/interactions/map_city/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { boundaryArcadeInteraction } from './boundaryArcade.interaction';
import { boundaryBurgerBarInteraction } from './boundaryBurgerBar.interaction';
import { enterMapArcadeInteraction } from './enterMapArcade.interactions';
import { enterMapForestInteraction } from './enterMapForest.interactions';
import { enterMapStartInteraction } from './enterMapStart.interaction';
import {
snackBarRedInteraction,
Expand All @@ -12,6 +13,7 @@ import { stall1Interaction, stall2Interaction } from './stalls.interaction';
const interactions = [
enterMapArcadeInteraction,
enterMapStartInteraction,
enterMapForestInteraction,
boundaryBurgerBarInteraction,
boundaryArcadeInteraction,
snackBarRedInteraction,
Expand Down
9 changes: 9 additions & 0 deletions src/interactions/map_forest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const interactions = [
// Add more interactions here
];

export const attachInteractions = (gameObj, k) => {
const map = k.get('main_map')[0];

interactions.forEach((cb) => cb(gameObj, k, map));
};
40 changes: 40 additions & 0 deletions src/scenes/forest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { makePlayer } from '../factories/player.factory';
import { initMap } from '../init/map.init';
import { k } from '../kplayCtx';
import { attachInteractions } from '../interactions/map_forest';
import { addGameObjects } from '../gameObjects/map_forest';
import { addPlayerControls } from '../player.controls';
import { getGameState } from '../utils/gameState';

k.scene('forest', async (enter_tag) => {
const objectConfig = {
static: [
'map_boundaries',
'building_boundaries',
'enter_new_map_boundaries',
],
spawnpoints: ['spawnpoints'],
interactionObjects: ['interaction_objects'],
};
const [map, spawnpoint] = await initMap(
k,
objectConfig,
'./exports/maps/map_forest.png',
'./maps/map_forest.json',
k.vec2(0, 11)
);

const gameState = getGameState();
const player = makePlayer(gameState.player);

player.pos = (enter_tag && spawnpoint[enter_tag]) || spawnpoint.player;

k.add(map);
k.add(player);
k.canvas.focus();

addGameObjects(k, map, spawnpoint).forEach((obj) => k.add(obj));
attachInteractions(player, k);

addPlayerControls(k, player);
});

0 comments on commit 532eb72

Please sign in to comment.