Im rehacer un juego hecho con Python / Pygame a C + + / SDL (pygame es un contenedor de Python para SDL, por lo que theyre bastante similar).
Acabo de empezar a aprender C + +, así que no soy exactamente seguro de cosas como las clases y Im teniendo algunos problemas.
Así que para asegurarse de que, a esta clase C + +, más o menos se comportan como el Python uno?
/***************
* C++ class
***************/
class game_object {
int x, y;
SDL_Surface* image;
public:
game_object(int a, int b, const *char filename) {
a = x;
b = y;
image = load_image(filename);
}
void display() {
//blit image
}
void move(int a, int b) {
if (a < WIDTH && b < HEIGHT) {
a = x;
b = y;
}
}
void change_image(const *char filename) {
image = load_image(filename);
}
};
###############
# Python class
###############
class game_object:
def __init__(self, a, b, filename):
self.x = a
self.y = b
self.image = load_image(filename)
def display():
#blit image
def move(a, b):
if a < WIDTH and b < HEIGHT:
self.x = a
self.y = b
def change_image(filename):
image = load_image(filename)
- /***************
- * C++ class
- ***************/
- class game_object {
- int x, y;
- SDL_Surface* image;
- public:
- game_object(int a, int b, const *char filename) {
- a = x;
- b = y;
- image = load_image(filename);
- }
- void display() {
- //blit image
- }
- void move(int a, int b) {
- if (a < WIDTH && b < HEIGHT) {
- a = x;
- b = y;
- }
- }
- void change_image(const *char filename) {
- image = load_image(filename);
- }
- };
- ###############
- # Python class
- ###############
- class game_object:
- def __init__(self, a, b, filename):
- self.x = a
- self.y = b
- self.image = load_image(filename)
- def display():
- #blit image
- def move(a, b):
- if a < WIDTH and b < HEIGHT:
- self.x = a
- self.y = b
- def change_image(filename):
- image = load_image(filename)