Monday, March 11, 2013

Making a Game Part 1

Decided to make something interesting so I decided on a simple game. The goal of the game will eventually be to keep the light within the row of lights. This is achieved by pushing the light back into the direction from which it came. It's basically a balancing game in which you don't want to have the light "fall over". Created a simple introduction for the game and worked on the basic mechanics. Will upload a finished product soon. Current code can be viewed after the break.





int count=0;
int currentOn=7;
void setup()
{

 
  for (int i=2; i<12; i++){
  digitalWrite(i,HIGH);
  delay(100);
  digitalWrite(i,LOW);}
 
  for (int i=12; i>1; i--){
  digitalWrite(i,HIGH);
  delay(100);
  digitalWrite(i,LOW);}
  introSeq();
  count=0;
  introSeq();
  count=0;
  introSeq();
  count=0;
 
  digitalWrite(currentOn,HIGH);
}

void loop() {
  int right = analogRead(0);
  int left = analogRead(1);
 
  Serial.println(right);
  delay(100);
  if (right == 0)
  {
    digitalWrite(currentOn,LOW);
    currentOn-=1;
    digitalWrite(currentOn,HIGH);
  }

  if (left == 0)
  {
    digitalWrite(currentOn,LOW);
    currentOn+=1;
    digitalWrite(currentOn,HIGH);
  }
 
}

void introSeq(){
  for(int j=6; j>1; j--){
  digitalWrite(j,HIGH);
  digitalWrite(j+1+count,HIGH);
  delay(200);
  digitalWrite(j,LOW);
  digitalWrite(j+1+count,LOW);
  count += + 2;}}

No comments:

Post a Comment