Hacking Minecraft on the Raspberry Pi using Python

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
Learning to program using Minecraft. Learning Objective Know what Minecraft is and to explain some of it’s uses Build a simple house in creative mode.
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.
An Introduction to Textual Programming
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
By the end of this session you should be able to...
Scratch Programming Lesson 4 Question asking and answering.
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.
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.
Hacking Minecraft on the Raspberry Pi using Python
Python Let’s get started!.
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.
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.
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.
Make a function This is a starter activity and should take 5 minutes [ slide 1 ] >>> def count(number): n=1 while n
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.
Introduction to Programming in RobotC
Class-Level Variables in Alice
Topic 02: Introduction to ActionScript 3.0
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.
Python Let’s get started!.
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.
Fractions, percentages and decimals
Programming Scratch to Control a K’NEX Fairground Ride
CompSci 230 Software Construction
Hacking Minecraft on the Raspberry Pi using Python
Hacking Minecraft on the Raspberry Pi using Python
Learning to program with Logo
Frozen Graphics Lesson 3.
BBC Microbit.
TRANSLATORS AND IDEs Key Revision Points.
Lesson 1 Learning Objectives
Traffic light programming challenges
Today’s lesson – Python next steps
Python Programming Language
Raspberry Pi with Pibrella
Exception Handling.
Beginner Programming Lesson
Recap the basics Lesson 1.
Hacking Minecraft on the Raspberry Pi using Python
Introduction to TouchDevelop
Repetition In today’s lesson we will look at:
A look at Python Programming Language 2018.
Python programming exercise
PYTHON: BUILDING BLOCKS Sequencing & Selection
Python Programming Language
CSCI N207 Data Analysis Using Spreadsheet
Programming In Lesson 4.
Beginning Python Programming
Recap the basics Lesson 1.
Python Programming Language
Introduction to Python
Starter Activities GCSE Python.
Class code for pythonroom.com cchsp2cs
Python SAT 1 Feedback.
Hardware is… Software is…
Presentation transcript:

Hacking Minecraft on the Raspberry Pi using Python Lesson 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)

Objective of the lesson Use Python to control a game called Minecraft All of you will: Use Python to teleport to a new location in Minecraft. Most of you will: Choose a new location of your own to teleport to Some of you will: Teleport when using a button and make a light come on to show that you have teleported

Minecraft Coordinates x is left and right y is up and down z is backwards and forwards

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()

Add in the xyz coordinates of where we will teleport to import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() x = 10 y = 11 z = 12

Now tell the program to teleport there import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() x = 10 y = 11 z = 12 mc.player.setPos(x, y, z) The way that code is written is called syntax Try to explain the syntax mc.player.setPos(x, y, z)

Did you get it correct? mc.player.setPos(x, y, z) We always start big and then get smaller (like delivering a letter to a house ) e.g. go to Merseyside, then St Helens, then Festive Avenue then number 52, then Mr Benn In code this would be merseyside.sthelens.festiveavenue.52.mrbenn and the dots means ‘next’ In Minecraft (mc for short), the player, set their position, to x,y,z This becomes mc.player.setPos(x, y, z)

Press F5 to save and run the program You should teleport to your new location. If you get an error try to troubleshoot it or ask a friend to try to spot your mistake

What you have learned Variable A variable stores a value. For example in our program we created three variables, x, y and z, which stored the values 10, 11 and 12 respectively. You can change the values 10, 11 and 12 to any number that you want. When we used setPos() we were using the variables x, y and z. Integers Integers are whole numbers, for example 10, 347 and 59. We use integers to set the values of variables when we want to use whole numbers. In this program we use the integers 10, 11 and 12. Function A function is a reusable piece of code that performs a specific task. e.g. the pre-written function setPos() to change the position of the player Function arguments Some functions need to be given data in order to work, this data is called an argument e.g. we gave the argument x, y and z to the setPos() in order to tell it where to teleport the player to.

Change the x, y and z coordinates to new values. Challenge 1 Change the x, y and z coordinates to new values. Teleport to your new location Challenge 2 Insert some of the following code to make the green light on the Pibrella come on when you teleport import pibrella pibrella.light.green.on()

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import pibrella x = 10 y = 11 z = 12 mc.player.setPos(x, y, z) pibrella.light.green.on

You will need these new lines of code import time time.sleep(3) Challenge 3 Make the red light on when you run the program but then change to a green light 3 seconds later You will need these new lines of code import time time.sleep(3) pibrella.red.light.off()

Did you get it correct? import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import pibrella import time x = 10 y = 11 z = 12 mc.player.setPos(x, y, z) pibrella.light.red.on() time.sleep(3) pibrella.light.green.on() pibrella.light.red.off()

Make the Pibrella button teleport you. Challenge 4 Make the Pibrella button teleport you. Make the red light until you press the teleport button The red light then goes off and the green light comes on You will need these new lines of code while True: if pibrella.button.read(): Remember capital T on True : at the end of while True loop : at the end of if After lines with a : you need to indent your code

Did you get it correct? When do you need a : import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import pibrella import time x = 10 y = 11 z = 12 pibrella.light.red.on() while True: if pibrella.button.read() mc.player.setPos(x, y, z) pibrella.light.red.off() pibrella.light.green.on() When do you need a : When do you need indentation Why do you need a while True loop? Why do you need an if

You can refine this code import mcpi.minecraft as minecraft mc = minecraft.Minecraft.create() import pibrella import time x = 10 y = 11 z = 12 while True: if pibrella.button.read() mc.player.setPos(x, y, z) pibrella.light.red.off() pibrella.light.green.on() time.sleep(3) pibrella.light.green.off() else: pibrella.light.red.on) Try to explain this code to say why it is better