| 106 asc_scene_add_node(MAIN_SCENE, sprite); |
106 asc_scene_add_node(MAIN_SCENE, sprite); |
| 107 |
107 |
| 108 // TODO: return something |
108 // TODO: return something |
| 109 } |
109 } |
| 110 |
110 |
| |
111 static asc_recti update_viewport_for_window_resize(asc_vec2i window_size) { |
| |
112 // Compute scaling and offsets |
| |
113 int viewport_size, offset_x = 0, offset_y = 0; |
| |
114 if (window_size.width > window_size.height) { |
| |
115 // Wider window: letterbox (black bars on top/bottom) |
| |
116 offset_x = (window_size.width - window_size.height) / 2; |
| |
117 viewport_size = window_size.height; |
| |
118 } else { |
| |
119 // Taller window: pillarbox (black bars on sides) |
| |
120 offset_y = (window_size.height - window_size.width) / 2; |
| |
121 viewport_size = window_size.width; |
| |
122 } |
| |
123 |
| |
124 // Set the viewport to the scaled and centered region |
| |
125 return (asc_recti){ |
| |
126 offset_x, |
| |
127 offset_y, |
| |
128 viewport_size, |
| |
129 viewport_size |
| |
130 }; |
| |
131 } |
| |
132 |
| 111 int main(int argc, char** argv) { |
133 int main(int argc, char** argv) { |
| 112 asc_context_initialize(); |
134 asc_context_initialize(); |
| 113 if (asc_has_error()) { |
135 if (asc_has_error()) { |
| 114 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, |
136 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, |
| 115 "Fatal Error",asc_get_error(), NULL); |
137 "Fatal Error",asc_get_error(), NULL); |
| 127 settings.title = "Snake"; |
149 settings.title = "Snake"; |
| 128 asc_window_initialize(0, &settings); |
150 asc_window_initialize(0, &settings); |
| 129 |
151 |
| 130 // initialize the main scene (a 500x500 game field) |
152 // initialize the main scene (a 500x500 game field) |
| 131 asc_scene_init(MAIN_SCENE); |
153 asc_scene_init(MAIN_SCENE); |
| 132 // TODO: this is intentionally bullshit at the moment to force me to care about aspect ratio |
|
| 133 asc_camera_ortho(&MAIN_SCENE->camera, (asc_recti){0, 0, 500, 500}); |
154 asc_camera_ortho(&MAIN_SCENE->camera, (asc_recti){0, 0, 500, 500}); |
| |
155 MAIN_SCENE->camera.viewport_update_func = update_viewport_for_window_resize; |
| 134 |
156 |
| 135 // load textures |
157 // load textures |
| 136 init_textures(); |
158 init_textures(); |
| 137 |
159 |
| 138 // create UI elements |
160 // create UI elements |