Guest User

engine.ci

a guest
Aug 21st, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. public class Engine
  2. {
  3.     GameObj[10] obj;
  4.    
  5.     bool isExitRequested;
  6.    
  7.     public const int screen_width  = 320;
  8.     public const int screen_height = 240;
  9.    
  10.     /// Constructor
  11.     Engine()
  12.     {
  13.         Debug.Print("Engine()\n");    
  14.                
  15.         isExitRequested = false;
  16.         // init with zero (null) value
  17.         for(int i = 0; i < obj.Length; i++)
  18.             obj[i] = null;
  19.            
  20.         obj[0] = new GameObj();
  21.         obj[1] = new MovingGameObj();
  22.         obj[1].x = 0;  obj[1].y = 40;
  23.        
  24.     }
  25.  
  26.     public void Run()
  27.     {
  28.         Debug.Print("Engine.Run()\n");            
  29.  
  30.         while(!isExitRequested)
  31.         {
  32.  
  33.             Platform.OnGameLoopBegin();
  34.                        
  35.             if(!Platform.HandleInput())
  36.                 isExitRequested = true;
  37.            
  38.             // move phase
  39.             for(int i = 0; i < obj.Length; i++)
  40.                 if(obj[i] != null)
  41.                     obj[i].Move();
  42.  
  43.             // draw phase
  44.             for(int i = 0; i < obj.Length; i++)
  45.                 if(obj[i] != null)
  46.                     obj[i].Draw();
  47.                                        
  48.             Platform.OnGameLoopEnd();
  49.            
  50.             // do only one pass of loop
  51.             isExitRequested = true;
  52.            
  53.         }
  54.     }
  55.    
  56.  
  57.  
  58.  
  59.        
  60. }
  61.  
  62.  
  63. public class Startup
  64. {
  65.     Engine engine;
  66.    
  67.     public void Run()
  68.     {
  69.         Debug.Print("Startup.Run()\n");    
  70.        
  71.         Platform.InitVideo(engine.screen_width, engine.screen_height);        
  72.         engine = new Engine();
  73.         engine.Run();
  74.         Platform.CleanupVideo();
  75.  
  76.     }
  77.    
  78. }
Advertisement
Add Comment
Please, Sign In to add comment