PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
object.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------
2 
3  object.h -- definitions for SNES objects
4 
5  Copyright (C) 2012-2024
6  Alekmaul, Nub1604
7 
8  This software is provided 'as-is', without any express or implied
9  warranty. In no event will the authors be held liable for any
10  damages arising from the use of this software.
11 
12  Permission is granted to anyone to use this software for any
13  purpose, including commercial applications, and to alter it and
14  redistribute it freely, subject to the following restrictions:
15 
16  1. The origin of this software must not be misrepresented; you
17  must not claim that you wrote the original software. If you use
18  this software in a product, an acknowledgment in the product
19  documentation would be appreciated but is not required.
20 
21  2. Altered source versions must be plainly marked as such, and
22  must not be misrepresented as being the original software.
23 
24  3. This notice may not be removed or altered from any source
25  distribution.
26 
27  Special thanks to Nub1604 for the slope management
28 
29 ---------------------------------------------------------------------------------*/
36 #ifndef SNES_OBJECTS_INCLUDE
37 #define SNES_OBJECTS_INCLUDE
38 
39 #include <snes/snestypes.h>
40 
41 #define OB_MAX 64
43 #define OB_TYPE_MAX 64
48 typedef struct
49 {
50  u16 prev;
51  u16 next;
52  u8 type;
53  u8 nID;
54  u16 sprnum;
55  u16 sprid3216;
56  u16 sprblk3216;
57  u8 sprflip;
58  u8 sprpal;
59  u16 sprframe;
60  u8 xpos[3];
61  u8 ypos[3];
62  u16 xofs;
63  u16 yofs;
64  u16 width;
65  u16 height;
66  u16 xmin;
67  u16 xmax;
68  s16 xvel;
69  s16 yvel;
70  u16 tilestand;
71  u16 tileabove;
72  u16 tilesprop;
73  u16 tilebprop;
74  u16 action;
75  u8 status;
76  u8 tempo;
77  u8 count;
78  u8 dir;
79  u16 parentID;
80  u8 hitpoints;
82  u8 onscreen;
83  u8 objnotused[7];
84 } t_objs __attribute__((__packed__)); // seems to do nothing :/
85 
86 extern u16 objptr;
87 extern u8 objtokill;
88 extern u16 objgetid;
90 extern t_objs objbuffers[OB_MAX];
92 #define T_EMPTY 0x0000
93 #define T_SOLID 0xFF00
94 #define T_LADDER 0x0001
95 #define T_FIRES 0x0002
96 #define T_SPIKE 0x0004
97 #define T_PLATE 0x0008
98 #define T_SLOPEU1 0x0020
99 #define T_SLOPED1 0x0021
100 #define T_SLOPELU2 0x0022
101 #define T_SLOPELD2 0x0023
102 #define T_SLOPEUU2 0x0024
103 #define T_SLOPEUD2 0x0025
105 #define ACT_STAND 0x0000
106 #define ACT_WALK 0x0001
107 #define ACT_JUMP 0x0002
108 #define ACT_FALL 0x0004
109 #define ACT_CLIMB 0x0008
110 #define ACT_DIE 0x0010
111 #define ACT_BURN 0x0020
116 void objInitEngine(void);
117 
123 void objInitGravity(u16 objgravity, u16 objfriction);
124 
140 void objInitFunctions(u8 objtype, void *initfct, void *updfct, void *reffct);
141 
153 void objLoadObjects(u8 *sourceO);
154 
162 u16 objNew(u8 objtype, u16 x, u16 y);
163 
168 void objGetPointer(u16 objhandle);
169 
174 void objKill(u16 objhandle);
175 
179 void objKillAll(void);
180 
185 void objUpdateAll(void);
186 
192 void objRefreshAll(void);
193 
200 void objCollidMap(u16 objhandle);
201 
209 void objCollidMapWithSlopes(u16 objhandle);
210 
217 void objCollidMap1D(u16 objhandle);
218 
225 u16 objCollidObj(u16 objhandle1, u16 objhandle2);
226 
232 void objUpdateXY(u16 objhandle);
233 
234 #endif // SNES_OBJECTS_INCLUDE
void objUpdateXY(u16 objhandle)
Update X & Y coordinates of object regarding its own velocitys.
void objRefreshAll(void)
call refresh function for all objects currently on screen.
void objCollidMapWithSlopes(u16 objhandle)
check if an object collides the map with map slopes management
t_objs objbuffers[OB_MAX]
current object buffer with all objects
u16 objNew(u8 objtype, u16 x, u16 y)
Initialize a new object in game, objgetid will has the id of the object.
void objCollidMap(u16 objhandle)
check if an object collides the map
void objInitFunctions(u8 objtype, void *initfct, void *updfct, void *reffct)
Initialize the object type functions (initialize, update)
u16 objptr
pointer to current object
void objUpdateAll(void)
call update function for all objects currently active (if they are in "virtual screen" coordinates).
#define OB_MAX
Definition: object.h:41
void objGetPointer(u16 objhandle)
get the pointer to an object from its handle (need to do -1 to have offset after),...
void objKill(u16 objhandle)
kill an object from the game
void objInitEngine(void)
Initialize object engine, need to be called once.
void objCollidMap1D(u16 objhandle)
check if an object collides the map
u16 objgetid
id of current object (useful when creating it)
u8 objtokill
put 1 in variable to kill current object
u16 objCollidObj(u16 objhandle1, u16 objhandle2)
check if two objects are colliding
void objLoadObjects(u8 *sourceO)
Load all objects for a specific table in memory.
void objKillAll(void)
kill all objects currently active
Custom types used by libsnes.
object definition (64 bytes)
Definition: object.h:49
u8 type
Definition: object.h:52
u16 parentID
Definition: object.h:79
u16 sprframe
Definition: object.h:59
u8 sprflip
Definition: object.h:57
u8 onscreen
Definition: object.h:82
u8 tempo
Definition: object.h:76
u8 sprrefresh
Definition: object.h:81
s16 xvel
Definition: object.h:68
u16 height
Definition: object.h:65
s16 yvel
Definition: object.h:69
u16 width
Definition: object.h:64
u16 sprblk3216
Definition: object.h:56
u16 tilebprop
Definition: object.h:73
u16 yofs
Definition: object.h:63
u8 hitpoints
Definition: object.h:80
u16 tilesprop
Definition: object.h:72
u8 nID
Definition: object.h:53
u8 count
Definition: object.h:77
u16 prev
Definition: object.h:50
u8 status
Definition: object.h:75
u8 sprpal
Definition: object.h:58
u16 sprid3216
Definition: object.h:55
u16 xmax
Definition: object.h:67
u16 xofs
Definition: object.h:62
u8 dir
Definition: object.h:78
u16 tileabove
Definition: object.h:71
u16 sprnum
Definition: object.h:54
u16 tilestand
Definition: object.h:70
u16 action
Definition: object.h:74
u16 next
Definition: object.h:51
u16 xmin
Definition: object.h:66