-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.blocks
6 lines (6 loc) · 15.3 KB
/
main.blocks
1
2
3
4
5
6
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable type="KIND_SpriteKind" id="iDG~CUBj=^C#r~3FWlYD">Critter</variable><variable id="%Z)zL]WLG{3xppLH2mWV">ginny</variable><variable id="4RdGCCsamLGE@63H8(wM">critterBeingCarried</variable><variable id="NRL~sMQa#E}y@}?9^t{O">thePause</variable><variable id="p~a:B,HUV]bIb8b^CW{.">critters</variable><variable id="OY:kdBYiL1fSX$|:grRU">theCritter</variable><variable id="U5(k9u2GKVGVVKoqyYy|">happinessFactor</variable><variable id="e%bo7QUplIx0Lb_{_/;7">foodFactorLeft</variable><variable id="TCM(L#,J+|P`?1:^S#0f">foodFactorMiddle</variable><variable id=";rdsdI`Ocz]tTv:EpASs">foodFactorRight</variable><variable id="?io;NQfR+ihM:9_BJBd3">happinessDegradeFactor</variable><variable id="%[[email protected]{fpnq)m+s">healthDegradeFactor</variable><variable id="IX$vrK)GZ`+Xi|rMS|:^">critter</variable></variables><block type="ctrlonbuttonevent" x="10" y="10"><field name="controller">controller.player1</field><field name="button">ControllerButton.A</field><field name="event">ControllerButtonEvent.Released</field><statement name="HANDLER"><block type="controls_if"><comment>Check if a creature is near, if so pick it up</comment><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="spritehasobstacle"><field name="direction">CollisionDirection.Top</field><value name="sprite"><block type="variables_get"><field name="VAR" id="%Z)zL]WLG{3xppLH2mWV">ginny</field></block></value></block></value><statement name="DO0"><block type="console_log"><value name="value"><shadow type="text"><field name="TEXT">Hit tile top?</field></shadow></value></block></statement></block></statement></block><block type="ctrlonbuttonevent" x="10" y="10"><field name="controller">controller.player1</field><field name="button">ControllerButton.B</field><field name="event">ControllerButtonEvent.Released</field><comment>Drop critters with B</comment><statement name="HANDLER"><block type="controls_if"><mutation else="1"/><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="variables_get"><field name="VAR" id="4RdGCCsamLGE@63H8(wM">critterBeingCarried</field></block></value><statement name="DO0"><block type="spriteFollowOtherSprite"><mutation xmlns="http://www.w3.org/1999/xhtml" _expanded="0" _input_init="false"></mutation><value name="sprite"><block type="typescript_expression" editable="false"><field name="EXPRESSION">critterBeingCarried.sprite</field></block></value><value name="target"><shadow type="variables_get"/><block type="typescript_expression" editable="false"><field name="EXPRESSION">null</field></block></value><next><block type="spritesetvel"><value name="sprite"><block type="typescript_expression" editable="false"><field name="EXPRESSION">critterBeingCarried.sprite</field></block></value><value name="vx"><shadow type="spriteSpeedPicker"><field name="speed">20</field></shadow></value><value name="vy"><shadow type="spriteSpeedPicker"><field name="speed">0</field></shadow></value><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="critterBeingCarried = null" numlines="1"></mutation><next><block type="console_log"><value name="value"><shadow type="text"><field name="TEXT">Drop the critter</field></shadow></value></block></next></block></next></block></next></block></statement><statement name="ELSE"><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="critters.forEach(critter => {" line1=" if (ginny.overlapsWith(critter.sprite) && !critterBeingCarried) {" line2=" console.log('Pick up the critter!')" line3=" critterBeingCarried = critter" line4=" critter.sprite.follow(ginny)" line5=" }" line6=" })" numlines="7"></mutation></block></statement></block></statement></block><block type="forever" x="10" y="10"><comment>Loop over each critter and degrade health/happiness</comment><statement name="HANDLER"><block type="variables_set"><field name="VAR" id="NRL~sMQa#E}y@}?9^t{O">thePause</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="device_random_deprecated"><value name="min"><shadow type="math_number"><field name="NUM">100</field></shadow></value><value name="limit"><shadow type="math_number"><field name="NUM">5000</field></shadow></value></block></value><next><block type="device_pause"><value name="pause"><shadow type="timePicker"/><block type="variables_get"><field name="VAR" id="NRL~sMQa#E}y@}?9^t{O">thePause</field></block></value><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="adjustHappiness(critters)" numlines="1"></mutation><next><block type="pxt_controls_for_of"><value name="VAR"><shadow type="variables_get_reporter"><field name="VAR" id="OY:kdBYiL1fSX$|:grRU">theCritter</field></shadow></value><value name="LIST"><block type="variables_get"><field name="VAR" id="p~a:B,HUV]bIb8b^CW{.">critters</field></block></value><statement name="DO"><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="moveCritter(theCritter)" numlines="1"></mutation><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="theCritter.health -= healthDegradeFactor" numlines="1"></mutation><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="theCritter.happiness -= happinessDegradeFactor" numlines="1"></mutation><next><block type="controls_if"><mutation elseif="1"/><comment>Display the emoji if they are not healthy/happy</comment><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare"><field name="OP">LT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="typescript_expression" editable="false"><field name="EXPRESSION">theCritter.health</field></block></value><value name="B"><shadow type="math_number"><field name="NUM">30</field></shadow></value></block></value><statement name="DO0"><block type="spritesaytext"><mutation xmlns="http://www.w3.org/1999/xhtml" _expanded="1" _input_init="true"></mutation><value name="this"><shadow type="variables_get"/><block type="typescript_expression" editable="false"><field name="EXPRESSION">theCritter.sprite</field></block></value><value name="text"><shadow type="text"><field name="TEXT">:o</field></shadow></value><value name="timeOnScreen"><shadow type="timePicker"><field name="ms">2000</field></shadow></value></block></statement><value name="IF1"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare"><field name="OP">LT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="typescript_expression" editable="false"><field name="EXPRESSION">theCritter.happiness</field></block></value><value name="B"><shadow type="math_number"><field name="NUM">30</field></shadow></value></block></value><statement name="DO1"><block type="spritesaytext"><mutation xmlns="http://www.w3.org/1999/xhtml" _expanded="1" _input_init="true"></mutation><value name="this"><shadow type="variables_get"/><block type="typescript_expression" editable="false"><field name="EXPRESSION">theCritter.sprite</field></block></value><value name="text"><shadow type="text"><field name="TEXT">:(</field></shadow></value><value name="timeOnScreen"><shadow type="timePicker"><field name="ms">2000</field></shadow></value></block></statement></block></next></block></next></block></next></block></statement></block></next></block></next></block></next></block></statement></block><block type="pxt-on-start" x="10" y="10"><statement name="HANDLER"><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="let ginny: Sprite = null" numlines="1" declaredvars="ginny"></mutation><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="let critterBeingCarried: Critter | null = null" numlines="1" declaredvars="critterBeingCarried"></mutation><next><block type="variables_set"><field name="VAR" id="U5(k9u2GKVGVVKoqyYy|">happinessFactor</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow></value><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="let randDirectionX = 0" numlines="1" declaredvars="randDirectionX"></mutation><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="let randDirectionY = 0" numlines="1" declaredvars="randDirectionY"></mutation><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="type Critter = {" line1=" name: string" line2=" sprite: Sprite" line3=" happiness: number" line4=" health: number" line5="}" numlines="6"></mutation><next><block type="gamesetbackgroundcolor"><value name="color"><shadow type="colorindexpicker"><field name="index">6</field></shadow></value><next><block type="tilemap_editor"><field name="tilemap">tilemap`farm`</field><data>{"commentRefs":[],"fieldData":{"tilemap":"level1"}}</data><next><block type="variables_set"><field name="VAR" id="%Z)zL]WLG{3xppLH2mWV">ginny</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="spritescreate"><value name="img"><shadow type="screen_image_picker"><field name="img">assets.image`ginny`</field><data>{"commentRefs":[],"fieldData":{"img":"myImages.image1"}}</data></shadow></value><value name="kind"><shadow type="spritekind"><field name="MEMBER">Player</field></shadow></value></block></value><next><block type="game_control_sprite"><mutation xmlns="http://www.w3.org/1999/xhtml" _expanded="2" _input_init="true"></mutation><value name="sprite"><shadow type="variables_get"><field name="VAR" id="%Z)zL]WLG{3xppLH2mWV">ginny</field></shadow></value><value name="vx"><shadow type="spriteSpeedPicker"><field name="speed">60</field></shadow></value><value name="vy"><shadow type="spriteSpeedPicker"><field name="speed">60</field></shadow></value><next><block type="camerafollow"><value name="sprite"><shadow type="variables_get"><field name="VAR" id="%Z)zL]WLG{3xppLH2mWV">ginny</field></shadow></value><next><block type="variables_set"><field name="VAR" id="e%bo7QUplIx0Lb_{_/;7">foodFactorLeft</field><value name="VALUE"><shadow type="math_number"><field name="NUM">3</field></shadow></value><next><block type="variables_set"><field name="VAR" id="TCM(L#,J+|P`?1:^S#0f">foodFactorMiddle</field><value name="VALUE"><shadow type="math_number"><field name="NUM">3</field></shadow></value><next><block type="variables_set"><field name="VAR" id=";rdsdI`Ocz]tTv:EpASs">foodFactorRight</field><value name="VALUE"><shadow type="math_number"><field name="NUM">3</field></shadow></value><next><block type="variables_set"><field name="VAR" id="?io;NQfR+ihM:9_BJBd3">happinessDegradeFactor</field><value name="VALUE"><shadow type="math_number"><field name="NUM">1</field></shadow></value><next><block type="variables_set"><field name="VAR" id="%[[email protected]{fpnq)m+s">healthDegradeFactor</field><value name="VALUE"><shadow type="math_number"><field name="NUM">1</field></shadow></value><next><block type="variables_set"><field name="VAR" id="p~a:B,HUV]bIb8b^CW{.">critters</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="lists_create_with"><mutation items="1" horizontalafter="3"/><value name="ADD0"><block type="typescript_expression" editable="false"><field name="EXPRESSION">{
name: 'CritterOne',
sprite: sprites.create(assets.image`critterOne`, SpriteKind.Critter),
happiness: 90,
health: 70
}</field></block></value></block></value><next><block type="pxt_controls_for_of"><comment>Place all the critters on load (temp)</comment><value name="VAR"><shadow type="variables_get_reporter"><field name="VAR" id="IX$vrK)GZ`+Xi|rMS|:^">critter</field></shadow></value><value name="LIST"><block type="variables_get"><field name="VAR" id="p~a:B,HUV]bIb8b^CW{.">critters</field></block></value><statement name="DO"><block type="spritesetpos"><value name="sprite"><block type="typescript_expression" editable="false"><field name="EXPRESSION">critter.sprite</field></block></value><value name="x"><shadow type="positionPicker"><field name="index">15</field></shadow></value><value name="y"><shadow type="positionPicker"><field name="index">15</field></shadow></value></block></statement><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="function moveCritter(critter: Critter) {" line1=" if (critter.sprite.vx == 0 && critter.sprite.vy == 0) {" line2=" // Move the critter" line3=" randDirectionX = Math.randomRange(-20, 20)" line4=" randDirectionY = Math.randomRange(-20, 20)" line5=" critter.sprite.setVelocity(randDirectionX, randDirectionY)" line6=" } else {" line7=" // Stop any movement" line8=" critter.sprite.setVelocity(0, 0)" line9=" }" line10="}" numlines="11"></mutation><next><block type="typescript_statement" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="function adjustHappiness(allCritters: Array<Critter>) {" line1=" let totalHappiness = 0" line2=" allCritters.forEach(critter => {" line3=" console.log(`Loc X: ${critter.sprite.x}`)" line4=" const tileX = Math.floor(critter.sprite.x * 16)" line5=" const tileY = Math.floor(critter.sprite.y * 16)" line6=" // Check to see if the critter is in the play area" line7=" if (tileX >= 3 && tileY >= 2) {" line8=" totalHappiness++" line9=" }" line10=" })" line11="" line12=" console.log(`Total happiness: ${totalHappiness}`)" line13="}" numlines="14"></mutation></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type="keyonevent" x="550" y="230"><field name="button">controller.down</field><field name="event">ControllerButtonEvent.Pressed</field><statement name="HANDLER"><block type="run_image_animation"><value name="sprite"><shadow type="variables_get"><field name="VAR" id="%Z)zL]WLG{3xppLH2mWV">ginny</field></shadow></value><value name="frames"><shadow type="animation_editor"><field name="frames">assets.animation`walkDown`</field><data>{"commentRefs":[],"fieldData":{"frames":"myAnimations.anim1"}}</data></shadow></value><value name="frameInterval"><shadow type="timePicker"><field name="ms">200</field></shadow></value><value name="loop"><shadow type="toggleOnOff"><field name="on">true</field></shadow></value></block></statement></block><block type="keyonevent" x="610" y="530"><field name="button">controller.down</field><field name="event">ControllerButtonEvent.Released</field><statement name="HANDLER"><block type="stop_animations"><field name="type">animation.AnimationTypes.All</field><value name="sprite"><shadow type="variables_get"><field name="VAR" id="%Z)zL]WLG{3xppLH2mWV">ginny</field></shadow></value></block></statement></block></xml>