Exemple #1
0
	bool Scene::run() {
		Graphics*		ptr_graphics = Graphics::instance();
		Audio*			ptr_audio = Audio::instance();
		TextureCache*	ptr_texture_cache = TextureCache::instance();
		InputManager*	ptr_inputManager = new InputManager();

		m_frame_timer.start(m_millis_per_frame);

		on_setup();
		setup_sprites();
		on_begin();
		while (!m_scene_is_ended) {
			ptr_inputManager->update();
			on_check_input(ptr_inputManager);
			if (!m_is_paused) {
				handle_messages();
				on_detect_collisions();
				on_update();
				update_sprites();
				ptr_graphics->begin_render();
				on_render(ptr_graphics);
				ptr_graphics->end_render();
			}
			while (!m_frame_timer.has_elapsed());
		}
		cleanup_sprites();
		on_cleanup();

		return !m_game_is_ended;
	}
Exemple #2
0
void update_player()
{
    extern int ticks; // FROM GAME.C

    update_near_blocks();
    update_particles();
    update_sprites();

    if (current_player.vx >= current_player.max_speed ||
                        current_player.vx <= -current_player.max_speed){
        current_player.state |= (1<<6);
    } else {
        current_player.state &= ~(1<<6);
    }

    if (current_player.near_blocks & ((1 << 0))){ //SOLID BLOCK BELLOW
        if (current_player.state & (1<<7)){ // if plummeting
            if (current_player.vy >= current_player.max_speed){
                int w = current_player.sprite->w;
                int h = current_player.sprite->h;
                int x = current_player.x + w/2;
                int y = current_player.y + 3*h/2;
                attempt_to_break_block(x,y);
            }
            current_player.action_timeout--;
            current_player.vx *=0.8;
            if (!current_player.action_timeout){
                current_player.state &= ~(1<<7); //stop plummeting
            }
        }
        current_player.vy = 0;
        //current_player.y-=0.01;
    } else if (current_player.vy < 5 && ticks % 5 == 0){
            current_player.vy+=0.5;
    }

    if (current_player.near_blocks & (1 << 4)){ //SOLID BLOCK ABOVE
        current_player.vy = 0;
        current_player.y+=0.2;
    }

    if (current_player.near_blocks & (1 << 2)){ // SOLID BLOCK ON RIGHT
        current_player.vx = -current_player.vx * 0.25;
        current_player.x-=0.1;
    }

    if (current_player.near_blocks & (1 << 6)){ // SOLID BLOCK ON LEFT
        current_player.vx = -current_player.vx * 0.25;
        current_player.x+=0.1;
    }

    if (!(current_player.state & (1<<0))){ // NOT DEAD
        if (current_player.vx > 0.5 || current_player.vx < -0.5){
        } else {
            current_player.vx *= 0.9;
        }
    } else { //IS DEAD
        current_player.vx *= 0.8;
    }

    if (current_player.state & (1<<1)){ // WET
        if (current_player.vx > 1 || current_player.vx < -1){
            current_player.vx *= 0.9;
        }
        current_player.vy *= 0.90;
    }

    current_player.x += current_player.vx;
    current_player.y += current_player.vy;

    map_draw_offsetx += (current_player.x - map_draw_offsetx - main_screen->w / 2) / (6.0);
    map_draw_offsety -= (current_player.y + map_draw_offsety - main_screen->h / 2) / (6.0);

    //limit screen from showing outside of the map
    if (map_draw_offsetx + main_screen->w  > map_buffer->w)
        map_draw_offsetx = map_buffer->w - main_screen->w;
    if(-map_draw_offsety + main_screen->h > map_buffer->h)
        map_draw_offsety = -map_buffer->h + main_screen->h;
    if(map_draw_offsetx < 0)
        map_draw_offsetx = 0;
    if(map_draw_offsety > 0)
        map_draw_offsety = 0;
}
Exemple #3
0
void
run_play()
{
   sp1_ClearRectInv(&cr, BRIGHT | INK_WHITE | PAPER_BLACK, 32, SP1_RFLAG_TILE | SP1_RFLAG_COLOUR);
   sp1_UpdateNow();

   sp1_SetPrintPos(&ps0, 0, 0);
   sp1_PrintString(&ps0, ptiles);

   // setup the game
   sprites[PLAYER].x = 15 * 8;
   sprites[PLAYER].y = 20 * 8;
   sprites[PLAYER].frame = 0;
   sprites[PLAYER].delay = 0;
   sprites[PLAYER].sprite = player;
   update_player();

   horde_count = 0;
   wave_delay = 0;
   wave = 0;
   score = 0;
   lives = 3;
   invulnerable = 0;
   update_score();

   while(1)
   {
      // TODO: pause/resume

      if (in_inkey() == 12)
         // exit current game
         break;

      key = (joyfunc)(&joy_k);
      if (key & IN_STICK_LEFT && !(key & IN_STICK_RIGHT))
      {
         if (sprites[PLAYER].x - 4 > ORIGINX)
         {
            sprites[PLAYER].x -= 4;
            sprites[PLAYER].frame = 2;
            sprites[PLAYER].delay = 4;
            update_player();
         }
      }

      if (key & IN_STICK_RIGHT && !(key & IN_STICK_LEFT))
      {
         if (sprites[PLAYER].x + 16 + 8 + 4 < WIDTH)
         {
            sprites[PLAYER].x += 4;
            sprites[PLAYER].frame = 1;
            sprites[PLAYER].delay = 4;
            update_player();
         }
      }

      if (cooldown > 0)
         --cooldown;

      if (key & IN_STICK_FIRE && !cooldown)
      {
         // fire rate
         cooldown = 10;
         add_bullet(ST_BULLET, sprites[PLAYER].x + 4, sprites[PLAYER].y - 2);

         playfx(FX_FIRE);
      }

      // change the frame to normal?
      if (sprites[PLAYER].delay)
      {
         if (!--sprites[PLAYER].delay)
         {
            sprites[PLAYER].frame = 0;
            update_player();
         }
      }

      update_horde();
      update_sprites();
      update_script();

      if (invulnerable > 0)
      {
         // will be 0, but in case of "the unexpected"
         if (lives <= 0)
         {
            // GAME OVER

            // some noise
            playfx(FX_EXPLO);
            playfx(FX_EXPLO);
            playfx(FX_EXPLO);

            // we don't want the player to miss the game over music
            in_wait_nokey();

            sp1_SetPrintPos(&ps0, 11, 8);
            sp1_PrintString(&ps0, "\x14\x46" "G A M E  O V E R");
            sp1_UpdateNow();

            dzx7_standard(song2, TEMPMEM);
            ntropic_play(TEMPMEM, 0);

            for (i = 0; i < 32; ++i)
               wait();

            // leave the game
            break;
         }

         --invulnerable;
         update_player();
      }

      wait();
      intrinsic_halt();   // inline halt without impeding optimizer
      sp1_UpdateNow();
   }

   destroy_type_sprite(ST_ALL);
   collect_sprites();

   // the player sprite is never destroyed, so hide it
   sp1_MoveSprAbs(sprites[PLAYER].s, &cr, NULL, 0, 34, 0, 0);
   sp1_UpdateNow();

   sp1_ClearRectInv(&cr, BRIGHT | INK_BLACK | PAPER_BLACK, 32, SP1_RFLAG_TILE | SP1_RFLAG_COLOUR);
   sp1_UpdateNow();
}