Skip to content

Commit

Permalink
Create blocks to execute code every n frames.
Browse files Browse the repository at this point in the history
Merge pull request #127 from haroldo-ok/every-n-frames
Fix #103
  • Loading branch information
haroldo-ok authored Oct 28, 2024
2 parents e3a2d5d + eb190f3 commit d081681
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 179 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vcs-game-maker",
"version": "0.26.0",
"version": "0.27.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
54 changes: 54 additions & 0 deletions src/blocks/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const STATE_OPTIONS = [
[`${GAMEOVER_ICON} Gameover`, 'gameover'],
];

const FRAME_OPTIONS = [...Array(7).keys()]
.map((n) => Math.pow(2, n + 1))
.map((n) => [`${n}`, `${n - 1}`]);

Blockly.defineBlocksWithJsonArray([
// Block for events
{
Expand All @@ -38,6 +42,7 @@ Blockly.defineBlocksWithJsonArray([
'colour': 'rgb(39, 176, 176)',
'tooltip': 'Will be executed when a given event happens',
},

// Block for changing game state
{
'type': 'event_change_state',
Expand All @@ -54,4 +59,53 @@ Blockly.defineBlocksWithJsonArray([
'colour': 'rgb(39, 176, 176)',
'tooltip': 'Change game state to a given one',
},

// Block for even/odd frames
{
'type': 'event_frame_even_odd',
'message0': 'On even frames',
'message1': '%1',
'args1': [{
'type': 'input_statement',
'name': 'DO_EVEN',
}],
'message2': 'On odd frames',
'message3': '%1',
'args3': [{
'type': 'input_statement',
'name': 'DO_ODD',
}],
'previousStatement': null,
'nextStatement': null,
'colour': 'rgb(39, 176, 176)',
'tooltip': 'Change game state to a given one',
},

// Block for executing every "n" frames
{
'type': 'event_frame_every_n',
'message0': 'Every %1 frames, plus %2',
'args0': [
{
'type': 'field_dropdown',
'name': 'MASK',
'options': FRAME_OPTIONS,
},
{
'type': 'field_number',
'name': 'DELTA',
'value': 0,
},
],
'message1': '%1',
'args1': [{
'type': 'input_statement',
'name': 'DO',
}],
'previousStatement': null,
'nextStatement': null,
'colour': 'rgb(39, 176, 176)',
'tooltip': 'Execute code every few frames',
},

]);
Loading

0 comments on commit d081681

Please sign in to comment.