int main( int argc, char* args[] ) { //Quit flag bool quit = false; Sprite mySprite(40, 40, 0, 40, 40); //The letter Letter myLetter; //The letterspace Letterspace myLetterspace( 600, 50); //The frame rate regulator Timer fps; //Initialize if( init() == false ) { return 1; } //Load the files if ( level_init() == false ) { return 1; } //While the user hasn't quit while( quit == false ) { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the letter myLetter.handle_input(); mySprite.input(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Move the letter myLetter.move(); mySprite.move(); //Fill the screen white SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); level_files(); //Show the letterspace myLetterspace.show(); myLetter.init("../media/a.png"); // mySprite.init(); //Show the letter on the screen myLetter.show(); mySprite.show(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //End the level level_end(); //mySprite.~Sprite(); //Clean up clean_up(); return 0; }
int main(int argc, char* argv[]) { Screen::Instance().Open(800,600,false); Screen::Instance().Refresh(); InputManager& myInputManager = InputManager::Instance(); myInputManager.Init(); double angle = 0; int imgHeight = 0; int imgWidth = 0; double scale=0.5; double scaleInc=2.0; int mouseX=400; int mouseY=300; int movementX=400; int movementY=300; double speedX=0.0; double speedY=0.0; myInputManager.CreateVirtualButton("ARRIBA",Key_W); myInputManager.CreateVirtualButton("ABAJO",Key_S); myInputManager.CreateVirtualButton("IZQUIERDA",Key_A); myInputManager.CreateVirtualButton("DERECHA",Key_D); myInputManager.CreateVirtualAxis("EJEX", Mouse_Right, Mouse_Left); myInputManager.CreateVirtualAxis("EJEY", Mouse_Up, Mouse_Down); //TAREA: Cargar la imagen "data/ball.png" //Image* myImage = ResourceManager::Instance().LoadImage("data/ball.png"); //Image* myImage = ResourceManager::Instance().LoadImage("data/soccer_npot.png"); //Image* myImage = ResourceManager::Instance().LoadImage("data/alien.png"); Image* myImage = new Image("data/alien.png"); imgHeight=myImage->GetHeight(); imgWidth=myImage->GetWidth(); //TAREA: Centrar imagen myImage->SetMidHandle(); Sprite mySprite(myImage); mySprite.SetX(400); mySprite.SetY(300); glfwSetMousePos(mouseX,mouseY); while(Screen::Instance().IsOpened() && glfwGetKey(GLFW_KEY_ESC)!=GLFW_PRESS) { XINPUT_STATE state; ZeroMemory(&state, sizeof(XINPUT_STATE));//inicializa una funcion a 0s XInputGetState(0,&state); if (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) { Beep(5000,100); Beep(4000,100); Beep(3000,100); } if (state.Gamepad.wButtons & XINPUT_GAMEPAD_B) { XINPUT_VIBRATION vibration; ZeroMemory( &vibration, sizeof(XINPUT_VIBRATION)); vibration.wLeftMotorSpeed=0; vibration.wLeftMotorSpeed=60000; XInputSetState(0,&vibration); } float xPad = (float) state.Gamepad.sThumbLX / 32768; float yPad = (float) state.Gamepad.sThumbLY / 32768; if (myInputManager.IsKeyPressed(Key_K)) { Beep(3000,100); } /////////////////////////////////////////////////////////////// // BUTTON DOWN if(myInputManager.IsVirtualButtonDown("ARRIBA")) { } if(myInputManager.IsVirtualButtonDown("ABAJO")) { } if(myInputManager.IsVirtualButtonDown("IZQUIERDA")) { //mySprite.RotateTo(30,40); } if(myInputManager.IsVirtualButtonDown("DERECHA")) { //mySprite.RotateTo(-30,40); } // BUTTON PRESSED if(myInputManager.IsVirtualButtonPressed("ARRIBA")) { if (speedY>-20.0) speedY=speedY-0.7; } if(myInputManager.IsVirtualButtonPressed("ABAJO")) { if (speedY<20.0) speedY=speedY+0.7; } if(myInputManager.IsVirtualButtonPressed("IZQUIERDA")) { //mySprite.RotateTo(30,40); if (speedX>-20.0) speedX=speedX-1; } if(myInputManager.IsVirtualButtonPressed("DERECHA")) { //mySprite.RotateTo(-30,40); if (speedX<20.0) speedX=speedX+1; } if( myInputManager.IsVirtualButtonPressed("IZQUIERDA") &&(myInputManager.IsVirtualButtonPressed("DERECHA"))) { //mySprite.RotateTo(0,200); speedX=speedX*4900/5000; } if( !myInputManager.IsVirtualButtonPressed("IZQUIERDA") &&(!myInputManager.IsVirtualButtonPressed("DERECHA"))) { speedX=speedX*4900/5000; } if ( !myInputManager.IsVirtualButtonPressed("ARRIBA")) if (speedY<15) speedY=speedY+0.3; // BUTTON UP if(myInputManager.IsVirtualButtonUp("ARRIBA")) { speedY=speedY*3/4; } if(myInputManager.IsVirtualButtonUp("ABAJO")) { speedY=speedY*3/4; } if(myInputManager.IsVirtualButtonUp("IZQUIERDA")){} //mySprite.RotateTo(0,40); if(myInputManager.IsVirtualButtonUp("DERECHA")){} //mySprite.RotateTo(0,40); /////////////////////////////////////////////////////////////// if (myInputManager.GetVirtualAxis("EJEX")==1.0) { mySprite.RotateTo(-30,50); speedX=speedX+1; } else if (myInputManager.GetVirtualAxis("EJEX")==-1.0) { mySprite.RotateTo(30,50); speedX=speedX-1; } else mySprite.RotateTo(0,200); if(movementX<-35) mySprite.SetX(840); if(movementX>840) mySprite.SetX(-35); movementY=(int)(mySprite.GetY()+speedY); if (movementY>=575) { mySprite.RotateTo(0,200); movementY=575; speedX=0; } else { if(movementY<=40) movementY=40; movementX=(int)(mySprite.GetX()+speedX); } if ((movementX!=mySprite.GetX())||(movementY!=mySprite.GetY())) mySprite.MoveTo(movementX,movementY,speedX*speedX/2,speedY*speedY/2); //TAREA: Limpiar pantalla y dibujar la imagen Renderer::Instance().Clear(); mySprite.Render(); //Refrescamos la pantalla*/ mySprite.Update(Screen::Instance().ElapsedTime(),NULL); Screen::Instance().Refresh(); myInputManager.Update(); } ResourceManager::Instance().FreeResources(); return 0; }