Example #1
3
//////////////////////////////////////////////////////////////////
// checkKeyboardMenu
//    Checks the keyboard for the menu options
//
//
// Returns:
//    void
//
void checkKeyboardMenu() {

    u8 *pvideo;


    delay(20);

    if (( cpct_isKeyPressed(Key_1)) || (((cpct_isKeyPressed(keys.fire) || (cpct_isKeyPressed(Joy0_Fire1)))  && (selectedOption == 0)))) {

        drawMarker();
        selectedOption = 0;
        drawMarker();

        waitKeyUp(Key_1);

        keys.up    = redefineKey("UP");
        keys.down  = redefineKey("DOWN");
        keys.left  = redefineKey("LEFT");
        keys.right = redefineKey("RIGHT");
        keys.fire  = redefineKey("FIRE");
        keys.pause = redefineKey("PAUSE");
        keys.abort = redefineKey("ABORT");
        //keys.music = redefineKey("MUSIC");

        pvideo = cpct_getScreenPtr(CPCT_VMEM_START, 8, 154);
        cpct_drawSolidBox(pvideo, #0, 64, FONT_H);

    }
Example #2
0
////////////////////////////////////////////////////////////////////////////////
// Scan Keyboard and update user actions as requested by the user
//
void updateUser(TCharacter* user) {
   // Scan Keyboard
   cpct_scanKeyboard_f();

   //
   // Check possible keys to press, and do actions
   //

   // KEY = Cursor Up, ACTION = Jump (only when not already jumping)
   if ( cpct_isKeyPressed(Key_CursorUp) && user->status != es_jump ) {
      performAction(user, es_jump, user->side);    // Perform the action of jumping
      getRandomUniform(user->entity.nx);           // Use X coordinate of the user when jumping to forward update the random seed
   
   // KEY = Cursor Right, ACTION = Walk Right
   } else if ( cpct_isKeyPressed(Key_CursorRight) )
      performAction(user, es_walk, s_right);       // Move player to the right

   // KEY = Cursor Left, ACTION = Walk Left
   else if ( cpct_isKeyPressed(Key_CursorLeft) ) 
      performAction(user, es_walk, s_left);        // Move player to the left

   // KEY = Cursor Down, ACTION = Move Floor
   else if ( cpct_isKeyPressed(Key_CursorDown) ) 
      performAction(user, es_moveFloor, user->side); // Enable moving floor

   // KEY = None pressed, ACTION = Change user to static
   else 
      performAction(user, es_static, user->side);
}
Example #3
0
/*MENU*/
int menu(){
   u8* memptr;
   int init = 50;
   int pushed =0;
   int cont =0;
   cpct_clearScreen(0);

   memptr = cpct_getScreenPtr(VMEM,10,10);
   cpct_drawSprite(portada1,memptr,60,60);

   //Opciones
   memptr = cpct_getScreenPtr(VMEM,20,90);
   cpct_drawStringM0("Nueva Partida",memptr,1,0);

   memptr = cpct_getScreenPtr(VMEM,20,110);
   cpct_drawStringM0("Creditos",memptr,1,0);

   memptr = cpct_getScreenPtr(VMEM,20,130);
   cpct_drawStringM0("Constroles",memptr,1,0);

   memptr = cpct_getScreenPtr(VMEM,20,150);
   cpct_drawStringM0("Salir",memptr,1,0);

    /*memptr = cpct_getScreenPtr(VMEM,18,180);
   cpct_drawStringM0("Pulsa Intro",memptr,4,5);*/

   //Indicador
   while(1){

      cpct_scanKeyboard();
      if(cpct_isKeyPressed(Key_CursorDown) && cont > 150){
        cpct_drawSolidBox(memptr, 0, 2, 8);
        if(pushed<3) pushed ++;
        cont =0;
      }
      if(cpct_isKeyPressed(Key_CursorUp) && cont > 150){
        cpct_drawSolidBox(memptr, 0, 2, 8);
        if(pushed>0) pushed --;
        cont = 0;
      }

      switch (pushed){
        case 0: init = 90;break;
        case 1: init = 110;break;
        case 2: init = 130;break;
        case 3: init = 150;break;
      }
      memptr = cpct_getScreenPtr(VMEM,15,init);
      cpct_drawSprite(marcador,memptr, 2, 8);
      if(cpct_isKeyPressed(Key_Space)){
        switch (pushed){
        case 0: return 1;break;
        case 1: return 2;break;
        case 2: return 3;break;
        case 3: return 0;break;
      }
      }
      cont++;
   }
}
Example #4
0
////////////////////////////////////////////////////////////////////////////////
// Waits for a key to be pressed, but from a previous state of not being pressed
//
void wait4Key(cpct_keyID key) {
   do
      cpct_scanKeyboard_f();
   while( ! cpct_isKeyPressed(key) );
   do
      cpct_scanKeyboard_f();
   while( cpct_isKeyPressed(key) );
}
Example #5
0
void mainMenu() {
		u8 option=0;
		cpct_etm_setTileset2x4(g_tile_tileset_bg);
		cpct_etm_drawTilemap2x4_f(MAP_WIDTH_TILES, MAP_HEIGHT_TILES, SCR_VMEM, g_background);

		cpct_drawSprite (g_tile_titulo, getScreenPosition(5, 2), 32, 16);
		cpct_drawStringM0 ("PLAY GAME", getScreenPosition(5, 5), 15, 7);
		cpct_drawStringM0 ("CONTROLS", getScreenPosition(5, 7), 15, 7);
		cpct_drawStringM0 ("CREDITS", getScreenPosition(5, 9), 15, 7);

		initScroll();
		initPlayer();
		cpct_scanKeyboard_f ();
		do {
		    waitNVSYNCs(3);
			cpct_akp_musicPlay();

			Road();
			drawPlayer();
			if ( cpct_isKeyPressed (Key_CursorUp) && option != 0) {
				--option;
			}
			else if ( cpct_isKeyPressed (Key_CursorDown) && option != 2) {
				++option;
			}

			switch (option) {
				case 0:
					cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 7), 4, 8);
					cpct_drawSprite(sprite_skate, getScreenPosition(3, 5), 4, 8);
					break;
				case 1:
					cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 5), 4, 8);
					cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 9), 4, 8);
					cpct_drawSprite(sprite_skate, getScreenPosition(3, 7), 4, 8);
					break;
				case 2:
					cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 7), 4, 8);
					cpct_drawSprite(sprite_skate, getScreenPosition(3, 9), 4, 8);
					break;
			}
			cpct_scanKeyboard_f ();
//			waitNVSYNCs(5);
	} while (!cpct_isKeyPressed(Key_Return));

		switch (option) {
    		case 0:	playMenu();
				break;
    		case 1: 
				gameScene=CONTROLSSCREEN;
				break;
		    case 2: 
				gameScene=CREDITSSCEENE;
				break;
		}
}
Example #6
0
void playMenu() {
		u8 option=0;

		cpct_etm_setTileset2x4(g_tile_tileset_bg);
		cpct_etm_drawTilemap2x4_f(MAP_WIDTH_TILES, MAP_HEIGHT_TILES, SCR_VMEM, g_background);

		cpct_drawSprite (g_tile_titulo, getScreenPosition(5, 2), 32, 16);
		cpct_drawStringM0 ("PLAY GAME", getScreenPosition(5, 5), 15, 7);
		cpct_drawStringM0 ("INFINITY MODE", getScreenPosition(6, 7), 15, 7);
		cpct_drawStringM0 ("LEVELS MODE", getScreenPosition(6, 9), 15, 7);

		initScroll();
		initPlayer();
		cpct_scanKeyboard_f ();
		do {
			waitNVSYNCs(3);
			cpct_akp_musicPlay();
			Road();
			drawPlayer();
			if ( cpct_isKeyPressed (Key_Esc)) {
				gameScene=MENUSCREEN;
				return;
			}
			else if ( cpct_isKeyPressed (Key_CursorUp) && option != 0) {
				--option;
			}
			else if ( cpct_isKeyPressed (Key_CursorDown) && option != 1) {
				++option;
			}

			switch (option) {
				case 0:
					cpct_drawSprite(g_tile_sky_blue, getScreenPosition(4, 9), 4, 8);
					cpct_drawSprite(sprite_skate, getScreenPosition(4, 7), 4, 8);
					break;
				case 1:
					cpct_drawSprite(g_tile_sky_blue, getScreenPosition(4, 7), 4, 8);
					cpct_drawSprite(sprite_skate, getScreenPosition(4, 9), 4, 8);
					break;
			}
			cpct_scanKeyboard_f ();
//			waitNVSYNCs(5);
	} while (!cpct_isKeyPressed(Key_Return));

		switch (option) {
			case 0:
				cpct_akp_stop();
				gameScene=PLAYGAMESCREEN;
				break;
			case 1:
				cpct_akp_stop();
				gameScene=NEXTLEVELSCREEN;
				break;
		}
}
Example #7
0
/////////////////////////////////////////////////////////////////////////////////
// Wait for a given key to be pressed
//
void wait4Key(cpct_keyID key) {
   // First, if the key is already pressed, wait for 
   // it being released
   do
      cpct_scanKeyboard_f();
   while(cpct_isKeyPressed(key));

   // And now, wait for the key being pressed again
   do
      cpct_scanKeyboard_f();
   while(!cpct_isKeyPressed(key));
}
Example #8
0
/////////////////////////////////////////////////////////////////////////////////
// Read User Keyboard Input and do associated actions
//
i16 wait4KeyboardInput(){
   // Read keyboard continuously until the user perfoms an action
   while(1) {
      // Scan Keyboard
      cpct_scanKeyboard_f(); 

      // Check user keys for controlling scroll. If one of them is pressed
      // return the associated scroll offset.
      if      (cpct_isKeyPressed(Key_CursorRight)) return  1;
      else if (cpct_isKeyPressed(Key_CursorLeft))  return -1;
   }
}
Example #9
0
//
// EXAMPLE: Measuring free cycles after moving an sprite
//
void main(void) {
   u8  i;                        // Loop index
   u8  x=0, y=0;                 // Sprite coordinates (in bytes)
   u8* pvideomem = (u8*)0xC000;  // Sprite initial video memory byte location (where it will be drawn)
   u16 avc = 0;                  // Available cycles until next VSYNC, after all main loop calculations

   // First, disable firmware to prevent it from intercepting our palette and video mode settings (and,
   // at the same time, winning some speed not having to process firmware code at every interrupt)
   cpct_disableFirmware();
   // Set palette and Screen Border (transform firmware to hardware colours and then set them)
   cpct_fw2hw     (G_palette, 4);
   cpct_setPalette(G_palette, 4);
   cpct_setBorder (G_palette[1]);
   // Ensure MODE 1 is set
   cpct_setVideoMode(1);

   // Main Loop
   while(1) {
      // First, wait VSYNC monitor signal to synchronize the loop with it. We'll start doing
      // calculations always at the same time (when VSYNC is first detected)
      cpct_waitVSYNC();

      // Scan Keyboard and change sprite location if cursor keys are pressed
      cpct_scanKeyboard_f();
      if      (cpct_isKeyPressed(Key_CursorRight) && x <  80 - SPR_W) { x++; pvideomem++; }
      else if (cpct_isKeyPressed(Key_CursorLeft)  && x >   0        ) { x--; pvideomem--; }
      if      (cpct_isKeyPressed(Key_CursorUp)    && y >   0        ) { pvideomem -= (y-- & 7) ? 0x0800 : 0xC850; }
      else if (cpct_isKeyPressed(Key_CursorDown)  && y < 200 - SPR_H) { pvideomem += (++y & 7) ? 0x0800 : 0xC850; }

      // Draw the sprite at its new location on screen. 
      // Sprite automatically erases previous copy of itself on the screen because it moves 
      // 1 byte at a time and has a 0x00 border that overwrites previous colours on that place
      cpct_drawSprite(G_death, pvideomem, SPR_W, SPR_H);
      
      // Wait to next VSYNC signal, calculating the amount of free cycles (time we wait for VSYNC)
      // As documented on <cpct_count2VSYNC>, function returns number of loop iterations (L), and 
      // cycles shall be calculated doing 22 + 34*L
      avc = 22 + 34 * cpct_count2VSYNC();

      // Print 5 digits on the upper right corner of the screen, 
      // with the amount of free cycles calculated in previous step. 
      // Digits will be printed at screen locations (0xC046, 0xC048, 0xC04A, 0xC04C, 0xC04E)
      for(i=0; i<5; i++) {
         u8 digit = '0' + (avc % 10);
         cpct_drawCharM1_f((void*)(0xC04E - 2*i), 3, 0, digit);
         avc /= 10;
      }
   }
}
Example #10
0
void credits() {
	cpct_memset(SCR_VMEM, 0, 0x4000);
	cpct_drawStringM0 ("CREDITS", getScreenPosition(6, 0), 15, 0);

	cpct_drawStringM0 ("DEVELOPERS", getScreenPosition(5, 3), 15, 0);
	cpct_drawStringM0 ("Cesar Ivorra Oliver", getScreenPosition(1, 5), 15, 0);
	cpct_drawStringM0 ("Alex Almira Molla", getScreenPosition(1, 7), 15, 0);

	cpct_drawStringM0 ("GAME POWERED BY", getScreenPosition(2, 11), 15, 0);
	cpct_drawStringM0 ("CPCtelera", getScreenPosition(5, 13), 15, 0);

	cpct_drawStringM0 ("SPECIAL THANKS", getScreenPosition(3, 18), 15, 0);
	cpct_drawStringM0 ("Francisco Gallego", getScreenPosition(1, 20), 15, 0);

	cpct_drawStringM0 ("Press Space", getScreenPosition(4, 23), 15, 0);
	cpct_drawStringM0 ("to go main menu", getScreenPosition(2, 24), 15, 0);
	cpct_scanKeyboard_f ();
	while (!cpct_isKeyPressed(Key_Space)) {
		cpct_waitVSYNC();
		cpct_akp_musicPlay();

		cpct_scanKeyboard_f ();
	}
	gameScene=MENUSCREEN;
}
Example #11
0
/* CREDITOS */
void credits(){
u8* memptr;
  cpct_clearScreen(0);

  memptr = cpct_getScreenPtr(VMEM, 18, 30); 
  cpct_drawStringM0("Grupo Pyxis", memptr, 1, 0); 

  memptr = cpct_getScreenPtr(VMEM, 23, 60); 
  cpct_drawStringM0("Miembros:", memptr, 1, 0); 
  
  memptr = cpct_getScreenPtr(VMEM, 10, 80); 
  cpct_drawStringM0("Alberto Martinez", memptr,2, 0); 
  memptr = cpct_getScreenPtr(VMEM, 27, 95); 
  cpct_drawStringM0("Martinez", memptr,2, 0); 
  
  memptr = cpct_getScreenPtr(VMEM, 13, 115); 
  cpct_drawStringM0("Josep Domenech", memptr,2, 0);
  memptr = cpct_getScreenPtr(VMEM, 27, 125); 
  cpct_drawStringM0("Mingot", memptr, 2, 0);  

  memptr = cpct_getScreenPtr(VMEM, 12, 175); 
  cpct_drawStringM0("Pulsa espacio", memptr, 1, 0); 



  while (1){
    cpct_scanKeyboard_f();
     if(cpct_isKeyPressed(Key_Space)) {

        return;
      }

   }
}
Example #12
0
/* Controles */
void controles(){
  u8* memptr;
  cpct_clearScreen(0);

  memptr = cpct_getScreenPtr(VMEM, 23, 60); 
  cpct_drawStringM0("Controles:", memptr, 1, 0); 
  
  memptr = cpct_getScreenPtr(VMEM, 11, 80); 
  cpct_drawStringM0("Movimiento: ", memptr, 2, 0); 
  memptr = cpct_getScreenPtr(VMEM, 27, 95); 
  cpct_drawStringM0("Flechas", memptr, 2, 0); 
  
  memptr = cpct_getScreenPtr(VMEM, 13, 115); 
  cpct_drawStringM0("Esc: Menu", memptr, 2, 0); 
  memptr = cpct_getScreenPtr(VMEM, 13, 130); 
  cpct_drawStringM0("Disparar: X", memptr, 2, 0); 

  memptr = cpct_getScreenPtr(VMEM, 12, 175); 
  cpct_drawStringM0("Pulsa espacio", memptr, 1, 0); 

   while (1){
    cpct_scanKeyboard_f();
     if(cpct_isKeyPressed(Key_Space)) {

        return;
      }

   }
}
Example #13
0
///////////////////////////////////////////////////////////////
/// EM_checkUserArrows
///   Checks if the user is pressing arrows and anotates it
///////////////////////////////////////////////////////////////
void EM_checkUserArrows(TEntity* e) {
   u8 nextAction = 0;
   
   // Interpret action requested by the user (Keyboard is read on interrupt)
   if (cpct_isKeyPressed(Key_CursorLeft)) {
      nextAction |= A_MoveLeft;
   } else if (cpct_isKeyPressed(Key_CursorRight)) {
      nextAction |= A_MoveRight;
   }
   if (cpct_isKeyPressed(Key_CursorUp)) {
      nextAction |= A_MoveUp;
   } else if (cpct_isKeyPressed(Key_CursorDown)) {
      nextAction |= A_MoveDown;
   }

   // Set next action for hero
   e->nextAction = nextAction;
}
Example #14
0
//
// MAIN: Using keyboard to move a sprite example
//
void main(void) {
   u8 x=20;                     // Sprite horizontal coordinate
   u8 lookingAt = LOOK_RIGHT;   // Know where the sprite is looking at 
   u8 nowLookingAt = lookingAt; // New looking direction after keypress

   // Initialize the Amstrad CPC
   initialize();

   // 
   // Infinite moving loop
   //
   while(1) {
      u8* pvideomem; // Pointer to video memory

      // Scan Keyboard (fastest routine)
      // The Keyboard has to be scanned to obtain pressed / not pressed status of
      // every key before checking each individual key's status.
      cpct_scanKeyboard_f();

      // Check if user has pressed a Cursor Key and, if so, move the sprite if
      // it will still be inside screen boundaries
      if (cpct_isKeyPressed(Key_CursorRight) && x < (SCR_W - SP_W) ) {
         ++x;
         nowLookingAt = LOOK_RIGHT;
      } else if (cpct_isKeyPressed(Key_CursorLeft)  && x > 0) {
         --x; 
         nowLookingAt = LOOK_LEFT;
      }

      // Check if we have changed looking direction      
      if (lookingAt != nowLookingAt) {
         lookingAt = nowLookingAt;
         cpct_hflipSpriteM0(SP_W, SP_H, g_spirit);
      }

      // Get video memory byte for coordinates x, y of the sprite (in bytes)
      pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, x, FLOOR_Y - SP_H);

      // Draw the sprite in the video memory location got from coordinates x, y
      cpct_drawSprite(g_spirit, pvideomem, SP_W, SP_H);
   }
}
Example #15
0
//
// MAIN: Using keyboard to move a sprite example
//
void main(void) {
   u8  x=10, y=10;   // Sprite coordinates
   u8* pvideomem;    // Pointer to video memory

   //
   // Set up the screen
   //
   // Disable firmware to prevent it from interfering with setPalette and setVideoMode
   cpct_disableFirmware();

   // Set the colour palette
   cpct_fw2hw     (G_palette, 4); // Convert our palette from firmware to hardware colours 
   cpct_setPalette(G_palette, 4); // Set up the hardware palette using hardware colours
   
   // Set video mode 1 (320x200, 4 colours)
   cpct_setVideoMode(1);

   // 
   // Infinite moving loop
   //
   while(1) {
      // Scan Keyboard (fastest routine)
      // The Keyboard has to be scanned to obtain pressed / not pressed status of
      // every key before checking each individual key's status.
      cpct_scanKeyboard_f();

      // Check if user has pressed a Cursor Key and, if so, move the sprite if
      // it will still be inside screen boundaries
      if      (cpct_isKeyPressed(Key_CursorRight) && x < (SCR_W - SP_W) ) ++x; 
      else if (cpct_isKeyPressed(Key_CursorLeft)  && x > 0              ) --x; 
      if      (cpct_isKeyPressed(Key_CursorUp)    && y > 0              ) --y;
      else if (cpct_isKeyPressed(Key_CursorDown)  && y < (SCR_H - SP_H) ) ++y;
      
      // Get video memory byte for coordinates x, y of the sprite (in bytes)
      pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, x, y);

      // Draw the sprite in the video memory location got from coordinates x, y
      cpct_drawSprite(G_spriteLogoCT, pvideomem, SP_W, SP_H);
   }
}
Example #16
0
void newLevel() {
	u8 str[6];
	initLevel();
	sprintf(str, "%2u", level);
	cpct_memset(SCR_VMEM, 0, 0x4000);
	cpct_drawStringM0 ("LEVEL", getScreenPosition(7, 11), 15, 0);
	cpct_drawStringM0 (str, getScreenPosition(13, 11), 15, 0);
	cpct_drawStringM0 ("Press Space", getScreenPosition(4, 23), 15, 0);
	cpct_drawStringM0 ("to go next level", getScreenPosition(2, 24), 15, 0);
	cpct_scanKeyboard_f ();
	while (!cpct_isKeyPressed(Key_Space)) {
		cpct_scanKeyboard_f ();
	}
	levelMode();
}
Example #17
0
///////////////////////////////////////////////////////////////
/// EM_S_waitingUserInput
///   Entity is waiting user input to move
///////////////////////////////////////////////////////////////
void EM_S_waitingUserInput(TEntity* e) {
   // Check if user wants to hit
   if (cpct_isKeyPressed(Key_Space)) {
      // Start hero attack
      e->t      = 2;   // 2 frames for set up
      e->sprite = e->spriteset[5];
      e->fstate = EM_S_heroSetupAttack;
      EM_addEntity2Draw(e);
   } else {
      // Check if user presses arrows
      EM_checkUserArrows();
      if (e->nextAction) {
         e->t      = FRAMES_STEP_WALK - 1;
         e->fstate = EM_S_walking;
         EM_S_walking(e);
      }
   }
}
Example #18
0
////////////////////////////////////////////////////////////////////////
// Checks if a Key has changed from pressed to released or viceversa
// If it has changed, that is considered and event, the status of 
// the key is changed and the concrete event is returned. If it is
// in its previous status, nothing is done and K_NOEVENT is returned
//
TKeyStatus checkKeyEvent(cpct_keyID key, TKeyStatus *keystatus) {
   TKeyStatus newstatus;   // Hold the new status of the key (pressed / released)

   // Check the new status of the key and save it into newstatus
   if ( cpct_isKeyPressed(key) )
      newstatus = K_PRESSED;   // Key is now pressed
   else
      newstatus = K_RELEASED;  // Key is now released

   // Check if newstatus is same or different than previous one
   // If it is different, change key status and report the event
   if (newstatus == *keystatus)
      return K_NOEVENT;       // Same key status, report NO EVENT
   else {
      *keystatus = newstatus; // Status has changed, save it...
      return newstatus;       // And return the new status
   }
}
Example #19
0
void controls() {
	cpct_memset(SCR_VMEM, 0, 0x4000);
	cpct_drawStringM0 ("CONTROLS", getScreenPosition(5, 3), 15, 0);

	cpct_drawStringM0 ("W: Move Up", getScreenPosition(4, 7), 15, 0);
	cpct_drawStringM0 ("S: Move Down", getScreenPosition(4, 9), 15, 0);
	cpct_drawStringM0 ("A: Move Left", getScreenPosition(4, 11), 15, 0);
	cpct_drawStringM0 ("D: Move Right", getScreenPosition(4, 13), 15, 0);

	cpct_drawStringM0 ("Press Space", getScreenPosition(4, 23), 15, 0);
	cpct_drawStringM0 ("to go main menu", getScreenPosition(2, 24), 15, 0);

	cpct_scanKeyboard_f ();
	while (!cpct_isKeyPressed(Key_Space)) {
		cpct_waitVSYNC();
		cpct_akp_musicPlay();
		cpct_scanKeyboard_f ();
	}
	// gameScene=MENUSCREEN;
	gameScene=MENUSCREEN;
}
Example #20
0
/*GAME OVER*/
void gameOver(){
    u8* memptr;
  cpct_clearScreen(0);
  memptr = cpct_getScreenPtr(VMEM,10,10);
  cpct_drawStringM0("Lounge Gladiator",memptr,1,0);

    memptr = cpct_getScreenPtr(VMEM,10,50);
   cpct_drawSprite(gameover,memptr,60,28);


  memptr = cpct_getScreenPtr(VMEM, 12, 175); 
  cpct_drawStringM0("Pulsa espacio", memptr, 1, 0); 



  while (1){
    cpct_scanKeyboard_f();
     if(cpct_isKeyPressed(Key_Space)) {

        return;
      }

   }
}
Example #21
0
/////////////////////////////////////////////////////////////////
// checkUserInputAndPerformActions
//    scans the keyboard and checks whether the user has pressed
// any action key or not. When the user presses an action key, 
// the corresponding action is performed.
//
void checkUserInputAndPerformActions() {
   // Scan the keyboard for user keypresses
   cpct_scanKeyboard();

   // Perform checks only when the user has
   // pressed at least one key
   if(cpct_isAnyKeyPressed()) {
      // Get current (x,y) coordinates of the cursor 
      u8 x = cursor_getX();
      u8 y = cursor_getY();

      // Check if the key pressed is one of the valid keys and
      // if sanity conditions are met

      // CURSOR_UP or CURSOR_DOWN (Only one at a time)
      //   Perform required action, if the cursor is not at the
      // edge of the map already.
      if (cpct_isKeyPressed(Key_CursorUp) && y > 0)
         cursor_move(DIR_UP);
      else if (cpct_isKeyPressed(Key_CursorDown) && y < MAP_HEIGHT-1)
         cursor_move(DIR_DOWN);

      // CURSOR_LEFT or CURSOR_RIGHT (Only one at a time)
      //   Perform required action, if the cursor is not at the
      // edge of the map already.
      if (cpct_isKeyPressed(Key_CursorLeft) && x > 0)
         cursor_move(DIR_LEFT);
      else if (cpct_isKeyPressed(Key_CursorRight) && x < MAP_WIDTH-1)
         cursor_move(DIR_RIGHT);

      // SPACE (change tile) or ESCAPE (clear map)
      //    Perform one of these actions if corresponding key is pressed
      if (cpct_isKeyPressed(Key_Space)) 
         map_changeTile(x, y);
      else if (cpct_isKeyPressed(Key_Esc))
         map_clear();

      // Always redraw the cursor after any of the above actions
      cursor_draw();
   }
}
Example #22
0
void getName() {
    u8* pvmem;
    u8 moved, pos, chr;
    u8 markerX, markerY;

    drawFrame(9, 60, 73, 150);

    drawText("NEW HIGH SCORE", 20, 70, 1);
    drawText("ENTER YOUR NAME", 18, 85, 1);
    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 11, 100);
    cpct_drawSprite(g_tile_symbols_1, pvmem, 3, 11);
    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 14, 100);
    cpct_drawSprite(g_tile_symbols_2, pvmem, 3, 11);
    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 17, 100);
    cpct_drawSprite(g_tile_symbols_3, pvmem, 3, 11);
    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 20, 100);
    cpct_drawSprite(g_tile_symbols_4, pvmem, 3, 11);
    drawText("CHANGE LETTER", 24, 100, 0);
    drawText(" _ TO END", 20, 115, 1);
    drawFrame(12, 130, 70, 160);
    strcpy(newNameHighScore, "A");
    drawText(newNameHighScore, 16, 140, 0);

    markerX = 15;
    markerY = 138;
    cpct_setBlendMode(CPCT_BLEND_XOR);
    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, markerX, markerY);
    cpct_drawSpriteBlended(pvmem, AM_MARKER_H, AM_MARKER_W, am_marker);
    pos = 0;
    chr = 65;
    moved = 0;
    while (1) {
        delay(24);

        if ((cpct_isKeyPressed(Joy0_Down)) || (cpct_isKeyPressed(keys.down))) {
            chr++;
            moved = 1;
        } else if ((cpct_isKeyPressed(Joy0_Up)) || (cpct_isKeyPressed(keys.up))) {
            chr--;
            moved = 1;
        } else if ((pos < 14) && ((cpct_isKeyPressed(Joy0_Right)) || (cpct_isKeyPressed(Joy0_Fire1)) || (cpct_isKeyPressed(keys.right)))) {
            if (chr == 95) {
                newNameHighScore[pos] = '\0';
                break;
            }
            else {
                pos++;
                newNameHighScore[pos] = 65;
                newNameHighScore[pos + 1] = '\0';
                chr = 65;
                moved = 1;
            }

        } else if ((pos > 0) && ((cpct_isKeyPressed(Joy0_Left)) || (cpct_isKeyPressed(keys.left)))) {
            newNameHighScore[pos] = '\0';
            pos--;
            chr = newNameHighScore[pos];
            moved = 1;
        } else if (cpct_isKeyPressed(keys.abort)) {
            break;
        }
        if (moved) {
            moved = 0;
            if (chr > 95)
                chr = 65;
            else if (chr < 65)
                chr = 95;
            newNameHighScore[pos] = chr;
            pvmem = cpct_getScreenPtr(CPCT_VMEM_START, markerX, markerY);
            cpct_drawSpriteBlended(pvmem, AM_MARKER_H, AM_MARKER_W, am_marker);
            pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 16, 140);
            cpct_drawSolidBox(pvmem, #0, 45, 11);
            drawText(newNameHighScore, 16, 140, 0);
            markerX = 15 + (pos * 3);
            pvmem = cpct_getScreenPtr(CPCT_VMEM_START, markerX, markerY);
            cpct_drawSpriteBlended(pvmem, AM_MARKER_H, AM_MARKER_W, am_marker);
        }
    }

}
Example #23
0
//////////////////////////////////////////////////////////////////
// game
//
//
//
// Returns:
//    void
//
void game(void) {
    u8 moved;
    u8 *pvmem;
    u8 dir = 0;


    initGame();

    // Clear Screen
    clearScreen();

    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 61, 72);
    cpct_drawSprite(logo_small, pvmem, 15, 55);

    //drawFrame(2, 1, 49, 182);
    drawTable();
    drawText("NEXT", 62, 2, 0);
    printCells();
    highestCardGame = getHighestCard();
    drawText("HIGHEST", 59, 138, 0);
    pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 63, 154);
    cpct_drawSprite(cards[highestCardGame], pvmem, CARD_W, CARD_H);

    moved = 0;
    // Loop forever
    while (1) {
        delay(24);

        rotatedCells = 0;

        if ((cpct_isKeyPressed(Joy0_Right)) || (cpct_isKeyPressed(keys.right))) {
            if (rotateCellsRight() > 0) {
                dir = RIGHT;
                addRandomCellTurn(RIGHT);
                moved = 1;
            }
        } else if ((cpct_isKeyPressed(Joy0_Left)) || (cpct_isKeyPressed(keys.left))) {
            if (rotateCellsLeft() > 0) {
                dir = LEFT;
                addRandomCellTurn(LEFT);
                moved = 1;
            }
        } else if ((cpct_isKeyPressed(Joy0_Down)) || (cpct_isKeyPressed(keys.down))) {
            if (rotateCellsDown() > 0) {
                dir = DOWN;
                addRandomCellTurn(DOWN);
                moved = 1;
            }
        } else if ((cpct_isKeyPressed(Joy0_Up)) || (cpct_isKeyPressed(keys.up))) {
            if (rotateCellsUp() > 0) {
                dir = UP;
                addRandomCellTurn(UP);
                moved = 1;
            }

        } else if ( cpct_isKeyPressed(keys.music)) {
            if (!playing) {
                activateMusic();
            } else {
                deActivateMusic();
            }
        } else if (cpct_isKeyPressed(keys.abort))
            break;

        if (moved) {
            //Empty the rotated cells buffer after ending the animation
            //cpct_waitVSYNC();

            if (changedCards.number > 0) {
                animate(dir);
                resetChangedCards();

                highestCardGame = getHighestCard();
                pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 63, 154);
                cpct_drawSprite(cards[highestCardGame], pvmem, CARD_W, CARD_H);

                // Play sound Effect
                cpct_akp_SFXPlay(3, 14, 50 + (highestCardGame * 2), 1, 0, AY_CHANNEL_A);

            }

            moved = 0;
            if (anyMovesLeft() == 0) {
                cpct_akp_stop();
                cpct_akp_musicInit(song05);
                cpct_akp_musicPlay();
                drawScore();
                wait4UserKeypress();
                drawFrame(14, 60, 68, 130);
                drawText("NO MORE MOVES", 20, 70, 1);
                drawText("GAME OVER", 22, 90, 1);
                sprintf(aux_txt, "SCORE  %d", score);
                drawText(aux_txt, 22, 110, 1);
                delay(200);
                wait4UserKeypress();
                setHighScore(score);
                drawScoreBoard();
                cpct_akp_stop();
                cpct_akp_musicInit(song02);
                cpct_akp_musicPlay();
                break;
            }
        }

    }
}
Example #24
0
/////////////////////////////////////////////////////////////////////////////////
// Read User Keyboard Input and do associated actions
//
void readKeyboardInput(TScreenTilemap *scr){
   
   // Read keyboard continuously until the user perfoms an action
   while(1) {
      // Scan Keyboard
      cpct_scanKeyboard_f(); 

      // Check all the user keys one by one and, if one of them is pressed
      // perform the action and return to the application
      //
      if (cpct_isKeyPressed(Key_CursorUp) && scr->y) {
         scr->y -= 4;   // Move Tilemap Up (4 by 4 pixels, as it can only be placed
         return;        // ... on pixel lines 0 and 4
      } else if (cpct_isKeyPressed(Key_CursorDown) && scr->y < (SCR_HEIGHT - 4*MAP_HEIGHT)) {
         scr->y += 4;   // Move Tilemap Down (same as moving Up, 4 by 4 pixels)
         return;
      } else if (cpct_isKeyPressed(Key_CursorLeft) && scr->x) {
         --scr->x;      // Move Tilemap Left 2 pixels (1 byte)
         return;
      } else if (cpct_isKeyPressed(Key_CursorRight) && scr->x < (SCR_WIDTH - 2*MAP_WIDTH)) {
         ++scr->x;      // Move Tilemap Right 2 pixels (1 byte)
         return;
      } else if (cpct_isKeyPressed(Key_2) && scr->viewport.x + scr->viewport.w < MAP_WIDTH) {
         ++scr->viewport.w;   // Enlarge viewport Horizontally
         return;
      } else if (cpct_isKeyPressed(Key_1) && scr->viewport.w > 1) {
         --scr->viewport.w;   // Reduce viewport Horizontally
         return;
      } else if (cpct_isKeyPressed(Key_4) && scr->viewport.y + scr->viewport.h < MAP_HEIGHT) {
         ++scr->viewport.h;   // Enlarge viewport Vertically
         return;
      } else if (cpct_isKeyPressed(Key_3) && scr->viewport.h > 1) {
         --scr->viewport.h;   // Reduce viewport Vertically
         return;
      } else if (cpct_isKeyPressed(Key_W) && scr->viewport.y) {
         --scr->viewport.y;   // Move viewport Up
         return;
      } else if (cpct_isKeyPressed(Key_S) && scr->viewport.y + scr->viewport.h < MAP_HEIGHT) {
         ++scr->viewport.y;   // Move viewport Down
         return;
      } else if (cpct_isKeyPressed(Key_A) && scr->viewport.x) {
         --scr->viewport.x;   // Move viewport Left
         return;
      } else if (cpct_isKeyPressed(Key_D) && scr->viewport.x + scr->viewport.w < MAP_WIDTH) {
         ++scr->viewport.x;   // Move viewport Right
         return;
      }
   }
}