-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitten.c
170 lines (145 loc) · 4.49 KB
/
kitten.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include "nitrofs.h"
#include "kitten.h"
#include "Hardware.h"
#include "game_stats.h"
// animation speed
#define FRAME_DELAY 0
// movement speed
#define KITTEN_SPEED 7
extern int catShouldBeBlinking;
static inline void KittenRotator(Kitten* cat) {
oamRotateScale(
&oamMain,
1,
-512+(cat->x-32)*10,
252,
252
);
}
static void KittenGoLeft(Kitten* cat) {
if (cat->x > 0) { cat->x-=KITTEN_SPEED; }
KittenRotator(cat);
}
static void KittenGoRight(Kitten* cat) {
if (cat->x < SCREEN_WIDTH-64) { cat->x+=KITTEN_SPEED; }
KittenRotator(cat);
}
void KittenInit(Kitten* cat) {
//DISPCNT_A = DISPCNT_MODE_0 | DISPCNT_BG3_ON | DISPCNT_OBJ_ON | DISPCNT_ON;
DISPCNT_A = DISPCNT_MODE_5|DISPCNT_3D|DISPCNT_BG0_ON|DISPCNT_BG3_ON|DISPCNT_ON|DISPCNT_OBJ_ON;
DISPCNT_B = DISPCNT_MODE_5|DISPCNT_BG2_ON|DISPCNT_ON|DISPCNT_OBJ_ON;
VRAMCNT_A = VRAMCNT_A_OBJ_VRAM_A;
VRAMCNT_B = VRAMCNT_B_BG_VRAM_A_OFFS_0K;
VRAMCNT_C = VRAMCNT_C_BG_VRAM_B;
VRAMCNT_D = VRAMCNT_D_OBJ_VRAM_B;
oamInit(&oamMain, SpriteMapping_1D_128, false);
oamInit(&oamSub, SpriteMapping_1D_128, false);
cat->spriteWalking[0] = loadSpriteA32("nitro:/gfx/kitten_walk1.img.bin");
cat->spriteWalking[1] = loadSpriteA32("nitro:/gfx/kitten_walk2.img.bin");
cat->spriteWalking[2] = loadSpriteA32("nitro:/gfx/kitten_walk3.img.bin");
cat->spriteWalking[3] = loadSpriteA32("nitro:/gfx/kitten_walk4.img.bin");
cat->spriteStanding[0] = loadSpriteA32("nitro:/gfx/kitten_stand1.img.bin");
cat->spriteStanding[1] = loadSpriteA32("nitro:/gfx/kitten_stand2.img.bin");
cat->spriteStanding[2] = loadSpriteA32("nitro:/gfx/kitten_stand3.img.bin");
cat->spriteStanding[3] = cat->spriteStanding[1];
cat->blink_sprite = loadSpriteA32(NULL);
cat->palette = malloc(512);
nitroLoad("nitro:/gfx/palette.pal.bin", cat->palette, 512);
dmaCopy(cat->palette, SPRITE_PALETTE, 512); //copy the sprites palette
dmaCopy(cat->palette, SPRITE_PALETTE_SUB, 512); //copy the sprites palette
}
void KittenReset(Kitten* cat) {
cat->state=STANDING;
cat->palette=NULL;
cat->x=SCREEN_WIDTH/2-16;
cat->y=SCREEN_HEIGHT - 64;
cat->frame=0;
cat->frametime=0;
}
static int KittenAnimate(Kitten* cat) {
if(cat->frametime++ >= FRAME_DELAY) {
cat->frametime=0;
if (catShouldBeBlinking) {
if(cat->frame == 0 ) {
cat->frame = 1;
cat->current_sprite = cat->blink_sprite;
} else {
cat->frame = 0;
cat->current_sprite = cat->spriteWalking[cat->frame];
}
} else if (WALKING == cat->state) {
if(cat->frame++ < sizeof(cat->spriteStanding)/sizeof(uint16_t*)-1 ) {
cat->current_sprite = cat->spriteWalking[cat->frame];
} else {
cat->frame = 0;
cat->current_sprite = cat->spriteWalking[cat->frame];
}
} else if (STANDING == cat->state) {
if(cat->frame++ < sizeof(cat->spriteWalking)/sizeof(uint16_t*)-1 ) {
cat->current_sprite = cat->spriteStanding[cat->frame];
} else {
cat->frame = 0;
cat->current_sprite = cat->spriteStanding[cat->frame];
}
}
}
}
int KittenUpdate(Kitten* cat) {
int i,j,k;
static int t=0;
t++;
touchPosition touch;
scanKeys();
int keys = keysHeld();
if(keys & KEY_TOUCH) {
touchRead(&touch);
if ( touch.px != 0x0 && touch.py != 0x0 )
{
//BG_GFX[touch.px + touch.py * 256] = rand();
//bg_buffer[touch.px + touch.py*SCREEN_WIDTH] = RGB15(5,5,31) | BIT(15);
for(i=-2;i<3;i++)
{
for(j=-2;j<3;j++) {
//bg_buffer_sub[touch.px+i + (touch.py+j)* SCREEN_WIDTH] = RGB15(5,10,31) | BIT(15);
}
}
}
}
if(keys & KEY_LEFT) {
KittenGoLeft(cat);
cat->state = WALKING;
} else if(keys & KEY_RIGHT) {
KittenGoRight(cat);
cat->state = WALKING;
int swoop = (t<<13)/50;
// } else if (WALKING == cat->lastState) {
// cat->state = STANDING;
} else {
cat->state = WALKING; //STANDING
if (cat->frame > sizeof(cat->spriteWalking)/sizeof(uint16_t*)-1)
{ cat->frame=0; }
// oamRotateScale(
// &oamMain,
// 1,
// 0,
// 256,
// 256
// );
}
KittenAnimate(cat);
cat->lastState = cat->state;
cat->y = SCREEN_HEIGHT - 64 - floorCenterHeight() * 5;
oamSet(&oamMain, 1, // 0
cat->x, cat->y, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color,
cat->current_sprite,
//-1, false, false, false, false, false);
1, true, false, false, false, false);
oamUpdate(&oamMain);
oamUpdate(&oamSub);
}