コード例 #1
0
ファイル: Main.cpp プロジェクト: scirelli/testForDX7
////FUNCTIONS//////////////////
//-----------------------------------------------------------------------------
// Name: Main()
// Desc: Where all work is done
//-----------------------------------------------------------------------------
bool main()
{
	static int nFrames = 0;
	//static CVECTOR shipsVelVector(0.f,0.f,0.f);
	
	if(GetKeyStatus(VK_ESCAPE) == true)
		return(0);
	
	//Clear the surface
	if(!ClrS(lpddsSecondary,&wndRect))//can't be within a lock-Unlock block or u can't blt
		return(0);
	
	DynamicStarField(NULL,800,Sprites[0].physProp.VelVector,nFrames);
	//Sprites[0].DrawSprite(lpddsSecondary);
	MoveShip();
	
	if(bDebugMode)
		DebugInfo(nFrames);
	
	//Flip primary and secondary surfaces
	Flip();
	//Sleep(1000);
	fFrameTime = frameTimer.EndTimerAndRestart();
	nFrames++;
	return(1);
}
コード例 #2
0
ファイル: game.cpp プロジェクト: romanz/crystal-maze-3d
int TMaze::Update()
{
	found = False; // Crystal isn't found
	if (Step) // Transform only if necessary
	{
		switch (AnimationType)
		{
			case aniMovement: // There is a movement
				Maze *= MoveMaze(Move);
				*Crystal *= MoveMaze(Move);

				if (Step == Frames) // First step
					Ship *= MoveShip(Move); // Move ship
				else if (Step == 1) // Last step
					Ship *= MoveShip(static_cast<Direction>(Move ^ 1)); // Move it back

				break;

			case aniCrystal: // Animating crystal
				*Crystal *=
				 TPivotRotateY(M_PI/12, 0, DeltaZ) *
				 TPivotScale(0.9, 1.0, 0.9, TVector(0,0,DeltaZ));

				sound(900+40*Step);

				break;

		} // switch (AnimationType)

		if (!--Step) // Last step is done
		{
			nosound();

			switch (AnimationType)
			{
				case aniMovement:
					if (Dest == Cube) // Check if crystal is found
					{
						AnimationType = aniCrystal;
						Step = 15; // Animation steps (frames)
					}
					break;

				case aniCrystal: // Crystal animation is done

					delete Crystal; // Delete crystal
					Crystal = NewCrystal(); // Create new crystal (continue)

					Viewer.RemoveFromTail(); // Remove old crystal
					Viewer.AddToTail(Crystal); // Add new crystal (continue)
					Viewer.Update(); // Update viewer's list

					found = True; // Now the crystal is found
					AnimationType = aniNone;

					break;

			} // switch (AnimationType)

		} // if (!--Step)

		return 1;

	} // if (Step)

	return 0;
}
コード例 #3
0
ファイル: draw.cpp プロジェクト: lxmzhv/starfight
void DrawShips( GdkDrawable *drawable, GdkGC* gc, GdkPoint sz )
{
  GdkColor color;
  GdkRectangle rc;

  int r = int(ShipRadius*Scale);
  for( int j = 0; j < 2; ++j )
    for( int i = 0; i < ShipTotal; i++ )
      {
        // Draw trajectory
        if( ship_owners[i] != pNONE && i == SelectedShip )
        {
          GdkPoint gp1, gp2;
          DPoint2D pnt[2], g, *p1 = NULL, *p2 = NULL;
          DPoint2D v( ships_vx[i], ships_vy[i] );
          double angle = ships_angle[i];
          double angle_chg = chg_angle[i];
          double energy = ships_energy[i];
          double acc = Acceler[i];

          pnt[0].Init( ships_x[i], ships_y[i] );

          GdkColor base_col = (ship_owners[i] == pWHITE ? SHIP_COLOR1 : SHIP_COLOR2), col;
          double brightness;

          for( int n = 0; n < ShipTrajDisplayLength; ++n )
          {
            p1 = &pnt[n%2];
            p2 = &pnt[1-n%2];

            *p2 = *p1;

            MoveShip( *p2, v, angle, angle_chg, energy, acc );

            gp1.x = XToScreen(p1->x, sz);
            gp1.y = YToScreen(p1->y, sz);
            gp2.x = XToScreen(p2->x, sz);
            gp2.y = YToScreen(p2->y, sz);

            brightness = 0.1 + 0.5*(1 - 1.0*n/ShipTrajDisplayLength);
            col.red   = guint16( base_col.red * brightness );
            col.green = guint16( base_col.green * brightness );
            col.blue  = guint16( base_col.blue * brightness );
            gdk_gc_set_rgb_fg_color( gc, &col );
            gdk_draw_line( drawable, gc, gp1.x, gp1.y, gp2.x, gp2.y );

            angle_chg = 0;
            acc = 0;
          }
        }

        GdkPoint p = { XToScreen(ships_x[i], sz), YToScreen(ships_y[i], sz) };
        GdkPoint d = { int(cos(ships_angle[i])*ShipRadius*Scale),
                      -int(sin(ships_angle[i])*ShipRadius*Scale) }; // Atack direction

        // Draw nozzle fire
        if( ship_owners[i] != pNONE && Acceler[i] >= NULL_DOUBLE )
          {
          double mul = Acceler[i]/MaxAcceleration;
          gdk_gc_set_rgb_fg_color( gc, &RED );
          gdk_draw_line( drawable, gc, int(p.x - d.x*(1+mul)), int(p.y - d.y*(1+mul)), p.x - d.x, p.y - d.y );
          gdk_draw_line( drawable, gc, p.x - d.x, p.y - d.y, int(p.x - d.x*(1+mul/2)), int(p.y - d.y*(1+mul/2)) );
          }

        if( j==0 ? ship_owners[i] != pNONE : ship_owners[i] == pNONE )
          continue; // this is needed to display destroyed ships first

        // Draw the vehicle
        DrawCircle( drawable, gc, true, p, r, ship_owners[i]==pWHITE ? SHIP_COLOR1 :
                                              ship_owners[i]==pBLACK ? SHIP_COLOR2 :
                                              Owners[i]==pWHITE ? DIM_SHIP_COLOR1 :
                                                                  DIM_SHIP_COLOR2 );
        if( i == SelectedShip )
          DrawCircle( drawable, gc, false, p, r, RED );

        // Draw state bars
        rc.x = p.x-r;
        rc.y = p.y+r;
        rc.width = 2*r;
        rc.height = 4;

        // Fill the bars with white
        gdk_gc_set_rgb_fg_color( gc, &WHITE );
        gdk_draw_line( drawable, gc, rc.x, rc.y+1, rc.x + rc.width, rc.y+1 );
        gdk_draw_line( drawable, gc, rc.x, rc.y+3, rc.x + rc.width, rc.y+3 );

        // Energy
        if( ships_energy[i] > 0 )
        {
          gdk_gc_set_rgb_fg_color( gc, &CYAN );
          gdk_draw_line( drawable, gc, rc.x, rc.y+1, int(rc.x+rc.width*ships_energy[i]), rc.y+1 );
        }

        // Health
        if( ships_health[i] > 0 && ship_owners[i] != pNONE )
        {
          gdk_gc_set_rgb_fg_color( gc, &RED );
          gdk_draw_line( drawable, gc, rc.x, rc.y+3, int(rc.x+rc.width*ships_health[i]), rc.y+3 );
        }

        // Atack direction
        gdk_gc_set_rgb_fg_color( gc, &RED );
        gdk_draw_line( drawable, gc, p.x, p.y, p.x+d.x, p.y+d.y );
      }

  // Laser atacks
  double k = 155.0/MaxShootEnergy;
  for( int i = 0; i < ShootsCount; i++ )
  {
    color = RGB( int(Shoots[i][4]*k)+100, 0, 0 );
    gdk_gc_set_rgb_fg_color( gc, &color );
    gdk_draw_line( drawable, gc, XToScreen(Shoots[i][0], sz),
                                 YToScreen(Shoots[i][1], sz),
                                 XToScreen(Shoots[i][2], sz),
                                 YToScreen(Shoots[i][3], sz) );
  }
}