
Tuesday, July 11, 2017
I was assigned to make a game call fight lander game using Pryret. I would read the tutorial in
http://www.pyret.org/docs/atest/Tutorial__A_FlightLander_Game.html . The first step was to go on to the website https://code.pyret.org/ and press my program where my gmail connected to Pyret. Then I would begin with coding down the Preliminaries. What I code was the two libraries and blind that were the results to the corresponding names into I and W.
import image as I
|
import world as W
|
Then I would tell Pryret to upload the image of plane and give it a name as follow:
AIRPLANE-URL =
|
"http://world.cs.brown.edu/1/clipart/airplane-small.png"
|
AIRPLANE = I.image-url(AIRPLANE-URL)
When Pyret agrees with it by showing a green light, but if does not pass it would glow a red light and it would highlight the error and it will tell you what you should do. I would then make the world state consists of just the airplane x-position, to move it to the right, we simply increment it's value. This code is the constance distance of a name:
This code is the function in which the plane moves. The site shows us some test case:
check:
|
move-airplane-x-on-tick(50) is 50 + AIRPLANE-X-MOVE
|
move-airplane-x-on-tick(0) is 0 + AIRPLANE-X-MOVE
|
move-airplane-x-on-tick(100) is 100 + AIRPLANE-X-MOVE
|
end
This would be the function's definiton:
fun move-airplane-x-on-tick(w):
|
w + AIRPLANE-X-MOVE
|
end
Pyret will confirm that this function passes all of its tests. Now I would be Displaying the World State. Now Im going to draw the game's visual output. I would defined some constants representing the visual output:
WIDTH = 800
|
HEIGHT = 500
|
|
BASE-HEIGHT = 50
|
WATER-WIDTH = 500
|
Then I would create two rectangles which would representing water and land:
BLANK-SCENE = I.empty-scene(WIDTH, HEIGHT)
|
|
WATER = I.rectangle(WATER-WIDTH, BASE-HEIGHT, "solid", "blue")
|
LAND = I.rectangle(WIDTH - WATER-WIDTH, BASE-HEIGHT, "solid", "brown")
|
|
BASE = I.beside(WATER, LAND)
|
|
BACKGROUND =
|
I.place-image(BASE,
|
WIDTH / 2, HEIGHT - (BASE-HEIGHT / 2),
|
BLANK-SCENE)
|
Then I would examine the value of BACKGROUND in the interaction area to confirm that it looks right. The function of the World state would be
|
|
|
fun place-airplane-x(w):
|
I.place-image(AIRPLANE,
|
w,
|
50,
|
BACKGROUND)
|
end
|
I'll be observing the time and combing the pieces by imputing the function call big-bang, which create animations.
W.big-bang(0, [list:
|
W.on-tick(move-airplane-x-on-tick),
|
W.to-draw(place-airplane-x)])
|
Then I would run it to see if their were no errors which their wasn't.When I run the test it the airplane files across the background
Now we got the preliminaries out of the way, we just need to go about enhancing it. We would need to modify the move-airplane-x-on-tick. To have the function of num-modulo does exactly what we need the plan to wrap around the page. Here is a video that would show you what to do: http://world.cs.brown.edu/1/projects/flight-lander/v2.swf That is, we want the x-location to always be modulo the width of the scene this the coding that I would use:
fun move-airplane-wrapping-x-on-tick(x):
|
num-modulo(move-airplane-x-on-tick(x), WIDTH)
|
end
|
But when I add that coding in Pyret it did not work. The Plane did not come back it when straight. So I decided to go back to see if I am missing something but everything was alright and I didn't miss a thing at all. Another Student looked at what I was doing and he also said the same thing and in the end the teacher would take a look at that and see what had happened.
Nice post! I was able to find the problem with the airplane not wrapping around. Rather than just tell you what the solution is, let me first try a hint. What is the function call that makes the animation run? Look carefully at that statement, and you will notice you are calling the wrong function inside it. It's a small change, but a very important one if you want the airplane to wrap around.
ReplyDelete