Ejemplo n.º 1
0
int fn_do_rand(Object * o)
{
	int r = rand() % 50;
	if (r == 0) {
		obj_move(o->world, o, -1, 0);
	}
	if (r == 1) {
		obj_move(o->world, o, 1, 0);
	}
	if (r == 2) {
		obj_move(o->world, o, 0, -1);
	}
	if (r == 3) {
		obj_move(o->world, o, 0, 1);
	}
	if (r == 4) {
		if (rand() % 10 == 0)
			new_mk_obj("bomb", o->world, o->x, o->y, o);
	}
}
Ejemplo n.º 2
0
int fn_thru_bullet_timer(Object * me)
{
	me->timer--;
	int ox=0, oy=0;
	if (me->timer <= 0)
	{
		delete_object(me);
		return 0;
	}
	if (!strcmp(me->direction, "left"))
		ox = -1;
	if (!strcmp(me->direction, "right"))
		ox = 1;
	if (!strcmp(me->direction, "up"))
		oy = -1;
	if (!strcmp(me->direction, "down"))
		oy = 1;
	
	//bullet cannot go forward, delete.
	//this behavior peculiar to bullet. some magic may need to behave differently.
	if(obj_move(me->world, me, ox,oy) == 0)
		delete_object(me);
}
Ejemplo n.º 3
0
void key_move_right(Object * obj)
{
	obj_move(obj->world, obj, 1, 0);
	strcpy(obj->last_action, "move_right");
}
Ejemplo n.º 4
0
void key_move_left(Object * obj)
{

	obj_move(obj->world, obj, -1, 0);
	strcpy(obj->last_action, "move_left");
}
Ejemplo n.º 5
0
void key_move_down(Object * obj)
{

	obj_move(obj->world, obj, 0, 1);
	strcpy(obj->last_action, "move_down");
}
Ejemplo n.º 6
0
void key_move_up(Object * obj)
{
	obj_move(obj->world, obj, 0, -1);
	strcpy(obj->last_action, "move_up");
}
Ejemplo n.º 7
0
//obj_x.txt need newline at the end!
int set_obj_with_line(Object * o, char *line)
{

	char *first = line;
	char *second = line + char_pos_ith(line, ' ', 0) + 1;
	int len = str_len_char(second, '\r');
	char buf[32];
	memset(buf, 0, sizeof(char) * 32);
	if (same_until_char(first, "type ", ' ')) {

		strncpy(o->type, second, len);
		o->type[len] = 0;
		return 1;
	}
	if (same_until_char(first, "shape.str ", ' ')) {

		strncpy(o->shape.str, second, len);
		o->shape.str[len] = 0;
		return 1;
	}
	if (same_until_char(first, "timer ", ' ')) {

		strncpy(buf, second, len);
		o->timer = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "shape.layer ", ' ')) {

		strncpy(buf, second, len);
		o->shape.layer = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "shape.fg_color ", ' ')) {

		strncpy(buf, second, len);
		o->shape.fg_color = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "shape.bg_color ", ' ')) {

		strncpy(buf, second, len);
		o->shape.bg_color = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "shape.block ", ' ')) {

		strncpy(buf, second, len);
		o->shape.block = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "hp ", ' ')) {

		strncpy(buf, second, len);
		o->hp = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "max_hp ", ' ')) {

		strncpy(buf, second, len);
		o->max_hp = atoi(buf);
		return 1;
	}

	if (same_until_char(first, "mp ", ' ')) {

		strncpy(buf, second, len);
		o->mp = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "max_mp ", ' ')) {

		strncpy(buf, second, len);
		o->max_mp = atoi(buf);
		return 1;
	}
	if (same_until_char(first, "power ", ' ')) {

		strncpy(buf, second, len);
		o->power = atoi(buf);
		return 1;
	}

	if (same_until_char(first, "item ", ' ')) {

		strncpy(buf, second, len);
		add_slot(o, "item", buf);
		return 1;
	}
	if (same_until_char(first, "skill ", ' ')) {

		strncpy(buf, second, len);
		add_slot(o, "skill", buf);
		return 1;
	}
	if (same_until_char(first, "debug ", ' ')) {
		strncpy(buf, second, len);
		add_slot(o, "debug", buf);
		return 1;
	}
	if (same_until_char(first, "offset_x ", ' ')) {

		strncpy(buf, second, len);
		obj_move(o->world, o, atoi(buf), 0);
		return 1;
	}
	if (same_until_char(first, "offset_y ", ' ')) {

		strncpy(buf, second, len);
		obj_move(o->world, o, 0, atoi(buf));
		return 1;
	}
	if (same_until_char(first, "fn_tick ", ' ')) {

		strncpy(buf, second, len);
		fnptr fn = table_obj_fn_by_long_name(table_tick_obj_fn, buf);
		o->tick_fn = fn;
		if (fn == 0)
			return 0;

		return 1;
	}

	if (same_until_char(first, "fn_overlap ", ' ')) {
		strncpy(buf, second, len);
		fnptr fn = table_obj_fn_by_long_name(table_overlap_obj_fn, buf);
		o->overlap_fn = fn;
		if (fn == 0)
			return 0;
		return 1;
	}
	//ignore unknown things
	//if you want to inspect unknown string use return 0;
	return 1;
}