Your browser does not support the canvas tag.

Week 2
Every game class talks about the Magic Circle or the "consecrated spot" but no class anywhere has a better example than the ULTIMATE HOCKEY FIGHT!

This is some serious game


What is better than using hockey fights to illustrate the rules of play?

simple and potentially attainable games.
Cursor 10
Planarity (BE CAREFUL)
Simmer Down Sprinter
4 Minutes and 33 Seconds of Uniqueness
1st person Tetris (doesn't work in chrome)
Lightbot One of my favorite teaching games.



Soldering


When you solder you heat up very soft metal, it becomes a liquid and forms a bond where you are trying to make an electrical connection. This bond, however, is not physically very strong. Soldering is not structural - soldering and welding are two very different animals. Here's how to solder in bullet form.
Keep the tip of the iron clean - use a damp sponge while soldering and periodically clean (or "tin" the tip with tip tinner)
Potentiometers


What is a potentiometer (or pot)? Simply put, it's an electric knob. Sometimes it will be called a variable resistor, which is also an accurate description of what it does - it variably resists the voltage.
It's actually easier to wire a pot than a button. The middle pole goes to an analog input pin. The other two poles are interchangeable - one goes to the 5v pin the other to ground. here's a picture of how to wire it.

NOTE: Even though this is easy, messing it up can fry your arduino. Make sure the center pin goes to the Analog port or you'll be going directly from the 5V to the Ground port.



DONT FORGET TO CHANGE THE [0] TO THE RIGHT NUMBER FOR YOUR MACHINE.

	import processing.serial.*;
	import cc.arduino.*;
	Arduino arduino;
	int analogPin = 0;
	float potX = 0; 
	void setup()
	{
	  size(400, 400); 
	  arduino = new Arduino(this, Arduino.list()[0], 57600); 
	}

	void draw()
	{ 
	  println ( arduino.analogRead(analogPin)); 
	}


	

Try swapping the ground and 5v and see what happens to the number.

In the following sketch we apply the pot to something on the screen. The "map" function is very useful for this - it allow us to remap an incoming number to another range, in this case the incoming range is between 0 and 1023, and we are mapping that value to a range between 0 and the width of the stage. Use the Processing API to look this (and other stuff) up.


	import processing.serial.*;
	import cc.arduino.*;
	Arduino arduino;
	int analogPin = 0;
	float potX = 0; 
	void setup()
	{
	  size(400, 400); 
	  arduino = new Arduino(this, Arduino.list()[0], 57600);
	  smooth(); 
	}

	void draw()
	{ 
	  background(200); 
	  int pot1 = arduino.analogRead(analogPin); 
	  potX = map(pot1, 0, 1023, 0, width); 
	  fill(0); 
	  ellipse (potX, 200, 6, 6); 
	}
	

PONG ... IT BEGINS

It's time to start thinking aobut PONG, which means making real pong before we can make augmented pong. Here's a good start. Add the Arduino and make the paddles move by moving potentiometers. There's a few things that might be new here, PVectors and classes. If they are, we cam recap how they work, and there's excellent tutorials on how to use them, but here's the short story. PVectors are just vairables that let us store two (or three, but 2 is all we need) float variables within it. So each PVector has a x and y value. At first it just makes things tidier, but we can use add() to add vectors together waving us some lines of code.
Classes (or objects) will let us make multiple balls really easily. In some CS classes everything is an object. It seems a like a lot of extra code at first but thinking in objects allows for much more complicated projects as your game expands.


ArrayList<BallClass> ballslist = new ArrayList<BallClass>();
PVector player1, player2; 
int playerW = 15; // width of paddle
int playerH = 60; // hieght of paddle

void setup() {
  size(600, 400); 
  smooth();// make the graphics look purdy. 
  rectMode(CENTER); // draw rects from center
  player1 = new PVector(20, height/2); 
  player2 = new PVector(width -20, height/2); 
  ballslist = new ArrayList();
  ballslist.add(new BallClass());
}

void draw () {
  background (50);// background color
  rect(player1.x, player1.y, playerW, playerH); 
  rect(player2.x, player2.y, playerW, playerH); 

  for (int i = ballslist.size()-1; i >= 0; i--) { 
    BallClass dball = ballslist.get(i); 
    dball.display();
  }
}

class BallClass {
  PVector ballLoc; 
  int ballsize = 16; // width of ball
  BallClass() {
    ballLoc = new PVector(width/2, height/2);
  }
  void display() {
    ellipse(ballLoc.x, ballLoc.y, ballsize, ballsize);
  }
}


presentation link

Reading link
As We May Think