Skip to content

Commit

Permalink
Create block for setting number and width of players and missiles
Browse files Browse the repository at this point in the history
Merge pull request #80 from haroldo-ok/nusiz-block
  • Loading branch information
haroldo-ok authored Jun 2, 2024
2 parents 909894f + e4937e6 commit 080ece5
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 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.17.1",
"version": "0.18.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
88 changes: 88 additions & 0 deletions src/blocks/sprites.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ const buildMissileOptions = (name) => [
[HEIGHT_ICON + ' Height', `${name}height`],
];

const PLAYER_SIZE_OPTIONS = [
['1 copy of player and missile.', '$0'],
['2 close-spaced copies of player and missile.', '$1'],
['2 medium-spaced copies of player and missile.', '$2'],
['3 close-spaced copies of player and missile.', '$3'],
['2 wide-spaced copies of player and missile.', '$4'],
['Double-sized player.', '$5'],
['3 medium-spaced copies of player and missile.', '$6'],
['Quad-sized', '$7'],
];

const MISSILE_SIZE_OPTIONS = [
['1', '$00'],
['2', '$10'],
['4', '$20'],
['8', '$30'],
];

const buildSpriteBlocks = ({name, description, icon, options, colour}) => {
Blockly.defineBlocksWithJsonArray([
// Block for the getter.
Expand Down Expand Up @@ -75,6 +93,48 @@ const buildSpriteBlocks = ({name, description, icon, options, colour}) => {
]);
};

const buildPlayerBlocks = ({name, description, icon, colour}) => {
Blockly.defineBlocksWithJsonArray([
// Block for changing a player's size and quantity.
{
'type': `sprite_${name}_size`,
'message0': `${icon} ${description} set width/quantity to %1`,
'args0': [
{
'type': 'field_dropdown',
'name': 'SIZE',
'options': PLAYER_SIZE_OPTIONS,
},
],
'previousStatement': null,
'nextStatement': null,
colour,
'extensions': ['math_change_tooltip'],
},
]);
};

const buildMissileBlocks = ({name, description, icon, colour}) => {
Blockly.defineBlocksWithJsonArray([
// Block for changing a player's size and quantity.
{
'type': `sprite_${name}_size`,
'message0': `${icon} ${description} set width to %1 pixels`,
'args0': [
{
'type': 'field_dropdown',
'name': 'SIZE',
'options': MISSILE_SIZE_OPTIONS,
},
],
'previousStatement': null,
'nextStatement': null,
colour,
'extensions': ['math_change_tooltip'],
},
]);
};

buildSpriteBlocks({
name: 'player0',
description: 'Player 0',
Expand All @@ -83,6 +143,13 @@ buildSpriteBlocks({
options: buildPlayerOptions('player0'),
});

buildPlayerBlocks({
name: 'player0',
description: 'Player 0',
icon: PLAYER_ICON,
colour: 'red',
});

buildSpriteBlocks({
name: 'player1',
description: 'Player 1',
Expand All @@ -91,6 +158,13 @@ buildSpriteBlocks({
options: buildPlayerOptions('player1'),
});

buildPlayerBlocks({
name: 'player1',
description: 'Player 1',
icon: PLAYER_ICON,
colour: 'blue',
});

buildSpriteBlocks({
name: 'missile0',
description: 'Missile 0',
Expand All @@ -99,6 +173,13 @@ buildSpriteBlocks({
options: buildMissileOptions('missile0'),
});

buildMissileBlocks({
name: 'missile0',
description: 'Missile 0',
icon: MISSILE_ICON,
colour: 'red',
});

buildSpriteBlocks({
name: 'missile1',
description: 'Missile 1',
Expand All @@ -107,6 +188,13 @@ buildSpriteBlocks({
options: buildMissileOptions('missile1'),
});

buildMissileBlocks({
name: 'missile1',
description: 'Missile 1',
icon: MISSILE_ICON,
colour: 'blue',
});

buildSpriteBlocks({
name: 'ball',
description: 'Ball',
Expand Down
4 changes: 4 additions & 0 deletions src/components/blockly-toolbox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
</shadow>
</value>
</block>
<block type="sprite_player0_size" />

<block type="sprite_player1_get"></block>
<block type="sprite_player1_set">
Expand All @@ -80,6 +81,7 @@
</shadow>
</value>
</block>
<block type="sprite_player1_size" />

<block type="sprite_missile0_get"></block>
<block type="sprite_missile0_set">
Expand All @@ -96,6 +98,7 @@
</shadow>
</value>
</block>
<block type="sprite_missile0_size" />

<block type="sprite_missile1_get"></block>
<block type="sprite_missile1_set">
Expand All @@ -112,6 +115,7 @@
</shadow>
</value>
</block>
<block type="sprite_missile1_size" />

<block type="sprite_ball_get"></block>
<block type="sprite_ball_set">
Expand Down
7 changes: 6 additions & 1 deletion src/generators/bbasic.bb.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ end
rem - set initial values
rem **************************************************************************
COLUBK = $0F
NUSIZ0 = $30
score = 00000 : scorecolor = $08

dim player0frame = x
Expand All @@ -42,6 +41,8 @@ end
dim loopcounter = w
dim channnel0duration = v
dim channnel1duration = u
dim player0size = t
dim player1size = s

newbackground = 1

Expand All @@ -51,6 +52,8 @@ end

player1color = $80
player0color = $40
player1size = $30
player0size = $30
COLUBK = $C4
COLUPF = $0E

Expand All @@ -68,6 +71,8 @@ main
draw
COLUP1 = player1color
COLUP0 = player0color
NUSIZ0 = player0size
NUSIZ1 = player1size
drawscreen

rem **************************************************************************
Expand Down
20 changes: 20 additions & 0 deletions src/generators/bbasic/sprites.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,25 @@ export default (Blockly) => {
};
};

const createGeneratorForPlayer = (name) => {
Blockly.BBasic[`sprite_${name}_size`] = function(block) {
const size = block.getFieldValue('SIZE') || '0';
const varName = name + 'size';
return `${varName} = ${varName} & $F0\n` +
`${varName} = ${varName} | ${size}\n`;
};
};

const createGeneratorForMissile = (name) => {
Blockly.BBasic[`sprite_${name}_size`] = function(block) {
const size = block.getFieldValue('SIZE') || 0;
const varName = name.replace('missile', 'player') + 'size';
return `${varName} = ${varName} & $0F\n` +
`${varName} = ${varName} | ${size}\n`;
};
};

['player0', 'player1', 'missile0', 'missile1', 'ball'].forEach(createGeneratorForSprite);
['player0', 'player1'].forEach(createGeneratorForPlayer);
['missile0', 'missile1'].forEach(createGeneratorForMissile);
};

0 comments on commit 080ece5

Please sign in to comment.