Beispiel #1
0
bool Map::majMap(Orientation o, int &score)
{
    _move_body();
    if (o == LEFT)
        --_head.x;
    else if (o == RIGHT)
        ++_head.x;
    else if (o == UP)
        --_head.y;
    else
        ++_head.y;

    if (_map[_head.y][_head.x] == WALL || _map[_head.y][_head.x] == BODY)
    {
        _map[_head.y][_head.x] = HEAD;
        return false;
    }
    else if (_map[_head.y][_head.x] == FOOD)
    {
        _map[_head.y][_head.x] = HEAD;
        if (!_add_body())
            return false;
        _add_food();
        score += 100;
    }

    _map[_head.y][_head.x] = HEAD;
    return true;
}
Beispiel #2
0
	virtual void init() {

		VisualServer *vs = VisualServer::get_singleton();
		Physics2DServer *ps = Physics2DServer::get_singleton();



		space=ps->space_create();
		ps->space_set_active(space,true);
		ps->set_active(true);
		ps->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY_VECTOR,Vector2(0,1));
		ps->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY,98);

		{

			RID vp = vs->viewport_create();
			canvas = vs->canvas_create();
			vs->viewport_attach_canvas(vp,canvas);
			vs->viewport_attach_to_screen(vp,Rect2(Vector2(),OS::get_singleton()->get_window_size()));
			Matrix32 smaller;
			//smaller.scale(Vector2(0.6,0.6));
			//smaller.elements[2]=Vector2(100,0);

			//view_xform = smaller;
			vs->viewport_set_canvas_transform(vp,canvas,view_xform);

		}

		ray = vs->canvas_item_create();
		vs->canvas_item_set_parent(ray,canvas);
		//ray_query = ps->query_create(this,"_ray_query_callback",Variant());
		//ps->query_intersection(ray_query,space);

		_create_body_shape_data();

		for(int i=0;i<32;i++) {

			Physics2DServer::ShapeType types[4]={
				Physics2DServer::SHAPE_CIRCLE,
				Physics2DServer::SHAPE_CAPSULE,
				Physics2DServer::SHAPE_RECTANGLE,
				Physics2DServer::SHAPE_CONVEX_POLYGON,

			};

			Physics2DServer::ShapeType type = types[i%4];
//			type=Physics2DServer::SHAPE_SEGMENT;
			_add_body(type,Matrix32(i*0.8,Point2(152+i*40,100-40*i)));
			//if (i==0)
			//	ps->body_set_mode(b,Physics2DServer::BODY_MODE_STATIC);
		}

		//RID b= _add_body(Physics2DServer::SHAPE_CIRCLE,Matrix32(0,Point2(101,140)));
		//ps->body_set_mode(b,Physics2DServer::BODY_MODE_STATIC);

		Point2 prev;

		Vector<Point2> parr;
		for(int i=0;i<30;i++) {

			Point2 p(i*60,Math::randf() * 70+340);
			if (i>0) {
				parr.push_back(prev);
				parr.push_back(p);
			}
			prev=p;
		}

		_add_concave(parr);
		//_add_plane(Vector2(0.0,-1).normalized(),-300);
		//_add_plane(Vector2(1,0).normalized(),50);
		//_add_plane(Vector2(-1,0).normalized(),-600);

	}