summaryrefslogtreecommitdiffhomepage
path: root/src/input.c
blob: 36614923e3261f292f0d37b7db22d7b9f56e13c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "input.h"

joypad_buttons_t pressed_p1;
joypad_buttons_t held_p1;
joypad_inputs_t inputs_p1;

joypad_buttons_t pressed_p2;
joypad_buttons_t held_p2;
joypad_inputs_t inputs_p2;

void updateController()
{
    joypad_poll();
    pressed_p1 = joypad_get_buttons_pressed(JOYPAD_PORT_1);
    held_p1 = joypad_get_buttons_held(JOYPAD_PORT_1);
    inputs_p1 = joypad_get_inputs(JOYPAD_PORT_1);
    pressed_p2 = joypad_get_buttons_pressed(JOYPAD_PORT_2);
    held_p2 = joypad_get_buttons_held(JOYPAD_PORT_2);
    inputs_p2 = joypad_get_inputs(JOYPAD_PORT_2);

	float x = inputs_p1.stick_x;
	float y = inputs_p1.stick_y;

	if(x > 60)
	{
		x = 60.0f;
	}
	else if(x < -60)
	{
		x = -60.0f;
	}
	else if((x > -5) && (x < 5))
	{
		x = 0.0f;
	}

	if(y > 60)
	{
		y = 60;
	}
	else if(y < -60)
	{
		y = -60;
	}
	else if((y > -5) && (y < 5))
	{
		y = 0;
	}

	if(x > 0)
	{
		x -= 5;
	}
	else if(x < 0)
	{
		x += 5;
	}

	if(y > 0)
	{
		y -= 5;
	}
	else if(y < 0)
	{
		y += 5;
	}

	//float distance = sqrtf((x * x) + (y * y));

	//char text[500];
	//char text2[500];
	//char text3[500];
	//sprintf(text, "x %f", x); 
	//sprintf(text2, "y %f", y); 
	//sprintf(text3, "d %f", distance); 
	//DrawText(text, 100, 10, 12, GREEN);
	//DrawText(text2, 100, 30, 12, GREEN);
	//DrawText(text3, 100, 60, 12, GREEN);

	/*
	if(distance != 0)
	{
		inputs_p1.stick_x = (x / distance) * 127.0f;
		inputs_p1.stick_y = (y / distance) * 127.0f;
	}
	*/

	inputs_p1.stick_x = x / 55.0f * 127.0f;
	inputs_p1.stick_y = y / 55.0f * 127.0f;

	x = inputs_p2.stick_x;
	y = inputs_p2.stick_y;

	if(x > 60)
	{
		x = 60.0f;
	}
	else if(x < -60)
	{
		x = -60.0f;
	}
	else if((x > -5) && (x < 5))
	{
		x = 0.0f;
	}

	if(y > 60)
	{
		y = 60;
	}
	else if(y < -60)
	{
		y = -60;
	}
	else if((y > -5) && (y < 5))
	{
		y = 0;
	}

	if(x > 0)
	{
		x -= 5;
	}
	else if(x < 0)
	{
		x += 5;
	}

	if(y > 0)
	{
		y -= 5;
	}
	else if(y < 0)
	{
		y += 5;
	}

	inputs_p2.stick_x = x / 55.0f * 127.0f;
	inputs_p2.stick_y = y / 55.0f * 127.0f;

}