Adding layer

This commit is contained in:
AnonymusRaccoon
2020-01-04 16:56:28 +01:00
parent af7fbefa57
commit 3bdda0c03d
13 changed files with 37 additions and 16 deletions
+1
View File
@@ -15,6 +15,7 @@ struct walk_action
gc_component base;
int acceleration;
int max_acceleration;
int decceleration;
};
extern const struct walk_action walk_action;
+2
View File
@@ -6,6 +6,8 @@
*/
#pragma once
int my_str_islower_or_num(const char *str);
int my_printf(const char *str, ...);
int count_valid_queens_placements(int n);
+2
View File
@@ -6,6 +6,8 @@
*/
#pragma once
int my_str_islower_or_num(const char *str);
int my_printf(const char *str, ...);
void print_ptr(void *ptr);
+2 -2
View File
@@ -7,7 +7,7 @@
int my_strlen(const char *str);
int my_compute_power_it(int i, int p);
int my_pow(int i, int p);
static int indexof(char c, const char *str)
{
@@ -29,7 +29,7 @@ static int parse(char *str, const char *base, long n, int i)
neg = -1;
i *= -1;
}
power = my_compute_power_it(base_length, i - 1);
power = my_pow(base_length, i - 1);
n += indexof(str[str_length - i], base) * power * neg;
if ((n > 0 && neg < 0) || (n < 0 && neg > 0))
return (0);
+11
View File
@@ -5,6 +5,8 @@
** Duplicate of the string.h (I think)
*/
int is_digit(char c);
int is_lowercase(char c)
{
if (c >= 'a' && c <= 'z')
@@ -20,3 +22,12 @@ int my_str_islower(const char *str)
}
return (1);
}
int my_str_islower_or_num(const char *str)
{
for (int i = 0; str[i] != '\0'; i++) {
if (!is_lowercase(str[i]) && !is_digit(str[i]))
return (0);
}
return (1);
}
+3 -3
View File
@@ -56,7 +56,7 @@
<renderer src="assets/sprites/grass.png">
<Rect height="auto" width="auto" top="0" left="0" />
</renderer>
<collision_component />
<collision_component layer="11000000" />
</gc_entity>
<gc_entity>
<transform_component>
@@ -66,7 +66,7 @@
<renderer src="assets/sprites/grass.png">
<Rect height="auto" width="auto" top="0" left="0" />
</renderer>
<collision_component />
<collision_component layer="11000000" />
</gc_entity>
<gc_entity>
<transform_component>
@@ -76,7 +76,7 @@
<renderer src="assets/sprites/grass.png">
<Rect height="auto" width="auto" top="0" left="0" />
</renderer>
<collision_component />
<collision_component layer="11000000" />
</gc_entity>
</gc_entities>
</gc_scene>
+2 -2
View File
@@ -11,9 +11,9 @@
<controllable_component />
<gravity_component speed="2000" />
<keyboard_controller left="16" right="3" jump="57" />
<walk_action acceleration="3000" max_acceleration="10000" />
<walk_action acceleration="3000" max_acceleration="100" decceleration="100"/>
<jump_action acceleration="7000" counterforce="6000"/>
<friction_component value=".7" />
<collision_component />
<collision_component layer="11000000" />
</gc_entity>
</gc_entities>
+2
View File
@@ -17,6 +17,7 @@ static void ctr(void *component, va_list args)
struct jump_action *cmp = (struct jump_action *)component;
cmp->acceleration = va_arg(args, int);
cmp->contered = false;
}
static void fdctr(gc_scene *scene, void *component, node *n)
@@ -25,6 +26,7 @@ static void fdctr(gc_scene *scene, void *component, node *n)
cmp->acceleration = xml_getintprop(n, "acceleration");
cmp->counterforce = xml_getintprop(n, "counterforce");
cmp->contered = false;
(void)scene;
}
+4 -1
View File
@@ -18,6 +18,7 @@ static void walk_ctr(void *component, va_list args)
cmp->acceleration = va_arg(args, int);
cmp->max_acceleration = va_arg(args, int);
cmp->decceleration = va_arg(args, int);
}
static void walk_fdctr(gc_scene *scene, void *component, node *n)
@@ -26,6 +27,7 @@ static void walk_fdctr(gc_scene *scene, void *component, node *n)
cmp->acceleration = xml_getintprop(n, "acceleration");
cmp->max_acceleration = xml_getintprop(n, "max_acceleration");
cmp->decceleration = xml_getintprop(n, "decceleration");
(void)scene;
}
@@ -57,5 +59,6 @@ const struct walk_action walk_action = {
destroy: &component_destroy
},
acceleration: 0,
max_acceleration: 0
max_acceleration: 0,
decceleration: 0
};
+5 -5
View File
@@ -22,12 +22,12 @@ gc_entity *entity, float dtime)
struct controllable_component *con = GETCMP(controllable_component);
struct movable_component *mov = GETCMP(movable_component);
struct walk_action *walk = GETCMP(walk_action);
bool clamp = mov->acceleration.x < walk->max_acceleration || mov->acceleration.x > -walk->max_acceleration;
gc_vector2 *acc = &mov->acceleration;
mov->acceleration.x -= con->moving_left * walk->acceleration;
mov->acceleration.x += con->moving_right * walk->acceleration;
if (clamp)
ABSCLAMP(mov->acceleration.x, walk->max_acceleration);
if (con->moving_left)
acc->x -= walk->acceleration;
if (con->moving_right)
acc->x += walk->acceleration;
(void)system;
(void)dtime;
(void)engine;