Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit

  • Loading branch information...
commit 6ec3a1a7c0729b3a2a1f6015a3d1f37ae71c0908 0 parents
mave1337@gmail.com authored

Showing 657 changed files with 38,560 additions and 0 deletions. Show diff stats Hide diff stats

  1. +135 0 client/Ball.cpp
  2. +36 0 client/Ball.h
  3. +232 0 client/Game.cpp
  4. +53 0 client/Game.h
  5. +54 0 client/Graphics.cpp
  6. +25 0 client/Graphics.h
  7. +50 0 client/Keyboard.cpp
  8. +26 0 client/Keyboard.h
  9. +185 0 client/Network.cpp
  10. +44 0 client/Network.h
  11. +122 0 client/Platform.cpp
  12. +34 0 client/Platform.h
  13. +1 0  client/StdInc.cpp
  14. +13 0 client/StdInc.h
  15. +260 0 client/main.cpp
  16. +244 0 client/pongmp-client.vcproj
  17. +19 0 deps/allegro/include/allegro5/alcompat.h
  18. +32 0 deps/allegro/include/allegro5/alinline.h
  19. +74 0 deps/allegro/include/allegro5/allegro.h
  20. +2 0  deps/allegro/include/allegro5/allegro5.h
  21. +40 0 deps/allegro/include/allegro5/allegro_acodec.h
  22. +373 0 deps/allegro/include/allegro5/allegro_audio.h
  23. +68 0 deps/allegro/include/allegro5/allegro_color.h
  24. +49 0 deps/allegro/include/allegro5/allegro_direct3d.h
  25. +110 0 deps/allegro/include/allegro5/allegro_font.h
  26. +42 0 deps/allegro/include/allegro5/allegro_image.h
  27. +32 0 deps/allegro/include/allegro5/allegro_iphone.h
  28. +40 0 deps/allegro/include/allegro5/allegro_memfile.h
  29. +90 0 deps/allegro/include/allegro5/allegro_native_dialog.h
  30. +144 0 deps/allegro/include/allegro5/allegro_opengl.h
  31. +41 0 deps/allegro/include/allegro5/allegro_physfs.h
  32. +161 0 deps/allegro/include/allegro5/allegro_primitives.h
  33. +46 0 deps/allegro/include/allegro5/allegro_ttf.h
  34. +38 0 deps/allegro/include/allegro5/allegro_windows.h
  35. +30 0 deps/allegro/include/allegro5/altime.h
  36. +103 0 deps/allegro/include/allegro5/base.h
  37. +196 0 deps/allegro/include/allegro5/bitmap.h
  38. +31 0 deps/allegro/include/allegro5/bitmap_io.h
  39. +23 0 deps/allegro/include/allegro5/color.h
  40. +45 0 deps/allegro/include/allegro5/config.h
  41. +77 0 deps/allegro/include/allegro5/debug.h
  42. +184 0 deps/allegro/include/allegro5/display.h
  43. +39 0 deps/allegro/include/allegro5/error.h
  44. +241 0 deps/allegro/include/allegro5/events.h
  45. +99 0 deps/allegro/include/allegro5/file.h
  46. +41 0 deps/allegro/include/allegro5/fixed.h
  47. +46 0 deps/allegro/include/allegro5/fmaths.h
  48. +130 0 deps/allegro/include/allegro5/fshook.h
  49. +258 0 deps/allegro/include/allegro5/inline/fmaths.inl
  50. +62 0 deps/allegro/include/allegro5/internal/aintern.h
  51. +23 0 deps/allegro/include/allegro5/internal/aintern_aatree.h
  52. +9 0 deps/allegro/include/allegro5/internal/aintern_acodec_cfg.h
  53. +120 0 deps/allegro/include/allegro5/internal/aintern_atomicops.h
  54. +319 0 deps/allegro/include/allegro5/internal/aintern_audio.h
  55. +6 0 deps/allegro/include/allegro5/internal/aintern_audio_cfg.h
  56. +155 0 deps/allegro/include/allegro5/internal/aintern_bitmap.h
  57. +110 0 deps/allegro/include/allegro5/internal/aintern_blend.h
  58. +29 0 deps/allegro/include/allegro5/internal/aintern_config.h
  59. +1,523 0 deps/allegro/include/allegro5/internal/aintern_convert.h
  60. +18 0 deps/allegro/include/allegro5/internal/aintern_direct3d.h
  61. +151 0 deps/allegro/include/allegro5/internal/aintern_display.h
  62. +31 0 deps/allegro/include/allegro5/internal/aintern_dtor.h
  63. +48 0 deps/allegro/include/allegro5/internal/aintern_events.h
  64. +27 0 deps/allegro/include/allegro5/internal/aintern_file.h
  65. +16 0 deps/allegro/include/allegro5/internal/aintern_float.h
  66. +33 0 deps/allegro/include/allegro5/internal/aintern_fshook.h
  67. +51 0 deps/allegro/include/allegro5/internal/aintern_gp2xwiz.h
  68. +73 0 deps/allegro/include/allegro5/internal/aintern_image.h
  69. +11 0 deps/allegro/include/allegro5/internal/aintern_image_cfg.h
  70. +42 0 deps/allegro/include/allegro5/internal/aintern_iphone.h
  71. +89 0 deps/allegro/include/allegro5/internal/aintern_joystick.h
  72. +62 0 deps/allegro/include/allegro5/internal/aintern_keyboard.h
  73. +75 0 deps/allegro/include/allegro5/internal/aintern_list.h
  74. +43 0 deps/allegro/include/allegro5/internal/aintern_mouse.h
  75. +51 0 deps/allegro/include/allegro5/internal/aintern_native_dialog.h
  76. +3 0  deps/allegro/include/allegro5/internal/aintern_native_dialog_cfg.h
  77. +140 0 deps/allegro/include/allegro5/internal/aintern_opengl.h
  78. +14 0 deps/allegro/include/allegro5/internal/aintern_path.h
  79. +460 0 deps/allegro/include/allegro5/internal/aintern_pixels.h
  80. +13 0 deps/allegro/include/allegro5/internal/aintern_prim.h
  81. +21 0 deps/allegro/include/allegro5/internal/aintern_prim_directx.h
  82. +10 0 deps/allegro/include/allegro5/internal/aintern_prim_opengl.h
  83. +13 0 deps/allegro/include/allegro5/internal/aintern_prim_soft.h
  84. +58 0 deps/allegro/include/allegro5/internal/aintern_system.h
  85. +52 0 deps/allegro/include/allegro5/internal/aintern_thread.h
  86. +16 0 deps/allegro/include/allegro5/internal/aintern_timer.h
  87. +24 0 deps/allegro/include/allegro5/internal/aintern_tls.h
  88. +27 0 deps/allegro/include/allegro5/internal/aintern_tri_soft.h
  89. +1 0  deps/allegro/include/allegro5/internal/aintern_ttf_cfg.h
  90. +55 0 deps/allegro/include/allegro5/internal/aintern_vector.h
  91. +235 0 deps/allegro/include/allegro5/internal/aintern_xglx.h
  92. +347 0 deps/allegro/include/allegro5/internal/alconfig.h
  93. +309 0 deps/allegro/include/allegro5/internal/bstrlib.h
  94. +90 0 deps/allegro/include/allegro5/joystick.h
  95. +71 0 deps/allegro/include/allegro5/keyboard.h
  96. +189 0 deps/allegro/include/allegro5/keycodes.h
  97. +73 0 deps/allegro/include/allegro5/memory.h
  98. +128 0 deps/allegro/include/allegro5/mouse.h
  99. +2,564 0 deps/allegro/include/allegro5/opengl/GLext/gl_ext_alias.h
  100. +2,563 0 deps/allegro/include/allegro5/opengl/GLext/gl_ext_api.h
  101. +5,108 0 deps/allegro/include/allegro5/opengl/GLext/gl_ext_defs.h
  102. +358 0 deps/allegro/include/allegro5/opengl/GLext/gl_ext_list.h
  103. +213 0 deps/allegro/include/allegro5/opengl/GLext/glx_ext_alias.h
  104. +212 0 deps/allegro/include/allegro5/opengl/GLext/glx_ext_api.h
  105. +505 0 deps/allegro/include/allegro5/opengl/GLext/glx_ext_defs.h
  106. +40 0 deps/allegro/include/allegro5/opengl/GLext/glx_ext_list.h
  107. +168 0 deps/allegro/include/allegro5/opengl/GLext/wgl_ext_alias.h
  108. +167 0 deps/allegro/include/allegro5/opengl/GLext/wgl_ext_api.h
  109. +386 0 deps/allegro/include/allegro5/opengl/GLext/wgl_ext_defs.h
  110. +38 0 deps/allegro/include/allegro5/opengl/GLext/wgl_ext_list.h
  111. +140 0 deps/allegro/include/allegro5/opengl/gl_ext.h
  112. +56 0 deps/allegro/include/allegro5/path.h
  113. +15 0 deps/allegro/include/allegro5/platform/aintiphone.h
  114. +174 0 deps/allegro/include/allegro5/platform/aintlnx.h
  115. +160 0 deps/allegro/include/allegro5/platform/aintosx.h
  116. +94 0 deps/allegro/include/allegro5/platform/aintunix.h
  117. +101 0 deps/allegro/include/allegro5/platform/aintuthr.h
  118. +208 0 deps/allegro/include/allegro5/platform/aintwin.h
  119. +16 0 deps/allegro/include/allegro5/platform/aintwiz.h
  120. +75 0 deps/allegro/include/allegro5/platform/aintwthr.h
  121. +10 0 deps/allegro/include/allegro5/platform/aintxglx.h
  122. +422 0 deps/allegro/include/allegro5/platform/al386gcc.h
  123. +269 0 deps/allegro/include/allegro5/platform/al386vc.h
  124. +241 0 deps/allegro/include/allegro5/platform/al386wat.h
  125. +100 0 deps/allegro/include/allegro5/platform/albcc32.h
  126. +91 0 deps/allegro/include/allegro5/platform/aldmc.h
  127. +11 0 deps/allegro/include/allegro5/platform/aliphone.h
  128. +35 0 deps/allegro/include/allegro5/platform/aliphonecfg.h
  129. +91 0 deps/allegro/include/allegro5/platform/almngw32.h
  130. +114 0 deps/allegro/include/allegro5/platform/almsvc.h
  131. +77 0 deps/allegro/include/allegro5/platform/alosx.h
  132. +39 0 deps/allegro/include/allegro5/platform/alosxcfg.h
  133. +183 0 deps/allegro/include/allegro5/platform/alplatf.h
  134. +55 0 deps/allegro/include/allegro5/platform/alucfg.h
  135. +23 0 deps/allegro/include/allegro5/platform/alunix.h
  136. +190 0 deps/allegro/include/allegro5/platform/alwatcom.h
  137. +58 0 deps/allegro/include/allegro5/platform/alwin.h
  138. +32 0 deps/allegro/include/allegro5/platform/alwiz.h
  139. +43 0 deps/allegro/include/allegro5/platform/alwizcfg.h
  140. +35 0 deps/allegro/include/allegro5/platform/astdbool.h
  141. +75 0 deps/allegro/include/allegro5/platform/astdint.h
  142. +49 0 deps/allegro/include/allegro5/system.h
  143. +67 0 deps/allegro/include/allegro5/threads.h
  144. +65 0 deps/allegro/include/allegro5/timer.h
  145. +65 0 deps/allegro/include/allegro5/tls.h
  146. +34 0 deps/allegro/include/allegro5/transformations.h
  147. +150 0 deps/allegro/include/allegro5/utf8.h
  148. +2,403 0 deps/allegro/include/physfs.h
  149. BIN  deps/allegro/lib/allegro-5.0.4-monolith-static-mt.lib
  150. BIN  deps/allegro/lib/allegro-5.0.4-static-mt.lib
  151. BIN  deps/allegro/lib/allegro_acodec-5.0.4-static-mt.lib
  152. BIN  deps/allegro/lib/allegro_audio-5.0.4-static-mt.lib
  153. BIN  deps/allegro/lib/allegro_color-5.0.4-static-mt.lib
  154. BIN  deps/allegro/lib/allegro_dialog-5.0.4-static-mt.lib
  155. BIN  deps/allegro/lib/allegro_font-5.0.4-static-mt.lib
  156. BIN  deps/allegro/lib/allegro_image-5.0.4-static-mt.lib
  157. BIN  deps/allegro/lib/allegro_memfile-5.0.4-static-mt.lib
  158. BIN  deps/allegro/lib/allegro_physfs-5.0.4-static-mt.lib
  159. BIN  deps/allegro/lib/allegro_primitives-5.0.4-static-mt.lib
  160. BIN  deps/allegro/lib/allegro_ttf-5.0.4-static-mt.lib
  161. BIN  deps/allegro/lib/dumb-0.9.3-static-mt.lib
  162. BIN  deps/allegro/lib/freetype-2.4.4-static-mt.lib
  163. BIN  deps/allegro/lib/libFLAC-1.2.1-static-mt.lib
  164. BIN  deps/allegro/lib/libogg-1.2.1-static-mt.lib
  165. BIN  deps/allegro/lib/libvorbis-1.3.2-static-mt.lib
  166. BIN  deps/allegro/lib/libvorbisfile-1.3.2-static-mt.lib
  167. BIN  deps/allegro/lib/zlib-1.2.5-static-mt.lib
  168. BIN  deps/raknet/Lib/RakNetLibStatic.lib
  169. +23 0 deps/raknet/Source/AutopatcherPatchContext.h
  170. +72 0 deps/raknet/Source/AutopatcherRepositoryInterface.h
  171. +1,172 0 deps/raknet/Source/BitStream.cpp
  172. +2,032 0 deps/raknet/Source/BitStream.h
  173. +332 0 deps/raknet/Source/CCRakNetSlidingWindow.cpp
  174. +209 0 deps/raknet/Source/CCRakNetSlidingWindow.h
  175. +798 0 deps/raknet/Source/CCRakNetUDT.cpp
  176. +394 0 deps/raknet/Source/CCRakNetUDT.h
  177. +1 0  deps/raknet/Source/CMakeLists.txt
  178. +97 0 deps/raknet/Source/CheckSum.cpp
  179. +53 0 deps/raknet/Source/CheckSum.h
  180. +242 0 deps/raknet/Source/CloudClient.cpp
  181. +163 0 deps/raknet/Source/CloudClient.h
  182. +159 0 deps/raknet/Source/CloudCommon.cpp
  183. +141 0 deps/raknet/Source/CloudCommon.h
  184. +1,673 0 deps/raknet/Source/CloudServer.cpp
  185. +375 0 deps/raknet/Source/CloudServer.h
  186. +161 0 deps/raknet/Source/CommandParserInterface.cpp
  187. +140 0 deps/raknet/Source/CommandParserInterface.h
  188. +299 0 deps/raknet/Source/ConnectionGraph2.cpp
  189. +118 0 deps/raknet/Source/ConnectionGraph2.h
  190. +311 0 deps/raknet/Source/ConsoleServer.cpp
  191. +77 0 deps/raknet/Source/ConsoleServer.h
  192. +1,146 0 deps/raknet/Source/DS_BPlusTree.h
Sorry, we could not display the entire diff because too many files (657) changed.
135 client/Ball.cpp
... ... @@ -0,0 +1,135 @@
  1 +#include "StdInc.h"
  2 +#include "Ball.h"
  3 +#include <math.h>
  4 +
  5 +Ball::Ball()
  6 + : m_bInteraction(false), m_fAngle(0.0f), m_fVelX(0.0f), m_fVelY(0.0f)
  7 +{
  8 + m_fPosX = SCREEN_W / 2.0f - BALL_SIZE / 2.0f;
  9 + m_fPosY = SCREEN_H / 2.0f - BALL_SIZE / 2.0f;
  10 +}
  11 +
  12 +Ball::~Ball()
  13 +{
  14 +}
  15 +
  16 +bool Ball::initialize()
  17 +{
  18 + m_pBitmap = al_create_bitmap(BALL_SIZE, BALL_SIZE);
  19 + if (!m_pBitmap)
  20 + {
  21 + return false;
  22 + }
  23 +
  24 + al_set_target_bitmap(m_pBitmap);
  25 + al_clear_to_color(al_map_rgb(255, 255, 255));
  26 +
  27 + return true;
  28 +}
  29 +
  30 +void Ball::deinitialize()
  31 +{
  32 + al_destroy_bitmap(m_pBitmap);
  33 +}
  34 +
  35 +bool Ball::process()
  36 +{
  37 + bool bInteraction = m_bInteraction;
  38 + m_bInteraction = false;
  39 +
  40 + bool bRedraw = bInteraction;
  41 +
  42 + if (m_bInteraction)
  43 + {
  44 + /*if (m_fVelocity > 10.0f)
  45 + {
  46 + m_fVelocity = 10.0f;
  47 + }
  48 + else if (m_fVelocity < -10.0f)
  49 + {
  50 + m_fVelocity = -10.0f;
  51 + }*/
  52 + }
  53 + /*else
  54 + {
  55 + if (m_fVelocity < 0.0f)
  56 + {
  57 + bRedraw = true;
  58 + m_fVelocity += 0.15f;
  59 + if (m_fVelocity > 0.0f) m_fVelocity = 0.0f;
  60 + }
  61 + else if (m_fVelocity > 0.0f)
  62 + {
  63 + bRedraw = true;
  64 + m_fVelocity -= 0.15f;
  65 + if (m_fVelocity < 0.0f) m_fVelocity = 0.0f;
  66 + }
  67 + }*/
  68 +
  69 + m_fPosX += sin(m_fAngle * (3.1415926f / 180.0f)) * m_fVelX;
  70 + m_fPosY += cos(m_fAngle * (3.1415926f / 180.0f)) * m_fVelY;
  71 +
  72 + if (m_fPosX < 0.0f)
  73 + {
  74 + m_fPosX = 0.0f;
  75 + m_fVelX = -m_fVelX;
  76 + }
  77 + else if (m_fPosX > SCREEN_W - BALL_SIZE)
  78 + {
  79 + m_fPosX = SCREEN_W - BALL_SIZE;
  80 + m_fVelX = -m_fVelX;
  81 + }
  82 +
  83 + if (m_fPosY < 0.0f)
  84 + {
  85 + m_fPosY = 0.0f;
  86 + m_fVelY = -m_fVelY;
  87 + }
  88 + else if (m_fPosY > SCREEN_H - BALL_SIZE)
  89 + {
  90 + m_fPosY = SCREEN_H - BALL_SIZE;
  91 + m_fVelY = -m_fVelY;
  92 + }
  93 +
  94 + return bRedraw;
  95 +}
  96 +
  97 +void Ball::draw()
  98 +{
  99 + al_draw_bitmap(m_pBitmap, m_fPosX, m_fPosY, 0);
  100 +}
  101 +
  102 +void Ball::setAngle(float fAngle)
  103 +{
  104 + m_fAngle = fAngle;
  105 +}
  106 +
  107 +float Ball::getAngle()
  108 +{
  109 + return m_fAngle;
  110 +}
  111 +
  112 +void Ball::setVelocity(float fVelX, float fVelY)
  113 +{
  114 + m_fVelX = fVelX;
  115 + m_fVelY = fVelY;
  116 + m_bInteraction = true;
  117 +}
  118 +
  119 +void Ball::getVelocity(float &fVelX, float &fVelY)
  120 +{
  121 + fVelX = m_fVelX;
  122 + fVelY = m_fVelY;
  123 +}
  124 +
  125 +void Ball::getPosition(float &fPosX, float &fPosY)
  126 +{
  127 + fPosX = m_fPosX;
  128 + fPosY = m_fPosY;
  129 +}
  130 +
  131 +void Ball::setPosition(float fPosX, float fPosY)
  132 +{
  133 + m_fPosX = fPosX;
  134 + m_fPosY = fPosY;
  135 +}
36 client/Ball.h
... ... @@ -0,0 +1,36 @@
  1 +class Ball;
  2 +
  3 +#ifndef _BALL_H
  4 +#define _BALL_H
  5 +
  6 +class Ball
  7 +{
  8 +public:
  9 + Ball();
  10 + ~Ball();
  11 +
  12 + bool initialize();
  13 + void deinitialize();
  14 +
  15 + bool process();
  16 + void draw();
  17 +
  18 + void setAngle(float fAngle);
  19 + float getAngle();
  20 + void setVelocity(float fVelX, float fVelY);
  21 + void getVelocity(float &fVelX, float &fVelY);
  22 + void getPosition(float &fPosX, float &fPosY);
  23 + void setPosition(float fPosX, float fPosY);
  24 +
  25 +private:
  26 + float m_fPosX;
  27 + float m_fPosY;
  28 + float m_fAngle;
  29 + float m_fVelX;
  30 + float m_fVelY;
  31 + bool m_bInteraction;
  32 +
  33 + ALLEGRO_BITMAP *m_pBitmap;
  34 +};
  35 +
  36 +#endif
232 client/Game.cpp
... ... @@ -0,0 +1,232 @@
  1 +#include "StdInc.h"
  2 +#include "Game.h"
  3 +#include <stdio.h>
  4 +
  5 +Game::Game()
  6 + : m_bRunning(false)
  7 +{
  8 + m_pGraphics = new Graphics();
  9 + m_pKeyboard = new Keyboard();
  10 +
  11 + m_pPlatform[0] = new Platform(5);
  12 + m_pPlatform[1] = new Platform(SCREEN_W - PLATFORM_W - 5);
  13 + m_pBall = new Ball();
  14 +
  15 + m_pNetwork = new Network();
  16 +}
  17 +
  18 +Game::~Game()
  19 +{
  20 + delete m_pGraphics;
  21 + delete m_pKeyboard;
  22 +
  23 + delete m_pPlatform[0];
  24 + delete m_pPlatform[1];
  25 + delete m_pBall;
  26 +
  27 + delete m_pNetwork;
  28 +}
  29 +
  30 +bool Game::initialize()
  31 +{
  32 + m_pNetwork->initialize();
  33 +
  34 + m_pFrameTimer = al_create_timer(1.0 / FPS);
  35 + if (!m_pFrameTimer)
  36 + {
  37 + return false;
  38 + }
  39 +
  40 + m_pNetworkTimer = al_create_timer(0.06);
  41 + if (!m_pNetworkTimer)
  42 + {
  43 + return false;
  44 + }
  45 +
  46 + if (!m_pGraphics->initialize())
  47 + {
  48 + al_destroy_timer(m_pFrameTimer);
  49 + return false;
  50 + }
  51 +
  52 + if (!m_pPlatform[0]->initialize() || !m_pPlatform[1]->initialize() || !m_pBall->initialize())
  53 + {
  54 + al_destroy_timer(m_pFrameTimer);
  55 + return false;
  56 + }
  57 +
  58 + m_pEventQueue = al_create_event_queue();
  59 + if (!m_pEventQueue)
  60 + {
  61 + al_destroy_timer(m_pFrameTimer);
  62 + return false;
  63 + }
  64 +
  65 + al_register_event_source(m_pEventQueue, al_get_display_event_source(m_pGraphics->getDisplay()));
  66 + al_register_event_source(m_pEventQueue, al_get_timer_event_source(m_pFrameTimer));
  67 + al_register_event_source(m_pEventQueue, al_get_timer_event_source(m_pNetworkTimer));
  68 + al_register_event_source(m_pEventQueue, al_get_keyboard_event_source());
  69 +
  70 + al_set_target_bitmap(al_get_backbuffer(m_pGraphics->getDisplay()));
  71 + al_clear_to_color(al_map_rgb(0, 0, 0));
  72 +
  73 + al_flip_display();
  74 +
  75 + al_start_timer(m_pFrameTimer);
  76 + al_start_timer(m_pNetworkTimer);
  77 +
  78 + return true;
  79 +}
  80 +
  81 +void Game::run()
  82 +{
  83 + bool bRedraw = true;
  84 + bool bSendPlatform = true;
  85 +
  86 + m_pBall->setAngle(-45.0f);
  87 + m_pBall->setVelocity(3.2f, 3.2f);
  88 +
  89 + m_bRunning = true;
  90 + do
  91 + {
  92 + ALLEGRO_EVENT ev;
  93 + al_wait_for_event(m_pEventQueue, &ev);
  94 +
  95 + if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
  96 + {
  97 + m_bRunning = false;
  98 + break;
  99 + }
  100 + else if (ev.type == ALLEGRO_EVENT_TIMER && ev.timer.source == m_pNetworkTimer)
  101 + {
  102 + if (bSendPlatform)
  103 + {
  104 + bSendPlatform = false;
  105 + float fX, fY;
  106 + m_pPlatform[0]->getPosition(fX, fY);
  107 + m_pNetwork->updatePlatform(fY, m_pPlatform[0]->getVelocity());
  108 + }
  109 + }
  110 + else if (ev.type == ALLEGRO_EVENT_TIMER && ev.timer.source == m_pFrameTimer)
  111 + {
  112 + m_pNetwork->process();
  113 +
  114 + if (m_pGraphics->process()) bRedraw = true;
  115 +
  116 + if (m_pKeyboard->isKeyDown(Keyboard::UP))
  117 + {
  118 + m_pPlatform[0]->decelerate(0.60f);
  119 + }
  120 + else if (m_pKeyboard->isKeyDown(Keyboard::DOWN))
  121 + {
  122 + m_pPlatform[0]->accelerate(0.60f);
  123 + }
  124 +
  125 + // sync the platforms
  126 + //m_pPlatform[1]->setVelocity(m_pPlatform[0]->getVelocity());
  127 +
  128 + float fX, fY;
  129 + m_pPlatform[0]->getPosition(fX, fY);
  130 + float fX2, fY2;
  131 + m_pPlatform[1]->getPosition(fX2, fY2);
  132 +
  133 + float fBallX, fBallY;
  134 + m_pBall->getPosition(fBallX, fBallY);
  135 +
  136 +#if 0
  137 + if (fBallX < fX + PLATFORM_W)
  138 + {
  139 + if (fBallY + BALL_SIZE < fY || fBallY - BALL_SIZE > fY + PLATFORM_H)
  140 + {
  141 + MessageBoxA(NULL, "lose tbh", "", 0);
  142 + ExitProcess(0);
  143 + }
  144 + else
  145 + {
  146 + float fVelX, fVelY;
  147 + m_pBall->getVelocity(fVelX, fVelY);
  148 + m_pBall->setVelocity(-fVelX, fVelY);
  149 + }
  150 + }
  151 + if (fBallX + BALL_SIZE > fX2)
  152 + {
  153 + if (fBallY + BALL_SIZE < fY2 || fBallY - BALL_SIZE > fY2 + PLATFORM_H)
  154 + {
  155 + MessageBoxA(NULL, "lose tbh", "", 0);
  156 + ExitProcess(0);
  157 + }
  158 + else
  159 + {
  160 + float fVelX, fVelY;
  161 + m_pBall->getVelocity(fVelX, fVelY);
  162 + m_pBall->setVelocity(-fVelX, fVelY);
  163 + }
  164 + }
  165 +#endif
  166 +
  167 + if (m_pPlatform[0]->process())
  168 + {
  169 + bRedraw = true;
  170 + bSendPlatform = true;
  171 + }
  172 + if (m_pPlatform[1]->process()) bRedraw = true;
  173 + if (m_pBall->process()) bRedraw = true;
  174 + }
  175 + else if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
  176 + {
  177 + m_pKeyboard->handleKeyDown(ev.keyboard.keycode);
  178 + }
  179 + else if (ev.type == ALLEGRO_EVENT_KEY_UP)
  180 + {
  181 + m_pKeyboard->handleKeyUp(ev.keyboard.keycode);
  182 + }
  183 +
  184 + if (bRedraw && al_is_event_queue_empty(m_pEventQueue))
  185 + {
  186 + bRedraw = false;
  187 +
  188 + m_pGraphics->draw();
  189 + for (int i = 0; i < 2; ++i)
  190 + {
  191 + m_pPlatform[i]->draw();
  192 + }
  193 + m_pBall->draw();
  194 +
  195 + al_flip_display();
  196 + }
  197 + }
  198 + while (m_bRunning);
  199 +}
  200 +
  201 +void Game::deinitialize()
  202 +{
  203 + m_pNetwork->deinitialize();
  204 +
  205 + m_pGraphics->deinitialize();
  206 + m_pPlatform[0]->deinitialize();
  207 + m_pPlatform[1]->deinitialize();
  208 + m_pBall->deinitialize();
  209 +
  210 + al_destroy_timer(m_pFrameTimer);
  211 + al_destroy_event_queue(m_pEventQueue);
  212 +}
  213 +
  214 +Graphics *Game::getGraphics()
  215 +{
  216 + return m_pGraphics;
  217 +}
  218 +
  219 +Keyboard *Game::getKeyboard()
  220 +{
  221 + return m_pKeyboard;
  222 +}
  223 +
  224 +Platform *Game::getPlatform(int i)
  225 +{
  226 + return m_pPlatform[i];
  227 +}
  228 +
  229 +Network *Game::getNetwork()
  230 +{
  231 + return m_pNetwork;
  232 +}
53 client/Game.h
... ... @@ -0,0 +1,53 @@
  1 +class Game;
  2 +
  3 +#ifndef _GAME_H
  4 +#define _GAME_H
  5 +
  6 +#include <allegro5/allegro.h>
  7 +
  8 +#include <allegro5/allegro_font.h>
  9 +#include <allegro5/allegro_ttf.h>
  10 +
  11 +#include "Graphics.h"
  12 +#include "Keyboard.h"
  13 +#include "Platform.h"
  14 +#include "Ball.h"
  15 +#include "Network.h"
  16 +
  17 +const float FPS = 60.0f;
  18 +const int SCREEN_W = 640;
  19 +const int SCREEN_H = 480;
  20 +const int PLATFORM_W = 10;
  21 +const int PLATFORM_H = 50;
  22 +const int BALL_SIZE = 15;
  23 +
  24 +class Game
  25 +{
  26 +public:
  27 + Game();
  28 + ~Game();
  29 +
  30 + bool initialize();
  31 + void run();
  32 + void deinitialize();
  33 +
  34 + Graphics *getGraphics();
  35 + Keyboard *getKeyboard();
  36 + Platform *getPlatform(int i);
  37 + Network *getNetwork();
  38 +
  39 +private:
  40 + Graphics *m_pGraphics;
  41 + Keyboard *m_pKeyboard;
  42 + Platform *m_pPlatform[2];
  43 + Ball *m_pBall;
  44 + Network *m_pNetwork;
  45 +
  46 + ALLEGRO_EVENT_QUEUE *m_pEventQueue;
  47 + ALLEGRO_TIMER *m_pFrameTimer;
  48 + ALLEGRO_TIMER *m_pNetworkTimer;
  49 +
  50 + bool m_bRunning;
  51 +};
  52 +
  53 +#endif
54 client/Graphics.cpp
... ... @@ -0,0 +1,54 @@
  1 +#include "StdInc.h"
  2 +#include "Graphics.h"
  3 +
  4 +Graphics::Graphics()
  5 +{
  6 +}
  7 +
  8 +Graphics::~Graphics()
  9 +{
  10 +}
  11 +
  12 +bool Graphics::initialize()
  13 +{
  14 + m_pDisplay = al_create_display(SCREEN_W, SCREEN_H);
  15 + if (!m_pDisplay)
  16 + {
  17 + return false;
  18 + }
  19 +
  20 + /*m_pDefaultFont = al_load_ttf_font("miscfs.ttf", 72, 0);
  21 + if (!m_pDefaultFont)
  22 + {
  23 + return false;
  24 + }*/
  25 +
  26 + return true;
  27 +}
  28 +
  29 +void Graphics::deinitialize()
  30 +{
  31 + //al_destroy_font(m_pDefaultFont);
  32 + al_destroy_display(m_pDisplay);
  33 +}
  34 +
  35 +bool Graphics::process()
  36 +{
  37 + return true;
  38 +}
  39 +
  40 +void Graphics::draw()
  41 +{
  42 + al_set_target_bitmap(al_get_backbuffer(m_pDisplay));
  43 + al_clear_to_color(al_map_rgb(0, 0, 0));
  44 +
  45 + g_pGame->getPlatform(0)->draw();
  46 + g_pGame->getPlatform(1)->draw();
  47 +
  48 + //al_draw_text(m_pDefaultFont, al_map_rgb(255, 255, 255), (SCREEN_W)/2, (SCREEN_H)/4, ALLEGRO_ALIGN_CENTRE, "hello world");
  49 +}
  50 +
  51 +ALLEGRO_DISPLAY *Graphics::getDisplay()
  52 +{
  53 + return m_pDisplay;
  54 +}
25 client/Graphics.h
... ... @@ -0,0 +1,25 @@
  1 +class Graphics;
  2 +
  3 +#ifndef _GRAPHICS_H
  4 +#define _GRAPHICS_H
  5 +
  6 +class Graphics
  7 +{
  8 +public:
  9 + Graphics();
  10 + ~Graphics();
  11 +
  12 + bool initialize();
  13 + void deinitialize();
  14 +
  15 + bool process();
  16 + void draw();
  17 +
  18 + ALLEGRO_DISPLAY *getDisplay();
  19 +
  20 +private:
  21 + ALLEGRO_DISPLAY *m_pDisplay;
  22 + ALLEGRO_FONT *m_pDefaultFont;
  23 +};
  24 +
  25 +#endif
50 client/Keyboard.cpp
... ... @@ -0,0 +1,50 @@
  1 +#include <allegro5/allegro.h>
  2 +#include "StdInc.h"
  3 +#include "Keyboard.h"
  4 +
  5 +Keyboard::Keyboard()
  6 +{
  7 + memset(m_bKeyState, 0, sizeof(bool) * NUMKEYS);
  8 +}
  9 +
  10 +Keyboard::~Keyboard()
  11 +{
  12 +}
  13 +
  14 +void Keyboard::handleKeyDown(int iKeyCode)
  15 +{
  16 + switch (iKeyCode)
  17 + {
  18 + case ALLEGRO_KEY_UP:
  19 + m_bKeyState[UP] = true;
  20 + break;
  21 +
  22 + case ALLEGRO_KEY_DOWN:
  23 + m_bKeyState[DOWN] = true;
  24 + break;
  25 + }
  26 +}
  27 +
  28 +void Keyboard::handleKeyUp(int iKeyCode)
  29 +{
  30 + switch (iKeyCode)
  31 + {
  32 + case ALLEGRO_KEY_UP:
  33 + m_bKeyState[UP] = false;
  34 + break;
  35 +
  36 + case ALLEGRO_KEY_DOWN:
  37 + m_bKeyState[DOWN] = false;
  38 + break;
  39 + }
  40 +}
  41 +
  42 +bool Keyboard::isKeyDown(int iKey)
  43 +{
  44 + if (iKey < 0 || iKey >= NUMKEYS)
  45 + {
  46 + return false;
  47 + }
  48 +
  49 + return m_bKeyState[iKey];
  50 +}
26 client/Keyboard.h
... ... @@ -0,0 +1,26 @@
  1 +class Keyboard;
  2 +
  3 +#ifndef _KEYBOARD_H
  4 +#define _KEYBOARD_H
  5 +
  6 +class Keyboard
  7 +{
  8 +public:
  9 + Keyboard();
  10 + ~Keyboard();
  11 +
  12 + enum
  13 + {
  14 + UP, DOWN,
  15 + NUMKEYS
  16 + };
  17 +
  18 + void handleKeyDown(int iKeyCode);
  19 + void handleKeyUp(int iKeyCode);
  20 + bool isKeyDown(int iKey);
  21 +
  22 +private:
  23 + bool m_bKeyState[NUMKEYS];
  24 +};
  25 +
  26 +#endif
185 client/Network.cpp
... ... @@ -0,0 +1,185 @@
  1 +#include "StdInc.h"
  2 +#include "Network.h"
  3 +#include <stdio.h>
  4 +#include <BitStream.h>
  5 +#include <RakNetTypes.h>
  6 +
  7 +Network::Network()
  8 +{
  9 +}
  10 +
  11 +Network::~Network()
  12 +{
  13 +}
  14 +
  15 +bool Network::initialize()
  16 +{
  17 + m_qwInitTime = GetTickCount64();
  18 +
  19 + m_pPeer = RakNet::RakPeerInterface::GetInstance();
  20 + if (!m_pPeer)
  21 + {
  22 + return false;
  23 + }
  24 +
  25 + m_pPeer->Startup(1, &RakNet::SocketDescriptor(), 1);
  26 +
  27 + m_pPeer->Connect("localhost", 45000, NULL, 0);
  28 +
  29 + return true;
  30 +}
  31 +
  32 +void Network::deinitialize()
  33 +{
  34 + RakNet::RakPeerInterface::DestroyInstance(m_pPeer);
  35 +}
  36 +
  37 +void Network::process()
  38 +{
  39 + for (RakNet::Packet *pPacket = m_pPeer->Receive(); pPacket; m_pPeer->DeallocatePacket(pPacket), pPacket = m_pPeer->Receive())
  40 + {
  41 + switch (pPacket->data[0])
  42 + {
  43 + case ID_REMOTE_DISCONNECTION_NOTIFICATION:
  44 + printf("Another client has disconnected.\n");
  45 + break;
  46 + case ID_REMOTE_CONNECTION_LOST:
  47 + printf("Another client has lost the connection.\n");
  48 + break;
  49 + case ID_REMOTE_NEW_INCOMING_CONNECTION:
  50 + printf("Another client has connected.\n");
  51 + break;
  52 + case ID_CONNECTION_REQUEST_ACCEPTED:
  53 + {
  54 + printf("Our connection request has been accepted.\n");
  55 +
  56 + // Use a BitStream to write a custom user message
  57 + // Bitstreams are easier to use than sending casted structures, and handle endian swapping automatically
  58 + RakNet::BitStream bsOut;
  59 + bsOut.Write((RakNet::MessageID)ID_INIT);
  60 +
  61 + Platform *p = g_pGame->getPlatform(1);
  62 + float fX, fY;
  63 + p->getPosition(fX, fY);
  64 + bsOut.Write(fY);
  65 + bsOut.Write(p->getVelocity());
  66 +
  67 + m_pPeer->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, pPacket->systemAddress, false);
  68 + }
  69 + break;
  70 + case ID_NO_FREE_INCOMING_CONNECTIONS:
  71 + printf("The server is full.\n");
  72 + break;
  73 + case ID_DISCONNECTION_NOTIFICATION:
  74 + printf("We have been disconnected.\n");
  75 + break;
  76 + case ID_CONNECTION_LOST:
  77 + printf("Connection lost.\n");
  78 + break;
  79 +
  80 + case ID_PLATFORM:
  81 + {
  82 + RakNet::BitStream bsIn(pPacket->data, pPacket->length, false);
  83 + bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
  84 +
  85 + float fTimestamp;
  86 + bsIn.Read(fTimestamp);
  87 +
  88 + if (m_fLastPlatformPacket > fTimestamp)
  89 + {
  90 + break;
  91 + }
  92 + m_fLastPlatformPacket = fTimestamp;
  93 +
  94 + float fPos, fVelocity;
  95 + bsIn.Read(fPos);
  96 + bsIn.Read(fVelocity);
  97 +
  98 + Platform *p = g_pGame->getPlatform(1);
  99 + float fX, fY;
  100 + p->getPosition(fX, fY);
  101 + p->setPosition(fX, fPos);
  102 + p->setVelocity(fVelocity);
  103 + }
  104 + break;
  105 +
  106 + /*case ID_INIT:
  107 + {
  108 + RakNet::BitStream bsIn(pPacket->data, pPacket->length, false);
  109 + bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
  110 +
  111 + bsIn.Read(m_fCurrentPos);
  112 + }
  113 + break;
  114 +
  115 + case ID_CLIENTUPDATE:
  116 + {
  117 + RakNet::BitStream bsIn(pPacket->data, pPacket->length, false);
  118 + bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
  119 +
  120 + float fTime;
  121 + unsigned char ucState;
  122 + float fPos, fVel;
  123 + bsIn.Read(fTime);
  124 + bsIn.Read(ucState);
  125 + bsIn.Read(fPos);
  126 + bsIn.Read(fVel);
  127 +
  128 + float fDeltaPos = m_fCurrentPos >= fPos ? m_fCurrentPos - fPos : fPos - m_fCurrentPos;
  129 + if (fDeltaPos > 1.0f)
  130 + {
  131 + m_fCurrentPos = fPos;
  132 + }
  133 + else if (fDeltaPos > 0.2f)
  134 + {
  135 + m_fCurrentPos += (m_fCurrentPos - fPos) * 0.1f;
  136 + }
  137 +
  138 + Platform *p = g_pGame->getPlatform(1);
  139 + float fX, fY;
  140 + p->getPosition(fX, fY);
  141 + p->setPosition(fX, m_fCurrentPos);
  142 + p->setVelocity(fVel);
  143 + }
  144 + break;*/
  145 +
  146 + default:
  147 + printf("Message with identifier %i has arrived.\n", pPacket->data[0]);
  148 + break;
  149 + }
  150 + }
  151 +}
  152 +
  153 +float Network::getCurrentTime()
  154 +{
  155 + DWORD64 qwDelta = GetTickCount64() - m_qwInitTime;
  156 + return (float)qwDelta / 1000.0f;
  157 +}
  158 +
  159 +void Network::updatePlatform(float fPos, float fVelocity)
  160 +{
  161 + RakNet::BitStream bsOut;
  162 + bsOut.Write((RakNet::MessageID)ID_PLATFORM);
  163 + bsOut.Write(fPos);
  164 + bsOut.Write(fVelocity);
  165 + m_pPeer->Send(&bsOut, HIGH_PRIORITY, UNRELIABLE_SEQUENCED, 0, RakNet::UNASSIGNED_SYSTEM_ADDRESS, true);
  166 +}
  167 +
  168 +void Network::updateInput(bool bUp, bool bDown)
  169 +{
  170 + unsigned char ucState = 0;
  171 + if (bUp)
  172 + {
  173 + ucState = 1;
  174 + }
  175 + else if (bDown)
  176 + {
  177 + ucState = 2;
  178 + }
  179 +
  180 + RakNet::BitStream bsOut;
  181 + bsOut.Write((RakNet::MessageID)ID_INPUT);
  182 + bsOut.Write(GetTickCount());
  183 + bsOut.Write(ucState);
  184 + m_pPeer->Send(&bsOut, HIGH_PRIORITY, UNRELIABLE_SEQUENCED, 0, RakNet::UNASSIGNED_SYSTEM_ADDRESS, true);
  185 +}
44 client/Network.h
... ... @@ -0,0 +1,44 @@
  1 +class Network;
  2 +
  3 +#ifndef _NETWORK_H
  4 +#define _NETWORK_H
  5 +
  6 +#include <RakPeerInterface.h>
  7 +#include <MessageIdentifiers.h>
  8 +
  9 +class Network
  10 +{
  11 +public:
  12 + Network();
  13 + ~Network();
  14 +
  15 + bool initialize();
  16 + void deinitialize();
  17 +
  18 + void process();
  19 +
  20 + float getCurrentTime();
  21 +
  22 + void updatePlatform(float fPosition, float fVelocity);
  23 + void updateInput(bool bUp, bool bDown);
  24 +
  25 +private:
  26 + enum GamePackets
  27 + {
  28 + ID_TEST = ID_USER_PACKET_ENUM + 1,
  29 + ID_PLATFORM,
  30 +
  31 + ID_INIT,
  32 + ID_INPUT,
  33 + ID_CLIENTUPDATE
  34 + };
  35 +
  36 + DWORD64 m_qwInitTime;
  37 + float m_fLastPlatformPacket;
  38 +
  39 + float m_fCurrentPos;
  40 +
  41 + RakNet::RakPeerInterface *m_pPeer;
  42 +};
  43 +
  44 +#endif
122 client/Platform.cpp
... ... @@ -0,0 +1,122 @@
  1 +#include "StdInc.h"
  2 +#include "Platform.h"
  3 +
  4 +Platform::Platform(float fX)
  5 + : m_bInteraction(false)
  6 +{
  7 + m_fPosX = fX;
  8 + m_fPosY = SCREEN_H / 2.0f - PLATFORM_H / 2.0f;
  9 +}
  10 +
  11 +Platform::~Platform()
  12 +{
  13 +}
  14 +
  15 +bool Platform::initialize()
  16 +{
  17 + m_pBitmap = al_create_bitmap(PLATFORM_W, PLATFORM_H);
  18 + if (!m_pBitmap)
  19 + {
  20 + return false;
  21 + }
  22 +
  23 + al_set_target_bitmap(m_pBitmap);
  24 + al_clear_to_color(al_map_rgb(255, 255, 255));
  25 +
  26 + return true;
  27 +}
  28 +
  29 +void Platform::deinitialize()
  30 +{
  31 + al_destroy_bitmap(m_pBitmap);
  32 +}
  33 +
  34 +bool Platform::process()
  35 +{
  36 + m_bInteraction = false;
  37 + bool bInteraction = m_bInteraction;
  38 +
  39 + bool bRedraw = bInteraction;
  40 +
  41 + if (m_bInteraction)
  42 + {
  43 + if (m_fVelocity > 7.0f)
  44 + {
  45 + m_fVelocity = 7.0f;
  46 + }
  47 + else if (m_fVelocity < -7.0f)
  48 + {
  49 + m_fVelocity = -7.0f;
  50 + }
  51 + }
  52 + else
  53 + {
  54 + if (m_fVelocity < 0.0f)
  55 + {
  56 + bRedraw = true;
  57 + m_fVelocity += 0.15f;
  58 + if (m_fVelocity > 0.0f) m_fVelocity = 0.0f;
  59 + }
  60 + else if (m_fVelocity > 0.0f)
  61 + {
  62 + bRedraw = true;
  63 + m_fVelocity -= 0.15f;
  64 + if (m_fVelocity < 0.0f) m_fVelocity = 0.0f;
  65 + }
  66 + }
  67 +
  68 + m_fPosY += m_fVelocity;
  69 + if (m_fPosY < 0)
  70 + {
  71 + m_fPosY = 0;
  72 + m_fVelocity = 0.0f;
  73 + }
  74 + else if (m_fPosY > SCREEN_H - PLATFORM_H)
  75 + {
  76 + m_fPosY = SCREEN_H - PLATFORM_H;
  77 + m_fVelocity = 0.0f;
  78 + }
  79 +
  80 + return bRedraw;
  81 +}
  82 +
  83 +void Platform::draw()
  84 +{
  85 + al_draw_bitmap(m_pBitmap, m_fPosX, m_fPosY, 0);
  86 +}
  87 +
  88 +void Platform::setPosition(float fPosX, float fPosY)
  89 +{
  90 + m_fPosX = fPosX;
  91 + m_fPosY = fPosY;
  92 +}
  93 +
  94 +void Platform::getPosition(float &fPosX, float &fPosY)
  95 +{
  96 + fPosX = m_fPosX;
  97 + fPosY = m_fPosY;
  98 +}
  99 +
  100 +void Platform::setVelocity(float fVelocity)
  101 +{
  102 + m_fVelocity = fVelocity;
  103 + m_bInteraction = true;
  104 +}
  105 +
  106 +float Platform::getVelocity()
  107 +{
  108 + return m_fVelocity;
  109 +}
  110 +
  111 +void Platform::accelerate(float fAcceleration)
  112 +{
  113 + m_bInteraction = true;
  114 + m_fVelocity += fAcceleration;
  115 +}
  116 +
  117 +void Platform::decelerate(float fDeceleration)
  118 +{
  119 + m_bInteraction = true;
  120 + m_fVelocity -= fDeceleration;
  121 +}
  122 +
34 client/Platform.h
... ... @@ -0,0 +1,34 @@
  1 +class Platform;
  2 +
  3 +#ifndef _PLATFORM_H
  4 +#define _PLATFORM_H
  5 +
  6 +class Platform
  7 +{
  8 +public:
  9 + Platform(float fX);
  10 + ~Platform();
  11 +
  12 + bool initialize();
  13 + void deinitialize();
  14 +
  15 + bool process();
  16 + void draw();
  17 +
  18 + void setPosition(float fPosX, float fPosY);
  19 + void getPosition(float &fPosX, float &fPosY);
  20 + void setVelocity(float fVelocity);
  21 + float getVelocity();
  22 + void accelerate(float fAcceleration);
  23 + void decelerate(float fDeceleration);
  24 +
  25 +private:
  26 + float m_fPosX;
  27 + float m_fPosY;
  28 + float m_fVelocity;
  29 + bool m_bInteraction;
  30 +
  31 + ALLEGRO_BITMAP *m_pBitmap;
  32 +};
  33 +
  34 +#endif
1  client/StdInc.cpp
... ... @@ -0,0 +1 @@
  1 +#include "StdInc.h"
13 client/StdInc.h
... ... @@ -0,0 +1,13 @@
  1 +#ifndef _STDINC_H
  2 +#define _STDINC_H
  3 +
  4 +#ifdef WIN32
  5 +#include <winsock2.h>
  6 +#include <windows.h>
  7 +#endif
  8 +
  9 +#include "Game.h"
  10 +
  11 +extern Game *g_pGame;
  12 +
  13 +#endif
260 client/main.cpp
... ... @@ -0,0 +1,260 @@
  1 +#include "StdInc.h"
  2 +#include "Game.h"
  3 +
  4 +Game *g_pGame = NULL;
  5 +
  6 +#if 0
  7 +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  8 +{
  9 + ALLEGRO_DISPLAY *display = NULL;
  10 + ALLEGRO_EVENT_QUEUE *event_queue = NULL;
  11 + ALLEGRO_TIMER *timer = NULL;
  12 + ALLEGRO_BITMAP *bouncer = NULL;
  13 + float bouncer_x = 10.0f;
  14 + float bouncer_y = SCREEN_H / 2.0 - PLATFORM_H / 2.0;
  15 + float bouncer_dx = -4.0, bouncer_dy = 4.0;
  16 + bool redraw = true;
  17 + bool doexit = false;
  18 +
  19 + bool key[4] = { false, false, false, false };
  20 +
  21 + if (!al_init())
  22 + {
  23 + error("failed to initialize allegro!\n");
  24 + return -1;
  25 + }
  26 +
  27 + al_init_font_addon(); // initialize the font addon
  28 + if (!al_init_ttf_addon())
  29 + {
  30 + error("failed to initialize ttf addon");
  31 + return -1;
  32 + }
  33 + if (!al_install_keyboard())
  34 + {
  35 + error("failed to initialize the keyboard!\n");
  36 + return -1;
  37 + }
  38 + ALLEGRO_FONT *font = al_load_ttf_font("miscfs.ttf", 72, 0); // load the font | Font from Larabie Free Fonts
  39 + if (!font)
  40 + {
  41 + error("failed to load font");
  42 + return -1;
  43 + }
  44 +
  45 +
  46 + timer = al_create_timer(1.0 / FPS);
  47 + if (!timer)
  48 + {
  49 + error("failed to create timer!\n");
  50 + return -1;
  51 + }
  52 +
  53 + display = al_create_display(SCREEN_W, SCREEN_H);
  54 + if (!display)
  55 + {
  56 + error("failed to create display!\n");
  57 + al_destroy_timer(timer);
  58 + return -1;
  59 + }
  60 +
  61 + bouncer = al_create_bitmap(PLATFORM_W, PLATFORM_H);
  62 + if (!bouncer)
  63 + {
  64 + error("failed to create bouncer bitmap!\n");
  65 + al_destroy_display(display);
  66 + al_destroy_timer(timer);
  67 + return -1;
  68 + }
  69 +
  70 + al_set_target_bitmap(bouncer);
  71 + al_clear_to_color(al_map_rgb(255, 255, 255));
  72 +
  73 + al_set_target_bitmap(al_get_backbuffer(display));
  74 + al_clear_to_color(al_map_rgb(0, 0, 0));
  75 +
  76 + event_queue = al_create_event_queue();
  77 + if (!event_queue)
  78 + {
  79 + error("failed to create event_queue!\n");
  80 + al_destroy_bitmap(bouncer);
  81 + al_destroy_display(display);
  82 + al_destroy_timer(timer);
  83 + return -1;