943,999 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 557
  • C++ RSS
Nov 1st, 2009
0

Allegro res change program, crashes occasionally :P

Expand Post »
I don't know where you sould put resources on this website so i'll just post it here. Also, if anyone can find the reason this program crashes occasionally and reply back, i'd be greatful! Thanks in advance.
*Reminder: I'm not pro

This is a simple(?) program that allows the user to change the resolution of the program to 5 preset options.
640x480
800x600
1024x768
1280x960
1280x1024

C++ Syntax (Toggle Plain Text)
  1. //
  2. //made by Brent D. Corr
  3. //written in Dev-Cpp 4.9.9.2
  4. //uses the allegro 4.1.1.1 game programming library or whatever
  5. //
  6. #include <cstdlib>
  7. #include <cstdio>
  8. #include <iostream>
  9. #include <stdlib.h>
  10. #include <ctime>
  11. #include <conio.h>
  12. #include <fstream>
  13. #include <allegro.h>
  14. #include <time.h>
  15. using namespace std;
  16. BITMAP *buffer;
  17. BITMAP *defaultx;
  18. BITMAP *x800x600;
  19. BITMAP *x640x480;
  20. BITMAP *x1024x768;
  21. BITMAP *x1280x960;
  22. BITMAP *x1280x1024;
  23. int cursor_x = 20;
  24. int cursor_y = 20;
  25. int grpf;
  26.  
  27. void getMouseInfo(){
  28.  
  29. if(mouse_b & 1){
  30.  
  31. cursor_x = mouse_x;
  32. cursor_y = mouse_y;
  33.  
  34. }
  35.  
  36. }
  37. void updateScreen(){
  38. if (grpf == 1){
  39. draw_sprite( screen, x640x480, 0, 0);
  40. }
  41. else if (grpf == 0){
  42. draw_sprite( screen, defaultx, 0, 0);
  43. }
  44. else if (grpf == 2){
  45. draw_sprite ( screen, x800x600, 0, 0);
  46. }
  47. else if (grpf == 3){
  48. draw_sprite ( screen, x1024x768, 0, 0);
  49. }
  50. else if (grpf == 4){
  51. draw_sprite ( screen, x1280x960, 0, 0);
  52. }
  53. else if (grpf == 5){
  54. draw_sprite ( screen, x1280x1024, 0, 0);
  55. }
  56.  
  57. }
  58.  
  59. int main(){
  60. int grapic;
  61. allegro_init();
  62. install_mouse();
  63. install_keyboard();
  64. set_color_depth(16);
  65. int lol;
  66. lol = 1;
  67. set_gfx_mode( GFX_AUTODETECT, 800, 600, 0, 0);
  68.  
  69.  
  70. x640x480 = load_bitmap( "x640x480.bmp", NULL);
  71. x800x600 = load_bitmap( "x800x600.bmp", NULL);
  72. x1024x768 = load_bitmap( "x1024x768.bmp", NULL);
  73. x1280x960 = load_bitmap( "x1280x960.bmp", NULL);
  74. x1280x1024 = load_bitmap( "x1280x1024.bmp", NULL);
  75. defaultx = load_bitmap( "defaultx.bmp", NULL);
  76. start:
  77. acquire_screen();
  78. while( !key[KEY_ESC]){
  79. if (lol == 1){
  80. grpf = 0;
  81. lol = 0;
  82. }
  83. else {
  84. goto next;
  85. }
  86. next:
  87.  
  88. if( key[KEY_ESC]){
  89. goto end;
  90. }
  91. if (grpf == 0){
  92. show_mouse(defaultx);
  93. }
  94. else if (grpf ==1){
  95. show_mouse(x640x480);
  96. }
  97. else if (grpf == 2){
  98. show_mouse(x800x600);
  99. }
  100. else if (grpf == 3){
  101. show_mouse (x1024x768);
  102. }
  103. else if (grpf == 4) {
  104. show_mouse (x1280x960);
  105. }
  106. else if (grpf == 5) {
  107. show_mouse (x1280x1024);
  108. }
  109. getMouseInfo();
  110. updateScreen();
  111.  
  112.  
  113.  
  114. if(mouse_b & 1){
  115.  
  116. if ( mouse_x >= 1 && mouse_x <= 385 and mouse_y >= 317 && mouse_y <= 400 ){
  117. grapic = 1;
  118. goto fail;
  119. }
  120. else if ( mouse_x >= 1 && mouse_x <= 385 and mouse_y >= 401 && mouse_y <= 480 ) {
  121. grapic = 2;
  122. goto fail;
  123. }
  124. else if ( mouse_x >= 1 && mouse_x <= 385 and mouse_y >= 481 && mouse_y <= 578 ) {
  125. grapic = 3;
  126. goto fail;
  127. }
  128. else if ( mouse_x >= 386 && mouse_x <= 799 and mouse_y >= 331 && mouse_y <= 406 ) {
  129. grapic = 4;
  130. goto fail;
  131. }
  132. else if ( mouse_x >= 386 && mouse_x <= 799 and mouse_y >= 408 && mouse_y <= 496 ){
  133. grapic = 5;
  134. goto fail;
  135. }
  136. else {
  137. goto fail;
  138. }
  139. }
  140.  
  141. fail:
  142. if (grapic == 1){
  143. set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
  144. draw_sprite( screen, x640x480, 0, 0);
  145. grpf = 1;
  146. grapic = 20;
  147. goto start;
  148. }
  149. else if (grapic == 2){
  150. set_gfx_mode( GFX_AUTODETECT, 800, 600, 0, 0);
  151. draw_sprite( screen, x800x600, 0, 0);
  152. grpf = 2;
  153. grapic = 20;
  154. goto start;
  155. }
  156. else if (grapic == 3){
  157. set_gfx_mode( GFX_AUTODETECT, 1024, 768, 0, 0);
  158. draw_sprite( screen, x1024x768, 0, 0);
  159. grpf = 3;
  160. grapic = 20;
  161. goto start;
  162. }
  163. else if (grapic == 4){
  164. set_gfx_mode( GFX_AUTODETECT, 1280, 960, 0, 0);
  165. draw_sprite( screen, x1280x960, 0, 0);
  166. grpf = 4;
  167. grapic = 20;
  168. goto start;
  169. }
  170. else if (grapic == 5){
  171. set_gfx_mode( GFX_AUTODETECT, 1280, 1024, 0, 0);
  172. draw_sprite( screen, x1280x1024, 0, 0);
  173. grpf = 5;
  174. grapic = 20;
  175. goto start;
  176. }
  177. else{
  178. goto start;
  179. }
  180. goto start;
  181. }
  182.  
  183. end:
  184. readkey();
  185. return 0;
  186.  
  187. }
  188. END_OF_MAIN();
I know that there are some includes that are not needed and some code that serves no purpose, (was either trying to fix a problem, or trying to cover my program's ass)

*uses the allegro 4.1.1.1 game programming library
*This post includes all files needed for the program to work
*if anyone has a problem with this post contact a mod and they will deal with it
*all files are contained in a zip
*remember to actually have allegro installed if you want to use the code within the program
Attached Files
File Type: zip allegrodev.zip (233.8 KB, 18 views)
Reputation Points: 8
Solved Threads: 4
Junior Poster in Training
Shinedevil is offline Offline
71 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: About C++ game programming, engines, etc
Next Thread in C++ Forum Timeline: Dynamic Adding of Widgets in GTKMM





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC