incrementing values in if loop (in C) -


i writing self-controlled pacman game (pacman moves algorithms decide it's movement, needs chase ghosts, etc.) in c. keep in mind new programming in c method use may not 1 @ all.

anyways, stumbled upon problem.

my pacman moves in array map it's placement at

map[ypacman][xpacman] == place of pacman; 

now, when pacman in "rage mode"; after picking sweet, him find ghosts seeks. ghost being char 'g' in array.

now, pacman see ahead of him catch , follow ghost when reaches distance near him. let's he's moving left; him 5 "x-coords" left of him, including x-coords "1,2,3,4,5". when of these coordinates equal char 'g', it'd have follow him.

now, implement it, can't seem find way how to.

if (map[ypacman][xpacman-i] == 'g')  { } 

with "i" having value 1-5. incrementing during process itself. not use

if (map[ypacman][xpacman-1] == 'g' || map[ypacman][xpacman-2] == 'g'|| map[ypacman][xpacman-3] == 'g'|| map[ypacman][xpacman-4] == 'g'|| map[ypacman][xpacman-5] == 'g')  { } 

even though exact result need. this, can't use loops!..

i think seems easy solve how this. @ moment have no clue. in advance

if understand correctly, want :

 bool aboolvalue=false;  int i;  (i=1;i<6;i++)  {      if (map[ypacman][xpacman-i]=='g')      {         aboolvalue=true;         break;      }  }  if (aboolvalue) {   // stuff  } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -