Create a simple game where the objective is to navigate a black dot (the player)
ID: 3815121 • Letter: C
Question
Create a simple game where the objective is to navigate a black dot (the player),
that is the size of a single pixel, from some point in the image to a goal point.
The score is based on the number of steps taken to reach the goal point and it is
shown when the game ends. The picture/background/"stage" on which the black dot
(the player) is placed has a solid colour (e.g. white) and the goal point is a
pixel of another colour (e.g. red). The dot can be moved up, down, left or right
by 10 pixels at a time by entering characters "w", "s", "a" and "d" respectively.
(The movement of the dot can be abrupt and it does not need to be animated. The
trail of the black dot does not need to be erased, for the sake of simplicitly).
You should also have an "x" option to end the game at any point. Name your
game/function 'antFoodGame'.
Explanation / Answer
CGPoint origin1 = self.ghost1.center;
CGPoint target1 = CGPointMake(self.ghost1.center.x, self.ghost1.center.y-124);
CABasicAnimation *bounce1 = [CABasicAnimation animationWithKeyPath:@"position.y"];
bounce1.fromValue = [NSNumber numberWithInt:origin1.y];
bounce1.toValue = [NSNumber numberWithInt:target1.y];
bounce1.duration = 2;
bounce1.autoreverses = YES;
bounce1.repeatCount = HUGE_VALF;
[self.ghost1.layer addAnimation:bounce1 forKey:@"position"];
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.