1 /* 2 C-Dogs SDL 3 A port of the legendary (and fun) action/arcade cdogs. 4 Copyright (c) 2013-2016, 2018-2019 Cong Xu 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions are met: 9 10 Redistributions of source code must retain the above copyright notice, this 11 list of conditions and the following disclaimer. 12 Redistributions in binary form must reproduce the above copyright notice, 13 this list of conditions and the following disclaimer in the documentation 14 and/or other materials provided with the distribution. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #pragma once 29 30 #include <json/json.h> 31 32 #include "defs.h" 33 #include "grafx.h" 34 #include "pic.h" 35 36 typedef struct 37 { 38 Pic pic; 39 char *name; 40 } NamedPic; 41 typedef struct 42 { 43 CArray pics; // of Pic 44 char *name; 45 } NamedSprites; 46 47 typedef enum 48 { 49 PICTYPE_NORMAL, 50 PICTYPE_DIRECTIONAL, 51 PICTYPE_ANIMATED, 52 PICTYPE_ANIMATED_RANDOM 53 } PicType; 54 PicType StrPicType(const char *s); 55 // Abstract drawable pic, can draw multiple types of pics 56 typedef struct 57 { 58 PicType Type; 59 union 60 { 61 const Pic *Pic; 62 const CArray *Sprites; // of Pic 63 struct 64 { 65 const CArray *Sprites; // of Pic 66 int Count; 67 int Frame; 68 int TicksPerFrame; 69 } Animated; 70 } u; 71 color_t Mask; 72 } CPic; 73 typedef struct 74 { 75 direction_e Dir; 76 struct vec2i Offset; 77 double Radians; 78 struct vec2 Scale; 79 color_t Mask; 80 SDL_RendererFlip Flip; 81 } CPicDrawContext; 82 CPicDrawContext CPicDrawContextNew(void); 83 typedef void (*DrawCPicFunc)(GraphicsDevice *, const int, const struct vec2i); 84 85 void NamedPicFree(NamedPic *n); 86 87 void NamedSpritesInit(NamedSprites *ns, const char *name); 88 void NamedSpritesFree(NamedSprites *ns); 89 90 void CPicLoadJSON(CPic *p, json_t *node); 91 void CPicInitNormal(CPic *p, const Pic *pic); 92 void CPicInitNormalFromName(CPic *p, const char *name); 93 void CPicLoadNormal(CPic *p, const json_t *node); 94 bool CPicIsLoaded(const CPic *p); 95 struct vec2i CPicGetSize(const CPic *p); 96 // Copy everything except frame 97 void CPicCopyPic(CPic *dest, const CPic *src); 98 void CPicUpdate(CPic *p, const int ticks); 99 const Pic *CPicGetPic(const CPic *p, const int idx); 100 void CPicDraw( 101 GraphicsDevice *g, const CPic *p, 102 const struct vec2i pos, const CPicDrawContext *context); 103