Starts an idea for skills. Not sure I like it.

This commit is contained in:
Linus Probert 2018-02-24 07:13:28 +01:00
parent fbf746d270
commit 462a22f7a0
6 changed files with 113 additions and 2 deletions

View File

@ -95,6 +95,7 @@ add_executable(breakhack
src/physfsrwops
src/skillbar
src/texturecache
src/skill
)
target_link_libraries(breakhack

View File

@ -47,8 +47,10 @@
#define SCREEN_WIDTH (GAME_VIEW_WIDTH + RIGHT_GUI_WIDTH)
#define SCREEN_HEIGHT (RIGHT_GUI_HEIGHT + BOTTOM_GUI_HEIGHT)
/* Quality of life stuff */
#define DEFAULT_DIMENSION (Dimension) { 16, 16 }
#define GAME_DIMENSION (Dimension) { TILE_DIMENSION, TILE_DIMENSION }
#define CLIP16(x, y) (SDL_Rect) { x, y, 16, 16 }
/* Windows and compile crap */
#ifdef _WIN32

64
src/skill.c Normal file
View File

@ -0,0 +1,64 @@
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "texturecache.h"
#include "skill.h"
#include "util.h"
static Skill *
create_default(const char *s_label, Sprite *s)
{
Skill *skill = ec_malloc(sizeof(Skill));
m_strcpy(skill->label, 20, s_label);
skill->icon = s;
skill->use = NULL;
return skill;
}
static Skill *
create_flurry(void)
{
Texture *t = texturecache_add("Items/MedWep.png");
Sprite *s = sprite_create();
sprite_set_texture(s, t, 0);
s->dim = DEFAULT_DIMENSION;
s->clip = CLIP16(0, 0);
s->fixed = true;
Skill *skill = create_default("Flurry", s);
return skill;
}
Skill*
skill_create(enum SkillType t)
{
switch (t) {
case FLURRY:
return create_flurry();
default:
fatal("Unknown SkillType %u", (unsigned int) t);
return NULL;
}
}
void
skill_destroy(Skill *skill)
{
sprite_destroy(skill->icon);
free(skill);
}

44
src/skill.h Normal file
View File

@ -0,0 +1,44 @@
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SKILL_H_
#define SKILL_H_
#include <stdbool.h>
#include "player.h"
#include "roommatrix.h"
#include "sprite.h"
enum SkillType {
FLURRY
};
typedef struct Skill_t {
char label[20];
Sprite *icon;
bool active;
void (*use)(struct Skill_t*, Player*, RoomMatrix*);
} Skill;
Skill*
skill_create(enum SkillType);
void
skill_destroy(Skill*);
#endif // SKILL_H_

View File

@ -32,7 +32,7 @@
#include "util.h"
void
m_strcpy(char *dest, size_t destsz, char *src)
m_strcpy(char *dest, size_t destsz, const char *src)
{
#ifndef _MSC_VER
UNUSED(destsz);

View File

@ -35,7 +35,7 @@ void *
ec_malloc(unsigned long size);
void
m_strcpy(char *dest, size_t destsz, char *src);
m_strcpy(char *dest, size_t destsz, const char *src);
void
m_strncat(char *dest, size_t destsz, char *src, size_t srcsz);