Skip to content

Commit

Permalink
starting work on collision layers
Browse files Browse the repository at this point in the history
  • Loading branch information
gummyfrog committed Apr 23, 2024
1 parent 2a6d018 commit 09505ee
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ flask/built_pages/*
.env.production.local
flask/__pycache__/*


flask/saved/*
blockly/compiled_games/*

# Logs
logs
*.log
Expand Down
72 changes: 71 additions & 1 deletion blockly/src/blocks/game.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
},
{
"type": "actor",
"message0": "New Actor With %1 Image %2 Start Horizontal %3 Start Vertical %4 Width %5 Height %6",
"message0": "New Actor With %1 Image %2 Start Horizontal %3 Start Vertical %4 Width %5 Height %6 Layer Name %7",
"args0": [
{
"type": "input_dummy"
Expand Down Expand Up @@ -295,6 +295,11 @@
"type": "input_value",
"name": "height",
"check": "Number"
},
{
"type": "input_value",
"name": "collision_layer",
"check": "String"
}
],
"output": null,
Expand Down Expand Up @@ -498,6 +503,32 @@
"tooltip": "",
"helpUrl": ""
},
{
"type": "velocity",
"message0": "Set Actor %1 velocity to x %2 and y %3",
"args0": [
{
"type": "input_value",
"name": "actor"
},
{
"type": "input_value",
"name": "x",
"check": "Number"
},
{
"type": "input_value",
"name": "y",
"check": "Number"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": 230,
"tooltip": "",
"helpUrl": ""
},
{
"type": "teleport",
"message0": "Teleport Actor %1 %2 to: %3 x %4 y %5",
Expand Down Expand Up @@ -546,5 +577,44 @@
"colour": 230,
"tooltip": "",
"helpUrl": ""
},
{
"type": "layer_collide",
"message0": "%1 %2 %3 %4 using %5 %6",
"args0": [
{
"type": "field_label_serializable",
"name": "layer1",
"text": "actor in layer"
},
{
"type": "input_value",
"name": "layer1"
},
{
"type": "field_label_serializable",
"name": "layer2",
"text": "collides with actor in"
},
{
"type": "input_value",
"name": "layer2"
},
{
"type": "field_variable",
"name": "actor one",
"variable": "actor one"
},
{
"type": "field_variable",
"name": "actor two",
"variable": "actor two"
}
],
"inputsInline": true,
"output": null,
"colour": 230,
"tooltip": "",
"helpUrl": ""
}
]}
35 changes: 34 additions & 1 deletion blockly/src/generators/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def collide_pixels(actor1, actor2):
return pygame.sprite.collide_mask(actor1, actor2)
actors = [];
collisions = {};
class Actor_Sprite_Obj(pygame.sprite.Sprite):
def __init__(self, imageName, x, y, width, height):
Expand All @@ -149,9 +150,15 @@ class Actor_Sprite_Obj(pygame.sprite.Sprite):
# add change image func
def create_actor(image_name, x, y, width, height):
def create_actor(image_name, x, y, width, height, collision_layer):
actor = Actor_Sprite_Obj(image_name, x, y, width, height)
actors.append(actor)
if collision_layer not in collisions.keys():
collisions[collision_layer] = pygame.sprite.Group()
collisions[collision_layer].add(actor)
return actor
font = pygame.font.Font('freesansbold.ttf', 32)
Expand Down Expand Up @@ -399,6 +406,19 @@ ${value_actor}.moveVertical(${value_y})
return code;
};


forBlock['velocity'] = function(block, generator) {
var value_actor = generator.valueToCode(block, 'actor', Order.ATOMIC);
var value_x = generator.valueToCode(block, 'x', Order.ATOMIC);
var value_y = generator.valueToCode(block, 'y', Order.ATOMIC);
// TODO: Assemble python into code variable.
var code =
`${value_actor}.horizontalVelocity(${value_x})
${value_actor}.verticalVelocity(${value_y})
`;
return code;
};

forBlock['actor_x'] = function(block, generator) {
var value_actor = generator.valueToCode(block, 'Actor', Order.ATOMIC);
// TODO: Assemble python into code variable.
Expand All @@ -419,4 +439,17 @@ forBlock['change_background_color'] = function(block, generator) {
return code;
};

forBlock['layer_collide'] = function(block, generator) {
var field_layer1 = block.getFieldValue('layer1');
var value_layer1 = generator.valueToCode(block, 'layer1', Order.ATOMIC);
var field_layer2 = block.getFieldValue('layer2');
var value_layer2 = generator.valueToCode(block, 'layer2', Order.ATOMIC);
var variable_actor_one = generator.nameDB_.getName(block.getFieldValue('actor one'), Blockly.Variables.NAME_TYPE);
var variable_actor_two = generator.nameDB_.getName(block.getFieldValue('actor two'), Blockly.Variables.NAME_TYPE);
// TODO: Assemble python into code variable.
var code = '...';
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.python.ORDER_NONE];
};

module.exports = forBlock;

0 comments on commit 09505ee

Please sign in to comment.