public blacky() { score = 0; pac_move = new pac_direction(); pac_move = pac_direction.right1; create_out_of_bound(); create_point(); }
public blacky2(int no_of_carbon) { score = 0; pac_move = new pac_direction(); pac_move = pac_direction.right1; no_of_carbons = no_of_carbon; bulb_changed = 0; CreateCarbon(no_of_carbons); create_out_of_bound(); create_point(); }
public void Update(GameTime gametime, out bool exit) { timecounter++; exit = false; if (timecounter > timelimit) { exit = true; return; } if (randomSeed > 2147483) { randomSeed = 0; } if (firstCheck == false) { firstCheck = true; firstRun = gametime.TotalGameTime.TotalSeconds; } KeyboardState currentstate = Keyboard.GetState(); Keys[] currentkey = currentstate.GetPressedKeys(); shutDoor = false; if (forced == true) { shutDoor = true; for (int i = 0; i < no_of_carbons; i++) { if (forceCarbons[i] == true) { shutDoor = false; } } if (shutDoor == true) { rect[42] = new Rectangle(458, 276, 42, 9); } } if (!endGame) { if (forced == false) { if (storedSecs == 0) { storedSecs = gametime.TotalGameTime.TotalSeconds; } if (gametime.TotalGameTime.TotalSeconds < storedSecs + 2) { if (gametime.TotalGameTime.Milliseconds % 250 == 0) { if (OpenDoor) { OpenDoor = false; } else { OpenDoor = true; } } } else { rect[42] = new Rectangle(1, 1, 1, 1); for (int i = 0; i < no_of_carbons; i++) { forceCarbons[i] = true; } forced = true; } } } Movecarbon(); int startsecs = 100; int[] moveSecs = new int[no_of_carbons]; for (int i = 0; i < no_of_carbons; i++) { moveSecs[i] = startsecs + i * 50; } for (int i = 0; i < no_of_carbons; i++) { if (gametime.TotalGameTime.Milliseconds % moveSecs[i] == 0) { gtChange[i] = true; } } foreach (Keys keys in currentkey) { if (keys == Keys.Up) { pac_move = pac_direction.up; movy = -5; movx = 0; if (CheckWalls(pac_X, pac_Y, movx, movy, pac_Up, true, 0)) { pac_Y += movy; } } if (keys == Keys.Down) { pac_move = pac_direction.down; movy = 5; movx = 0; if (CheckWalls(pac_X, pac_Y, movx, movy, pac_Down, true, 0)) { pac_Y += movy; } } if (keys == Keys.Left) { movy = 0; movx = -5; if (walk_first_left) { pac_move = pac_direction.left1; walk_first_left = false; if (CheckWalls(pac_X, pac_Y, movx, movy, pac_Left, true, 0)) { pac_X += movx; } } else { pac_move = pac_direction.left2; walk_first_left = true; if (CheckWalls(pac_X, pac_Y, movx, movy, pac_Left2, true, 0)) { pac_X += movx; } } } if (keys == Keys.Right) { movy = 0; movx = 5; if (walk_first_right) { pac_move = pac_direction.right1; walk_first_right = false; if (CheckWalls(pac_X, pac_Y, movx, movy, pac_Right, true, 0)) { pac_X += movx; } } else { pac_move = pac_direction.right2; walk_first_right = true; if (CheckWalls(pac_X, pac_Y, movx, movy, pac_Right, true, 0)) { pac_X += movx; } } } } if (gametime.TotalGameTime.Milliseconds % 1000 == 0) { if (edibleCarbons) { secondsPassed++; if (secondsPassed == 5) // number of seconds that Carbons are edible! { secondsPassed = 0; edibleCarbons = false; } } } //check the boundry of the screen if (pac_X < 0) { pac_X = 0; } if (pac_Y < 0) { pac_Y = 0; } if (pac_X + movx > 760) { pac_X = 760; } if (pac_Y + movy > 560) { pac_Y = 560; } }
public void Update(GameTime gametime, out bool exit) { exit = false; if (timecounter > timelimit) { exit = true; return; } timecounter++; KeyboardState currentstate = Keyboard.GetState(); Keys[] currentkey = currentstate.GetPressedKeys(); foreach (Keys keys in currentkey) { if (keys == Keys.Up) { pac_move = pac_direction.up; movy = -5; movx = 0; if (CheckWalls(pac_Up, true)) { pac_Y += movy; } } if (keys == Keys.Down) { pac_move = pac_direction.down; movy = 5; movx = 0; if (CheckWalls(pac_Down, true)) { pac_Y += movy; } } if (keys == Keys.Left) { movy = 0; movx = -5; if (walk_first_left) { pac_move = pac_direction.left1; walk_first_left = false; if (CheckWalls(pac_Left, true)) { pac_X += movx; } } else { pac_move = pac_direction.left2; walk_first_left = true; if (CheckWalls(pac_Left2, true)) { pac_X += movx; } } } if (keys == Keys.Right) { movy = 0; movx = 5; if (walk_first_right) { pac_move = pac_direction.right1; walk_first_right = false; if (CheckWalls(pac_Right, true)) { pac_X += movx; } } else { pac_move = pac_direction.right2; walk_first_right = true; if (CheckWalls(pac_Right, true)) { pac_X += movx; } } } } //check the boundry of the screen if (pac_X < 0) { pac_X = 0; } if (pac_Y < 0) { pac_Y = 0; } if (pac_X + movx > 760) { pac_X = 760; } if (pac_Y + movy > 560) { pac_Y = 560; } exit = false; }