element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Making  a Flash game with arduino uno; one glitch keeps happening
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 5 replies
  • Subscribers 392 subscribers
  • Views 426 views
  • Users 0 members are here
  • lcd
  • help
  • game
  • arduino
Related

Making  a Flash game with arduino uno; one glitch keeps happening

Former Member
Former Member over 10 years ago

My game works perfectly except for the  fact that the gameover doesn't worK. It only does game over if line2 hits it. Pleased help for a solution. Here is the code:

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,7,4,3,2);

int pbu = 13;

int pbd = 10;

int pbr = 8;

int pbl = 6;

int currentcirc = 0;

int xp = 0;

int yp = 0;

int xlp;

int ylp;

int curline;

int shootdelay = 1250;

int prevline;

int ranline;

int gameover = false;

byte circle1[8] =

{

B01110,

B11111,

B11111,

B11111,

B01110,

B00000,

B00000,

B00000,

};

byte circle2[8] =

{

B00000,

B01110,

B11111,

B11111,

B11111,

B01110,

B00000,

B00000,

};

byte circle3[8] =

{

B00000,

B00000,

B01110,

B11111,

B11111,

B11111,

B01110,

B00000,

};

byte circle4[8] =

{

B00000,

B00000,

B00000,

B01110,

B11111,

B11111,

B11111,

B01110,

};

byte line1[8] =

{

B11111,

B00000,

B00000,

B00000,

B00000,

B00000,

B00000,

B00000,

};

 

byte line2[8] =

{

B00000,

B00000,

B11111,

B00000,

B00000,

B00000,

B00000,

B00000,

};

 

byte line3[8] =

{

B00000,

B00000,

B00000,

B00000,

B11111,

B00000,

B00000,

B00000,

};

 

byte line4[8] =

{

B00000,

B00000,

B00000,

B00000,

B00000,

B00000,

B11111,

B00000,

};

void setup()

{

lcd.begin(16,2);

pinMode(9,OUTPUT);

analogWrite(9,50);

pinMode(pbu,INPUT);

pinMode(pbd,INPUT);

pinMode(pbr,INPUT);

pinMode(pbl,INPUT);

lcd.createChar(0,circle1);

lcd.createChar(1,circle2);

lcd.createChar(2,circle3);

lcd.createChar(3,circle4);

lcd.createChar(4,line1);

lcd.createChar(5,line2);

lcd.createChar(6,line3);

lcd.createChar(7,line4);

xlp = 16;

}

 

 

void loop()

{

if (gameover != true)

 

{

lcd.setCursor(0,0);

 

if (xlp <2)

{

if (curline == 4 && ylp == yp)

{

if (currentcirc != 0)

 

{

gameover = true;

}

}

if (curline == 5 && ylp == yp)

{

if (currentcirc != 3)

{

gameover = true;

}

}

if (curline == 6 && ylp == yp)

{

gameover == true;

}

 

if (curline == 7 && ylp == yp)

{

if (currentcirc == 3)

{

  gameover = true;

}

}

 

 

}

 

 

 

if (xlp == 15)

{ylp = random(0,2);

curline = random(4,8);

 

 

}

if (xlp == 1)

{

xlp = 16;

}

if (digitalRead(pbu) == HIGH)

{

if (currentcirc == 0)

{

  if (yp == 1)

  {

  yp = yp - 1;

  currentcirc = 3;

  }

}

else

{

  currentcirc = currentcirc - 1;

}

}

if (digitalRead(pbd) == HIGH)

{

  if (currentcirc == 3)

  {

   if  (yp == 0)

   {

    yp = yp + 1;

    currentcirc = 0;

   }

  }

  else

  {

   currentcirc = currentcirc + 1;

  }

}

 

//if (digitalRead(pbr) == HIGH)

//{

//if (xp < 16)

//{

  //xp = xp + 1;

//}

//}

//if (digitalRead(pbl) == HIGH)

//{

//if (xp > 0)

//{

  //xp = xp - 1;

//}

//}

 

 

if (xp > 16)

{

xp = 16;

}

if (yp > 1)

{

yp = 1;

}

xlp = xlp - 1;

lcd.setCursor(xp,yp);

lcd.write((byte)currentcirc);

shoot();

delay(100);

lcd.clear();

shootdelay = shootdelay - 15;

}

else

{

lcd.clear();

lcd.setCursor(6,0);

lcd.print("GAME");

lcd.setCursor(6,1);

lcd.print("OVER");

if (digitalRead(pbu) == HIGH)

{

  gameover = false;

shootdelay= 1250;

}

}

 

}

 

 

void shoot()

{

if (shootdelay < 125)

{

  shootdelay = 115;

}

delay(shootdelay);

lcd.setCursor(xlp,ylp);

lcd.write((byte)curline);

 

}

 

 

 

 

 

 

  • Sign in to reply
  • Cancel
Parents
  • mcb1
    0 mcb1 over 10 years ago

    Kyle

     

    For future reference use the >> symbol and select Syntax Highlighting then C++ to make you code more like in the IDE.

     

    I think you'll find your problem is this line

     

    if (curline == 6 && ylp == yp)
    {
         gameover == true;
    }

     

    It seems to be a simple typo.

    You have a lot of nested loops, which you may wish to revise to see if there is a more elegant and simple way to achieve the same thing.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to mcb1

    Mark,

     

    Thanks for the tip on the syntax and for pointing out that typo. The only problem is that it glitches to not show up game over for all the curlines except for 5.(that typo will probably fix the curline6 one) I am bewildered on what the problem could be on the other ones.

     

    -Kyle

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 10 years ago in reply to mcb1

    Mark,

     

    Thanks for the tip on the syntax and for pointing out that typo. The only problem is that it glitches to not show up game over for all the curlines except for 5.(that typo will probably fix the curline6 one) I am bewildered on what the problem could be on the other ones.

     

    -Kyle

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • mcb1
    0 mcb1 over 10 years ago in reply to Former Member

    Kyle

     

    You basically have a single 'if' statement ( if (gameover != true) ), and then a lot of checks.

    It seems you never exit the if statement when you change the gameover state.

    if (curline == 4 && ylp == yp)
          {
            if (currentcirc != 0)
            {
              gameover = true;
            }
          }

     

    You may be better changing the 'game over' display to a separate routine and call it when you change the state.

     

    You can also use 'While' instead of this

    if (gameover != true)

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to mcb1

    Mark

     

    Thanks for all your help. I will fix the typo and replace big if statement with a small while statement and see if it fixes my problem.  Also, what did you mean when you said I had lots of nested ifs? and how would I clean up or fix them?

     

    Kyle

     

    PS Sorry for the rookie mistakes and such. This is only my 4th day with an arduino and my 3rd sketch.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 10 years ago in reply to Former Member

    Sorry for the rookie mistakes and such. This is only my 4th day with an arduino and my 3rd sketch

    We all have to start somewhere.

     

     

    You can add some serial.println and a delay for debugging to see if it is going where you want it to

     

    A nested loop is a loop inside a loop inside another loop.

     

    When I'm doing something I tend to draw out a bit of a flow diagram to flesh it out.

    This can highlight where you can do common things, or perhaps a better way.

     

    Your first 4 nested 'if' statements have the same " ... && ylp == yp) ...", so you could probably check that and then use the switch case for the other part.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube