126 )); |
126 )); |
127 } |
127 } |
128 } |
128 } |
129 |
129 |
130 static void create_fps_counter(void) { |
130 static void create_fps_counter(void) { |
131 asc_font(ASC_FONT_REGULAR, 12); |
131 AscSceneNode *node = asc_text( |
132 asc_ink_rgb(255, 255, 255); |
132 .name = "FPS Counter", |
133 AscSceneNode *node = asc_text(.name = "FPS Counter"); |
133 .color = ASC_RGB(255, 255, 255), |
|
134 .font = asc_font(ASC_FONT_REGULAR, 12), |
|
135 ); |
134 asc_behavior_add(node, .func = update_fps_counter, .interval = asc_seconds(1)); |
136 asc_behavior_add(node, .func = update_fps_counter, .interval = asc_seconds(1)); |
135 asc_behavior_add(node, tie_fps_counter_to_corner); |
137 asc_behavior_add(node, tie_fps_counter_to_corner); |
136 asc_ui_add_node(node); |
138 asc_ui_add_node(node); |
137 } |
139 } |
138 |
140 |
139 static void create_score_counter(void) { |
141 static void create_score_counter(void) { |
140 asc_font(ASC_FONT_BOLD, 16); |
|
141 asc_ink_rgb(0, 255, 0); |
|
142 AscSceneNode *node = asc_text( |
142 AscSceneNode *node = asc_text( |
143 .name = "Score Counter", |
143 .name = "Score Counter", |
144 .x = 10, .y = 10, |
144 .x = 10, .y = 10, |
145 .text = "Score: 0" |
145 .text = "Score: 0", |
|
146 .color = ASC_RGB(0, 255, 0), |
|
147 .font = asc_font(ASC_FONT_BOLD, 16), |
146 ); |
148 ); |
147 asc_ui_add_node(node); |
149 asc_ui_add_node(node); |
148 } |
150 } |
149 |
151 |
150 static void move_spaceship(AscBehavior *behavior) { |
152 static void move_spaceship(AscBehavior *behavior) { |
178 static void create_gamefield() { |
180 static void create_gamefield() { |
179 // TODO: create a proper data structure and a more interesting map than just a basic grid |
181 // TODO: create a proper data structure and a more interesting map than just a basic grid |
180 AscSceneNode *gamefield = asc_scene_node_empty(); |
182 AscSceneNode *gamefield = asc_scene_node_empty(); |
181 for (unsigned x = 0; x < game_field_size; x+=game_field_tile_size) { |
183 for (unsigned x = 0; x < game_field_size; x+=game_field_tile_size) { |
182 for (unsigned y = 0; y < game_field_size; y+=game_field_tile_size) { |
184 for (unsigned y = 0; y < game_field_size; y+=game_field_tile_size) { |
183 asc_ink_rgb(0, 128, 255); |
|
184 AscSceneNode *tile = asc_rectangle( |
185 AscSceneNode *tile = asc_rectangle( |
185 .x = x, .y = y, .filled = true, .thickness = 1, |
186 .x = x, .y = y, .filled = true, .thickness = 1, |
186 .width = game_field_tile_size, .height = game_field_tile_size, |
187 .width = game_field_tile_size, .height = game_field_tile_size, |
|
188 .color = ASC_RGB(0, 128, 255), |
187 .border_color = ASC_RGB(64, 196, 255), |
189 .border_color = ASC_RGB(64, 196, 255), |
188 ); |
190 ); |
189 asc_scene_node_link(gamefield, tile); |
191 asc_scene_node_link(gamefield, tile); |
190 } |
192 } |
191 } |
193 } |
240 // initialize the scenes |
242 // initialize the scenes |
241 asc_scene_init(BACKDROP_SCENE, |
243 asc_scene_init(BACKDROP_SCENE, |
242 .type = ASC_CAMERA_ORTHO, |
244 .type = ASC_CAMERA_ORTHO, |
243 .projection_update_func = asc_camera_ortho_update_size |
245 .projection_update_func = asc_camera_ortho_update_size |
244 ); |
246 ); |
245 asc_ink_rgb(0, 128, 90); |
|
246 asc_scene_init(MAIN_SCENE, |
247 asc_scene_init(MAIN_SCENE, |
247 .type = ASC_CAMERA_ORTHO, |
248 .type = ASC_CAMERA_ORTHO, |
248 .ortho.rect = ASC_RECT( |
249 .ortho.rect = ASC_RECT( |
249 -game_field_tile_size/2, |
250 -game_field_tile_size/2, |
250 -game_field_tile_size/2, |
251 -game_field_tile_size/2, |
251 game_field_size+game_field_tile_size, |
252 game_field_size+game_field_tile_size, |
252 game_field_size+game_field_tile_size |
253 game_field_size+game_field_tile_size |
253 ), |
254 ), |
254 .viewport_clear = true, |
255 .viewport_clear = true, |
|
256 .clear_color = ASC_RGB(0, 128, 90), |
255 .viewport_update_func = update_viewport_for_window_resize |
257 .viewport_update_func = update_viewport_for_window_resize |
256 ); |
258 ); |
257 |
259 |
258 // backdrop for letterbox/pillarbox |
260 // backdrop for letterbox/pillarbox |
259 create_backdrop(); |
261 create_backdrop(); |