Smarkus

Member
  • Content count

    13
  • Joined

  • Last visited

Community Reputation

142 Neutral

About Smarkus

  • Rank
    Member

Personal Information

  • Interests
    Art
    Design
    DevOps
    Education
    Production
    Programming
    QA

Recent Profile Visitors

1030 profile views
  1. Got it. So what I was thinking when I made this vector was that this would be the distance which is the range in which the enemy would shoot and if I'm out of the distance range then the enemy won't shoot at the player. How else do you suggest me to implement that?
  2. Thanks for the reply. What's wrong with my code is that the enemy continues to shoot even if i'm farther away than distance.x and distance.z which is 10.0f each. So the someValue that you suggested is in my case is the range in which the enemy shoots which in my case is distance.x and distance.z.
  3. float CalculateDistance(D3DXVECTOR3 enemyPos, D3DXVECTOR3 playerPos) { float length; float distanceX; float distanceZ; distanceX = enemyPos.x - playerPos.x; distanceZ = enemyPos.z - playerPos.z; length = sqrt((distanceX*distanceX) + (distanceZ * distanceZ)); return length; } //And then in my Update D3DXVECTOR3 distance = D3DXVECTOR3(10.0f, 0.0f, 10.0f); if (distance.x || distance.z <= CalculateDistance(D3DXVECTOR3(position.x, 0.0f, position.z), D3DXVECTOR3(CGame::GetPlayer()->GetPos().x, 0.0f, CGame::GetPlayer()->GetPos().z))) { int Random = rand() % 50; if (Random == 0) { D3DXVECTOR3 towardsPlayer = CGame::GetPlayer()->GetPos() - position; Bullet::CreateBullet((D3DXVECTOR3(position.x, position.y - 5.0f, position.z)), D3DXVECTOR3(10.0f, 10.0f, 0.0f), 25.0f, towardsPlayer, 30, BULLET_TYPE_ENEMY); } } I've tried doing this. The enemy continues to shoot even if I'm farther than distance.x and distance.z. Can someone tell me what's wrong?
  4. Neither. It"s actually in Tokyo lol hence the Japanese comments
  5. I know it's stupid but it's required by my school for some reason
  6. Thank you so much! I was able to fix it
  7. Can someone help out with this. The code builds but I get "Exception thrown: Read Access Violation" and says my index buffer was a nullptr. I'm going to attach my code and a screenshot of the error below or above. Any help is greatly appreciated. //------------------------------- //ヘッダファイル //------------------------------- #include "manager.h" #include "renderer.h" #include "dome.h" #include "camera.h" //------------------------------- //コンストラクタ //------------------------------- CDome::CDome() { m_pIndxBuff = nullptr; m_pVtxBuff = nullptr; m_HorizontalGrid = NULL; m_VerticalGrid = NULL; // ワールドの位置・拡大・回転を設定 m_Scale = D3DXVECTOR3(1.0f, 1.0f, 1.0f); m_Pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); //m_Rotate = 0.0f; } CDome::CDome(int HorizontalGrid, int VerticalGrid, float Length) { m_pIndxBuff = nullptr; m_pVtxBuff = nullptr; m_HorizontalGrid = HorizontalGrid; m_VerticalGrid = VerticalGrid; // ワールドの位置・拡大・回転を設定 m_Scale = D3DXVECTOR3(1.0f, 1.0f, 1.0f); m_Pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); m_Length = Length; } CDome::CDome(int HorizontalGrid, int VerticalGrid, float Length, D3DXVECTOR3 Pos) { m_pIndxBuff = nullptr; m_pVtxBuff = nullptr; m_HorizontalGrid = HorizontalGrid; m_VerticalGrid = VerticalGrid; // ワールドの位置・拡大・回転を設定 m_Scale = D3DXVECTOR3(1.0f, 1.0f, 1.0f); m_Pos = Pos; m_Length = Length; } //------------------------------- //デストラクタ //------------------------------- CDome::~CDome() { } //------------------------------- //初期化処理 //------------------------------- void CDome::Init(void) { LPDIRECT3DDEVICE9 pDevice; pDevice = CManager::GetRenderer()->GetDevice(); m_VtxNum = (m_HorizontalGrid + 1) * (m_VerticalGrid + 1); m_IndxNum = (m_HorizontalGrid * 2 + 2) * m_VerticalGrid + (m_VerticalGrid - 1) * 2; // テクスチャの生成 if (FAILED(D3DXCreateTextureFromFile(pDevice, "data/TEXTURE/dome.jpg", &m_pTexture))) { MessageBox(NULL, "Couldn't read Texture file destination", "Error Loading Texture", MB_OK | MB_ICONHAND); } //頂点バッファの作成 if (FAILED(pDevice->CreateVertexBuffer(sizeof(VERTEX_3D) * m_VtxNum, D3DUSAGE_WRITEONLY, FVF_VERTEX_3D, D3DPOOL_MANAGED, &m_pVtxBuff, NULL))) //作成した頂点バッファのサイズ { MessageBox(NULL, "Error making VertexBuffer", "Error", MB_OK); } //インデクスバッファの作成 if (FAILED(pDevice->CreateIndexBuffer(sizeof(VERTEX_3D) * m_IndxNum, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIndxBuff, NULL))) { MessageBox(NULL, "Error making IndexBuffer", "Error", MB_OK); } VERTEX_3D *pVtx; //仮想アドレス用ポインターVertex WORD *pIndx; //仮想アドレス用ポインターIndex //頂点バッファをロックして仮想アドレスを取得する。 m_pVtxBuff->Lock(0, 0, (void**)&pVtx, 0); //インデクスをロックして仮想アドレスを取得する。 m_pIndxBuff->Lock(0, 0, (void**)&pIndx, 0); for (int i = 0; i < (m_VerticalGrid + 1); i++) { for (int j = 0; j < (m_HorizontalGrid + 1); j++) { pVtx[0].pos = D3DXVECTOR3(m_Length * sinf(i * (D3DX_PI * 0.5f / ((int)m_VerticalGrid - 1))) * sinf(j * (D3DX_PI * 2 / ((int)m_HorizontalGrid - 1))), m_Length * cosf(i * (D3DX_PI * 0.5f / ((int)m_VerticalGrid - 1))), m_Length * sinf(i * (D3DX_PI* 0.5f / ((int)m_VerticalGrid - 1))) * cosf(j * (D3DX_PI * 2 / ((int)m_HorizontalGrid - 1)))); D3DXVECTOR3 tempNormalize; D3DXVec3Normalize(&tempNormalize, &pVtx[0].pos); pVtx[0].normal = -tempNormalize; pVtx[0].color = D3DXCOLOR(255, 255, 255, 255); pVtx[0].tex = D3DXVECTOR2((float)j / (m_HorizontalGrid - 1), (float)i / (m_VerticalGrid - 1)); pVtx++; } } for (int i = 0; i < m_VerticalGrid; i++) { if (i != 0) { pIndx[0] = ((m_HorizontalGrid + 1) * (i + 1)); pIndx++; } for (int j = 0; j < (m_HorizontalGrid + 1); j++) { pIndx[0] = ((m_HorizontalGrid + 1) * (i + 1)) + j; pIndx[1] = ((m_HorizontalGrid + 1) * i) + j; pIndx += 2; } if (i + 1 != m_VerticalGrid) { pIndx[0] = pIndx[-1]; pIndx++; } } //インデクスをアンロックする m_pIndxBuff->Unlock(); //頂点バッファをアンロックする m_pVtxBuff->Unlock(); } //------------------------------- //終了処理 //------------------------------- void CDome::Uninit(void) { // 頂点バッファの破棄 SAFE_RELEASE(m_pVtxBuff); // インデクスの破棄 SAFE_RELEASE(m_pIndxBuff); Release(); } //------------------------------- //更新処理 //------------------------------- void CDome::Update(void) { m_Pos = CManager::GetCamera()->GetCameraPosEye(); } //------------------------------- //描画処理 //------------------------------- void CDome::Draw(void) { LPDIRECT3DDEVICE9 pDevice; pDevice = CManager::GetRenderer()->GetDevice(); D3DXMATRIX mtxWorld; D3DXMATRIX mtxPos; D3DXMATRIX mtxScale; D3DXMATRIX mtxRotation; // ワールドID D3DXMatrixIdentity(&mtxWorld); // 3D拡大行列 D3DXMatrixScaling(&mtxScale, m_Scale.x, m_Scale.y, m_Scale.z); D3DXMatrixMultiply(&mtxWorld, &mtxWorld, &mtxScale); // 3D平行移動行列 D3DXMatrixTranslation(&mtxPos, m_Pos.x, m_Pos.y + 70.0f, m_Pos.z); D3DXMatrixMultiply(&mtxWorld, &mtxWorld, &mtxPos); // ワールド座標変換 pDevice->SetTransform(D3DTS_WORLD, &mtxWorld); // 頂点バッファをデータストリームに設定 pDevice->SetStreamSource(0, m_pVtxBuff, 0, sizeof(VERTEX_3D)); // 頂点フォーマットの設定 pDevice->SetFVF(FVF_VERTEX_3D); // テクスチャの設定 pDevice->SetTexture(0, m_pTexture); // インデクスの設定 pDevice->SetIndices(m_pIndxBuff); // カラーが見えるようにライトを消す pDevice->SetRenderState(D3DRS_LIGHTING, FALSE); // ポリゴンの描画 pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, m_VtxNum, 0, m_IndxNum - 2); // ライトを元に戻す pDevice->SetRenderState(D3DRS_LIGHTING, TRUE); } //------------------------------- //Create MeshDome //------------------------------- CDome *CDome::Create(int HorizontalGrid, int VerticalGrid, float Length) { CDome *pMeshDome; pMeshDome = new CDome(HorizontalGrid, VerticalGrid, Length); pMeshDome->Init(); return pMeshDome; } CDome *CDome::Create(int HorizontalGrid, int VerticalGrid, float Length, D3DXVECTOR3 Pos) { CDome *pMeshDome; pMeshDome = new CDome(HorizontalGrid, VerticalGrid, Length, Pos); pMeshDome->Init(); return pMeshDome; }
  8. Hey guys, I'm halfway through my third year at a Game School in Tokyo. My job hunting process starts soon. The way job hunting works here is everyone makes a project/game/tool(game related) and then present it to the game studios/game companies. Here's a few things that I wanted to ask: What kind of a game could I make that'd be a solid one and get me hired? I want to showcase good C++ knowledge and Direct X(which they teach us at school) Specifically, what features should my game have that could come across as valuable? What are they looking for in fresh graduates? What game features are the industry people looking for? What could I make that'd impress them? I'd really appreciate your advice/comments/answers
  9. Oh awesome! It works now, thank you so much!
  10. Not sure if this is the problem, the book has the same code for device as mine. Is there anything that could possibly be wrong?
  11. //page 120 #include <Windows.h> #include <windef.h> #include <winuser.h> #include <d3d9.h> #include <d3dx9.h> #include <stdio.h> #include <stdlib.h> #include <time.h> //#pragma comment (lib,"d3d9.lib") //library's link //#pragma comment (lib,"d3dx9.lib") //#pragma comment (lib,"dxguid.lib") //#pragma comment (lib,"winmm.lib") //システム時刻取得に必要 | マルチメディアライブラリ(Windows Multimedia Library) //#pragma comment (lib,"dinput8.lib") #define APPTITLE "CreateSurface" #define KEY_DOWN(vk_code)((GetAsyncKeyState(vk_code)&0x8000)?1:0) #define KEY_UP(vk_code)((GetAsyncKeyState(vk_code)&0x8000)?1:0) #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 //function prototypes LRESULT WINAPI WinProc(HWND, UINT, WPARAM, LPARAM); ATOM MyRegisterClass(HINSTANCE); int GameInit(HWND); void GameRun(HWND); void GameEnd(HWND); //Direct3D Objects LPDIRECT3D9 d3d = NULL; LPDIRECT3DDEVICE9 d3ddev = NULL; LPDIRECT3DSURFACE9 surface = NULL; LPDIRECT3DSURFACE9 backbuffer = NULL; LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_QUIT: GameEnd(hWnd); PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } //helper function to set up windows properties ATOM MyRegisterClass(HINSTANCE hInstance) { // create struucture WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); //fill the structure with information wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPTITLE; wc.hIconSm = NULL; //set up the window with the class info return RegisterClassEx(&wc); } //Entry point for a windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; MyRegisterClass(hInstance); HWND hWnd; hWnd = CreateWindow( APPTITLE, APPTITLE, WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL ); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); if (!GameInit(hWnd)) { return 0; } //Main Message loop int done = 0; while (!done) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { done = 1; } TranslateMessage(&msg); DispatchMessage(&msg); } else { GameRun(hWnd); } } return msg.wParam; } int GameInit(HWND hwnd) { HRESULT result; //initialize Direct3D d3d = Direct3DCreate9(D3D_SDK_VERSION); if (d3d == NULL) { MessageBox(hwnd, "Error initializing Direct3D", "Error", MB_OK); return 0; } //set Direct3D presentation parameters D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = SCREEN_WIDTH; d3dpp.BackBufferHeight = SCREEN_HEIGHT; d3dpp.hDeviceWindow = hwnd; //create Direct3D device d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); if (d3ddev = NULL) { MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK); return 0; } //set random number seed srand(time(NULL)); //Clear the backbuffer to black d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); //Create pointer to back buffer d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //create surface result = d3ddev->CreateOffscreenPlainSurface( 100, 100, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); if (result!=D3D_OK) { return 1; } //load surface from file result = D3DXLoadSurfaceFromFile( surface, NULL, NULL, "char.jpg", NULL, D3DX_DEFAULT, 0, NULL); //make sure file was loaded fine if (result != D3D_OK) { return 1; } //draw surface to back buffer d3ddev->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE); //return okay return 1; } void GameRun(HWND hwnd) { RECT rect; int r, g, b; if (d3ddev == NULL) { return; } if (d3ddev->BeginScene()) { //Create pointer to the back buffer d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //draw surface to the back buffer d3ddev->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE); //stop rendering d3ddev->EndScene(); } d3ddev->Present(NULL, NULL, NULL, NULL); //check for escape key to exit program if (KEY_DOWN(VK_ESCAPE)) { PostMessage(hwnd, WM_DESTROY, 0, 0); } } void GameEnd(HWND hwnd) { //free the surface surface->Release(); if (d3ddev != NULL) { d3ddev->Release(); } if (d3d != NULL) { d3d->Release(); } } So this is the code. I'm following a book and I checked If I made any mistakes. The picture shows what the error is. Can someone help? Also, what is the default location for a file/bitmap/jpg in my case?
  12. I've actually already ordered this book: https://www.amazon.com/Introduction-Programming-DirectX-Computer-Science/dp/1942270062 So, I was just trying to get my hands dirty and get ready to study the book. I mean I can't really switch now that I've already ordered the book. Also, I'm in Japan and some how the Amazon site here said that i'll get the book that I ordered the next day, whereas if I ordered the same book by the same author, just the DirectX 11 version, it'd take 2 to 3 months to ship. So I had no choice. But I'd appreciate if you told me some links or resources that explain how I set it up.
  13. I've tried looking for tutorials but nothing's really helping. Can anyone help?
  14. #include <Windows.h> #include <windef.h> #include <winuser.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #define APPTITLE "Game Loop" //function prototypes LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM); ATOM MyRegisterClass(HINSTANCE); BOOL InitInstance(HINSTANCE, int); void DrawBitmap(HDC, char*, int, int); void GameInit(); void GameRun(); void GameEnd(); //Local Variables HWND globalHwnd; HDC globalHdc; //Event callback function LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { globalHwnd = hWnd; globalHdc = GetDC(hWnd); switch (message) { case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); } //helper function to set up windows properties ATOM MyRegisterClass(HINSTANCE hInstance) { // create struucture WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); //fill the structure with information wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPTITLE; wc.hIconSm = NULL; //set up the window with the class info return RegisterClassEx(&wc); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; //create New window hWnd = CreateWindow( APPTITLE, APPTITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1080, 720, NULL, NULL, hInstance, NULL); //if error if (!hWnd) return FALSE; //display the window ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } //Entry point for a windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int done = 0; MSG msg; MyRegisterClass(hInstance); if (!InitInstance(hInstance, nCmdShow)) { return FALSE; } GameInit(); // main message loop while (!done) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { //look for quit message if (msg.message == WM_QUIT) { done = 1; } TranslateMessage(&msg); DispatchMessage(&msg); } //process the Gameloop GameRun(); } //cleanup GameEnd(); return msg.wParam; } void GameInit() { //Initialize the game //load bitmaps, mesh, textures, sounds etc //initialize the random number generator srand(time(NULL)); } void GameRun() { //this is called once every frame //don't include yourn own loop here int x = 0, y = 0; RECT rect; GetClientRect(globalHwnd, &rect); if (rect.right > 0) { x = rand() % (rect.right - rect.left); y = rand() % (rect.bottom - rect.top); DrawBitmap(globalHdc, "c.bmp", x, y); } } void GameEnd() { } void DrawBitmap(HDC hdcDest, char *filename, int x, int y) { HBITMAP image; BITMAP bm; HDC hdcMem; image = LoadImage(0, "c.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject(image, sizeof(BITMAP), &bm); hdcMem = CreateCompatibleDC(globalHdc); SelectObject(hdcMem, image); BitBlt( globalHdc, x, y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); DeleteDC(hdcMem); DeleteObject((HBITMAP)image); }   I Just wrote this code practicing game loops and basically copied everything the reference book said but there's a red underline on the equals sign and the errors are as follows. Can somebody help?