Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller system update #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 133 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <sstream>
#include <cstdlib>
#include <vector>
#include <cmath>

using namespace genv;
using namespace std;
Expand All @@ -17,12 +18,86 @@ string to_str(const T& a) {
return ss.str();
}

void circle(int rx, int ry, int r, int _col, int _type){
int _x,_y;
if(_col == 1){gout << color(0,0,0);}
if(_col == 2){gout << color(150,150,150);}
if(_col == 3){gout << color(50,50,50);}
if(_col == 4){gout << color(150,150,0);}
if(_col == 5){gout << color(255,255,0);}
if(_col == 6){gout << color(150,0,0);}
if(_col == 7){gout << color(255,0,0);}
if(_col == 8){gout << color(0,0,150);}
if(_col == 9){gout << color(0,0,255);}
if(_col == 10){gout << color(0,150,0);}
if(_col == 11){gout << color(0,255,0);}

if(_type == 0){
for(_x=rx-r; _x<=rx+r; _x++){
for(_y=ry-r; _y<=ry+r; _y++){
int dx = abs(rx-_x);
int dy = abs(ry-_y);
if (sqrt((dx*dx)+(dy*dy)) < r){
gout << move_to(_x,_y) << dot;
}
}
}
}

if(_type == 1){
for(_x=rx; _x<=rx+r; _x++){
for(_y=ry-r; _y<=ry; _y++){
int dx = abs(rx-_x);
int dy = abs(ry-_y);
if (sqrt((dx*dx)+(dy*dy)) < r){
gout << move_to(_x,_y) << dot;
}
}
}
}

if(_type == 2){
for(_x=rx; _x<=rx+r; _x++){
for(_y=ry; _y<=ry+r; _y++){
int dx = abs(rx-_x);
int dy = abs(ry-_y);
if (sqrt((dx*dx)+(dy*dy)) < r){
gout << move_to(_x,_y) << dot;
}
}
}
}

if(_type == 3){
for(_x=rx-r; _x<=rx; _x++){
for(_y=ry; _y<=ry+r; _y++){
int dx = abs(rx-_x);
int dy = abs(ry-_y);
if (sqrt((dx*dx)+(dy*dy)) < r){
gout << move_to(_x,_y) << dot;
}
}
}
}
if(_type == 4){
for(_x=rx-r; _x<=rx; _x++){
for(_y=ry-r; _y<=ry; _y++){
int dx = abs(rx-_x);
int dy = abs(ry-_y);
if (sqrt((dx*dx)+(dy*dy)) < r){
gout << move_to(_x,_y) << dot;
}
}
}
}
}

int main()
{
gout.open(X, Y);
gout << move_to(10,10) << color(255,255,255) << box(X-20,Y-20);
//gout << move_to(10,10) << color(255,255,255) << box(X-20,Y-20);
event ev;
gin.timer(1000);
gin.timer(30);
if (!gout.load_font("LiberationSans-Regular.ttf", 16))
{
cout << "Font megnyitasa sikertelen! Ellenorizd az eleresi utat!\n";
Expand Down Expand Up @@ -143,7 +218,8 @@ int main()
}

gout << move_to(0,0) << color(0,0,0) << box(X,Y) << color(255,255,255) << refresh;
while (gin>>ev && ev.keycode != key_escape) {
while (gin>>ev && ev.keycode != key_space)
{
if (ev.type == ev_key) {
gout << stamp(gout, 0,0,X,Y-40, 0, 40);
gout << color(0,0,0) << move_to(0,0) << box(X,40) << color(255,255,255);
Expand All @@ -152,5 +228,58 @@ int main()
}
}

return 0;
while (gin>>ev && ev.keycode != key_escape)
{

if(ev.type == controller){
gout << move_to(0,0) << color(0,0,0) << box(X,Y);
circle(X/5,1.5*Y/5,45,2,0);
circle(X/5,1.5*Y/5,40,1,0);
circle(X-250,Y/2,45,2,0);
circle(X-250,Y/2,40,1,0);
circle(X-125,100,20,5,0);
circle(X-75,150,20,7,0);
circle(X-175,150,20,9,0);
circle(X-125,200,20,11,0);
circle(237,Y/2+2,39,2,0);
gout << move_to(230,150) << color(200,200,200) << text("BACK");
gout << move_to(330,150) << color(200,200,200) << text("START");
if(ev.hat == hat_rup){circle(237,Y/2+2,39,3,1);}
if(ev.hat == hat_rdown){circle(237,Y/2+2,39,3,2);}
if(ev.hat == hat_ldown){circle(237,Y/2+2,39,3,3);}
if(ev.hat == hat_lup){circle(237,Y/2+2,39,3,4);}
gout << move_to(200,Y/2-10) << color(200,200,200) << box(75,25);
gout << move_to(225,Y/2-35) << color(200,200,200) << box(25,75);
gout << move_to(136,420) << color(200,200,200) << box(64,40);
gout << move_to(440,420) << color(200,200,200) << box(64,40);

circle(ev.move_lx/13+X/5,ev.move_ly/13+1.5*Y/5,20,2,0); //Bal joystick mozgásának reprezentálása
circle(X-250+ev.move_rx/13,ev.move_ry/13+Y/2,20,2,0); //Jobb joystick mozgásának reprezentálása

for(int i = 0; i < 64-ev.trig_l/4; ++i){
gout << color(200,200,200) << move_to(200,350) << line_to(200-i,400);
}
for(int i = 0; i < 64-ev.trig_r/4; ++i){
gout << color(200,200,200) << move_to(440,350) << line_to(440+i,400);
}

if(ev.joy_btn == jbutton_left_click){circle(X/5,1.5*Y/5,20,3,0);}
if(ev.joy_btn == jbutton_right_click){circle(X-250,Y/2,20,3,0);}
if(ev.joy_btn == jbutton_y){circle(X-125,100,20,4,0);}
if(ev.joy_btn == jbutton_b){circle(X-75,150,20,6,0);}
if(ev.joy_btn == jbutton_x){circle(X-175,150,20,8,0);}
if(ev.joy_btn == jbutton_a){circle(X-125,200,20,10,0);}
if(ev.joy_btn == jbutton_back){gout << move_to(230,150) << color(100,100,100) << text("BACK");}
if(ev.joy_btn == jbutton_start){gout << move_to(330,150) << color(100,100,100) << text("START");}
if(ev.joy_btn == jbutton_lb){gout << move_to(136,420) << color(100,100,100) << box(64,40);}
if(ev.joy_btn == jbutton_rb){gout << move_to(440,420) << color(100,100,100) << box(64,40);}
if(ev.hat == hat_up){gout << move_to(225,Y/2-35) << color(100,100,100) << box(25,25);}
if(ev.hat == hat_right){gout << move_to(250,Y/2-10) << color(100,100,100) << box(25,25);}
if(ev.hat == hat_down){gout << move_to(225,Y/2+15) << color(100,100,100) << box(25,25);}
if(ev.hat == hat_left){gout << move_to(200,Y/2-10) << color(100,100,100) << box(25,25);}

}
gout<<refresh;
}
return 0;
}