void move_box(box *b, letter *l, int cur_delta_y, int final_delta_y)
{
    if (cur_delta_y == 0)
        return;

    /*if (cur_delta_y % 15 == 0){
      draw_update_letter(l, b->offsety);
      }*/

    /* Delta location jika offeset x/y di increment 1 */
    int offsetx_location_inc = vinfo.bits_per_pixel / 8;
    int offsety_location_inc = finfo.line_length;

    /* Initial location berdasarkan offset x/y box */
    int initial_offsetx_loc = offsetx_location_inc * vinfo.xoffset;
    int initial_offsety_loc = offsety_location_inc * vinfo.yoffset;


    /* Lokasi awal / offset awal */
    long int initial_location = initial_offsetx_loc + ( b->offsetx * offsetx_location_inc )  + initial_offsety_loc + (b->offsety * offsety_location_inc);

    /* finished_location : lokasi setelah iterasi ini berakhir */

    if (final_delta_y > 0) {
        long int finished_location = initial_location + (1 * offsety_location_inc);
        for (int i = b->y - 1; i >= 0; i--) {
            memcpy(fbp + finished_location + (i * offsety_location_inc), fbp + initial_location + (i * offsety_location_inc), b->x*4);
        }
        memset(fbp + initial_location, 0, 4*b->x);
    } else {
        long int finished_location = initial_location - (2 *offsety_location_inc);
        for (int i = 0; i < b->y; i++) {
            memcpy(fbp + finished_location + (i * offsety_location_inc), fbp + initial_location + (i * offsety_location_inc), b->x*4);
        }
        memset(fbp + initial_location + (b->y * offsety_location_inc), 0, 4*b->x);

    }


    if (final_delta_y > 0) {
        b->offsety ++;
        usleep(30000);
        move_box(b, l, cur_delta_y - 1, final_delta_y);
    } else {
        b->offsety --;
        usleep(30000);
        move_box(b, l, cur_delta_y + 1, final_delta_y);
    }

}
Пример #2
0
void CHARACTER_CORE::move()
{
	float rampvalue = velocity_ramp(length(vel)*50, world->tuning.velramp_start, world->tuning.velramp_range, world->tuning.velramp_curvature);

	vel.x = vel.x*rampvalue;
	move_box(&pos, &vel, vec2(28.0f, 28.0f), 0);
	vel.x = vel.x*(1.0f/rampvalue);
}
Пример #3
0
Файл: ball.c Проект: shiftky/GBA
void ball_step(void)
{
  int x, y;
  switch ( game_get_state() ) {
    case START:
      remaining = 3;
      init_ball();
      break;

    case NEXTSTAGE:
      init_ball();
      break;

    case REMAINING:
      break;

    case RUNNING:
      x = old_x + dx; y = old_y + dy;

      if ( x != old_x && ( x <= 0 || LCD_WIDTH-ball.width < x )) {
        dx = dx > 0 ? -1*BALL_DX : BALL_DX;
        return;
      }

      if ( y != old_y && y <= 0 ) {
        dy = dy > 0 ? -1*BALL_DY : BALL_DY;
        return;
      } else if ( y!= old_y && LCD_HEIGHT-ball.width < y ) {
        if ( remaining <= 1 ) {
          game_set_state(DEAD);
        } else {
          draw_box(&ball, ball.x, ball.y, COLOR_BLACK);
          remaining--;
          init_ball();
          game_set_state(REMAINING);
        }
        return;
      }

      move_box(&ball, x, y, BALL_COLOR);
      old_x = x; old_y = y;
      break;

    case CLEAR:
      draw_box(&ball, old_x, old_y, BALL_COLOR);
      break;

    case DEAD:
      break;

    case RESTART:
      remaining = 3;
      init_ball();
      break;
  }
}
int main(int argc, char const *argv[])
{
    long int screensize = 0;

    // Open the frame buffer file for reading and writing
    fbfd = open("/dev/fb0", O_RDWR);
    if (fbfd == -1) {
        perror("Error: cannot open framebuffer device");
        exit(1);
    }
    printf("The framebuffer device was opened successfully.\n");

    // Get fixed screen information
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
        perror("Error reading fixed information");
        exit(2);
    }


    // Get variable screen information
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
        perror("Error reading variable information");
        exit(3);
    }

    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

    // Figure out the size of the screen in bytes
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

    // Map the device to memory
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
    if ((long int)fbp == -1) {
        perror("Error: failed to map framebuffer device to memory");
        exit(4);
    }
    printf("The framebuffer device was mapped to memory successfully.\n");

	int x0, x1, y0, y1;
	scanf("%d %d %d %d",&x0, &x1, &y0, &y1);

	system("clear");
    drawLine(x0, x1, y0, y1);

    box line = {vinfo.xoffset, y0, abs(vinfo.xoffset-vinfo.xres), abs(y1-y0+1)};
    move_box(&line, NULL, 100, 100);

    // Unmap the device from memory
    munmap(fbp, screensize);
    close(fbfd);

    return 0;
}
Пример #5
0
box
pager_rep::make_pages () {
  if (paper) pages_make ();
  else papyrus_make ();
  int i, nr_pages= N(pages);
  array<SI>  x  (nr_pages);
  array<SI>  y  (nr_pages);
  for (i=0; i<nr_pages; i++) {
    x[i]= 0;
    y[i]= (i==0? 0: y[i-1]- pages[i-1]->h());
  }
  return move_box (ip, scatter_box (ip, pages, x, y), 0, 0);
}
Пример #6
0
void
bridge_ornament_rep::my_typeset (int desired_status) {
  ornament_parameters ps= env->get_ornament_parameters ();
  SI   l = env->get_length (PAR_LEFT ) + ps->lpad;
  SI   r = env->get_length (PAR_RIGHT) + ps->rpad;
  with   = tuple (PAR_LEFT , tree (TMLEN, as_string (l))) *
           tuple (PAR_RIGHT, tree (TMLEN, as_string (r)));
  box  b = typeset_ornament (desired_status);
  box  xb;
  if (N(st) == 2) xb= typeset_as_concat (env, st[1], descend (ip, 1));
  box  hb= highlight_box (ip, b, xb, ps);
  box  mb= move_box (decorate (ip), hb, -l, 0);
  insert_ornament (remember_box (decorate (ip), mb));
}
Пример #7
0
static box
make_ornament_body (path ip, array<page_item> l) {
  int i, n= N(l);
  array<box> lines_bx (n);
  array<SI>  lines_ht (n);
  for (i=0; i<n; i++) {
    page_item item= copy (l[i]);
    lines_bx[i]= item->b;
    lines_ht[i]= item->spc->def;
  }
  box b= stack_box (ip, lines_bx, lines_ht);
  SI dy= n==0? 0: b[0]->y2;
  return move_box (decorate (ip), stack_box (ip, lines_bx, lines_ht), 0, dy);
}
Пример #8
0
box
delimiter_box (path ip, string s, font fn, pencil pen, SI bot, SI top) {
  SI h= top - bot;
  string r= get_delimiter (s, fn, h);
  box b= text_box (ip, 0, r, fn, pen);
  SI x= -b->x1;
  SI y= (top + bot - b->y1 - b->y2) >> 1;
  //cout << s << ", " << bot/PIXEL << " -- " << top/PIXEL
  //     << " -> " << r << "; " << x/PIXEL << ", " << y/PIXEL << "\n";
  //cout << "  extents: " << b->x1/PIXEL << ", " << b->y1/PIXEL
  //     << "; " << b->x2/PIXEL << ", " << b->y2/PIXEL << "\n";
  box mvb= move_box (ip, b, x, y, false, true);
  return macro_box (ip, mvb, fn);
}
Пример #9
0
box
pager_rep::pages_make_page (pagelet pg) {
  box sb= pages_format (pg);
  box lb= move_box (ip, sb, 0, 0);
  int nr= N(pages) + 1 + page_offset;
  SI  left= (nr&1)==0? even: odd;
  env->write (PAGE_NR, as_string (nr));
  env->write (PAGE_THE_PAGE, style[PAGE_THE_PAGE]);
  tree page_t= env->exec (compound (PAGE_THE_PAGE));
  bool empty= N (pg->ins) == 0;
  box header= make_header (empty);
  box footer= make_footer (empty);
  brush bgc = make_background (empty);
  adjust_margins (empty);
  return page_box (ip, lb, page_t, nr, bgc, width, height,
                   left, top + dtop, top + dtop + text_height,
		   header, footer, head_sep, foot_sep);
}
Пример #10
0
/* html_path:
 * Return a box in a table containing the given endpoint.
 * If the top flow is text (no internal structure), return 
 * the box of the flow
 * Else return the box of the subtable containing the point.
 * Because of spacing, the point might not be in any subtable.
 * In that case, return the top flow's box.
 * Note that box[0] must contain the edge point. Additional boxes
 * move out to the boundary.
 *
 * At present, unimplemented, since the label may be inside a
 * non-box node and we need to figure out what this means.
 */
int html_path(node_t * n, port* p, int side, box * rv, int *k)
{
#ifdef UNIMPL
    point p;
    tbl_t *info;
    tbl_t *t;
    box b;
    int i;

    info = (tbl_t *) ND_shape_info(n);
    assert(info->tbls);
    info = info->tbls[0];	/* top-level flow */
    assert(IS_FLOW(info));

    b = info->box;
    if (info->tbl) {
	info = info->tbl;
	if (pt == 1)
	    p = ED_tail_port(e).p;
	else
	    p = ED_head_port(e).p;
	p = flip_pt(p, GD_rankdir(n->graph));	/* move p to node's coordinate system */
	for (i = 0; (t = info->tbls[i]) != 0; i++)
	    if (INSIDE(p, t->box)) {
		b = t->box;
		break;
	    }
    }

    /* move box into layout coordinate system */
    if (GD_flip(n->graph))
	b = flip_trans_box(b, ND_coord_i(n));
    else
	b = move_box(b, ND_coord_i(n));

    *k = 1;
    *rv = b;
    if (pt == 1)
	return BOTTOM;
    else
	return TOP;
#endif
    return 0;
}
Пример #11
0
static int
set_zoom(void)
{
if ((zoom_form = alloc_screen())!=NULL)
	{
	copy_form(&uf,zoom_form);	/* save undo screen */
	copy_form(&vf,&uf);		/* save undo for marqi routines */
	rub_in_place(vs.zoomx,vs.zoomy,vs.zoomx+vs.zoomw-1,vs.zoomy+vs.zoomh-1);
	if (PJSTDN)	/* move zoom box... */
		{
		move_box(&vs.zoomx,&vs.zoomy,vs.zoomw,vs.zoomh);
		clip_zoom();
		}
	copy_form(zoom_form, &uf);	/* replace undo buffer */
	set_alloced_zoom();
	return(1);
	}
else
	{
	return(0);
	}
}
Пример #12
0
void GAMECONTROLLER_CTF::tick()
{
	GAMECONTROLLER::tick();

	do_team_score_wincheck();
	do_race_time_check();
	
	for(int fi = 0; fi < 2; fi++)
	{
		FLAG *f = flags[fi];
		
		if(!f)
			continue;
		
		// flag hits death-tile, reset it
		if(col_get((int)f->pos.x, (int)f->pos.y)&COLFLAG_DEATH)
		{
			game.create_sound_global(SOUND_CTF_RETURN);
			f->reset();
			continue;
		}
		
		//
		if(f->carrying_character)
		{
			// update flag position
			f->pos = f->carrying_character->pos;
			
			if(flags[fi^1] && flags[fi^1]->at_stand)
			{
				if(distance(f->pos, flags[fi^1]->pos) < 32)
				{
					// CAPTURE! \o/
					teamscore[fi^1] += 100;
					f->carrying_character->player->score += 500;

					dbg_msg("game", "flag_capture player='%d:%s'",
						f->carrying_character->player->client_id,
						server_clientname(f->carrying_character->player->client_id));

					char buf[512];
					float capture_time = (server_tick() - f->grab_tick)/(float)server_tickspeed();
					if(capture_time <= 60)
					{
						str_format(buf, sizeof(buf), "the %s flag was captured by %s (%d.%s%d seconds)", fi ? "blue" : "red", server_clientname(f->carrying_character->player->client_id), (int)capture_time%60, ((int)(capture_time*100)%100)<10?"0":"", (int)(capture_time*100)%100);
					}
					else
					{
						str_format(buf, sizeof(buf), "the %s flag was captured by %s", fi ? "blue" : "red", server_clientname(f->carrying_character->player->client_id));
					}
					game.send_chat(-1, -2, buf);
					for(int i = 0; i < 2; i++)
						flags[i]->reset();
					
					game.create_sound_global(SOUND_CTF_CAPTURE);
				}
			}			
		}
		else
		{
			CHARACTER *close_characters[MAX_CLIENTS];
			int num = game.world.find_entities(f->pos, 32.0f, (ENTITY**)close_characters, MAX_CLIENTS, NETOBJTYPE_CHARACTER);
			for(int i = 0; i < num; i++)
			{
				if(!close_characters[i]->alive || close_characters[i]->player->team == -1 || col_intersect_line(f->pos, close_characters[i]->pos, NULL, NULL))
					continue;
				
				if(close_characters[i]->team == f->team)
				{
					// return the flag
					if(!f->at_stand)
					{
						CHARACTER *chr = close_characters[i];
						chr->player->score += 100;

						dbg_msg("game", "flag_return player='%d:%s'",
							chr->player->client_id,
							server_clientname(chr->player->client_id));

						game.create_sound_global(SOUND_CTF_RETURN);
						f->reset();
					}
				}
				else
				{
					// take the flag
					if(f->at_stand)
					{
						teamscore[fi^1]++;
						f->grab_tick = server_tick();
					}
					f->at_stand = 0;
					f->carrying_character = close_characters[i];
					f->carrying_character->player->score += 300;

					dbg_msg("game", "flag_grab player='%d:%s'",
						f->carrying_character->player->client_id,
						server_clientname(f->carrying_character->player->client_id));
					
					for(int c = 0; c < MAX_CLIENTS; c++)
					{
						if(!game.players[c])
							continue;
							
						if(game.players[c]->team == fi)
							game.create_sound_global(SOUND_CTF_GRAB_EN, game.players[c]->client_id);
						else
							game.create_sound_global(SOUND_CTF_GRAB_PL, game.players[c]->client_id);
					}
					break;
				}
			}
			
			if(!f->carrying_character && !f->at_stand)
			{
				if(server_tick() > f->drop_tick + server_tickspeed()*30)
				{
					game.create_sound_global(SOUND_CTF_RETURN);
					f->reset();
				}
				else
				{
					f->vel.y += game.world.core.tuning.gravity;
					move_box(&f->pos, &f->vel, vec2(f->phys_size, f->phys_size), 0.5f);
				}
			}
		}
	}
}
Пример #13
0
int CHARACTER::handle_ninja()
{
	if(active_weapon != WEAPON_NINJA)
		return 0;
	
	vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y));
	
	if(!col_get_ninjafly((int)pos.x, (int)pos.y) && player->ninjalol==1)
	{
		weapons[WEAPON_NINJA].got = false;
		active_weapon = last_weapon;
		if(active_weapon == WEAPON_NINJA)
			active_weapon = WEAPON_GUN;
		set_weapon(active_weapon);
		player->ninjalol = 0;	
	}

	if(player->authed || col_get_ninjafly((int)pos.x, (int)pos.y))
	{
		//do nothing
	}
	else
	{
	if ((server_tick() - ninja.activationtick) > (data->weapons.ninja.duration * server_tickspeed() / 1000))
	{
		// time's up, return
		weapons[WEAPON_NINJA].got = false;
		active_weapon = last_weapon;
		if(active_weapon == WEAPON_NINJA)
			active_weapon = WEAPON_GUN;
		set_weapon(active_weapon);
		return 0;
	}
	
	// force ninja weapon
	set_weapon(WEAPON_NINJA);
	}
	ninja.currentmovetime--;

	if (ninja.currentmovetime == 0)
	{
		// reset player velocity
		core.vel *= 0.2f;
		//return MODIFIER_RETURNFLAGS_OVERRIDEWEAPON;
	}

	if (ninja.currentmovetime > 0)
	{
		// Set player velocity
		core.vel = ninja.activationdir * data->weapons.ninja.velocity;
		vec2 oldpos = pos;
		move_box(&core.pos, &core.vel, vec2(phys_size, phys_size), 0.0f);
		// reset velocity so the client doesn't predict stuff
		core.vel = vec2(0.0f,0.0f);
		if ((ninja.currentmovetime % 2) == 0)
		{
			//create_smoke(pos);
		}

		// check if we hit anything along the way
		{
			CHARACTER *ents[64];
			vec2 dir = pos - oldpos;
			float radius = phys_size * 2.0f; //length(dir * 0.5f);
			vec2 center = oldpos + dir * 0.5f;
			int num = game.world.find_entities(center, radius, (ENTITY**)ents, 64, NETOBJTYPE_CHARACTER);

			for (int i = 0; i < num; i++)
			{
				// Check if entity is a player
				if (ents[i] == this)
					continue;
				// make sure we haven't hit this object before
				bool balreadyhit = false;
				for (int j = 0; j < numobjectshit; j++)
				{
					if (hitobjects[j] == ents[i])
						balreadyhit = true;
				}
				if (balreadyhit)
					continue;

				// check so we are sufficiently close
				if (distance(ents[i]->pos, pos) > (phys_size * 2.0f))
					continue;

				// hit a player, give him damage and stuffs...
				game.create_sound(ents[i]->pos, SOUND_NINJA_HIT);
				// set his velocity to fast upward (for now)
				if(numobjectshit < 10)
					hitobjects[numobjectshit++] = ents[i];
					
				ents[i]->take_damage(vec2(0,10.0f), data->weapons.ninja.base->damage, player->client_id,WEAPON_NINJA);
			}
		}
		return 0;
	}

	return 0;
}
Пример #14
0
  (void) real_bot; (void) real_top;
  SI h= top - bot;
  string r= get_delimiter (s, fn, h);
  box b= text_box (ip, 0, r, fn, pen);
  SI x= -b->x1;
  SI y= (top + bot - b->y1 - b->y2) >> 1;
  if (b->y2 - b->y1 < h) {
    y= (mid - b->y1 - b->y2) >> 1;
    y= min (top - b->y2, y);
    y= max (bot - b->y1, y);
  }
  //cout << s << ", " << bot/PIXEL << " -- " << top/PIXEL
  //     << " -> " << r << "; " << x/PIXEL << ", " << y/PIXEL << "\n";
  //cout << "  extents: " << b->x1/PIXEL << ", " << b->y1/PIXEL
  //     << "; " << b->x2/PIXEL << ", " << b->y2/PIXEL << "\n";
  box mvb= move_box (ip, b, x, y, false, true);
  return macro_box (ip, mvb, fn);
}

box
big_operator_box (path ip, string s, font fn, pencil pen, int n) {
  ASSERT (N(s) >= 2 && s[0] == '<' && s[N(s)-1] == '>',
	  "invalid rubber character");
  string r= s (0, N(s)-1) * "-" * as_string (n) * ">";
  metric ex;
  fn->get_extents (r, ex);
  SI y= fn->yfrac - ((ex->y1 + ex->y2) >> 1);
  box mvb= move_box (ip, text_box (ip, 0, r, fn, pen), 0, y, false, true);
  return macro_box (ip, mvb, fn, BIG_OP_BOX);
}