Skip to content

Commit

Permalink
initial upload - working prototype
Browse files Browse the repository at this point in the history
this prototype works with xbox controller, typing in the terminal window is working but nothing more, no backspace yet.
  • Loading branch information
Jo-Blade authored Mar 6, 2022
1 parent 12bf87e commit 7b167b5
Show file tree
Hide file tree
Showing 13 changed files with 982 additions and 0 deletions.
51 changes: 51 additions & 0 deletions 2d-engine.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "2d-engine.h"

/* detect if a point is in a convex polygon:
* 1 = true // 0 = false
* IMPORTANT: if the point is on an edge,
* return true*/
int pointInConvexPoly (struct vec2 point, struct poly *poly){
/* method: calculate determinant for each edge
* to know if the point is on the left or right side.
* if the point is on the same side of all edges then
* it is in the poly */

long det;
/* edge [AB] */
struct vec2 vertex_A;
struct vec2 vertex_B;
char sign;

/* last edge (last vertex to first vertex) */
vertex_A = poly->vertex_array[poly->vertex_len -1];
vertex_B = poly->vertex_array[0];

det = (point.y - vertex_A.y)*(vertex_B.x - vertex_A.x)
- (point.x - vertex_A.x)*(vertex_B.y - vertex_A.y);

if( det == 0 )
/* if the first det is null, we
* must look for the sign of the second det */
sign = 0;
else
/* all det must have the same sign than the first det */
sign = (det > 0) * 2 -1;

for (int i = 1; i < poly->vertex_len; i++) {
vertex_A = poly->vertex_array[i-1];
vertex_B = poly->vertex_array[i];

det = (point.y - vertex_A.y)*(vertex_B.x - vertex_A.x)
- (point.x - vertex_A.x)*(vertex_B.y - vertex_A.y);

if (sign == 0)
/* if the first det was zero
* get the sign of all det */
sign = (det > 0) * 2 -1;
else
/* if different sign */
if ((det * sign) < 0)
return 0;
}
return 1;
}
16 changes: 16 additions & 0 deletions 2d-engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TWODENGINE_H
#define TWODENGINE_H

struct vec2 {
char x;
char y;
};

struct poly {
char vertex_len;
struct vec2 *vertex_array;
};

int pointInConvexPoly (struct vec2 point, struct poly *poly);

#endif
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#########################
# customise these
CFILES := main.c input.c config.c graphics.c 2d-engine.c free-selection-keyboard.c
PROG := prog
CFLAGS := -Wall -Wextra -g
LDFLAGS := -lSDL2
########################

# -MMD generates dependencies while compiling
CFLAGS += -MMD
CC := gcc

OBJFILES := $(CFILES:.c=.o)
DEPFILES := $(CFILES:.c=.d)

$(PROG) : $(OBJFILES)
$(LINK.o) $(LDFLAGS) -o $@ $^

clean :
rm -f $(PROG) $(OBJFILES) $(DEPFILES)

-include $(DEPFILES)
Binary file added azerty.bmp
Binary file not shown.
23 changes: 23 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef CONFIG_H
#define CONFIG_H

#include <stdbool.h>

#include "input.h"

struct mapping {
struct btn btn_east;
struct btn btn_west;
struct btn btn_north;
struct btn btn_left;

struct btn left_bumper;
struct btn right_bumper;

struct joy joy_L;
struct joy joy_R;

bool rumble;
};

#endif
Loading

0 comments on commit 7b167b5

Please sign in to comment.