forked from cyxx/f2bgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.cpp
103 lines (92 loc) · 3.08 KB
/
menu.cpp
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
/*
* Fade To Black engine rewrite
* Copyright (C) 2006-2012 Gregory Montoir ([email protected])
*/
#include "game.h"
#include "render.h"
static const int _y0 = -36;
static const int _y1 = _y0 - 8;
void Game::resetObjectAnim(GameObject *o) {
GameObjectAnimation *anim = &o->anim;
anim->aniheadData = _res.getData(kResType_ANI, anim->animKey, "ANIHEAD");
anim->currentAnimKey = _res.getChild(kResType_ANI, anim->animKey);
anim->anikeyfData = _res.getData(kResType_ANI, anim->currentAnimKey, "ANIKEYF");
anim->framesCount = 0;
anim->ticksCount = 0;
}
int Game::setNextObjectAnim(GameObject *o, int direction) {
int16_t key;
GameObjectAnimation *anim = &o->anim;
switch (direction) {
case 1:
key = _res.getNext(kResType_ANI, anim->currentAnimKey);
if (key == 0) {
return 0;
}
anim->currentAnimKey = key;
++anim->framesCount;
break;
case -1:
key = _res.getPrevious(kResType_ANI, anim->currentAnimKey);
if (key == 0) {
return 0;
}
anim->currentAnimKey = key;
--anim->framesCount;
break;
}
anim->anikeyfData = _res.getData(kResType_ANI, anim->currentAnimKey, "ANIKEYF");
return 1;
}
void Game::initMenu() {
setPalette(_roomsTable[_objectsPtrTable[kObjPtrConrad]->room].palKey);
resetObjectAnim(_objectsPtrTable[kObjPtrSaveloadOption]);
_objectsPtrTable[kObjPtrSaveloadOption]->specialData[1][9] = 16;
SceneObject *so = &_sceneObjectsTable[0];
so->x = 0 << kPosShift;
so->y = _y0 << kPosShift;
so->z = 56 << kPosShift;
}
void Game::loadMenuObjectMesh(GameObject *o, int16_t key) {
SceneObject *so = &_sceneObjectsTable[0];
key = _res.getChild(kResType_ANI, key);
const uint8_t *p_anifram = _res.getData(kResType_ANI, key, "ANIFRAM");
if (p_anifram[2] == 9) {
uint8_t *p_poly3d;
uint8_t *p_form3d = initMesh(kResType_F3D, READ_LE_UINT16(p_anifram), &so->verticesData, &so->polygonsData, o, &p_poly3d, 0);
so->verticesCount = READ_LE_UINT16(p_form3d + 18);
so->pitch = (o->pitch + (p_anifram[3] << 4)) & 1023;
}
}
void Game::doMenu() {
GameObject *o = _objectsPtrTable[kObjPtrSaveloadOption];
loadMenuObjectMesh(o, o->anim.currentAnimKey);
_render->clearScreen();
_render->setupProjection(1);
SceneObject *so = &_sceneObjectsTable[0];
_render->beginObjectDraw(so->x, so->y, so->z, so->pitch, kPosShift);
drawSceneObjectMesh(so->polygonsData, so->verticesData, so->verticesCount);
_render->endObjectDraw();
const int option = (((so->pitch + 512) & 1023) + 64) / 128;
if (getMessage(o->objKey, option, &_tmpMsg)) {
memset(&_drawCharBuf, 0, sizeof(_drawCharBuf));
int w, h;
getStringRect((const char *)_tmpMsg.data, _tmpMsg.font, &w, &h);
drawString((kScreenWidth - w) / 2, 0, (const char *)_tmpMsg.data, _tmpMsg.font, 0);
}
if (inp.dirMask & kInputDirLeft) {
o->pitch += o->specialData[1][9];
o->pitch &= 1023;
}
if (inp.dirMask & kInputDirRight) {
o->pitch -= o->specialData[1][9];
o->pitch &= 1023;
}
if (inp.dirMask & kInputDirUp) {
setNextObjectAnim(o, 1);
}
if (inp.dirMask & kInputDirDown) {
setNextObjectAnim(o, -1);
}
so->y = (_y0 << kPosShift) + (o->anim.framesCount * (_y1 - _y0) << kPosShift) / (o->anim.aniheadData[1] - 1);
}