//------------------------------------------------------------------------------ //! \brief Check to see if a bowling ball hit this objects body //! //! \param tobj = bowling ball Object //! \param pcb = The collision box //! //! \return 0 = No collision occured //------------------------------------------------------------------------------ int CClockBoss::HitBody( CBowlingObj *tobj, OBJSIZE *pcb ) { InitSize(*pcb); if (CheckHit( tobj )) { tobj->SetExplode(); return 1; } return 0; }
//------------------------------------------------------------------------------ //! \brief Check to see if a tomato hit this objects body //! //! \param tobj = Tomato Object //! \param pcb = The collision box //! //! \return 0 = No collision occured //------------------------------------------------------------------------------ int CClownBoss::HitBody( CTomatoObj *tobj, OBJSIZE *pcb ) { InitSize(*pcb); if (CheckHit( tobj )) { tobj->SetExplode(); return 1; } return 0; }
//------------------------------------------------------------------------------ //! \brief Check to see if a spike hit this objects body //! //! \param tobj = Spike Object //! \param pcb = The collision box //! //! \return 0 = No collision occured //------------------------------------------------------------------------------ int CCrabBoss::HitBody( CSpikeObj *tobj, OBJSIZE *pcb ) { InitSize(*pcb); if (CheckHit( tobj )) { tobj->SetExplode(); return 1; } return 0; }
// Called every frame void AExplodeRay::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); if (m_nHit == 0) { CheckHit(); } m_fTime -= DeltaTime; // Removing translucency because it looks bad, I could remove the dynamic material instance // and use the a static material instance / material instead, but im leaving it as a dynamic // instance incase I want to fix the way the opacity blends. //m_pMatInst->SetScalarParameterValue(TEXT("Opacity"), FMath::Clamp(m_fTime/FADE_TIME, 0.0f, 1.0f)); // Destroy the exploderay if it has faded out if (m_fTime < 0.0f) { Destroy(); } }
void CColumnTreeCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) { if (CheckHit(point)) { CTreeCtrl::OnLButtonDblClk(nFlags, point); UINT fFlags; HTREEITEM hItem = HitTest(point, &fFlags); CEdit *edit = EditLabel(hItem); //SetFocus(); class CMyEdit : public CEdit { public: virtual LRESULT DefWindowProc ( UINT message, WPARAM wParam, LPARAM lParam ) { switch(message) { case WM_GETDLGCODE: return DLGC_WANTALLKEYS; // has to do this, otherwise, ESC and RETURN don't work (don't know why ...) break; } return CEdit::DefWindowProc(message, wParam, lParam); } }; CString strSub; AfxExtractSubString(strSub, GetItemText(hItem), 0, '\t'); edit->SetWindowText(strSub); edit->SetSel(0, -1); CMyEdit *me = new CMyEdit; me->SubclassWindow(edit->Detach()); } }
/* * "shoot" a bolt from the current bolt location to the "aim" location */ static void ShootBolt( HWND window_handle ) /*****************************************/ { extra_data *edata_ptr; HDC hdc; HBITMAP screensavebmp; MSG msg; FARPROC proc; HANDLE inst_handle; icon_mover mover; edata_ptr = (extra_data *) GetWindowLong( window_handle, EXTRA_DATA_OFFSET ); hdc = GetDC( window_handle ); inst_handle = GetWindowWord( window_handle, GWW_HINSTANCE ); /* set up an "icon_mover" struct to give all needed data to DrawBolt */ mover.icon = edata_ptr->bolt_icon; mover.size.x = BOLTWIDTH; mover.size.y = BOLTHEIGHT; mover.last.x = -1; mover.last.y = -1; mover.screen_dc = hdc; mover.storage_dc = CreateCompatibleDC( hdc ); mover.speed = edata_ptr->bolt_speed; screensavebmp = CreateCompatibleBitmap( hdc, mover.size.x, mover.size.y ); SelectObject( mover.storage_dc, screensavebmp ); if( edata_ptr->sound_on ) { BoltSound(); } /* * for each point on the line between the points BOLT and AIM, * call DrawBolt * use aim - boltheight so that the bottom left corner of the bolt icon * stops at the point AIM */ proc = MakeProcInstance( (FARPROC)DrawBolt, inst_handle ); LineDDA( edata_ptr->bolt.x, edata_ptr->bolt.y, edata_ptr->aim.x, edata_ptr->aim.y - BOLTHEIGHT, proc, (LPARAM)(LPVOID)&mover ); FreeProcInstance( proc ); /* * remove all WM_LBUTTONDOWN messages from the application queue which * occured while the bolt was "in the air" * this prevents the shots from building up - only 1 can happen at a time */ while( PeekMessage( &msg, window_handle, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_REMOVE ) ); /* make sure the bolt is drawn at the final location regardless of speed */ mover.speed = 1; DoDrawBolt( edata_ptr->aim.x, edata_ptr->aim.y - BOLTHEIGHT, &mover ); if( edata_ptr->sound_on ) { BoomSound(); } /* redraw the background behind the icon */ BitBlt( mover.screen_dc, mover.last.x, mover.last.y, mover.size.x, mover.size.y, mover.storage_dc, 0, 0, SRCCOPY); CheckHit( hdc, edata_ptr->aim ); DeleteDC( mover.storage_dc ); DeleteObject( screensavebmp ); ReleaseDC(window_handle, hdc); } /* ShootBolt */
int main (void) { const double YS_PI=3.1415927; FsOpenWindow(16, 16, 800, 600, 1); int ObstaclesState[5]; int x1[5], y1[5], x2[5], y2[5]; int Point[10000];//trajectory int p[10000],q[10000];//trajectory srand((unsigned)time(NULL)); // for(int i=0;i<10000;i++) // { // Point[i]=1; // }//draw points for(int i=0;i<5;++i) { x1[i]=rand()%720; y1[i]=rand()%520; x2[i]=x1[i]+80+rand()%70; y2[i]=y1[i]+80+rand()%70; ObstaclesState[i]=1; } int terminate=0; int y=0; int x=30; int a=55; int b=545; double m=1.0; double dt=0.025; int CannonballState=0; int angle=30; double vx; double vy; int Hit=0; int TargetState=1; while(0==terminate) { FsPollDevice(); angle++; if(angle>=90) angle=0; int key=FsInkey(); if(FSKEY_ESC==key) { terminate=1; } else if(FSKEY_SPACE==key) { if(0==CannonballState) { CannonballState=1; vx=cos(angle*YS_PI/180)*400; vy=-sin(angle*YS_PI/180)*400; } } //draw screen glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if(0!=ObstaclesState) { for(int i=0; i<5; ++i) { if(0!=ObstaclesState[i]) { DrawObstacles(x1[i],y1[i],x2[i],y2[i]); if(0!=CannonballState && 0!=CheckCollision(a, b, x1[i], y1[i], x2[i], y2[i])) { printf("Hit An Obstacle!\n"); ObstaclesState[i]=0; CannonballState=0; Hit=1; a=55; b=545; } } if(0!=Hit) { DrawObstacles2(x1[i],y1[i],x2[i],y2[i]); } } } if(0!=TargetState) { if(0!=CannonballState && 0!=CheckHit(a, b, y)) { printf("HitTarget!\n"); TargetState=0; CannonballState=0; break; } } DrawCannonLine(x); RotateCannonline(x, 90); DrawCannon(); DrawTarget(y); MoveTarget(y, 600); if(0!=CannonballState) { DrawCannonball(a, b); MoveCannonball(a, b, vx, vy, m, dt); // for(int i=0;i<10000;i++) // { // Point[i]=1; // }//draw points // if(0!=Point)//not working // { for(int i=0; i<10000; ++i) { // if(0!=Point[i]) // { p[i]=a; // printf("%d\n",a); q[i]=b; // DrawTrajectory(p[i], q[i]); /// } // } } if(a>800||b>600) { CannonballState=0; a=55; b=545; } } FsSwapBuffers(); FsSleep(25); } return 0; }
// レンダリング HRESULT Render( void ) { //int i; int nHitResult; // 当たり判定結果 // 画面クリア XMFLOAT4 v4Color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f ); g_pImmediateContext->ClearRenderTargetView( g_pRTV, ( float * )&v4Color ); // *** Zバッファクリア *** g_pImmediateContext->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 ); // サンプラセット g_pImmediateContext->PSSetSamplers( 0, 1, &g_pSamplerState ); // 描画設定 UINT nStrides = sizeof( CUSTOMVERTEX ); UINT nOffsets = 0; g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &nStrides, &nOffsets ); g_pImmediateContext->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 ); g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); g_pImmediateContext->IASetInputLayout( g_pInputLayout ); // シェーダ設定 g_pImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 ); g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pCBNeverChanges ); g_pImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 ); g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_pCBNeverChanges ); // 多角形との当たり判定 nHitResult = CheckHit( &( Player_1.v3Pos ) ); // 変換行列 CBNeverChanges cbNeverChanges; XMMATRIX mWorld; XMMATRIX mView; XMMATRIX mProjection; XMMATRIX mViewProjection; // Initialize the view matrix XMVECTOR Eye = XMVectorSet( Player_1.v3Pos.x, Player_1.v3Pos.y + 3.0f, Player_1.v3Pos.z - 5.0f, 0.0f ); XMVECTOR At = XMVectorSet( Player_1.v3Pos.x, Player_1.v3Pos.y, Player_1.v3Pos.z, 0.0f ); XMVECTOR Up = XMVectorSet( 0.0f, 1.0f, 0.0f, 0.0f ); mView = XMMatrixLookAtLH( Eye, At, Up ); // Initialize the projection matrix mProjection = XMMatrixPerspectiveFovLH( XM_PIDIV4, VIEW_WIDTH / ( FLOAT )VIEW_HEIGHT, 0.01f, 100.0f ); mViewProjection = mView * mProjection; // 描画 g_pImmediateContext->OMSetDepthStencilState( g_pDSDepthState, 1 ); g_pImmediateContext->RSSetState( g_pRS_Cull_CW ); // カリングあり // 地面 g_pImmediateContext->OMSetBlendState( NULL, NULL, 0xFFFFFFFF ); DrawMyModel( &g_mmGround, &mViewProjection ); //// 当たり判定多角形 DrawMyModel( &g_mmHitPolygon, &mViewProjection ); // 当たり黒三角 g_pImmediateContext->OMSetRenderTargets( 1, &g_pRTV, NULL ); g_mmHitPolygon.v4AddColor = XMFLOAT4( -1.0f, -1.0f, -1.0f, 1.0f ); DrawMyModelPartial( &g_mmHitPolygon, &mViewProjection, nHitResult, 1 ); g_pImmediateContext->OMSetRenderTargets( 1, &g_pRTV, g_pDepthStencilView ); g_mmHitPolygon.v4AddColor = XMFLOAT4( 0.0f, 0.0f, 0.0f, 0.0f ); // プレイヤー g_pImmediateContext->OMSetBlendState( NULL, NULL, 0xFFFFFFFF ); g_mmPlayer.mMatrix = CreateWorldMatrix( Player_1.v3Pos.x, Player_1.v3Pos.y, Player_1.v3Pos.z, 1.0f ); DrawMyModel( &g_mmPlayer, &mViewProjection ); return S_OK; }
void CColumnTreeCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) { if (CheckHit(point)) CTreeCtrl::OnLButtonDblClk(nFlags, point); }
void CColumnTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point) { // mask left click if outside the real item's label if (CheckHit(point)) CTreeCtrl::OnLButtonDown(nFlags, point); }