- Timestamp:
- Nov 24, 2012, 2:55:59 PM (12 years ago)
- Branches:
- master
- Children:
- 9a3e6b1
- Parents:
- 94ebbd9
- Location:
- client
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Client.vcxproj
r94ebbd9 rd352805 42 42 <WarningLevel>Level3</WarningLevel> 43 43 <Optimization>Disabled</Optimization> 44 <AdditionalIncludeDirectories> C:\Program Files\boost\boost_1_51;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>44 <AdditionalIncludeDirectories>c:\allegro\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> 45 45 </ClCompile> 46 46 <Link> 47 47 <GenerateDebugInformation>true</GenerateDebugInformation> 48 <AdditionalLibraryDirectories>c:\allegro\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> 49 <AdditionalDependencies>allegro-5.0.7-monolith-md-debug.lib;%(AdditionalDependencies)</AdditionalDependencies> 48 50 </Link> 49 51 </ItemDefinitionGroup> -
client/Client/Client.vcxproj.user
r94ebbd9 rd352805 4 4 <LocalDebuggerCommandArguments>medievaltech.com 10000</LocalDebuggerCommandArguments> 5 5 <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> 6 <LocalDebuggerEnvironment>PATH=c:\allegro\bin;%PATH%</LocalDebuggerEnvironment> 6 7 </PropertyGroup> 7 8 </Project> -
client/Client/main.cpp
r94ebbd9 rd352805 1 1 #include "../../common/compiler.h" 2 3 #include <sys/types.h>4 2 5 3 #if defined WINDOWS … … 15 13 #endif 16 14 15 #include <sys/types.h> 17 16 #include <stdio.h> 18 17 #include <stdlib.h> 19 18 #include <string> 20 21 19 #include <iostream> 22 20 23 #include <boost/lambda/lambda.hpp> 21 #include <allegro5/allegro.h> 22 #include <allegro5/allegro_font.h> 23 #include <allegro5/allegro_ttf.h> 24 24 25 25 #include "../../common/message.h" … … 35 35 void error(const char *); 36 36 37 const float FPS = 60; 38 const int SCREEN_W = 640; 39 const int SCREEN_H = 480; 40 const int BOUNCER_SIZE = 32; 41 enum MYKEYS { 42 KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT 43 }; 44 45 int main(int argc, char **argv) 46 { 47 ALLEGRO_DISPLAY *display = NULL; 48 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 49 ALLEGRO_TIMER *timer = NULL; 50 ALLEGRO_BITMAP *bouncer = NULL; 51 float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0; 52 float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0; 53 bool key[4] = { false, false, false, false }; 54 bool redraw = true; 55 bool doexit = false; 56 57 if(!al_init()) { 58 fprintf(stderr, "failed to initialize allegro!\n"); 59 return -1; 60 } 61 62 al_init_font_addon(); 63 al_init_ttf_addon(); 64 65 ALLEGRO_FONT *font = al_load_ttf_font("../pirulen.ttf", 12, 0); 66 67 if (!font) { 68 fprintf(stderr, "Could not load 'pirulen.ttf'.\n"); 69 getchar(); 70 return -1; 71 } 72 73 if(!al_install_keyboard()) { 74 fprintf(stderr, "failed to initialize the keyboard!\n"); 75 return -1; 76 } 77 78 timer = al_create_timer(1.0 / FPS); 79 if(!timer) { 80 fprintf(stderr, "failed to create timer!\n"); 81 return -1; 82 } 83 84 display = al_create_display(SCREEN_W, SCREEN_H); 85 if(!display) { 86 fprintf(stderr, "failed to create display!\n"); 87 al_destroy_timer(timer); 88 return -1; 89 } 90 91 bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); 92 if(!bouncer) { 93 fprintf(stderr, "failed to create bouncer bitmap!\n"); 94 al_destroy_display(display); 95 al_destroy_timer(timer); 96 return -1; 97 } 98 99 event_queue = al_create_event_queue(); 100 if(!event_queue) { 101 fprintf(stderr, "failed to create event_queue!\n"); 102 al_destroy_bitmap(bouncer); 103 al_destroy_display(display); 104 al_destroy_timer(timer); 105 return -1; 106 } 107 108 al_set_target_bitmap(bouncer); 109 110 al_clear_to_color(al_map_rgb(255, 0, 255)); 111 112 al_set_target_bitmap(al_get_backbuffer(display)); 113 114 al_register_event_source(event_queue, al_get_display_event_source(display)); 115 116 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 117 118 al_register_event_source(event_queue, al_get_keyboard_event_source()); 119 120 al_clear_to_color(al_map_rgb(0,0,0)); 121 122 al_flip_display(); 123 124 al_start_timer(timer); 125 126 while(!doexit) 127 { 128 ALLEGRO_EVENT ev; 129 al_wait_for_event(event_queue, &ev); 130 131 if(ev.type == ALLEGRO_EVENT_TIMER) { 132 if(key[KEY_UP] && bouncer_y >= 4.0) { 133 bouncer_y -= 4.0; 134 } 135 136 if(key[KEY_DOWN] && bouncer_y <= SCREEN_H - BOUNCER_SIZE - 4.0) { 137 bouncer_y += 4.0; 138 } 139 140 if(key[KEY_LEFT] && bouncer_x >= 4.0) { 141 bouncer_x -= 4.0; 142 } 143 144 if(key[KEY_RIGHT] && bouncer_x <= SCREEN_W - BOUNCER_SIZE - 4.0) { 145 bouncer_x += 4.0; 146 } 147 148 redraw = true; 149 } 150 else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 151 break; 152 } 153 else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { 154 switch(ev.keyboard.keycode) { 155 case ALLEGRO_KEY_UP: 156 key[KEY_UP] = true; 157 break; 158 159 case ALLEGRO_KEY_DOWN: 160 key[KEY_DOWN] = true; 161 break; 162 163 case ALLEGRO_KEY_LEFT: 164 key[KEY_LEFT] = true; 165 break; 166 167 case ALLEGRO_KEY_RIGHT: 168 key[KEY_RIGHT] = true; 169 break; 170 } 171 } 172 else if(ev.type == ALLEGRO_EVENT_KEY_UP) { 173 switch(ev.keyboard.keycode) { 174 case ALLEGRO_KEY_UP: 175 key[KEY_UP] = false; 176 break; 177 178 case ALLEGRO_KEY_DOWN: 179 key[KEY_DOWN] = false; 180 break; 181 182 case ALLEGRO_KEY_LEFT: 183 key[KEY_LEFT] = false; 184 break; 185 186 case ALLEGRO_KEY_RIGHT: 187 key[KEY_RIGHT] = false; 188 break; 189 190 case ALLEGRO_KEY_ESCAPE: 191 doexit = true; 192 break; 193 } 194 } 195 196 if(redraw && al_is_event_queue_empty(event_queue)) { 197 redraw = false; 198 199 al_clear_to_color(al_map_rgb(0,0,0)); 200 201 al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0); 202 al_draw_text(font, al_map_rgb(255,255,255), 10, 10, ALLEGRO_ALIGN_LEFT, "Your Text Here!"); 203 204 al_flip_display(); 205 } 206 } 207 208 al_destroy_event_queue(event_queue); 209 al_destroy_bitmap(bouncer); 210 al_destroy_display(display); 211 al_destroy_timer(timer); 212 213 return 0; 214 } 215 216 /* 37 217 int main(int argc, char *argv[]) 38 218 { … … 105 285 return 0; 106 286 } 287 */ 107 288 108 289 void initWinSock()
Note:
See TracChangeset
for help on using the changeset viewer.