items can now trigger functions with use key (SPACE for now) with cooldown afterwards. Now i just need to make these functions.. and animations for the tools.. animations.. sigh
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
- https://nyknck.itch.io/fx084
|
||||
-
|
||||
- Hana Caraka - Base Character [sample]
|
||||
- Sunnyside_World_ASSET_PACK_V2.1
|
||||
|
||||
+6
-1
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <raylib.h>
|
||||
|
||||
typedef struct Player player_t;
|
||||
# include "../include/anim.h"
|
||||
|
||||
typedef struct World world_t;
|
||||
typedef struct Player player_t;
|
||||
|
||||
typedef struct ItemTransl {
|
||||
Vector2 position;
|
||||
@@ -19,9 +21,12 @@ typedef struct Item {
|
||||
Vector2 render_offset;
|
||||
|
||||
itemtype_t type;
|
||||
int cooldown_ms;
|
||||
|
||||
void* item_data;
|
||||
void (*item_action)(player_t*, world_t*);
|
||||
} item_t;
|
||||
|
||||
void free_item(item_t* item);
|
||||
|
||||
void do_item_action(player_t* player, world_t* world);
|
||||
|
||||
@@ -13,7 +13,8 @@ typedef struct ItemDataMeele {
|
||||
float attack_speed;
|
||||
} itemdata_meele_t;
|
||||
|
||||
|
||||
itemdata_meele_t* get_meele_data(void* data);
|
||||
|
||||
item_t* create_meele_item_base();
|
||||
|
||||
void meele_item_attack(player_t* player, world_t* world);
|
||||
|
||||
+4
-1
@@ -5,7 +5,8 @@
|
||||
|
||||
#include "../include/world.h"
|
||||
#include "../include/entity.h"
|
||||
#include "../include/item.h"
|
||||
|
||||
typedef struct Item item_t;
|
||||
|
||||
typedef enum State {
|
||||
// index == spritesheet row
|
||||
@@ -14,7 +15,9 @@ typedef enum State {
|
||||
} state_t;
|
||||
|
||||
typedef struct Player {
|
||||
// item
|
||||
item_t* current_item;
|
||||
timeval_t last_item_action;
|
||||
|
||||
// visual
|
||||
float anim_speed;
|
||||
|
||||
+15
@@ -1,8 +1,23 @@
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
|
||||
# include "../include/item.h"
|
||||
# include "../include/player.h"
|
||||
|
||||
void free_item(item_t* item) {
|
||||
free(item->item_data);
|
||||
free(item);
|
||||
}
|
||||
|
||||
void do_item_action(player_t* player, world_t* world) {
|
||||
item_t* item = player->current_item;
|
||||
|
||||
if (!item) { return; }
|
||||
if (!item->item_action) { return; }
|
||||
|
||||
if (get_time_since_ms(player->last_item_action) >= item->cooldown_ms) {
|
||||
item->item_action(player, world);
|
||||
gettimeofday(&player->last_item_action, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <assert.h>
|
||||
|
||||
# include "../include/item_meele.h"
|
||||
@@ -17,3 +18,9 @@ item_t* create_meele_item_base() {
|
||||
|
||||
return item_p;
|
||||
}
|
||||
|
||||
void meele_item_attack(player_t* player, world_t* world) {
|
||||
printf("TODO: make it attack stuff\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -9,11 +9,12 @@ item_t* create_item_sword() {
|
||||
|
||||
item_t* item_p = create_meele_item_base();
|
||||
|
||||
// item_p->icon = LoadTexture("");
|
||||
item_p->cooldown_ms = 1000;
|
||||
|
||||
item_p->sprite = LoadTexture("assets/sprites/items/sword.png");
|
||||
item_p->render_offset = (Vector2) { 4, -5 };
|
||||
|
||||
item_p->type = MEELE_WEAPON;
|
||||
item_p->item_action = NULL;
|
||||
item_p->item_action = &meele_item_attack;
|
||||
return item_p;
|
||||
}
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ int enemy_follow_path(enemy_t* enemy, player_t* player, world_t* world) {
|
||||
if (step_len > max_len) {
|
||||
step = Vector2Scale(Vector2Normalize(step), max_len);
|
||||
}
|
||||
printf("step: %f\n", step_len);
|
||||
enemy->path.currently_moving = step_len > 0.1;
|
||||
// printf("step: %f\n", step_len);
|
||||
enemy->path.currently_moving = step_len > 10;
|
||||
|
||||
// enemy->entity.position = Vector2Add(enemy->entity.position, step);
|
||||
enemy->entity.velocity = step;
|
||||
|
||||
@@ -11,10 +11,15 @@
|
||||
#include "../include/anim.h"
|
||||
#include "../include/movement.h"
|
||||
#include "../include/renderer.h"
|
||||
#include "../include/item.h"
|
||||
|
||||
void init_player(player_t* player) {
|
||||
|
||||
player->current_item = NULL;
|
||||
gettimeofday(&player->last_damage, NULL);
|
||||
player->last_item_action.tv_usec = 0;
|
||||
player->last_item_action.tv_sec = 0;
|
||||
|
||||
player->no_arms_tex = LoadTexture("assets/sprites/player_no_hand.png");
|
||||
assert(IsTextureValid(player->no_arms_tex));
|
||||
|
||||
@@ -156,6 +161,11 @@ void player_update_state(player_t* player) {
|
||||
}
|
||||
|
||||
void update_player(player_t* player, world_t* world) {
|
||||
// use item
|
||||
if (IsKeyDown(KEY_SPACE)) {
|
||||
do_item_action(player, world);
|
||||
}
|
||||
|
||||
player_update_velocity_by_input(player);
|
||||
if (get_config_ptr()->player_collision) {
|
||||
entity_move_and_collide(&(player->entity), world);
|
||||
|
||||
Reference in New Issue
Block a user