Day of AI Australia
Day of AI Australia – Lessons
Day of AI Australia Read More »
Each time the car collides with an instance of the array of obstacles we remove that instance from the array. At the same time we want to add one to the score variable In order to do that we need to pass the score variable to the Coll function and return the score at the end of
10. Racey – Score from Collision Read More »
Pygame has a Rect function we can use to determine if two objects collide. We need to create a Rect for each instanace of our class and we need to create a Rect for the car. but first We are going to use the Rect function to determine the height and width of our images. Near the
9. Racey – Using Rect Collisions Read More »
Now we want to add a vector for movement. STEP ONE: MODIFYING THE INIT FUNCTION Inside our class initialisation function ( __init__) we can create a vector for movement add the following to the __init__ function # Create a random speed vector.movespeed = random.randint(1, 10)directionx = random.random()*movespeed * random.choice((-1, 1))directiony = random.random()*movespeed * random.choice((-1, 1))self.vector
8. Racey – Direction Vectors Read More »
In order to assign different movement directions to different instances of our class we need to use Vectors. The best way to use Vectors is to also use a Position as a vector instead of x and y values. for example instead ofx=220, y = 100 we useposition(220,100) STEP ONE: MODIFY OUR INIT FUNCTION Combine
7. Racey – Using Vectors Read More »
STEP ONE: ADDING A MOVE FUNCTION TO OUR CLASS Inside our class declaration we need to define a new function called movedef move(self): and inside that function we need to modify the x and/or y values of the class. Move Left: decrease the x valueself.x -= 1 Move Down: increase the y valueself.y += 1
6. Racey – Move class instance Read More »
Now you might want to add multiple instances of your class STEP ONE: Randomly placing instances on the screen Python has a function called randrange and can be used to generate a number between a top and bottom valuei.e. random.randrange(1,10) will randomly generate a number between 1 and 10 There for to randomly place our
5. Racey – Adding Instances Read More »
STEP ONE: LOAD A DOG IMAGE You will need to find an image and save it into the code folder You should do this near the top of your code where you are already loading images STEP TWO: CREATE A BASIC CLASS You should do this near the top of the page, under where you
4. Racey – Creating a Class Read More »
Modify the game play so that you get points for hitting the thing rather than dodging it. Steps Change the things_dodged() function call so that it uses the variable score. change the variable dodged to score Change the code when your crash into a thing to increase the scoreYou will also need to move the
3. Racey – Change Game Play Read More »
Look at the code we have for adding the car image and drawing it on the screen and use this as a guide to see if you can add an image for our thing and display it.
2. Racey – Thing Image Read More »