-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #7
- Loading branch information
Showing
11 changed files
with
977 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |