Hacking Minecraft on the Raspberry Pi using Python

Slides:



Advertisements
Similar presentations
EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
Advertisements

COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
HACKING MINECRAFT. LET’S OVERCLOCK sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
An Introduction to Textual Programming
Introduction to Python
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Type accurately challenge! This is a starter activity and should take 2 minutes [ slide 1 ] 1.Can you type out the code in Code Box 2.1 with no errors.
Scratch Programming Lesson 4 Question asking and answering.
Fill the screen challenge! This is a starter activity and should take 3 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In interactive mode,
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
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.
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.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
Decision Structures, String Comparison, Nested Structures
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Hacking Minecraft on the Raspberry Pi using Python
HACKING MINECRAFT.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
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.
HACKING MINECRAFT 1. LET’S OVERCLOCK Type sudo raspi-config Change 7: Over clock 900Mhz at max Change 8: Select memory share = 128MB.
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.
Python: File Directories What is a directory? A hierarchical file system that contains folders and files. Directory (root folder) Sub-directory (folder.
Getting Started With Python Brendan Routledge
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Introduction to Python Lesson 2a Print and Types.
Input, Output and Variables GCSE Computer Science – Python.
Create Your Own Quiz using_Python KS3 COMPUTING KS3 Computing
Whatcha doin'? Aims: To start using Python. To understand loops.
Bbc microbit Lesson 3 – Temperature hot medium.
Lesson 1 - Sequencing.
PYGAME.
Lesson 4 - Challenges.
Lesson 1 An Introduction
IF statements.
Introduction to Programming
Let's Race! Typing on the Home Row
Engineering Innovation Center
Starter Write a program that asks the user if it is raining today.
Iterations Programming Condition Controlled Loops (WHILE Loop)
Hacking Minecraft on the Raspberry Pi using Python
Hacking Minecraft on the Raspberry Pi using Python
Frozen Graphics Lesson 3.
Decision Structures, String Comparison, Nested Structures
Python I/O.
Decision Structures, String Comparison, Nested Structures
Learning Outcomes –Lesson 4
BBC Microbit.
COMPUTER PROGRAMMING PYTHON
Hacking Minecraft on the Raspberry Pi using Python
Task 1 Computer Programming LEVEL 6 PROGRAMMING:
Introduction to TouchDevelop
Introduction to Programming
Python programming exercise
Starter answer these questions in your book
Variables In today’s lesson we will look at: what a variable is
Programming In Lesson 4.
Beginning Python Programming
Introduction to Programming
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Starter Activities GCSE Python.
Starter Which of these inventions is: Used most by people in Britain
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
3.3 – Invoke Workflow File Exercise 3.2: Extract as Workflow
Presentation transcript:

Hacking Minecraft on the Raspberry Pi using Python Lesson 4

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: Use Python to make text print to the screen Most of you will: Use code to make a doormat to tell you when you have arrived home Some of you will: Use a Pibrella to make an electronic doorbell when you have arrived home

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 new line of code mc.postToChat (“Hello World”) import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() mc.postToChat (“Hello World”)

Press F5 to save and run the program Your message should print to the screen Change the message which prints to the screen.

We need to find our position. We can use pos = mc.player.getTilePos() We now want it to print a message to the screen if you arrive home and stand on the doormat We need to find our position. We can use pos = mc.player.getTilePos() to find the coordinates of the tile below the player. This gives a x,y,z as integers (whole numbers) which is better when tying to match up a player’s position against the position of the doormat. Add this line of code in

You can get it to print your position using the following code pos.x is your position along the x axis pos.y is your position along the y axis pos.z is your position along the z axis str stands for string. This converts the x,y,z numbers into text so that it can be printed to the screen import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() pos = mc.player.getTilePos() mc.postToChat (“Your x position is ” +str(pos.x) + “, your y position is ” +str(pos.y) + (“, your z position is ” +str(pos.z) )

You now need it to keep updating your position You will need to - import time - add a while True: Add a time.sleep command depending on how quickly you want your position to update

You can get it to print your position using the following code import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getTilePos() mc.postToChat (“Your x position is, ” +str(pos.x) + “, your y position is ” +str(pos.y) + (“, your z position is ” +str(pos.z) ) time.sleep(2)

I have added some code. What will it do? Build a house and identify the x,y,z coordinates of the tile outside of the door (the doormat). Mine is at x=10,y=0,z=10 I have added some code. What will it do? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getTilePos() mc.postToChat (“Your x position is, ” +str(pos.x) + “, your y position is ” +str(pos.y) + (“, your z position is ” +str(pos.z) ) time.sleep(2) mc.postToChat (“Your are looking for x=10, y=0, z=10”) time.sleep(5)

We will need an line of code using ‘if’ to see if we are at the doormat position. To check to see if a value is the same as another value held in a variable, we use == Your y coordinate will automatically match if you are stood on the ground. import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getTilePos() mc.postToChat (“Your x position is, ” +str(pos.x) + “, your y position is ” +str(pos.y) + (“, your z position is ” +str(pos.z) ) time.sleep(2) mc.postToChat (“Your are looking for x=10, y=0, z=10”) time.sleep(2) if pos.x ==10 and pos.z==10: mc.postToChat (“Your are home”) else: mc.postToChat (“Are you lost?)

postToChat() This displays text in the Minecaft game What you have learned Strings Strings are a kind of data type called text. They have speech marks around them. Same as == This compares a value to a value held in a variable. e.g. Your age is 12. This is a value. I keep asking you is your age 5,6,7 etc which always returns a false value until I ask is your age 12? and then this returns a true value postToChat() This displays text in the Minecaft game

pibrella.buzzer.success() Challenge 1 We will now get a Pibrella doorbell to sound a ‘success’ tune if you land on the doormat. You need to add in the line pibrella.buzzer.success() import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time mc.postToChat (“Your x position is, ” +str(pos.x) + “your y position is, ” +str(pos.y) + (“your z position is ” +str(pos.z) ) time.sleep(2) mc.postToChat (“Your are looking for x=10 and z=10”) time.sleep(2) while True: if pos.x ==10 and pos.z==10: mc.postToChat (“Your are home”) else: mc.postToChat (“Are you lost?)

We will need an line of code using ‘if’ to see if we are at the doormat position. To check to see if a value is the same as another value held in a variable, we use == Your y coordinate will automatically match if you are stood on the ground. import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time while True: pos = mc.player.getTilePos() mc.postToChat (“Your x position is, ” +str(pos.x) + “, your y position is ” +str(pos.y) + (“, your z position is ” +str(pos.z) ) time.sleep(2) mc.postToChat (“Your are looking for x=10, y=0, z=10”) time.sleep(2) if pos.x ==10 and pos.z==10: mc.postToChat (“Your are home”) pibrella.buzzer.success() else: mc.postToChat (“Are you lost?) pibrella.buzzer.fail() time.sleep(2)

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import time import pibrella mc.postToChat (“Your x position is, ” +str(pos.x) + “your y position is, ” +str(pos.y) + (“your z position is ” +str(pos.z) ) time.sleep(2) mc.postToChat (“Your are looking for x=10 and z=10”) time.sleep(2) while True: if pos.x ==10 and pos.z==10: mc.postToChat (“Your are home”) pibrella.buzzer.success() else: mc.postToChat (“Are you lost?) pibrella.buzzer.off()