Advertisement Jump to content
  • Advertisement

JoshBaker

Member
  • Content Count

    20
  • Joined

  • Last visited

Community Reputation

100 Neutral

About JoshBaker

  • Rank
    Member
  1. Hi! I have a 2d texture drawing (my car) . Now i want this car to rotate left and right when the buttons are pushed. Since this is a game where its birds eye view, rotation im guessing would only need to be on the X-axis . On top of that , it has to be relative to the players speed. If you imagine a car driving around holding forward and right would cause the car to sort of 'swerve'. Also , how could i make my camera follow my player.x and player.y position? Ive tried various ways and each seems to not work properly. Car: #include <math.h> #include "Car.h" #include "MenuSystem.h" #pragma comment(lib, "d3dx10d.lib") extern MenuSystem gamemenu; extern Car carclass; // variables defined // constructor Car::Car() { playerX = 0; // player x pos playerY = 0; // player y pos playerZ = 0; playerSpeed = 0.0f; // players speed playerMaxSpeed= 0.5f; // players maximum speed playerRotation = 0.000000001f; // player rotation angle } void Car::PlayerMovement() { if ( gamemenu.startOn == true ) { if ( carclass.playerSpeed > carclass.playerMaxSpeed) { playerSpeed = 0.2f; } if (GetAsyncKeyState(VK_UP ) ) { playerSpeed += 0.001f * 0.0001f; playerY += playerSpeed; } if (GetAsyncKeyState(VK_DOWN ) ) { playerY -= 0.001f; } if (GetAsyncKeyState(VK_RIGHT ) ) { //playerX -= 0.001f; playerY -= playerY - sin(playerRotation); } if (GetAsyncKeyState(VK_RIGHT ) ) { playerY -= 0.001f; } } } //void Car::Rotation() //{ // playerX = playerX + cos(playerRotation); // playerY = playerY - sin(playerRotation); // // } Rendering: if ( gamemenu.startOn == true) { //set resources for plane 2 (PLAYER) D3DXMatrixTranslation( &worldMatrix, carclass.playerX, carclass.playerY,2.0 ); worldMatrix = scalingPlayer * worldMatrix ; pWorldMatrixEffectVariable->SetMatrix(worldMatrix); pTextureSR->SetResource( pPlayerTex ); //apply technique pBasicTechnique->GetPassByIndex( p )->Apply( 0 ); pCubeMesh->DrawSubset(0); Camera: // Set up the view and projection matrices //***************************************************************************** const D3DXVECTOR3 camera[] = { D3DXVECTOR3(0.0f, 0.0f, 0.0f), D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR3(0.0f, 1.0f, 0.0f)}; D3DXMatrixLookAtLH(&viewMatrix, &camera[0], &camera[1], &camera[2] ); D3DXMatrixPerspectiveFovLH(&projectionMatrix, (float)D3DX_PI * 0.5f, (float)width/(float)height, 0.1f, 20.0f); D3DX10CreateFont(pD3DDevice, 32, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &mFont); //set shader matrices pViewMatrixEffectVariable->SetMatrix(viewMatrix); pProjectionMatrixEffectVariable->SetMatrix(projectionMatrix);
  2. JoshBaker

    Class confusion?

    Thank you for this , i got it working after including the extern carclass.car Been working on getting rotation to work and camera following for quite sometime. I didn't want to use sleep() but since at this moment of time my keyinput isnt properly done , im having to use sleep otherwise my changing states number goes way to fast(causing it to go through the menu way to fast). In c# i used a keypress as opposed to keydown in things such as the menu.
  3. JoshBaker

    Class confusion?

    I have but im still confused as to why this isnt working?
  4. JoshBaker

    Class confusion?

    Hello please take a look at my code. I want to access variables in certain classes and use them in other situations? Please note most of these class's have been shortened . Main #include <windows.h> #include <tchar.h> #include <stdio.h> #include <vector> using namespace std; #include "dxManager.h" #include "Car.h" #include "MenuSystem.h" /******************************************************************* * Global Variables *******************************************************************/ HWND hWnd; //window handle int windowWidth = 1024; int windowHeight = 768; //directX manager dxManager dx; // Game Menu MenuSystem gamemenu; // Car Class Car carclass; /******************************************************************* * WinMain *******************************************************************/ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { // Set up the application window if ( !initWindow(hWnd, hInstance, windowWidth, windowHeight)) return 0; //set up directx manager if ( !dx.initialize(&hWnd) ) return 0; // Main message loop MSG msg = {0}; while (WM_QUIT != msg.message) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) { TranslateMessage(&msg); DispatchMessage(&msg); } dx.renderScene(); gamemenu.Menu(); carclass.PlayerMovement(); carclass.Rotation(); } return (int) msg.wParam; } Car Header // C++ header created by Josh Baker for player. #ifndef CAR #define CAR #include <windows.h> #include <d3d10.h> #include <d3dx10.h> #pragma comment(lib, "d3dx10d.lib") class Car { /******************************************************************* * Methods ********************************************************************/ public: //constructor and destructor Car(); ~Car(); static float playerX; static float playerY ; float playerSpeed ; float playerMaxSpeed ; float playerRotation; void PlayerMovement(); void Rotation(); }; #endif Car Class #include <math.h> #include "Car.h" #include "MenuSystem.h" #pragma comment(lib, "d3dx10d.lib") // variables defined // constructor Car::Car() { playerX = 0.0f; // player x pos playerY = 0.0f; // player y pos playerSpeed = 0.0f; // players speed playerMaxSpeed = 0.5f; // players maximum speed playerRotation = 0.0f; // player rotation angle } void Car::PlayerMovement() { if (MenuSystem::startOn == true ) { if (playerSpeed > playerMaxSpeed) { playerSpeed = 0.2f; } if (GetAsyncKeyState(VK_UP ) ) { playerSpeed += 0.001f * 0.0001f; playerY += playerSpeed; } if (GetAsyncKeyState(VK_DOWN ) ) { playerY -= 0.001f; } if (GetAsyncKeyState(VK_RIGHT ) ) { playerX -= 0.001f; } if (GetAsyncKeyState(VK_RIGHT ) ) { playerY -= 0.001f; } } } void Car::Rotation() { playerX = playerX + cos(playerRotation); playerY = playerY - sin(playerRotation); } Menu.H // C++ header created by Josh Baker for player. #ifndef MENUSYSTEM #define MENUSYSTEM #include <windows.h> #include <d3d10.h> #include <d3dx10.h> #pragma comment(lib, "d3dx10d.lib") class MenuSystem { /******************************************************************* * Methods ********************************************************************/ public: //constructor and destructor MenuSystem(); ~MenuSystem(); int statenumber; bool creditsOn; bool startOn; bool settingsOn; bool menuOn; void Menu(); void MenuState(); }; #endif Menu.cpp #include <math.h> #include "MenuSystem.h" #pragma comment(lib, "d3dx10d.lib") SHORT WINAPI GetAsyncKeyState // Gets Keyinput ( __in int vKey ); void MenuSystem::Menu() { if (menuOn == true) { if (GetAsyncKeyState(VK_DOWN)) { statenumber += 1; Sleep(200); } if (GetAsyncKeyState(VK_UP )) { MenuSystem::statenumber -= 1; Sleep(200); } if(statenumber > 3) // fixes off menu { statenumber = 0; } if(statenumber < 0) // fixes off menu { statenumber = 3; } if (GetAsyncKeyState(VK_RETURN) && creditsOn == false && statenumber == 2) { creditsOn = true; } if (GetAsyncKeyState(VK_RETURN) && startOn == false && statenumber == 0) { startOn = true; } if (startOn == true) { menuOn = false; } if (GetAsyncKeyState(VK_RETURN) && statenumber == 3) { PostQuitMessage(0); } if (GetAsyncKeyState(VK_RETURN) && settingsOn == false && statenumber == 1) { settingsOn = true; } if (GetAsyncKeyState(VK_ESCAPE) && creditsOn == true) { creditsOn = false; } if (startOn == true && GetAsyncKeyState(VK_ESCAPE)) { startOn = false; } } } Draw Function void dxManager::renderScene() { pD3DDevice->ClearRenderTargetView( pRenderTargetView, D3DXCOLOR(0.5,0.5,0.5,1) ); pD3DDevice->ClearDepthStencilView( pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0 ); D3DXMATRIX scaling; D3DXMatrixScaling(&scaling, 2.7f, 2.0f, 2.0f); D3DXMATRIX scalingPlayer; D3DXMatrixScaling(&scalingPlayer, 0.1f, 0.2f, 0.1f); //draw for( UINT p = 0; p < techDesc.Passes; p++ ) { if (MenuSystem::startOn == false) { //set resources for plane 1 (MENU) D3DXMatrixTranslation( &worldMatrix, 0,0,2 ); worldMatrix = scaling * worldMatrix ; pWorldMatrixEffectVariable->SetMatrix(worldMatrix); pTextureSR->SetResource( pMenuTex ); //apply technique pBasicTechnique->GetPassByIndex( p )->Apply( 0 ); pCubeMesh->DrawSubset(0); } if (MenuSystem::startOn == true) { //set resources for plane 2 (PLAYER) D3DXMatrixTranslation( &worldMatrix, Car::playerX,Car::playerY,2.0 ); worldMatrix = scalingPlayer * worldMatrix ; pWorldMatrixEffectVariable->SetMatrix(worldMatrix); pTextureSR->SetResource( pPlayerTex ); //apply technique pBasicTechnique->GetPassByIndex( p )->Apply( 0 ); pCubeMesh->DrawSubset(0); //set resources for plane 3 (HUD) D3DXMatrixTranslation( &worldMatrix, 0,0,2 ); worldMatrix = scaling * worldMatrix ; pWorldMatrixEffectVariable->SetMatrix(worldMatrix); pTextureSR->SetResource( pGameHUD ); //apply technique pBasicTechnique->GetPassByIndex( p )->Apply( 0 ); pCubeMesh->DrawSubset(0); } RECT rc = { 100, 100, 400, 400}; Hope you can help thanks
  5. Hi , Im trying to make my program detect a 'Keypress' not a keydown. I have it working although beacuse its detecting keydown and not keypress it repeats what i want it to do extremly fast. In Xna i had this problem but fixed it simply by adding a second keyboard variabe for the previous key press abit like this pseudo: if (keypress = up && !prevkeypress = up) { sprite.x +=1; } prevkeypress = keypress; SHORT WINAPI GetAsyncKeyState // keyinput ( __in int vKey ); if (GetAsyncKeyState(VK_DOWN)) { //statenumber += 1; } This detects keydown , but i just want keypress?
  6. JoshBaker

    Texture2D cropping && Array checking

    Okay my texture is a 'speedo' dial ... I wish to crop it down so only 'one green' bar is shown . Instead it shrinks it down like so - Uploaded with ImageShack.us Once i know how to do it once . I could do it to my health too. shrinking down the rectangle's width does not crop my texture , it shrinks it to fit... I do not want this!
  7. [font="arial, sans-serif"] I current have an array of 45 enemies.. These enemies are drawn , animated , updated and what have you. When the enemies health = 0 , it dies... So if (aEnemy.enemyHealth <= 0) // if enemy health is equal or below 0 kill the enemy { aEnemy.enemyAlive = false; } The enemy is drawn when this value is true and when false , it dies.. Now how would i check that every enemy is the array has the value of false... The reason i want to do this is because i want to check the player has killed all the enemies before progressing to the next wave.. As for texture2d clipping... how can i do it? I have a health bar implemented and it strechs up and down (using a rectangle) depending on the players health.. Rather than stretching it up and down i wish to clip the image or 'crop' the texture... Ive tried this draw method overload spriteBatch.Draw(FullSpeedo, new Rectangle(770, 600, FullSpeedo.Width, FullSpeedo.Height), new Rectangle(770, 600, FullSpeedo.Width / 5, FullSpeedo.Height), Color.White); But it doesnt do anything... Ive also looked at the scissorrect? but i dont quite understand how to properly use it . If you could help it would be good! [/font]
  8. JoshBaker

    Awful hit collision?

    Unfortunately, that's not a very technical description of a problem. It sounds like you have some logic interaction between the space key being pressed and other keypresses or mouse-clicks (you don't mention what "scroll up and down" means or how it's done). Perhaps if you describe what you expect to happen and what actually happens (other than "it doesn't work"), and post some code showing how you get key/mouse information, etc., we can help you find the problem. It would also be helpful if you describe what you've done to determine where the error is. [/quote] Okay the game is a side scoller shoot em up. Heres a picture of an example Uploaded with ImageShack.us Basically if i hold space (which makes it fire each time) my hit collision doesnt work properly... Heres my space input: if (keyboard.IsKeyDown(Keys.Space) && (FireRate >= 100) && (RedFireMode == true)) { BulletPosition = new Vector2(SpritePosition.X, SpritePosition.Y); laserSound.Play(); animatedBullet.currentFrame = 0f; FireRate = 0; } fire rate if (FireRate >= 100) { FireRate = 100; } Animation if (FireRate < 100 && RedFireMode == true ) { Vector2 beamOffset = FixOrigin(SpritePosition); beamOffset.X += 38; beamOffset.Y -= 10; // fixes laser offset animatedBullet.Draw(spriteBatch, beamOffset); animatedBullet.currentFrame = animatedBullet.currentFrame + 0.5f; if (animatedBullet.currentFrame > 20) { FireRate = 100; // new fire rate system . once frame is greater than 20 do this } }
  9. My hit collision is just dreadful , i cant see why ? Basically the hit collision works fine when i press space , then let go and press space again to hit enemies... But when i hold space down and scroll up and down it doesnt work?! :| public void EnemyCollision() { for (i = 0; i < 20; i++) if (Math.Abs(BulletPosition.Y - aEnemy.y) < badShip.Height && RedFireMode == true && aEnemy.enemyAlive == true) // hit collision for red enemies { aEnemy.enemyAlive = false; aEnemy.showingScore = true; // these 2 lines of code show the faded 100 points when you kill them aEnemy.scoreFrame = 0; if (aEnemy.enemyAlive == false) { BulletPosition.X = -5000; BulletPosition.Y = -5000; playerScore += 100; enemyExplosion.Play();
  10. But where would i get the particle system from in the first place?
  11. Hi , How would i go about implementing cool particle explosions like in geometry wars?... [font=arial, verdana, tahoma, sans-serif][size=2] I dont have much time as this is a uni project... But either way how would i go about doing cool explosions like that? Also when the enemies get hit... there score appears and it gradually fades away.. . How would i go about doing this?! Thanks [/font]
  12. JoshBaker

    Problems with my 2D animation

    That worked thanks! But im still having problems with having two things animate at the same time? :| Anyone had this problem before...
  13. JoshBaker

    Problems with my 2D animation

    Sorry to bring this back up. But i never fixed my problem... when one of my animating.update is occuring , the other doesnt work... Uploaded with ImageShack.us Here the shield is animating , but when i fire , my laser doesnt animate? if (powerCollision == true && powerUp1Collected == true) { animatedShield.Update(); } shield animating... if (FireRate < 100 && RedFireMode == true) { animatedBullet.Update(); } Firing animating... These do not work together?... for (i = 0; i < 20; i++) { if (aEnemy.x > BulletPosition.X && aEnemy.y > BulletPosition.Y && aEnemy.y < BulletPosition.Y && RedFireMode == true && aEnemy.enemyAlive == true) { aEnemy.enemyAlive = false; BulletPosition.X = -5000; BulletPosition.Y = -5000; } This code if for my enemy collision... My bullet only fires on the X axis ( its a laser...) yet the collision is awful and don't know why? Please help!
  14. JoshBaker

    Problems with my 2D animation

    Okay i added a timeinterval and made the class add a frame every time the counter reached 500 milliseconds. This is making the Animation working good although now ive hit another problem... As soon as i have more than 1 thing animating (deriving from the same class) the game decides to stop animating the previous sprite sheet... talk about problem after problem :| ill post code as soon as im back from Uni ...
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!