M4::M4() { obj = M4_GUN; maxAmmo = 40; currentAmmo = 40; remainingAmmo = 80; reloading = false; click = M4_CLICK; gunShot = M4_SHOT; reloadTimer = 800; shootingTimer = dbTimer(); dbLoadObject("weapons//m4.dbo", obj); dbScaleObject(obj,100, 100, 100); //works in percentages e.g. 10 makes the gun 10 times smaller(10% of full size) dbLoadSound("sounds//M4A1 shot.wav", click); dbLoadSound("sounds//m4 click.wav", gunShot); }
void world::setWorld(char input[], int &xCord, int &yCord) { //Used to we our current level or stage if(strcmp(input,"stage1") == 0) { //If it's equal to stage 1: strcpy(currentworld,"stage1"); //Set our current world to stage1 strcpy(character,"character.png"); //Set our character map to character.png dbCreateAnimatedSprite(1,character,4,4,1); //Do our initial setups such as making our sprite sheet usable and setting our x and y coordinates. xCord = 150; yCord = 50; currentX = &xCord; currentY = &yCord; dbLoadImage("carpet.png",2); //Now we can load out images for later. These images can be used by both sprites and actual pictures. dbLoadImage("wall.png",3); dbLoadImage("closet.png",4); dbLoadImage("bunkBed.png",5); dbLoadImage("bedLower.png",6); dbLoadImage("characterTV.png",7); dbLoadImage("computer.png",8); dbLoadImage("mainTV.png",9); dbLoadImage("mainTable.png",10); dbLoadImage("couch.png",11); dbLoadImage("chair.png",12); dbLoadImage("kitchenTable.png",13); dbLoadImage("kitchenFloor.png",14); dbLoadImage("kitchenLeftCounter.png",15); dbLoadImage("kitchenRightCounter.png",16); dbLoadImage("background.png",17); dbLoadImage("doorRight.png",18); dbLoadImage("doorLeft.png",19); dbLoadImage("mainDoor.png",20); dbLoadImage("mainComputer.png",21); dbLoadImage("smallTable.png",22); dbLoadImage("doorFacing.png",23); dbLoadImage("roomDoorFacing.png",24); dbLoadImage("roomDoorSide.png",25); dbLoadSound("doorOpen.wav",1); dbLoadSound("doorClose.wav",2); dbLoadSound("silence.wav",3); dbLoadSound("TV.wav",4); dbLoadSound("mainTV.wav",5); dbLoadSound("mainPC.wav",6); dbLoadSound("characterComp.wav",7); dbLoadSound("sink.wav",8); dbLoadSound("fridge.wav",9); dbLoadSound("locked.wav",10); dbLoadSound("blocked.wav",11); dbLoadSound("beep.wav",12); dbLoadSound("wrong.wav",13); dbLoadSound("correct.wav",14); numOfImages = 25; //Sprites 2 through 17 are used for the walls. For demonstration on how to set sprites and objects, please see sprite 19+ dbSprite(2,80,0,3); dbSizeSprite(2,15,440); setObject(80,0,15,440); dbSprite(3,80,0,3); dbSizeSprite(3,140,15); setObject(80,0,140,15); dbSprite(4,170,98,3); dbSizeSprite(4,15,47); setObject(170,98,15,47); dbSprite(5,220,0,3); dbSizeSprite(5,15,142); setObject(220,0,15,142); dbSprite(6,80,130,3); dbSizeSprite(6,98,135); setObject(80,145,98,120); dbSprite(7,227,0,3); dbSizeSprite(7,90,280); setObject(227,0,90,280); dbSprite(8,220,182,3); dbSizeSprite(8,30,38); setObject(220,182,30,38); dbSprite(9,170,185,3); dbSizeSprite(9,15,15); setObject(170,185,15,15); dbSprite(10,170,240,3); dbSizeSprite(10,15,113); setObject(170,240,15,112); dbSprite(12,220,260,3); dbSizeSprite(12,30,20); setObject(220,260,30,20); dbSprite(13,80,430,3); dbSizeSprite(13,305,15); setObject(80,430,305,15); dbSprite(14,376,280,3); dbSizeSprite(14,9,20); setObject(376,280,9,20); dbSprite(15,376,340,3); dbSizeSprite(15,9,100); setObject(376,340,9,100); dbSprite(16,95,110,4); dbSizeSprite(16,75,20); dbSprite(17,95,25,5); dbSizeSprite(17,35,53); //Whenever you wish to set object collision checking, you can simply use the setObject function. This function takes 4 arguments. The x1 coordinate, the y1 coordinate, the x length, and the y length. Within these boundaries, it is treated as solid material. Characters cannot walk through these coordinates on the screen. //Example: setObject(95,26,33,2) makes an object at x coordinate 95, y coordinate 26, and makes it have a width of 33 pixels and a height of 2 pixels. setObject(95,26,33,2); //Character bed top setObject(95,26,2,50); //Character bed left side setObject(95,74,34,1); //Character bed bottom setObject(193,29,27,34); //CharacterTV dbSprite(19,160,15,8); //Character computer dbSizeSprite(19,28,17); //Makes the image for the sprite stretch to the specifications. The second argument is width, and the third is height. setObject(160,15,28,17); dbSprite(20,265,303,9); //Character Tv (Rotation involved) dbSizeSprite(20,24,37); dbRotateSprite(20,-90); setObject(265,280,36,23); dbSprite(21,263,365,10); //Main table dbSizeSprite(21,40,25); setObject(263,365,40,25); dbSprite(22,95,265,15); //Left counter dbSizeSprite(22,21,90); setObject(95,265,21,66); dbSprite(23,149,265,16); //Right counter dbSizeSprite(23,21,90); setObject(149,265,21,83); setObject(95,384,33,46); //All of this chunk is the kitchen table. One for each. (Round objects to be implemented) setObject(95,381,23,3); setObject(130,388,2,42); setObject(133,391,1,39); setObject(136,394,1,36); setObject(137,396,1,34); setObject(138,397,1,33); setObject(139,399,1,31); setObject(140,402,1,28); dbSprite(24,218,142,18); //Relative room dbSizeSprite(24,9,40); setObject(220,142,9,40); dbSprite(25,218,220,18); //Closet below relative room dbSizeSprite(25,9,40); setObject(220,220,9,40); dbSprite(26,178,145,19); //Upper closet dbSizeSprite(26,9,40); setObject(178,145,7,40); dbSprite(27,178,200,19); //Bathroom dbSizeSprite(27,9,40); setObject(178,200,7,40); dbSprite(28,374,300,20); //Main door dbSizeSprite(28,11,40); setObject(376,300,9,40); dbSprite(29,185,316,21); //Main computer dbSizeSprite(29,16,32); setObject(185,316,16,32); dbSprite(30,360,370,22); //Small table dbSizeSprite(30,12,17); setObject(360,370,12,17); dbSprite(31,352,0,3); //Wall to the right of main closet dbSizeSprite(31,33,280); setObject(352,0,33,280); dbSprite(32,317,0,3); //Wall behind main closet dbSizeSprite(32,35,278); setObject(317,0,35,278); dbSprite(33,317,268,23); //Closet close to door dbSizeSprite(33,35,12); setObject(317,268,35,12); dbSprite(34,185,98,24); //Character door dbSizeSprite(34,35,12); setObject(185,98,35,12); numOfSprites = 34; //Much like the objects, to set an event at a certain coordinate, use the setEvent function. The arguments are the x1 coordinate, the y1 coordinate, the x length, the y length, the argument to be sent to the function, and the actual function name itself. Note: currently, the argument has to be a string. //Example: setEvent(80,24,50,54,"bed",printText) makes an event at the x coordinate 80 and y coordinate 24. It has a width of 50 and a height downward of 54. Whenever and event happens, the text "bed" is sent to the printText function. setEvent(80,24,50,54,"bed",printText); setEvent(80,24,50,54,"40",dimArea); setEvent(193,29,27,34,"characterTV",printText); setEvent(160,15,28,17,"characterComputer",printText); setEvent(265,279,36,24,"familyTV",printText); setEvent(185,316,16,32,"familyComp",printText); setEvent(263,365,40,12,"tableFront",printText); setEvent(263,378,40,12,"tableBack",printText); setEvent(360,370,12,17,"smallTable",printText); setEvent(243,400,80,30,"couch",printText); setEvent(325,400,45,30,"chair",printText); setEvent(317,268,35,12,"mainCloset",printText); setEvent(93,375,55,55,"kitchnTable",printText); setEvent(95,265,21,22,"counter",printText); setEvent(95,288,21,20,"kitchnSink",printText); setEvent(95,309,21,23,"counter",printText); setEvent(149,265,21,20,"fridge",printText); setEvent(149,286,21,20,"counter",printText); setEvent(149,307,21,24,"stove",printText); setEvent(149,332,21,17,"counter",printText); setEvent(178,145,9,40,"upCloset",printText); setEvent(218,142,9,40,"upperRoom",printText); setEvent(178,200,9,40,"bathroom",printText); setEvent(218,220,9,40,"lowCloset",printText); setEvent(185,98,35,12,"roomDoor",changeState); setEvent(376,300,9,40,"mainDoor",passGuess); } }
// Main entry point for the application void DarkGDK ( void ) { dbSyncOn ( ); dbSyncRate ( FRAMES_PER_SECOND ); dbSetWindowOff(); dbSetDisplayMode( SCREEN_WIDTH, SCREEN_HEIGHT, 16 ); dbDisableEscapeKey ( ); dbHideMouse(); dbSetImageColorKey ( 255, 0, 255 ); // Set transparency key for images dbDrawSpritesFirst(); // So that we can draw and write over sprites // Probably not necessary now since we don't actually use DGDK sprite objects dbLoadSound("bullet.wav",1); dbLoadSound("explosion.wav",2); // Load a new map Map *map = new Map(); bool gotmap = map->loadFromFile( "testmap.txt" ); assert( gotmap && "Loading map failed" ); // Set up a camera looking at our map Camera camera; camera.setMap( map ); camera.setScreenPosition( 10, 10 ); camera.setSize( 380, 480 ); // Camera2 Camera camera2; camera2.setMap( map ); camera2.setScreenPosition( 410, 10 ); camera2.setSize( 380, 480 ); camera2.getStateMachine()->changeState( CameraFollowWASDKeysState::getInstance() ); // Set up some enemies for( int i=0; i<NUM_TEST_ENEMIES; i++ ) { Enemy *enemy = new Enemy(); enemy->setPosition( Vector2D(rand()%SCREEN_WIDTH,rand()%SCREEN_HEIGHT) ); // Set up a test path Path *path = new Path(); path->addWaypoint( Vector2D(200.0,200.0) ); path->addWaypoint( Vector2D(400.0,300.0) ); path->addWaypoint( Vector2D(700.0,-30.0) ); path->setLooped(true); enemy->setPath( path ); // Create a new enemy using that path enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() ); //enemy->getStateMachine()->changeState( EnemyCollideWithPlayerState::getInstance() ); //entityManager.registerEntity( enemy ); MessageManager::getInstance()->dispatchMessage(0,0,messageCreateEntity,(i+1)*3,enemy); } dbPerformChecklistControlDevices(); if( dbChecklistString(1) ) dbSetControlDevice( dbChecklistString(1) ); char debugText[100]; // Set up variables to keep track of elapsed time double previousTime = (double)dbTimer(); double currentTime; double elapsedTime; // Set up the target Vector2D target; target.x = 400; target.y = 300; double timeSinceLastSpawn = 10.0; double timeBetweenSpawns = 2.0; bool spacePressedLastFrame = false; Vector2D testPosition(1.0,3.0); Vector2D testHeading(1.0,0.0); Vector2D testSide = testHeading.Perp(); Vector2D testPoint(-1.0,4.0); Vector2D testVector = TransformFromWorldToLocalSpace(testPoint,testHeading,testSide,testPosition); // main loop while ( LoopGDK ( ) ) { // Calculate elapsed time currentTime = (double)dbTimer(); elapsedTime = (currentTime - previousTime)/1000; previousTime = currentTime; MessageManager::getInstance()->update(elapsedTime); // Clear the screen white dbCLS( RGB( 0, 0, 0 ) ); camera.update( 0.0 ); //camera.draw(); camera2.update( 0.0 ); //camera2.draw(); // Spawn a new enemy for testing timeSinceLastSpawn += elapsedTime; if( timeSinceLastSpawn > timeBetweenSpawns ) { timeSinceLastSpawn = 0.0; entityManager.spawnRandomWave(); /* Enemy *enemy = new Enemy(Vector2D(100.0,-10.0)); // Set up a test path Path *path = new Path(); path->addWaypoint( Vector2D(200.0,200.0) ); path->addWaypoint( Vector2D(400.0,300.0) ); path->addWaypoint( Vector2D(700.0,-10.0) ); path->setLooped(false); enemy->setPath( path ); enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() ); entityManager.registerEntity( enemy ); */ } // Update and draw the enemies entityManager.updateAllEntities( elapsedTime ); entityManager.drawAllEntities(); // Reset the first entities position if( dbMouseClick() == 2 ) { Vector2D position( dbMouseX(), dbMouseY() ); Vector2D velocity( 0.0, -20.0 ); //Vector2D velocity = target - position; //velocity.Normalize(); //velocity *= 20.0; Bullet *bullet = new Bullet(position,velocity); entityManager.registerEntity( bullet ); } // Reset the enemies randomly if space pressed if( dbSpaceKey() && spacePressedLastFrame == false ) { spacePressedLastFrame = true; Enemy *enemy = new Enemy(); enemy->setPosition(Vector2D(100.0,-30.0)); // Set up a test path Path *path = new Path(); path->addWaypoint( Vector2D(200.0,200.0) ); path->addWaypoint( Vector2D(400.0,300.0) ); path->addWaypoint( Vector2D(700.0,-30.0) ); path->setLooped(false); enemy->setPath( path ); enemy->getStateMachine()->changeState( EnemyFollowPathThenDieState::getInstance() ); entityManager.registerEntity( enemy ); } if( !dbSpaceKey() ) spacePressedLastFrame = false; // Update the target if( dbMouseClick() == 1 ) { target.x = dbMouseX(); target.y = dbMouseY(); } // Draw the target //DrawTarget( target ); // Put any debugging messages here //sprintf( debugText, "Key code: %d", dbScanCode() ); // For finding keyboard scan codes //sprintf( debugText, "Elapsed time: %f", elapsedTime ); //sprintf( debugText, "Entities: %d FPS: %d", entityManager.getSize(), dbScreenFPS() ); //sprintf( debugText, "%s", dbChecklistString (1) ); //sprintf( debugText, "JoystickY: %d", joystickY ); //sprintf( debugText, "FPS: %d", dbScreenFPS() ); sprintf( debugText, "Score: %d", entityManager.getPlayer()->getScore() ); //sprintf( debugText, "Player Position: %f,%f", entityManager.getPlayer()->getPosition().x, entityManager.getPlayer()->getPosition().y ); //sprintf( debugText, "VectorX: %f VectorY: %f", testVector.x, testVector.y ); //sprintf( debugText, "screenWidth: %d screenHeight: %d", dbScreenWidth(), dbScreenHeight() ); // Print out the debug text dbInk( RGB(0,0,255), RGB(255,255,255) ); dbText( 0, SCREEN_HEIGHT-20, debugText ); // Draw scanlines //drawScanlines(3); // break out if escape has been pressed if ( dbEscapeKey ( ) ) break; // update the contents of the screen dbSync ( ); } // and now everything is ready to return back to Windows return; }