test/snake/snake.c

changeset 88
6234b7ea48f3
parent 86
943bf9d7c6d6
child 89
e1f682a8a145
equal deleted inserted replaced
87:874a02a683c5 88:6234b7ea48f3
73 .text = "Score: 0" 73 .text = "Score: 0"
74 ); 74 );
75 asc_add_ui_node(node); 75 asc_add_ui_node(node);
76 } 76 }
77 77
78 static void free_spaceship(AscSceneNode *node) {
79 asc_texture_destroy(&((AscSprite*)node)->tex);
80 free(node);
81 }
82
83 static void create_spaceship(void) {
84 // TODO: textures should be passed by pointers (and probably ref-counted)
85 AscTexture texture;
86 asc_texture_init_2d(&texture);
87 asc_texture_from_file(&texture, "ship.png");
88 AscSceneNode *sprite = asc_sprite(
89 .texture = texture,
90 .x = 250,
91 .y = 300,
92 .width = 64,
93 .height = 64
94 );
95
96 // TODO: add to 2D scene instead of UI scene, once we have one
97 asc_add_ui_node(sprite);
98
99 // TODO: remove this hack by refactoring how textures work
100 sprite->free_func = free_spaceship;
101
102 // TODO: return something
103 }
104
78 int main(int argc, char** argv) { 105 int main(int argc, char** argv) {
79 asc_context_initialize(); 106 asc_context_initialize();
80 if (asc_has_error()) { 107 if (asc_has_error()) {
81 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, 108 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
82 "Fatal Error",asc_get_error(),NULL); 109 "Fatal Error",asc_get_error(),NULL);
98 125
99 // create UI elements 126 // create UI elements
100 create_fps_counter(); 127 create_fps_counter();
101 create_score_counter(); 128 create_score_counter();
102 129
130 // create spaceship
131 create_spaceship();
132
103 // Main Loop 133 // Main Loop
104 do { 134 do {
105 // quit application on any error 135 // quit application on any error
106 if (asc_has_error()) { 136 if (asc_has_error()) {
107 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, 137 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,

mercurial