int Controls::update (SDL_Event *event, LoopType type)
#endif
{
	int count;
	count = CONTROLS;
	#ifdef CASIO
		for(count=0;count<CONTROLS;++count){
			keys[count].state=keydownlast(keys[count].key);
		}
	#else
	switch (event->type) {

		case SDL_KEYDOWN:

			if (type == SET_KEY_LOOP) return event->key.keysym.sym;

			for (count = 0; count < CONTROLS; count++)
				if (event->key.keysym.sym == keys[count].key)
					keys[count].state = true;

			if (type == TYPING_LOOP) return event->key.keysym.sym;

			break;

		case SDL_KEYUP:

			for (count = 0; count < CONTROLS; count++)
				if (event->key.keysym.sym == keys[count].key)
					keys[count].state = false;

			break;
		}
	#endif
	return E_NONE;
}
Exemple #2
0
void game() {
	/* MAIN LOOP, DO NOT BREAK */
	while (1) {
		/* GETKEY */
		keyupdate();
		// handle [menu]
		if (PRGM_GetKey()==48) {
			GetKey(&key);
		}

		// direction keys
		if (keydownlast(KEY_PRGM_LEFT) && cursor_pos[0]>33) {
			cursor_pos[0] -= cursor_speed;
		} else if (keydownlast(KEY_PRGM_RIGHT) && cursor_pos[0]<LCD_WIDTH_PX-33) {
			cursor_pos[0] += cursor_speed;
		}
		if (keydownlast(KEY_PRGM_UP) && cursor_pos[1]>0) {
			cursor_pos[1] -= cursor_speed;
		} else if (keydownlast(KEY_PRGM_DOWN) && cursor_pos[1]<(LCD_HEIGHT_PX-dash_height-cart_height-man_height-10)) {
			cursor_pos[1] += cursor_speed;
		}

		// control keys
		// shift
		if (keydownlast(KEY_PRGM_SHIFT) && man_is_hanging) {
			// drop man
			man_is_hanging = false;
			man_pos[0] = copter_pos[0];
			man_pos[1] = copter_pos[1]+9;
		}

		/* OPERATIONS */
		// move copter
		if (cursor_pos[0] > copter_pos[0]) {
			copter_pos[0]+=copter_speed;
		} else if (cursor_pos[0] < copter_pos[0]) {
			copter_pos[0]-=copter_speed;
		}

		if (cursor_pos[1] > copter_pos[1]) {
			copter_pos[1]+=copter_speed;
		} else if (cursor_pos[1] < copter_pos[1]) {
			copter_pos[1]-=copter_speed;
		}

		// if man is falling, drop him
		if (!man_is_hanging) {
			man_pos[1] += man_speed;
		}
		// if man is below cart level, check if he is in the cart
		if (!man_is_hanging && man_pos[1]>(LCD_HEIGHT_PX-dash_height-cart_height-5)) {
			if (!man_is_dead && man_pos[0]>cart_pos && man_pos[0]<cart_pos+35) {
				next_try();
			} else {
				die_animation(man_pos[0], man_pos[1]);
			}
		}

		// move cart
		cart_counter = (cart_counter+1) % LCD_WIDTH_PX;
		cart_pos = cart_counter-70;
		// update frame
		cart_frame = (cart_frame+1) % 2;

		/* GRAPHICS */
		// clear screen
		Bdisp_AllClr_VRAM();

		// display functions
		draw_copter(copter_pos[0], copter_pos[1], man_is_hanging);
		draw_cart(cart_pos, LCD_HEIGHT_PX-dash_height-cart_height, cart_frame);

		// if man is falling, draw him
		if (!man_is_hanging /* && !man_is_dead */) {
			draw_man(man_pos[0], man_pos[1]);
		}

		// draw dash
		draw_dash();

		// draw cursor on top of everything
		draw_cursor(cursor_pos[0], cursor_pos[1]);
		
		// copy VRAM to screen
		Bdisp_PutDisp_DD();
	}
}