Welcome back!



imageThis term we are going to add a touch of class to our python coding. This year we have learned how to create, store and retrieve data of different types. We have also learned out to manipulate and transform this data using functions. Often in our projects we have had to use the global keyword to ensure that our functions are all operating on the same items of data (not just creating a copy of the data which is only used within the function). Wouldn’t it be useful if the data and functions for a particular entity (or object) in your game could be kept together, without having to pass the data, in a global form, explicitly between each function call? It would also be great if you need lots of these entities, the functions would ‘know’ which object instance they were acting on?

For example, we want lots of aliens in our game. Each alien will move using the same logic and be destroyed in a similar way by our missiles, but each will have its own position and perhaps its own sprite image? In other words, we want to reuse the same functions, but on different data for each alien object instance.

The final data structure we want to tackle this year capable of achieving this, and other very useful features and it is called a Class. To introduce classes we are going to work through the following exercise:

https://www.codecademy.com/courses/python-intermediate-en-WL8e4/0/1

Comments


Comments powered by Disqus