Hacking Minecraft on the Raspberry Pi using Python Lesson 2 1.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Bug Session One. Session description In this session, pupils are introduced to a programming sequence which will make a light pattern on their Bug. Objectives.
Right-click on the colored box and remove it.
HACKING MINECRAFT. LET’S OVERCLOCK sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
Bug Session Three. Session description In this session, pupils will discover how the Bug software makes drawing shapes easier (this is based on the use.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Bug Session One. Session description In this session, pupils are introduced to a programming sequence which will make a light pattern on their Bug. Objectives.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
An Introduction to Textual Programming
1 iSee Player Tutorial Using the Forest Biomass Accumulation Model as an Example ( Tutorial Developed by: (
CATCH SCRATCH! Programming from Scratch. Remember Scratch?
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Spreadsheets in Finance and Forecasting Presentation 9 Macros.
By the end of this session you should be able to...
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
 There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
Hacking Minecraft on the Raspberry Pi using Python
HACKING MINECRAFT.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Introduction to Minecraft Pi Aims: To know what Minecraft is To learn how to enter code into Minecraft Pi To successfully enter at least 2 Python programs.
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
HACKING MINECRAFT 1. LET’S OVERCLOCK Type sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
Getting Started With Python Brendan Routledge
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 10: Files.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
Open the standard.idw template. Save copy as a different file name. If you want to create as a template, save to the c:\Program Files\Autodesk \Inventor10.
Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.
Create Your Own Quiz using_Python KS3 COMPUTING KS3 Computing
A Simple Quiz for Alice 3.2:
Scratch Unit Overview We are going to look at computer programming and how to create your very own computer game The piece of software we will be using.
Lesson 4 - Challenges.
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Programming Scratch to Control a K’NEX Fairground Ride
Lighting LEDs with a RASPBERRY PI
Objective of the lesson
Hacking Minecraft on the Raspberry Pi using Python
Hacking Minecraft on the Raspberry Pi using Python
Hacking Minecraft on the Raspberry Pi using Python
BBC Microbit.
BBC Microbit.
Today’s lesson – Python next steps
Variables Lesson 3.
BBC Microbit.
A Simple Quiz for Alice 3.2:
Recap the basics Lesson 1.
Hacking Minecraft on the Raspberry Pi using Python
Introduction to TouchDevelop
BBC Microbit.
3.1 Iteration Loops For … To … Next 18/01/2019.
Python programming exercise
For Loops (Iteration 1) Programming Guides.
Put it all together Lesson 5.
CSCI N207 Data Analysis Using Spreadsheet
Put it all together Lesson 6.
Variables Lesson 3.
Recap the basics Lesson 1.
Lesson One Movement.
Iteration – While Loops
Objective of the lesson
Presentation transcript:

Hacking Minecraft on the Raspberry Pi using Python Lesson 2 1

Starter Switch on your Raspberry Pi. Open Minecraft Open Idle (not Idle 3) Click on File>New File This opens up the Idle editor where you can write and edit your Python code Open Minecraft>Create New World (Minecraft must be open for you to hack it) 2

Objective of the lesson Use Python to control a game called Minecraft All of you will: – Use Python to make a tail of flowers in Minecraft. Most of you will: – Change the flowers to a different kind of block and make them closer or further apart Some of you will: – Make a light blink on and off to show that a block has been placed 3

Type the following into the editor You always use these lines first in your Minecraft code This connects your code to Minecraft so that you can hack it. Careful, Python code is case sensitive Remember to have Minecraft open) import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create()

You will be using time. You will need to add a line of code import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create()

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time We will need a loop. Add in a line of code

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: Did you remember the capital T Did you remember the :

You now need to get the player’s position by adding the line of code import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getPos() It saves the player’s position as pos pos is called a variable What is a variable? Why is pos a variable?

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getPos() Did you remember to indent after a line of code that ends in :

When it gets the player’s position called pos, it saves the player’s position as three separate variables The position along the x axis called pos.x The position along the y axis called pos.y The position along the x axis called pos.z

Each block has an ID number Flower has the ID number 38 The function in Minecraft to set down a block is mc.setBlock We therefore need to add the line of code mc.setBlock(pos.x, pos.y, pos.z, 38)

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getPos() mc.setBlock(pos.x, pos.y,pos.z,38) Did you remember to indent the line of code because it belongs in the loop while True:

You now need to make it sleep for 0.2 seconds before looping again and setting down another flower block

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getPos() mc.setBlock(pos.x, pos.y,pos.z,38) time.sleep(0.2) Did you remember to indent the line of code and put the dot in time.sleep Did you put the 0.2 seconds in brackets

Press F5 to save and run the program You should lay down a trail of flowers behind you If you get an error try to troubleshoot it or ask a friend to try to spot your mistake

What you have learned while loop A while loop repeats a section of Python code. The True part of the while loop means that it will repeat forever or until the user stops the program. time Using time in Python allows us to use functions that control time. getPos() The getPos() function allows us to find the co-ordinates of the player in the game world. setBlock() The setBlock() function allows us to create blocks in the Minecraft Pi world. It takes four arguments, the first three of which are co-ordinates and the fourth argument is the type of block that we want to create.

Challenge 1 Change the block number to a new block. Lay a new trail of blocks Change the times so that they are closer or further apart Click here for a list of Block IDs Challenge 2 Insert some of the following code to make the green light on the Pibrella come on when a block is set down and then go off again before a new block is set down import pibrella pibrella.light.green.on()

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getPos() mc.setBlock(pos.x, pos.y,pos.z,38) pibrella.light.green.on() time.sleep(0.1) pibrella.light.green.on() time.sleep(0.1)

Challenge 3 Variables such as pos.x pos.y pos.z 38 Can be given suitable names that are easier to remember and use later on in your code e.g. x = pos.x y = pos.y z = pos.z block = 38 This is called declaring a variable

Challenge 3 You can now replace pos.x with x pos.y with y pos.z with z 38 with block These new names can be used later in the code to make it easier to program

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() x = pos.x y = pos.y z = pos.z block = 38 import time while True: pos = mc.player.getPos() mc.setBlock(x, y, z, block) pibrella.light.green.on() time.sleep(0.1) pibrella.light.green.on() time.sleep(0.1)