mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-21 09:35:27 -04:00
75bfa5cb45
- Global or scene variables can be used with a unique action and condition. - Object variables can be used with a unique action and condition. - Variables need to be declared following the same logic as the new expression syntax. - Local variable can be declared on events - Extensions have their own variables - Show a diagnostic report when a preview is launched and there are missing scene variables, object variables or behaviors. - This is especially useful if external events are shared between several scenes.
285 lines
7.7 KiB
JavaScript
285 lines
7.7 KiB
JavaScript
|
|
const makePlatformerTestRuntimeScene = (timeDelta = 1000 / 60) => {
|
|
const runtimeGame = gdjs.getPixiRuntimeGame();
|
|
const runtimeScene = new gdjs.TestRuntimeScene(runtimeGame);
|
|
runtimeScene.loadFromScene({sceneData: {
|
|
layers: [{ name: '', visibility: true, effects: [] }],
|
|
variables: [],
|
|
behaviorsSharedData: [],
|
|
objects: [],
|
|
instances: [],
|
|
}, usedExtensionsWithVariablesData: []});
|
|
runtimeScene._timeManager.getElapsedTime = function () {
|
|
return timeDelta;
|
|
};
|
|
return runtimeScene;
|
|
};
|
|
|
|
const addPlatformObject = (runtimeScene) => {
|
|
const platform = new gdjs.TestRuntimeObject(runtimeScene, {
|
|
name: 'obj2',
|
|
type: '',
|
|
behaviors: [
|
|
{
|
|
type: 'PlatformBehavior::PlatformBehavior',
|
|
name: 'Platform',
|
|
canBeGrabbed: true,
|
|
},
|
|
],
|
|
effects: [],
|
|
});
|
|
platform.setCustomWidthAndHeight(60, 32);
|
|
runtimeScene.addObject(platform);
|
|
|
|
return platform;
|
|
};
|
|
|
|
const addUpSlopePlatformObject = (runtimeScene) => {
|
|
const platform = new gdjs.TestSpriteRuntimeObject(runtimeScene, {
|
|
name: 'slope',
|
|
type: '',
|
|
behaviors: [
|
|
{
|
|
type: 'PlatformBehavior::PlatformBehavior',
|
|
name: 'Platform',
|
|
canBeGrabbed: true,
|
|
},
|
|
],
|
|
effects: [],
|
|
animations: [
|
|
{
|
|
name: 'animation',
|
|
directions: [
|
|
{
|
|
sprites: [
|
|
{
|
|
originPoint: { x: 0, y: 0 },
|
|
centerPoint: { x: 50, y: 50 },
|
|
points: [
|
|
{ name: 'Center', x: 0, y: 0 },
|
|
{ name: 'Origin', x: 50, y: 50 },
|
|
],
|
|
hasCustomCollisionMask: true,
|
|
customCollisionMask: [
|
|
[
|
|
{ x: 100, y: 100 },
|
|
{ x: 0, y: 100 },
|
|
{ x: 100, y: 0 },
|
|
],
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
runtimeScene.addObject(platform);
|
|
platform.setUnscaledWidthAndHeight(100, 100);
|
|
platform.setCustomWidthAndHeight(100, 100);
|
|
|
|
return platform;
|
|
};
|
|
|
|
const addDownSlopePlatformObject = (runtimeScene) => {
|
|
const platform = new gdjs.TestSpriteRuntimeObject(runtimeScene, {
|
|
name: 'slope',
|
|
type: '',
|
|
behaviors: [
|
|
{
|
|
type: 'PlatformBehavior::PlatformBehavior',
|
|
name: 'Platform',
|
|
canBeGrabbed: true,
|
|
},
|
|
],
|
|
effects: [],
|
|
animations: [
|
|
{
|
|
name: 'animation',
|
|
directions: [
|
|
{
|
|
sprites: [
|
|
{
|
|
originPoint: { x: 0, y: 0 },
|
|
centerPoint: { x: 50, y: 50 },
|
|
points: [
|
|
{ name: 'Center', x: 0, y: 0 },
|
|
{ name: 'Origin', x: 50, y: 50 },
|
|
],
|
|
hasCustomCollisionMask: true,
|
|
customCollisionMask: [
|
|
[
|
|
{ x: 100, y: 100 },
|
|
{ x: 0, y: 100 },
|
|
{ x: 0, y: 0 },
|
|
],
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
runtimeScene.addObject(platform);
|
|
platform.setUnscaledWidthAndHeight(100, 100);
|
|
platform.setCustomWidthAndHeight(100, 100);
|
|
|
|
return platform;
|
|
};
|
|
|
|
const addTunnelPlatformObject = (runtimeScene) => {
|
|
const platform = new gdjs.TestSpriteRuntimeObject(runtimeScene, {
|
|
name: 'tunnel',
|
|
type: '',
|
|
behaviors: [
|
|
{
|
|
type: 'PlatformBehavior::PlatformBehavior',
|
|
name: 'Platform',
|
|
canBeGrabbed: true,
|
|
},
|
|
],
|
|
effects: [],
|
|
animations: [
|
|
{
|
|
name: 'animation',
|
|
directions: [
|
|
{
|
|
sprites: [
|
|
{
|
|
originPoint: { x: 0, y: 0 },
|
|
centerPoint: { x: 50, y: 50 },
|
|
points: [
|
|
{ name: 'Center', x: 0, y: 0 },
|
|
{ name: 'Origin', x: 50, y: 50 },
|
|
],
|
|
hasCustomCollisionMask: true,
|
|
customCollisionMask: [
|
|
[
|
|
{ x: 0, y: 0 },
|
|
{ x: 0, y: 100 },
|
|
{ x: 100, y: 100 },
|
|
{ x: 100, y: 0 },
|
|
],
|
|
[
|
|
{ x: 0, y: 200 },
|
|
{ x: 0, y: 300 },
|
|
{ x: 100, y: 300 },
|
|
{ x: 100, y: 200 },
|
|
],
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
runtimeScene.addObject(platform);
|
|
platform.setUnscaledWidthAndHeight(100, 300);
|
|
platform.setCustomWidthAndHeight(100, 300);
|
|
|
|
return platform;
|
|
};
|
|
|
|
/**
|
|
* @returns A platform with 2 hitboxes that can act as a floor and a wall at
|
|
* the same time.
|
|
* It can happen when a tile map collision mask object is used because all
|
|
* the platforms are part of the same object instance.
|
|
*/
|
|
const addFloorAndWallPlatformObject = (runtimeScene) => {
|
|
const platform = new gdjs.TestSpriteRuntimeObject(runtimeScene, {
|
|
name: 'elbow',
|
|
type: '',
|
|
behaviors: [
|
|
{
|
|
type: 'PlatformBehavior::PlatformBehavior',
|
|
name: 'Platform',
|
|
canBeGrabbed: true,
|
|
},
|
|
],
|
|
effects: [],
|
|
animations: [
|
|
{
|
|
name: 'animation',
|
|
directions: [
|
|
{
|
|
sprites: [
|
|
{
|
|
originPoint: { x: 0, y: 0 },
|
|
centerPoint: { x: 50, y: 50 },
|
|
points: [
|
|
{ name: 'Origin', x: 0, y: 0 },
|
|
{ name: 'Center', x: 50, y: 50 },
|
|
],
|
|
hasCustomCollisionMask: true,
|
|
customCollisionMask: [
|
|
// Wall
|
|
[
|
|
{ x: 80, y: 0 },
|
|
{ x: 80, y: 100 },
|
|
{ x: 100, y: 100 },
|
|
{ x: 100, y: 0 },
|
|
],
|
|
// Floor
|
|
[
|
|
{ x: 0, y: 80 },
|
|
{ x: 0, y: 100 },
|
|
{ x: 100, y: 100 },
|
|
{ x: 100, y: 80 },
|
|
],
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
runtimeScene.addObject(platform);
|
|
platform.setUnscaledWidthAndHeight(100, 300);
|
|
platform.setCustomWidthAndHeight(100, 300);
|
|
|
|
return platform;
|
|
};
|
|
|
|
const addJumpThroughPlatformObject = (runtimeScene) => {
|
|
const platform = new gdjs.TestRuntimeObject(runtimeScene, {
|
|
name: 'obj2',
|
|
type: '',
|
|
behaviors: [
|
|
{
|
|
type: 'PlatformBehavior::PlatformBehavior',
|
|
name: 'Platform',
|
|
platformType: 'Jumpthru',
|
|
canBeGrabbed: false,
|
|
},
|
|
],
|
|
effects: [],
|
|
});
|
|
platform.setCustomWidthAndHeight(60, 32);
|
|
runtimeScene.addObject(platform);
|
|
|
|
return platform;
|
|
};
|
|
|
|
const addLadderObject = (runtimeScene) => {
|
|
const ladder = new gdjs.TestRuntimeObject(runtimeScene, {
|
|
name: 'obj3',
|
|
type: '',
|
|
behaviors: [
|
|
{
|
|
type: 'PlatformBehavior::PlatformBehavior',
|
|
name: 'Platform',
|
|
canBeGrabbed: false,
|
|
platformType: 'Ladder',
|
|
},
|
|
],
|
|
effects: [],
|
|
});
|
|
ladder.setCustomWidthAndHeight(20, 60);
|
|
runtimeScene.addObject(ladder);
|
|
|
|
return ladder;
|
|
}; |