예제 #1
0
/* move camera using i,k,j,l keys */
int camera_move(int input_character)
{
    switch (input_character) {
        case K_CAM_UP:
            if (dy > 0)
                dy--;
            break;
        case K_CAM_DOWN:
            if (dy < (map_data->height - LINES/2))
                dy++;
            break;
        case K_CAM_LEFT:
            if (dx > 0)
                dx--;
            break;
        case K_CAM_RIGHT:
            if (dx < (map_data->length - COLS))
                dx++;
            break;
        default:
            return 0;
    }
    /* add SCR_ALL to screen update queue */
    ScreenUpdate camera_move = SCR_ALL;
    dyn_arr_append(&ScrUpdates, &camera_move);
    debug_d(1, "dx", dx);
    debug_d(1, "dy", dx);
    return 1;
}
예제 #2
0
/* manage space in lobby */
int lobby_menu(int input_character)
{
    if (loc_player->state != PS_JOINED)
        return 0;
    switch (input_character) {
        case KEY_LEFT:
            loc_player->ability_id--;
            if (Abilities.count == 0) {
                loc_player->ability_id++;
                break;
            }
            if (find_ability(loc_player->ability_id) == NULL) {
                struct ability *tmp_a = dyn_arr_get(&Abilities,
                        Abilities.count-1);
                loc_player->ability_id = tmp_a->id;
            }
            break;
        case KEY_RIGHT:
            loc_player->ability_id++;
            if (Abilities.count == 0) {
                loc_player->ability_id--;
                break;
            }
            if (find_ability(loc_player->ability_id) == NULL) {
                struct ability *tmp_a = dyn_arr_get(&Abilities, 0);
                loc_player->ability_id = tmp_a->id;
            }
            break;
        case K_SET_READY:
            if (loc_player->state == PS_JOINED) {
                send_int8(sock, C_SET_ABILITY);
                send_int16(sock, loc_player->ability_id);
                send_int8(sock, C_READY);
                fetch_changes();
            }
            break;
        default:
            return 0;
    }
    debug_d(1, "LocAbilityID", loc_player->ability_id);
    /* add SCR_LOBBY to screen update queue */
    ScreenUpdate u_lobby = SCR_LOBBY;
    dyn_arr_append(&ScrUpdates, &u_lobby);
    return 1;
}
예제 #3
0
void APTouchManager::removeNode(cocos2d::Node* node) {
	if(_amp == nullptr) {
		_amp = apHookActionManager::getInstance();
	}

	if (_d.find(node) != _d.end()) {

		for(auto& item:_d[node].hook) {
			_amp->removeHook(item.second);
		}
		auto result = _d.erase(node);
		//cocos2d::log("%d memer deleted! from touch manager _d map.",result);



		node->release();
		//cocos2d::log("node released!from touch manager --> %d",node);
	}

	debug_d();
}
예제 #4
0
void init()
{
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default

	/*There are four debug levels: debug=3, info=2, warn=1, error=0
	 * You can set the debug level by making with DEBUG_VERBOSE_LEVEL
	 * set to the desired level (0-3). Ex make rebuild DEBUG_VERBOSE_LEVEL=2 will
	 * show only info messages and above, will not show debug messages
	 * (they will be removed from the build at compile time, saving flash space)
	 *
	 * Functions debugf, debug_d, debug_i, debug_w, and debug_e store the format string
	 * in flash so that the RAM is freed for more important information.
	 *
	 * Another useful feature is printing the filename and line number of every debug line
	 * This will require extra space on flash and can be enabled
	 * using make parameter PRINT_FILENAME_AND_LINE=1*/

	debug_d("(DEBUG) message printed on UART0");

	debug_i("(INFO) message printed on UART0");

	debug_w("(WARNING) message printed on UART0");

	debug_e("(ERROR) message printed on UART0");

	/*debugf is equivalent to debug_i*/
	debugf("(INFO) message printed with debugf on UART0");

	/*
	 * Notice: The line below disables the debugf output on all UARTs.
	 */
	Serial.systemDebugOutput(false);

	debugf("(DEBUG) don't print me at all");

	/*
	 * The debugf output is redirected to UART0
	 * together with the system debug messages.
	 */
	Serial.systemDebugOutput(true);
	delay(200);

	debugf("(DEBUG) print me again on UART0");

	/**
	 * Serial1 uses UART1, TX pin is GPIO2.
	 * UART1 can not be used to receive data because normally
	 * it's RX pin is occupied for flash chip connection.
	 *
	 * If you have a spare serial to USB converter do the following to see the
	 * messages printed on UART1:
	 * - connect converter GND to esp8266 GND
	 * - connect converter RX to esp8266 GPIO2
	 */
	HardwareSerial Serial1(UART1);
	Serial1.begin(SERIAL_BAUD_RATE);

	/*
	 * The line below redirect debug output to UART1
	 */
	Serial1.systemDebugOutput(true);
	Serial1.printf("====Debug Information=====\n");

	debugf("(DEBUG) message printed on UART1"); // You should see the debug message in UART1 only.

	procTimer.initializeMs(2000, sayHello).start();

	testPrintf();

	/// Reading callback example:
	//  * Option 1
	//	Set Serial Callback to global routine:
	//	   Serial.setCallback(onDataCallback);
	// If you want to test local echo set the following callback
	//	   Serial.setCallback(echoCallback);

	// 	* Option 2
	//  Instantiate hwsDelegateDemo which includes Serial Delegate class
	delegateDemoClass.begin();
}
예제 #5
0
void APTouchManager::onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event){

	debug_d();
	auto id = touch->getID();

	if(id > 5) return;

	if(_amp == nullptr) {
		_amp = apHookActionManager::getInstance();
	}
	// if not began
	//if (_touchToBeganNode[id] == nullptr || id > 5)

	// they can be nullptr.
	auto nowNode = getTouchedNode(touch);
	auto beforeNode = _touchToNowNode[id];
	_touchToNowNode[id] = nowNode;

	//cocos2d::log("yo");

	auto originNode = _touchToBeganNode[id];
	// outside
	//auto& originNodeHook = _d[originNode].hook;
	//auto& nowNodeHook = _d[nowNode].hook;

	// originNode : node when began that touch.
	// nowNode: now touching node.
	// beforeNode: last touched node.

	// go in or go out. now touching node differs with the last touched one.

	////cocos2d::log("nowNode:%d, beforeNode:%d, originNode:%d", nowNode, beforeNode, originNode);

	if(beforeNode != nowNode) {
		//cocos2d::log("yo2");
		// drag to origin node
		if(nowNode == originNode) {
			runHook(nowNode, APTouchType::MovedInner, touch);
			runHook(beforeNode, APTouchType::MovedOuterIgnoreBegan, touch);
		}

		// if dragged not to origin node and the last node was origin Node
		else if(beforeNode == originNode) {
			runHook(nowNode, APTouchType::MovedInnerIgnoreBegan, touch);
			runHook(beforeNode, APTouchType::MovedOuter, touch);
		}

		// all different!
		else {
			runHook(nowNode, APTouchType::MovedInnerIgnoreBegan, touch);
			runHook(beforeNode, APTouchType::MovedOuterIgnoreBegan, touch);
		}
	}

	// before node and now node are same.
	else {
		//cocos2d::log("yo3");
		// if all same.
		if(nowNode == originNode) {
			runHook(nowNode, APTouchType::MovedInside, touch);
		}
		// if only origin node differs.
		else {
			runHook(nowNode, APTouchType::MovedInsideIgnoreBegan, touch);
			runHook(originNode, APTouchType::MovedOutside, touch);
		}

	}
	//cocos2d::log("yo4");




/*




	if (beforeNode != originNode && nowNode != originNode
			&& originNodeHook.find(APTouchType::MovedOutside) != originNodeHook.end()) {

		if(nowNode )
		_amp->runHook(originNodeHook[APTouchType::MovedOutside]);
	}
	// inside
	else if (beforeNode == originNode && nowNode == originNode
			&& originNodeHook.find(APTouchType::MovedInside) != originNodeHook.end()) {
		_amp->runHook(originNodeHook[APTouchType::MovedInside]);
	}

	// go to out
	else if (beforeNode == originNode && nowNode != originNode
			&& originNodeHook.find(APTouchType::MovedOuter) != originNodeHook.end()) {
		_amp->runHook(originNodeHook[APTouchType::MovedOuter]);

	}

	// inner
	else if (beforeNode != originNode && nowNode == originNode
			&& originNodeHook.find(APTouchType::MovedInner) != originNodeHook.end()) {
		_amp->runHook(originNodeHook[APTouchType::MovedInner]);
	}
*/

}
예제 #6
0
void render_shot(struct shot *shot, int s_id)
{
    struct player *shoot_pl = dyn_arr_get(&Players, s_id);
    center_camera(shoot_pl->pos);
    clear();
    render_map();
    render_tanks();
    debug_d(1, "RenderShotX", shoot_pl->pos.x);
    debug_d(1, "RenderShotY", shoot_pl->pos.y);
    debug_d(1, "RenderShot Angle", shot->angle);
    debug_d(1, "RenderShot Power", shot->power);
    int input_ch;
    struct f_pair init_v = initial_v(shot);
    struct f_pair acc = acceleration();
    /* position (x,y) must be either double or float */
    struct f_pair init_pos = map_pos_to_float(shoot_pl->pos);
    timeout(SHOOT_TIMEOUT);
    float t=1;
    /* this part is duplicated, because it's initial */
    struct f_pair b_pos = shot_pos(init_pos, init_v, acc, t);
    struct map_position map_pos = round_to_map_pos(b_pos);
    draw_bullet(dx, dy, map_pos.x, map_pos.y);
    refresh();
    /* end */
    input_ch = getch();
    if (input_ch != ERR)
        quit_key(input_ch);
    while (loc_player->state) {
        /* remove drew bullet */
        draw_blank_bullet(dx, dy, map_pos.x, map_pos.y);
        debug_d(1, "BulletX", map_pos.x);
        debug_d(1, "BulletY", map_pos.y);
        t+=(float)SHOOT_TIMEOUT/100;
        b_pos = shot_pos(init_pos, init_v, acc, t);
        map_pos = round_to_map_pos(b_pos);
        /* draw a new one */
        switch (draw_bullet(dx, dy, map_pos.x, map_pos.y)) {
            case SCR_OK:
                break;
            case SCR_UP:
            case SCR_DOWN:
            case SCR_LEFT:
            case SCR_RIGHT:
                center_camera(map_pos);
                clear();
                render_map();
                render_tanks();
                draw_bullet(dx, dy, map_pos.x, map_pos.y);
                break;
            default:
                debug_s(5, "ScreenMove(shot)", "Wrong ScrMove value");
        }
        refresh();
        if (map_pos.x > map_data->length  || map_pos.x < 0)
            break;
        if (t > g_impact_t) {
            b_pos = shot_pos(init_pos, init_v, acc, g_impact_t);
            map_pos = round_to_map_pos(b_pos);
            center_camera(map_pos);
            clear();
            render_map();
            render_tanks();
            draw_bullet_explosion(dx, dy, map_pos.x, map_pos.y);
            refresh();
            break;
        }
        /* let player see the change */
        input_ch = getch();
        if (input_ch != ERR)
            quit_key(input_ch);
    }
    input_ch = getch(); // let players
    input_ch = getch(); // see the explosion
    struct player *c_player = dyn_arr_get(&Players, camera_focus);
    center_camera(c_player->pos);
    /* SCR_ALL is already in screen update queue by center_camera*/
    timeout(DEFAULT_TIMEOUT); //back to original
}