Understanding the Games_Object Class


Understanding the Games_Object Class

The games module has a foundational class called Games_Object upon which all classes that represent graphics objects are based. The classes Text, Message, and Sprite are all (directly or indirectly) derived from Games_Object. This means that those three classes all inherit a long list of important methods for manipulating graphics objects and extracting information about an object's location on a graphics screen. Table 11.3 lists some useful Games_Object methods that all three classes inherit.

Table 11.3: USEFUL Games_Object METHODS

Method

Description

get_pos()

Returns the object's x-coordinate and y-coordinate.

get_xpos()

Returns the object's x-coordinate.

get_ypos()

Returns the object's y-coordinate.

get_left()

Returns the x-coordinate of the object's left edge.

get_right()

Returns the x-coordinate of the object's right edge.

get_top()

Returns the y-coordinate of the object's top edge.

get_bottom()

Returns the y-coordinate of the object's bottom edge.

get_velocity()

Returns the object's x and y velocity components as a two-element tuple.

move_to(x,y)

Moves the object to the new coordinates (x,y).

set_left(x)

Moves the object horizontally so that its left edge is at the new coordinate x.

set_right(x)

Moves the object horizontally so that its right edge is at the new coordinate x.

set_top(y)

Moves the object vertically so that its top edge is at the new coordinate y.

set_bottom(y)

Moves the object vertically so that its bottom edge is at the new coordinate y.

set_velocity(dx, dy)

Sets the object's x velocity to dx and its y velocity to dy.

overlapping_objects()

Returns a list of objects that overlap the object.

destroy()

Removes all of the associated Screen object's references to an object.

HINT

In the course of writing a game, you'll never directly instantiate an object of Games_Object. The class is meant only as a base for other classes. This type of class is called an abstract class.

Again, there's no need to try to remember all of the methods described in Table 11.3. Just know they're available through all Text, Message, and Sprite objects.




Python Programming for the Absolute Beginner
Python Programming for the Absolute Beginner, 3rd Edition
ISBN: 1435455002
EAN: 2147483647
Year: 2003
Pages: 194

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net