SlideShare a Scribd company logo
Introduction to Programming
Class 12 – A Complete Game
Paul Brebner
Game design – car and traffic lights
Design
• Green car
• Drive it around
• Goal is to hit Green Traffic lights
• Once hit, green lights go RED
• Don’t hit RED lights again or gameover
• Don’t hit edge of screen of gameover
• Score for each green light hit
• Speed increases for each green light hit
• Display score in top left
• Display end of game message in middle
Variables (1)
color carColor = color(0,0,255); // blue for car
color targetColor = color(0,255,0); // green for GO!
color redColor = color(255,0,0); // red for danger
int moveX = 0; // -1, 0, or 1 for direction
int moveY = 0;
int carX = 0; // car x y location
int carY = 0;
int targetX = 0; // green light x y location
int targetY = 0;
Variables (2)
boolean newTarget = true; // create new target
int reds = 0; // current number of reds
int maxReds = 5; // max possible reds
int[] redX = new int[maxReds]; // red light array x locations
int[] redY = new int[maxReds]; // red light array y locations
int windowSize = 500; // screen size
boolean gameOver = false; // while true keep playing
PFont Font = createFont("Arial",20, true); // font for scores etc
int score = 0; // player score
float startSpeed = 2; // start speed in pixels
float speed = startSpeed; // car speed
int carSize = 10; // car size (width)
int lightSize = 10; // red and green light size (diameter)
int crashSize = carSize/2+lightSize/2; // how close car and light get before crash
Setup and draw
void setup()
{
size(windowSize, windowSize);
frameRate(25);
background(0);
rectMode(CENTER);
reset();
}
void draw()
{
runGame();
}
Divide program into functions
reset() used at start and end to set
variables to start values
void reset()
{
carX = width/2;
carY = height/2;
gameOver = false;
newTarget = true;
moveY = 0;
moveX = 0;
speed = startSpeed;
reds = 0;
score = 0;
}
Main actions of game
void runGame()
{
background(0);
if (gameOver)
{ // TODO Later
}
else
{
drawCar();
drawTarget();
drawReds();
carMove();
checkBoundary();
hitTarget();
hitReds();
scoreBoard();
}
}
Make empty functions
void drawCar()
{
}
etc
Fill in details
void drawCar()
{
fill(carColor);
rect(carX, carY, carSize, carSize);
}
// allow movement
void keyPressed()
{
if (keyCode == UP) { moveY = -1; moveX = 0; }
if (keyCode == DOWN) { moveY = 1; moveX = 0; }
if (keyCode == LEFT) { moveX = -1; moveY = 0; }
if (keyCode == RIGHT) { moveX = 1; moveY = 0; }
if (keyCode == 'R') { reset(); }
}
carMove()
void carMove()
{
carX += moveX*speed;
carY += moveY*speed;
}
drawTarget()
void drawTarget()
{
fill(targetColor);
if (newTarget) // if newTarget work out location for it
{
targetX = (int)random(lightSize, windowSize-lightSize);
targetY = (int)random(lightSize, windowSize-lightSize);
newTarget = false;
}
ellipse(targetX, targetY, lightSize, lightSize);
}
hitTarget() [simple]
void hitTarget()
{
if (dist(targetX, targetY, carX, carY) <= crashSize)
{
newTarget = true;
speed += 0.3;
score++;
}
}
scoreBoard()
void scoreBoard()
{
String s = "SCORE " + score + " SPEED " + speed;
textAlign(LEFT);
textFont(Font);
fill(237,149,0);
text(s,10,30,40);
}
checkBoundary()
void checkBoundary()
{
if (carX > ?|| carX < ? || carY > ?|| carY < ?)
gameOver = true;
}
checkBoundary()
void checkBoundary()
{
if (carX > windowSize || carX < 0 || carY > windowSize || carY < 0)
gameOver = true;
}
hitTarget() [full]
void hitTarget()
{
if (dist(targetX, targetY, carX, carY) <= crashSize)
{
newTarget = true;
speed += 0.3;
score++;
reds++;
if (reds >= maxReds) // no more room in array!
gameOver = true;
else
{
// new red where target was
redX[reds] = targetX;
redY[reds] = targetY;
}
}
}
hitReds()
void hitReds()
{
// Tricky! i < reds so you don't die immediately by hitting the green light that turned red
// What if it is i <= reds?
for (int i=0; i < reds; i++)
if (dist(carX, carY, redX[i], redY[i]) <= crashSize)
gameOver = true;
}
runGame()
code for gameOver == true
void runGame()
{
background(0);
if (gameOver)
{
scoreBoard();
String s = "Game over! You scored " + score;
textAlign(CENTER);
textFont(Font);
fill(100,200,50);
text(s,width/2,height/2,40);
}
else // code from before
Tricky version (V2)
void hitTarget()
{
float d = dist(targetX, targetY, carX, carY);
boolean hit = (d <= crashSize);
if (hit || (d < 100 && random(0,1) >= 0.99))
{
newTarget = true;
speed += 0.3;
reds++;
if (reds >= maxReds) // no more room in array!
gameOver = true;
else
{
// new red where target was
redX[reds] = targetX;
redY[reds] = targetY;
}
if (hit) score++;
}
}
Extensions
• Add a time limit to hit light then move it
• Give the red lights speed so they move around
• Need another 2 arrays for x and y speed
• As game progresses create new reds with higher speed

More Related Content

Viewers also liked

Converter - C- Language Program
Converter - C- Language ProgramConverter - C- Language Program
Converter - C- Language Program
Zuhaib Ali
 
Introduction to programming - class 10
Introduction to programming - class 10Introduction to programming - class 10
Introduction to programming - class 10
Paul Brebner
 
Random Quiz Maker in C Language Project Slide
Random Quiz Maker in C Language Project SlideRandom Quiz Maker in C Language Project Slide
Random Quiz Maker in C Language Project Slide
Raiyad Raad
 
Umesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole College
Umesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole CollegeUmesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole College
Umesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole College
dezyneecole
 
C programming project by navin thapa
C programming project by navin thapaC programming project by navin thapa
C programming project by navin thapa
Navinthp
 
Programming languages
Programming languagesProgramming languages
Programming languages
Asmasum
 
Computer Languages.
Computer Languages.Computer Languages.
Computer Languages.
Aditya Sheoran
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
JavaTpoint.Com
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
Varun Garg
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
 

Viewers also liked (10)

Converter - C- Language Program
Converter - C- Language ProgramConverter - C- Language Program
Converter - C- Language Program
 
Introduction to programming - class 10
Introduction to programming - class 10Introduction to programming - class 10
Introduction to programming - class 10
 
Random Quiz Maker in C Language Project Slide
Random Quiz Maker in C Language Project SlideRandom Quiz Maker in C Language Project Slide
Random Quiz Maker in C Language Project Slide
 
Umesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole College
Umesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole CollegeUmesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole College
Umesh Taglani,Project on C language,Final Year BCA ,Dezyne E'cole College
 
C programming project by navin thapa
C programming project by navin thapaC programming project by navin thapa
C programming project by navin thapa
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Computer Languages.
Computer Languages.Computer Languages.
Computer Languages.
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 

Similar to Introduction to programming class 12

Creating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdfCreating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdf
ShaiAlmog1
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
Maja Kraljič
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
The C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptxThe C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptx
VitsRangannavar
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
shehabhamad_90
 
c++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdfc++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdf
apexjaipur
 
David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018
Codemotion
 
Creating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdfCreating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdf
ShaiAlmog1
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
Maja Kraljič
 
#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf
sudhinjv
 
Pygame presentation
Pygame presentationPygame presentation
Pygame presentation
Felix Z. Hoffmann
 
Proga 0608
Proga 0608Proga 0608
Proga 0608
Atsushi Tadokoro
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
anjandavid
 
What's wrong with my code- I am coding a battleship game that uses a d (1).pdf
What's wrong with my code- I am coding a battleship game that uses a d (1).pdfWhat's wrong with my code- I am coding a battleship game that uses a d (1).pdf
What's wrong with my code- I am coding a battleship game that uses a d (1).pdf
atexgarments
 
The Ring programming language version 1.5 book - Part 2 of 31
The Ring programming language version 1.5 book - Part 2 of 31The Ring programming language version 1.5 book - Part 2 of 31
The Ring programming language version 1.5 book - Part 2 of 31
Mahmoud Samir Fayed
 

Similar to Introduction to programming class 12 (16)

Creating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdfCreating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdf
 
[EN] Ada Lovelace Day 2014 - Tampon run
[EN] Ada Lovelace Day 2014  - Tampon run[EN] Ada Lovelace Day 2014  - Tampon run
[EN] Ada Lovelace Day 2014 - Tampon run
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
The C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptxThe C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptx
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
c++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdfc++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdf
 
David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018David Kopal - Write better React with ReasonML - Codemotion Milan 2018
David Kopal - Write better React with ReasonML - Codemotion Milan 2018
 
Creating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdfCreating an Uber Clone - Part XXX - Transcript.pdf
Creating an Uber Clone - Part XXX - Transcript.pdf
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
 
#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf
 
Pygame presentation
Pygame presentationPygame presentation
Pygame presentation
 
Proga 0608
Proga 0608Proga 0608
Proga 0608
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
What's wrong with my code- I am coding a battleship game that uses a d (1).pdf
What's wrong with my code- I am coding a battleship game that uses a d (1).pdfWhat's wrong with my code- I am coding a battleship game that uses a d (1).pdf
What's wrong with my code- I am coding a battleship game that uses a d (1).pdf
 
The Ring programming language version 1.5 book - Part 2 of 31
The Ring programming language version 1.5 book - Part 2 of 31The Ring programming language version 1.5 book - Part 2 of 31
The Ring programming language version 1.5 book - Part 2 of 31
 

More from Paul Brebner

The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
The Impact of Hardware and Software Version Changes on Apache Kafka Performan...The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
Paul Brebner
 
Apache ZooKeeper and Apache Curator: Meet the Dining Philosophers
Apache ZooKeeper and Apache Curator: Meet the Dining PhilosophersApache ZooKeeper and Apache Curator: Meet the Dining Philosophers
Apache ZooKeeper and Apache Curator: Meet the Dining Philosophers
Paul Brebner
 
Spinning your Drones with Cadence Workflows and Apache Kafka
Spinning your Drones with Cadence Workflows and Apache KafkaSpinning your Drones with Cadence Workflows and Apache Kafka
Spinning your Drones with Cadence Workflows and Apache Kafka
Paul Brebner
 
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
Paul Brebner
 
Scaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/HardScaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/Hard
Paul Brebner
 
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/HardOPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
Paul Brebner
 
A Visual Introduction to Apache Kafka
A Visual Introduction to Apache KafkaA Visual Introduction to Apache Kafka
A Visual Introduction to Apache Kafka
Paul Brebner
 
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
Paul Brebner
 
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
Paul Brebner
 
Grid Middleware – Principles, Practice and Potential
Grid Middleware – Principles, Practice and PotentialGrid Middleware – Principles, Practice and Potential
Grid Middleware – Principles, Practice and Potential
Paul Brebner
 
Grid middleware is easy to install, configure, secure, debug and manage acros...
Grid middleware is easy to install, configure, secure, debug and manage acros...Grid middleware is easy to install, configure, secure, debug and manage acros...
Grid middleware is easy to install, configure, secure, debug and manage acros...
Paul Brebner
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Paul Brebner
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Paul Brebner
 
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Paul Brebner
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Paul Brebner
 
0b101000 years of computing: a personal timeline - decade "0", the 1980's
0b101000 years of computing: a personal timeline - decade "0", the 1980's0b101000 years of computing: a personal timeline - decade "0", the 1980's
0b101000 years of computing: a personal timeline - decade "0", the 1980's
Paul Brebner
 
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
Paul Brebner
 
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
Paul Brebner
 
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
Paul Brebner
 
How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...
Paul Brebner
 

More from Paul Brebner (20)

The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
The Impact of Hardware and Software Version Changes on Apache Kafka Performan...The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
The Impact of Hardware and Software Version Changes on Apache Kafka Performan...
 
Apache ZooKeeper and Apache Curator: Meet the Dining Philosophers
Apache ZooKeeper and Apache Curator: Meet the Dining PhilosophersApache ZooKeeper and Apache Curator: Meet the Dining Philosophers
Apache ZooKeeper and Apache Curator: Meet the Dining Philosophers
 
Spinning your Drones with Cadence Workflows and Apache Kafka
Spinning your Drones with Cadence Workflows and Apache KafkaSpinning your Drones with Cadence Workflows and Apache Kafka
Spinning your Drones with Cadence Workflows and Apache Kafka
 
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
Change Data Capture (CDC) With Kafka Connect® and the Debezium PostgreSQL Sou...
 
Scaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/HardScaling Open Source Big Data Cloud Applications is Easy/Hard
Scaling Open Source Big Data Cloud Applications is Easy/Hard
 
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/HardOPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
OPEN Talk: Scaling Open Source Big Data Cloud Applications is Easy/Hard
 
A Visual Introduction to Apache Kafka
A Visual Introduction to Apache KafkaA Visual Introduction to Apache Kafka
A Visual Introduction to Apache Kafka
 
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
Massively Scalable Real-time Geospatial Anomaly Detection with Apache Kafka a...
 
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
Building a real-time data processing pipeline using Apache Kafka, Kafka Conne...
 
Grid Middleware – Principles, Practice and Potential
Grid Middleware – Principles, Practice and PotentialGrid Middleware – Principles, Practice and Potential
Grid Middleware – Principles, Practice and Potential
 
Grid middleware is easy to install, configure, secure, debug and manage acros...
Grid middleware is easy to install, configure, secure, debug and manage acros...Grid middleware is easy to install, configure, secure, debug and manage acros...
Grid middleware is easy to install, configure, secure, debug and manage acros...
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
 
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
Melbourne Big Data Meetup Talk: Scaling a Real-Time Anomaly Detection Applica...
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
 
0b101000 years of computing: a personal timeline - decade "0", the 1980's
0b101000 years of computing: a personal timeline - decade "0", the 1980's0b101000 years of computing: a personal timeline - decade "0", the 1980's
0b101000 years of computing: a personal timeline - decade "0", the 1980's
 
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
ApacheCon Berlin 2019: Kongo:Building a Scalable Streaming IoT Application us...
 
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...ApacheCon2019 Talk: Kafka, Cassandra and Kubernetesat Scale – Real-time Ano...
ApacheCon2019 Talk: Kafka, Cassandra and Kubernetes at Scale – Real-time Ano...
 
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
 
How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...How to Improve the Observability of Apache Cassandra and Kafka applications...
How to Improve the Observability of Apache Cassandra and Kafka applications...
 

Recently uploaded

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 

Introduction to programming class 12

  • 1. Introduction to Programming Class 12 – A Complete Game Paul Brebner
  • 2. Game design – car and traffic lights
  • 3. Design • Green car • Drive it around • Goal is to hit Green Traffic lights • Once hit, green lights go RED • Don’t hit RED lights again or gameover • Don’t hit edge of screen of gameover • Score for each green light hit • Speed increases for each green light hit • Display score in top left • Display end of game message in middle
  • 4. Variables (1) color carColor = color(0,0,255); // blue for car color targetColor = color(0,255,0); // green for GO! color redColor = color(255,0,0); // red for danger int moveX = 0; // -1, 0, or 1 for direction int moveY = 0; int carX = 0; // car x y location int carY = 0; int targetX = 0; // green light x y location int targetY = 0;
  • 5. Variables (2) boolean newTarget = true; // create new target int reds = 0; // current number of reds int maxReds = 5; // max possible reds int[] redX = new int[maxReds]; // red light array x locations int[] redY = new int[maxReds]; // red light array y locations int windowSize = 500; // screen size boolean gameOver = false; // while true keep playing PFont Font = createFont("Arial",20, true); // font for scores etc int score = 0; // player score float startSpeed = 2; // start speed in pixels float speed = startSpeed; // car speed int carSize = 10; // car size (width) int lightSize = 10; // red and green light size (diameter) int crashSize = carSize/2+lightSize/2; // how close car and light get before crash
  • 6. Setup and draw void setup() { size(windowSize, windowSize); frameRate(25); background(0); rectMode(CENTER); reset(); } void draw() { runGame(); }
  • 7. Divide program into functions reset() used at start and end to set variables to start values void reset() { carX = width/2; carY = height/2; gameOver = false; newTarget = true; moveY = 0; moveX = 0; speed = startSpeed; reds = 0; score = 0; }
  • 8. Main actions of game void runGame() { background(0); if (gameOver) { // TODO Later } else { drawCar(); drawTarget(); drawReds(); carMove(); checkBoundary(); hitTarget(); hitReds(); scoreBoard(); } }
  • 9. Make empty functions void drawCar() { } etc
  • 10. Fill in details void drawCar() { fill(carColor); rect(carX, carY, carSize, carSize); } // allow movement void keyPressed() { if (keyCode == UP) { moveY = -1; moveX = 0; } if (keyCode == DOWN) { moveY = 1; moveX = 0; } if (keyCode == LEFT) { moveX = -1; moveY = 0; } if (keyCode == RIGHT) { moveX = 1; moveY = 0; } if (keyCode == 'R') { reset(); } }
  • 11. carMove() void carMove() { carX += moveX*speed; carY += moveY*speed; }
  • 12. drawTarget() void drawTarget() { fill(targetColor); if (newTarget) // if newTarget work out location for it { targetX = (int)random(lightSize, windowSize-lightSize); targetY = (int)random(lightSize, windowSize-lightSize); newTarget = false; } ellipse(targetX, targetY, lightSize, lightSize); }
  • 13. hitTarget() [simple] void hitTarget() { if (dist(targetX, targetY, carX, carY) <= crashSize) { newTarget = true; speed += 0.3; score++; } }
  • 14. scoreBoard() void scoreBoard() { String s = "SCORE " + score + " SPEED " + speed; textAlign(LEFT); textFont(Font); fill(237,149,0); text(s,10,30,40); }
  • 15. checkBoundary() void checkBoundary() { if (carX > ?|| carX < ? || carY > ?|| carY < ?) gameOver = true; }
  • 16. checkBoundary() void checkBoundary() { if (carX > windowSize || carX < 0 || carY > windowSize || carY < 0) gameOver = true; }
  • 17. hitTarget() [full] void hitTarget() { if (dist(targetX, targetY, carX, carY) <= crashSize) { newTarget = true; speed += 0.3; score++; reds++; if (reds >= maxReds) // no more room in array! gameOver = true; else { // new red where target was redX[reds] = targetX; redY[reds] = targetY; } } }
  • 18. hitReds() void hitReds() { // Tricky! i < reds so you don't die immediately by hitting the green light that turned red // What if it is i <= reds? for (int i=0; i < reds; i++) if (dist(carX, carY, redX[i], redY[i]) <= crashSize) gameOver = true; }
  • 19. runGame() code for gameOver == true void runGame() { background(0); if (gameOver) { scoreBoard(); String s = "Game over! You scored " + score; textAlign(CENTER); textFont(Font); fill(100,200,50); text(s,width/2,height/2,40); } else // code from before
  • 20. Tricky version (V2) void hitTarget() { float d = dist(targetX, targetY, carX, carY); boolean hit = (d <= crashSize); if (hit || (d < 100 && random(0,1) >= 0.99)) { newTarget = true; speed += 0.3; reds++; if (reds >= maxReds) // no more room in array! gameOver = true; else { // new red where target was redX[reds] = targetX; redY[reds] = targetY; } if (hit) score++; } }
  • 21. Extensions • Add a time limit to hit light then move it • Give the red lights speed so they move around • Need another 2 arrays for x and y speed • As game progresses create new reds with higher speed