Hacking Minecraft on the Raspberry Pi using Python

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
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.
HACKING MINECRAFT. LET’S OVERCLOCK sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
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.
Scratch Internet- Open Chrome hit “Create” 1.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Scratch Programming Lesson 4 Question asking and answering.
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.
Variables. Todays Lesson  In todays lesson you are going to:  Learn to use variables  Learn to ask for user input  Learn to save the users response.
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.
Scratch pong challenge Pong is a classic 1970s video game  Open the pongv1.sb2 file in Scratch  Click the.
Make a dice challenge! This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Copy the code below in.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
BBC Microbit Getting set up and making your first program.
Hacking Minecraft on the Raspberry Pi using Python
HACKING MINECRAFT.
Marble Racer. 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.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
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.
HACKING MINECRAFT 1. LET’S OVERCLOCK Type sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Hacking Minecraft on the Raspberry Pi using Python Lesson 2 1.
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.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
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.
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.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Sound and more Animations
Scratch Helicopter Game
Module 1: Investigation 2 Repeating and Alternating Patterns
Co-ordinates And Geometry Module 6: Investigation 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.
IF statements.
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
CompSci 230 Software Construction
Objective of the lesson
Hacking Minecraft on the Raspberry Pi using Python
Introduction to LabVIEW
Iterations Programming Condition Controlled Loops (WHILE Loop)
Hacking Minecraft on the Raspberry Pi using Python
Frozen Graphics Lesson 3.
BBC Microbit.
BBC Microbit.
Raspberry Pi: External Inputs & Outputs
BBC Microbit.
Raspberry Pi with Pibrella
Introduction to TouchDevelop
Introductory Presentation
INTERMEDIATE PROGRAMMING LESSON
Recap the basics Lesson 1.
Hacking Minecraft on the Raspberry Pi using Python
Introduction to TouchDevelop
BBC Microbit.
Introductory Presentation
Using the sensor Lesson 5.
Python programming exercise
INTERMEDIATE PROGRAMMING LESSON
CSCI N207 Data Analysis Using Spreadsheet
Aeroponic Engineering and Vertical Farming
BBC Microbit.
Recap the basics Lesson 1.
Chapter 9 Using Decisions to
3.2 Working with Data Scope of variables 29/07/2019.
Presentation transcript:

Hacking Minecraft on the Raspberry Pi using Python Lesson 6

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)

Objective of the lesson Use Python to control a game called Minecraft All of you will: Create a tower of blocks Most of you will: Make a tower by clicking a button which grows higher the longer you press Some of you will: If you release the button the program resets

import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() 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 need to add a ‘repeat’ which will repeatedly add blocks to the tower for a in range(50): This repeats 50 times Each time it makes the letter a = 1, then a=2, then a=3 etc until a = 50 import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() for a in range(50):

We now need to get the player’s position Add a line of code for a in range(50): ends in a : so think what you will need to do import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() for a in range(50):

Did you get it correct? Define x.pos as x y.pos as y z.pos as z import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() for a in range(50): pos = mc.player.getPos()

Decide on a block ID for your tower and define it as ‘block’ Did you get it correct? Decide on a block ID for your tower and define it as ‘block’ I am going to build in Gold (Block ID 41) import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() for a in range(50): pos = mc.player.getPos() x = x.pos y = y.pos z = z.pos

Did you get it correct? Now you need to set a block down The x coordinate should be x+3 (so that it is to one side of you) The y coordinate should be y+a so that it keeps adding blocks until it reaches height 50 The z coordinate can be z (the same depth backwards as the player import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() for a in range(50): pos = mc.player.getPos() x = x.pos y = y.pos z = z.pos block = 41

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() for a in range(50): pos = mc.player.getPos() x = x.pos y = y.pos z = z.pos block = 41 mc.setBlock(x+3,y+a,z,block)

Press F5 to save and run the program When you run it, a tower should be built to the side of Steve

We can declare these variables (rename them) as x and y and z by using What you have learned for a in range(50): The for a in range() function produces a loop which repeats 50 times (although the number of repeats can be changed) and makes a = 1, then a = 2 then a = 3 and so on until a = 50 pos = mc.player.getPos() The pos = mc.player.getPos() function gets the coordinates of where the player is within the game. The position variable is declared and save as ‘pos’. The x coordinate is pos.x and the y coordinate is pos.y and z coordinate is pos.z We can declare these variables (rename them) as x and y and z by using x = pos.x y = pos.y z = pos.z

Change the block to be another block e.g. TNT (Block ID 46) Challenge 1 Change the block to be another block e.g. TNT (Block ID 46) import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() for a in range(50): pos = mc.player.getPos() x = x.pos y = y.pos z = z.pos block = 46 mc.setBlock(x+3,y+a,z,block)

Challenge 2 Make it so that the tower is built when the Pibrella button is pressed and a green light and a success buzz sounds and then goes off once the tower is placed

Challenge 2 Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() while True: if pibrella.button.read(): pibrella.light.green.on() pibrella.buzzer.success() time.sleep(1) pibrella.light.green.off() pibrella.buzzer.off() for a in range(50): pos = mc.player.getPos() x = x.pos y = y.pos z = z.pos block = 46 mc.setBlock(x+3,y+a,z,block)

Challenge 2 Did you remember the while True: Why does it need this? The if pibrella.button.read(): needs indenting. Why? The for a in range(50): line needs indenting again. Why? Why does the pibrella code need to go outside of the for a in range: repeat? if pibrella.button.read(): pibrella.light.green.on() pibrella.buzzer.success() time.sleep(1) pibrella.light.green.off() pibrella.buzzer.off()

Get it so that the longer you press the button, the higher the tower Challenge 3 Get it so that the longer you press the button, the higher the tower HINTS You will need to declare a new variable to store how long the button is pressed. Call it timepressed You will need to set this to equal 0 at the start of the program If the button is pressed then timepressed needs to increase by 1 every 1 second timepressed is the new value for the height of the tower (which was previously 50

Challenge 3 Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() timepressed = 0 while True: if pibrella.button.read(): timepressed = timepressed + 1 pibrella.light.green.on() pibrella.buzzer.success() time.sleep(1) pibrella.light.green.off() pibrella.buzzer.off() for a in range(timepressed): pos = mc.player.getPos() x = x.pos y = y.pos z = z.pos block = 46 mc.setBlock(x+3,y+a,z,block)

The height of the tower which is ‘timepressed’ needs resetting HINT Challenge 3 The problem is that the tower does not reset when you move to a new location and press the button again The height of the tower which is ‘timepressed’ needs resetting HINT When the button is pressed the tower builds However if the button is not pressed then timepressed (which is the height of the tower) needs resetting back to equal 0 Remember that a button is either on, or else it is off Remember that if and else are conditions that may or may not be true and need a : and indenting afterwards

Challenge 3 Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() timepressed = 0 while True: if pibrella.button.read(): timepressed = timepressed + 1 pibrella.light.green.on() pibrella.buzzer.success() time.sleep(1) pibrella.light.green.off() pibrella.buzzer.off() for a in range(timepressed): pos = mc.player.getPos() x = x.pos y = y.pos z = z.pos block = 46 mc.setBlock(x+3,y+a,z,block) else: timepressed = 0