From 06ad229b24b585acc59ea732bbdb36517dc2d38d Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Mon, 28 Oct 2024 19:00:43 -0300 Subject: [PATCH 1/7] Create block for handling even/odd frames. Starting to implement #103 --- src/blocks/event.js | 23 +++++++++++++++++++++++ src/components/blockly-toolbox.xml.hbs | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/blocks/event.js b/src/blocks/event.js index d1ff09d..be1a7cd 100644 --- a/src/blocks/event.js +++ b/src/blocks/event.js @@ -38,6 +38,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', @@ -54,4 +55,26 @@ 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', + }, + ]); diff --git a/src/components/blockly-toolbox.xml.hbs b/src/components/blockly-toolbox.xml.hbs index 750dc15..5a85a03 100644 --- a/src/components/blockly-toolbox.xml.hbs +++ b/src/components/blockly-toolbox.xml.hbs @@ -230,6 +230,8 @@ + + From ff7aaae95091f8520c80742790efb73e384c90b7 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Mon, 28 Oct 2024 19:26:49 -0300 Subject: [PATCH 2/7] Implement code generation for odd-even frames. --- src/generators/bbasic.bb.hbs | 4 ++++ src/generators/bbasic/event.js | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/generators/bbasic.bb.hbs b/src/generators/bbasic.bb.hbs index d073aa5..9180d41 100644 --- a/src/generators/bbasic.bb.hbs +++ b/src/generators/bbasic.bb.hbs @@ -24,6 +24,7 @@ dim player1realcolor = q dim player0animation = p dim player1animation = o + dim framecounter = n newbackground = 1 @@ -80,6 +81,9 @@ main rem ************************************************************************** commongamelogic + + framecounter = framecounter + 1 + rem ************************************************************************** rem Sound handling. rem ************************************************************************** diff --git a/src/generators/bbasic/event.js b/src/generators/bbasic/event.js index 29f7448..b8f3b34 100644 --- a/src/generators/bbasic/event.js +++ b/src/generators/bbasic/event.js @@ -15,4 +15,27 @@ export default (Blockly) => { Blockly.VARIABLE_CATEGORY_NAME); return `goto ${stateName}_start_begin`; }; + + Blockly.BBasic['event_frame_even_odd'] = function(block) { + // Block for even/odd frames + const blockNumber = Blockly.BBasic.blockNumbers.next(); + + const labelStart = `_if_${blockNumber}`; + const labelOdd = `${labelStart}_odd`; + const labelEnd = `${labelStart}_end`; + + const evenCode = Blockly.BBasic.statementToCode(block, 'DO_EVEN').trim(); + const oddCode = Blockly.BBasic.statementToCode(block, 'DO_ODD').trim(); + return '\n' + + [ + 'temp1 = framecounter & 1', + `if temp1 then goto ${labelOdd}`, + evenCode, + `goto ${labelEnd}`, + `@ ${labelOdd}`, + oddCode, + `@ ${labelEnd}`, + ].join('\n') + + '\n'; + }; }; From 8d7d92547e7bfc121ced42a5ccbb6d1b188cda0f Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Mon, 28 Oct 2024 19:36:41 -0300 Subject: [PATCH 3/7] Update the "Diagonal bouncing ball" example to use the even/odd frames block. --- .../blockly-toolbox-ball-movement.xml | 320 ++++++++---------- 1 file changed, 142 insertions(+), 178 deletions(-) diff --git a/src/components/blockly-toolbox-ball-movement.xml b/src/components/blockly-toolbox-ball-movement.xml index a9b1a70..7c1ce4a 100644 --- a/src/components/blockly-toolbox-ball-movement.xml +++ b/src/components/blockly-toolbox-ball-movement.xml @@ -156,7 +156,7 @@ - + @@ -217,213 +217,177 @@ - - - - - Even Frame - - - - - Even Frame - - - FALSE - - - - - - - Even Frame - - - TRUE - - - - - + + - - - Even Frame + + ball + playfield - - - - ball - playfield - - - - - 1 - 16 - 7 - 5 - 0 - - - - - - EQ - - - Ball Y Speed - - - - - 1 - - + + 1 + 16 + 7 + 5 + 0 + + + + + + EQ + + + Ball Y Speed - - - Ball Y Speed - - - 255 - - + + + 1 - - - - Ball Y Speed - - - 1 - - + + + + + + Ball Y Speed + + + 255 - - - - bally - - - 1 - - - Ball Y Speed - - + + + + + + Ball Y Speed + + + 1 - + - - - - - - ballx - - - 1 - - - Ball X Speed + + + + bally + + + 1 + + + Ball Y Speed + + - + - - - - - ball - playfield + + + ballx + + + 1 + + + Ball X Speed - - - 1 - 15 - 7 - 5 - 0 - - - - - - EQ - - - Ball X Speed - - - - - 1 - - + + + + + + + + + ball + playfield + + + + + 1 + 15 + 7 + 5 + 0 + + + + + + EQ + + + Ball X Speed - - - Ball X Speed - - - 255 - - + + + 1 - - - - Ball X Speed - - - 1 - - + + + + + + Ball X Speed + + + 255 - - - - ballx - - - 1 - - - Ball X Speed - - + + + + + + Ball X Speed + + + 1 - + - - - - - - bally - - - 1 - - - Ball Y Speed + + + + ballx + + + 1 + + + Ball X Speed + + - + + + + bally + + + 1 + + + Ball Y Speed + + + + - + From 4cae221c38736d9cbd8bb5ecd68b10f1b137d1ff Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Mon, 28 Oct 2024 19:39:21 -0300 Subject: [PATCH 4/7] Fix label to a more descriptive name --- src/generators/bbasic/event.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/bbasic/event.js b/src/generators/bbasic/event.js index b8f3b34..841ad67 100644 --- a/src/generators/bbasic/event.js +++ b/src/generators/bbasic/event.js @@ -20,7 +20,7 @@ export default (Blockly) => { // Block for even/odd frames const blockNumber = Blockly.BBasic.blockNumbers.next(); - const labelStart = `_if_${blockNumber}`; + const labelStart = `_frame_even_odd_${blockNumber}`; const labelOdd = `${labelStart}_odd`; const labelEnd = `${labelStart}_end`; From 00989f1990c5e4a55a6cc16c06c8458673c0e76c Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Mon, 28 Oct 2024 19:58:36 -0300 Subject: [PATCH 5/7] Create a block to do something every few frames. --- src/blocks/event.js | 31 ++++++++++++++++++++++++++ src/components/blockly-toolbox.xml.hbs | 1 + 2 files changed, 32 insertions(+) diff --git a/src/blocks/event.js b/src/blocks/event.js index be1a7cd..2acb3c8 100644 --- a/src/blocks/event.js +++ b/src/blocks/event.js @@ -16,6 +16,10 @@ const STATE_OPTIONS = [ [`${GAMEOVER_ICON} Gameover`, 'gameover'], ]; +const FRAME_OPTIONS = [...Array(8).keys()] + .map((n) => Math.pow(2, n)) + .map((n) => [`${n}`, `${n - 1}`]); + Blockly.defineBlocksWithJsonArray([ // Block for events { @@ -77,4 +81,31 @@ Blockly.defineBlocksWithJsonArray([ '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', + }, + ]); diff --git a/src/components/blockly-toolbox.xml.hbs b/src/components/blockly-toolbox.xml.hbs index 5a85a03..a43cea8 100644 --- a/src/components/blockly-toolbox.xml.hbs +++ b/src/components/blockly-toolbox.xml.hbs @@ -232,6 +232,7 @@ + From a7943db560e73ae5588b59c20b8f571fd9e56627 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Mon, 28 Oct 2024 20:16:17 -0300 Subject: [PATCH 6/7] Generate code for the "Every n frames" block. --- src/blocks/event.js | 4 ++-- src/generators/bbasic/event.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/blocks/event.js b/src/blocks/event.js index 2acb3c8..ba77723 100644 --- a/src/blocks/event.js +++ b/src/blocks/event.js @@ -16,8 +16,8 @@ const STATE_OPTIONS = [ [`${GAMEOVER_ICON} Gameover`, 'gameover'], ]; -const FRAME_OPTIONS = [...Array(8).keys()] - .map((n) => Math.pow(2, n)) +const FRAME_OPTIONS = [...Array(7).keys()] + .map((n) => Math.pow(2, n + 1)) .map((n) => [`${n}`, `${n - 1}`]); Blockly.defineBlocksWithJsonArray([ diff --git a/src/generators/bbasic/event.js b/src/generators/bbasic/event.js index 841ad67..4d16bb4 100644 --- a/src/generators/bbasic/event.js +++ b/src/generators/bbasic/event.js @@ -38,4 +38,25 @@ export default (Blockly) => { ].join('\n') + '\n'; }; + + Blockly.BBasic['event_frame_every_n'] = function(block) { + // Every n frames + const blockNumber = Blockly.BBasic.blockNumbers.next(); + + const labelStart = `_frame_every_n_${blockNumber}`; + const labelEnd = `${labelStart}_end`; + + const frameMask = block.getFieldValue('MASK'); + const frameDelta = block.getFieldValue('DELTA'); + const code = Blockly.BBasic.statementToCode(block, 'DO').trim(); + + return '\n' + + [ + `temp1 = (framecounter + ${frameDelta}) & ${frameMask}`, + `if temp1 then goto ${labelEnd}`, + code, + `@ ${labelEnd}`, + ].join('\n') + + '\n'; + }; }; From eb190f32b36ad242db1c344c6f7ee8faa80d0880 Mon Sep 17 00:00:00 2001 From: Haroldo de Oliveira Pinheiro Date: Mon, 28 Oct 2024 20:17:17 -0300 Subject: [PATCH 7/7] Bump version to 0.27.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e7fc221..139222b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vcs-game-maker", - "version": "0.26.0", + "version": "0.27.0", "private": true, "scripts": { "serve": "vue-cli-service serve",