Castlevania 64: Implement New Game (#2472)
This commit is contained in:
69
worlds/cv64/src/drop_sub_weapon.c
Normal file
69
worlds/cv64/src/drop_sub_weapon.c
Normal file
@@ -0,0 +1,69 @@
|
||||
// Written by Moisés
|
||||
#include "include/game/module.h"
|
||||
#include "include/game/math.h"
|
||||
#include "cv64.h"
|
||||
|
||||
extern vec3f player_pos;
|
||||
extern vec3s player_angle; // player_angle.y = Player's facing angle (yaw)
|
||||
extern f32 player_height_with_respect_of_floor; // Stored negative in-game
|
||||
|
||||
#define SHT_MAX 32767.0f
|
||||
#define SHT_MINV (1.0f / SHT_MAX)
|
||||
|
||||
void spawn_item_behind_player(s32 item) {
|
||||
interactuablesModule* pickable_item = NULL;
|
||||
const f32 spawnDistance = 8.0f;
|
||||
vec3f player_backwards_dir;
|
||||
|
||||
pickable_item = (interactuablesModule*)module_createAndSetChild(moduleList_findFirstModuleByID(ACTOR_CREATOR), ACTOR_ITEM);
|
||||
if (pickable_item != NULL) {
|
||||
// Convert facing angle to a vec3f
|
||||
// SHT_MINV needs to be negative here for the item to be spawned properly on the character's back
|
||||
player_backwards_dir.x = coss(-player_angle.y) * -SHT_MINV;
|
||||
player_backwards_dir.z = sins(-player_angle.y) * -SHT_MINV;
|
||||
// Multiply facing vector with distance away from the player
|
||||
vec3f_multiplyScalar(&player_backwards_dir, &player_backwards_dir, spawnDistance);
|
||||
// Assign the position of the item relative to the player's current position.
|
||||
vec3f_add(&pickable_item->position, &player_pos, &player_backwards_dir);
|
||||
// The Y position of the item will be the same as the floor right under the player
|
||||
// The player's height with respect of the flower under them is already stored negative in-game,
|
||||
// so no need to substract
|
||||
pickable_item->position.y = player_pos.y + 5.0f;
|
||||
pickable_item->height = pickable_item->position.y;
|
||||
|
||||
// Assign item ID
|
||||
pickable_item->item_ID = item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const f32 droppingAccel = 0.05f;
|
||||
const f32 maxDroppingSpeed = 1.5f;
|
||||
f32 droppingSpeed = 0.0f;
|
||||
f32 droppingTargetYPos = 0.0f;
|
||||
u8 dropItemCalcFuncCalled = FALSE;
|
||||
|
||||
s32 drop_item_calc(interactuablesModule* pickable_item) {
|
||||
if (dropItemCalcFuncCalled == FALSE) {
|
||||
droppingTargetYPos = player_pos.y + player_height_with_respect_of_floor + 1.0f;
|
||||
if (pickable_item->item_ID == CROSS || pickable_item->item_ID == AXE ||
|
||||
pickable_item->item_ID == CROSS__VANISH || pickable_item->item_ID == AXE__VANISH) {
|
||||
droppingTargetYPos += 3.0f;
|
||||
}
|
||||
dropItemCalcFuncCalled = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
if (pickable_item->position.y <= droppingTargetYPos) {
|
||||
droppingSpeed = 0.0f;
|
||||
dropItemCalcFuncCalled = FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
if (droppingSpeed < maxDroppingSpeed) {
|
||||
droppingSpeed += droppingAccel;
|
||||
}
|
||||
pickable_item->position.y -= droppingSpeed;
|
||||
pickable_item->height = pickable_item->position.y;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
116
worlds/cv64/src/print.c
Normal file
116
worlds/cv64/src/print.c
Normal file
@@ -0,0 +1,116 @@
|
||||
// Written by Moisés.
|
||||
// NOTE: This is an earlier version to-be-replaced.
|
||||
#include <memory.h>
|
||||
#include <textbox.h>
|
||||
|
||||
// Helper function
|
||||
// https://decomp.me/scratch/9H1Uy
|
||||
u32 convertUTF8StringToUTF16(char* src, u16* buffer) {
|
||||
u32 string_length = 0;
|
||||
|
||||
// If the source string starts with a null char (0), we assume the string empty.
|
||||
if (*src != 0) {
|
||||
// Copy the char from the source string into the bufferination.
|
||||
// Then advance to the next char until we find the null char (0).
|
||||
do {
|
||||
*buffer = *src;
|
||||
src++;
|
||||
buffer++;
|
||||
string_length++;
|
||||
} while (*src != 0);
|
||||
}
|
||||
// Make sure to add the null char at the end of the bufferination string,
|
||||
// and then return the length of the string.
|
||||
*buffer = 0;
|
||||
return string_length;
|
||||
}
|
||||
|
||||
// Begin printing ASCII text stored in a char*
|
||||
textbox* print_text(const char* message, const s16 X_pos, const s16 Y_pos, const u8 number_of_lines, const s16 textbox_width, const u32 txtbox_flags, const void* module) {
|
||||
textbox* (*ptr_textbox_create)(void*, void*, u32) = textbox_create;
|
||||
void (*ptr_textbox_setPos)(textbox*, u16, u16, s32) = textbox_setPos;
|
||||
void (*ptr_textbox_setDimensions)(textbox*, s8, s16, u8, u8) = textbox_setDimensions;
|
||||
void (*ptr_textbox_setMessagePtr)(textbox*, u16*, s32, s16) = textbox_setMessagePtr;
|
||||
u16* (*ptr_convertUTF16ToCustomTextFormat)(u16*) = convertUTF16ToCustomTextFormat;
|
||||
void* (*ptr_malloc)(s32, u32) = malloc;
|
||||
|
||||
textbox* txtbox = NULL;
|
||||
|
||||
// Allocate memory for the text buffer
|
||||
u16* text_buffer = (u16*) ptr_malloc(0, 100);
|
||||
|
||||
// Create the textbox data structure
|
||||
if (module != NULL) {
|
||||
txtbox = ptr_textbox_create(module, HUD_camera, txtbox_flags);
|
||||
}
|
||||
|
||||
if (txtbox != NULL && text_buffer != NULL && message != NULL) {
|
||||
// Set text position and dimensions
|
||||
ptr_textbox_setPos(txtbox, X_pos, Y_pos, 1);
|
||||
ptr_textbox_setDimensions(txtbox, number_of_lines, textbox_width, 0, 0);
|
||||
|
||||
// Convert the ASCII message to the CV64 custom format
|
||||
convertUTF8StringToUTF16(message, text_buffer);
|
||||
ptr_convertUTF16ToCustomTextFormat(text_buffer);
|
||||
|
||||
// Set the text buffer pointer to the textbox data structure
|
||||
ptr_textbox_setMessagePtr(txtbox, text_buffer, 0, 0);
|
||||
}
|
||||
// We return the textbox so that we can modify its properties once it begins printing
|
||||
// (say to show, hide the text)
|
||||
return txtbox;
|
||||
}
|
||||
|
||||
// Begin printing signed integer
|
||||
textbox* print_number(const s32 number, u16* text_buffer, const s16 X_pos, const s16 Y_pos, const u8 number_of_digits, const u32 txtbox_flags, const u32 additional_text_flag, const void* module) {
|
||||
textbox* (*ptr_textbox_create)(void*, void*, u32) = textbox_create;
|
||||
void (*ptr_textbox_setPos)(textbox*, u16, u16, s32) = textbox_setPos;
|
||||
void (*ptr_textbox_setDimensions)(textbox*, s8, s16, u8, u8) = textbox_setDimensions;
|
||||
void (*ptr_textbox_setMessagePtr)(textbox*, u16*, s32, s16) = textbox_setMessagePtr;
|
||||
void (*ptr_text_convertIntNumberToText)(u32, u16*, u8, u32) = text_convertIntNumberToText;
|
||||
|
||||
textbox* txtbox = NULL;
|
||||
|
||||
// Create the textbox data structure
|
||||
if (module != NULL) {
|
||||
txtbox = ptr_textbox_create(module, HUD_camera, txtbox_flags);
|
||||
}
|
||||
|
||||
if (txtbox != NULL && text_buffer != NULL) {
|
||||
// Set text position and dimensions
|
||||
ptr_textbox_setPos(txtbox, X_pos, Y_pos, 1);
|
||||
ptr_textbox_setDimensions(txtbox, 1, 100, 0, 0);
|
||||
|
||||
// Convert the number to the CV64 custom format
|
||||
ptr_text_convertIntNumberToText(number, text_buffer, number_of_digits, additional_text_flag);
|
||||
|
||||
// Set the text buffer pointer to the textbox data structure
|
||||
ptr_textbox_setMessagePtr(txtbox, text_buffer, 0, 0);
|
||||
}
|
||||
// We return the textbox so that we can modify its properties once it begins printing
|
||||
// (say to show, hide the text)
|
||||
return txtbox;
|
||||
}
|
||||
|
||||
// Update the value of a number that began printing after calling "print_number()"
|
||||
void update_printed_number(textbox* txtbox, const s32 number, u16* text_buffer, const u8 number_of_digits, const u32 additional_text_flag) {
|
||||
void (*ptr_text_convertIntNumberToText)(u32, u16*, u8, u32) = text_convertIntNumberToText;
|
||||
|
||||
if (text_buffer != NULL) {
|
||||
ptr_text_convertIntNumberToText(number, text_buffer, number_of_digits, additional_text_flag);
|
||||
txtbox->flags |= 0x1000000; // Needed to make sure the number updates properly
|
||||
}
|
||||
}
|
||||
|
||||
void display_text(textbox* txtbox, const u8 display_textbox) {
|
||||
if (txtbox != NULL) {
|
||||
if (display_textbox == TRUE) {
|
||||
// Show text
|
||||
txtbox->flags &= ~HIDE_TEXTBOX;
|
||||
}
|
||||
else {
|
||||
// Hide text
|
||||
txtbox->flags |= HIDE_TEXTBOX;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
worlds/cv64/src/print_text_ovl.c
Normal file
26
worlds/cv64/src/print_text_ovl.c
Normal file
@@ -0,0 +1,26 @@
|
||||
// Written by Moisés
|
||||
#include "print.h"
|
||||
#include <textbox.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define counter_X_pos 30
|
||||
#define counter_Y_pos 40
|
||||
#define counter_number_of_digits 2
|
||||
#define GOLD_JEWEL_FONT 0x14
|
||||
|
||||
extern u8 bytes[13];
|
||||
|
||||
u16* number_text_buffer = NULL;
|
||||
textbox* txtbox = NULL;
|
||||
|
||||
void begin_print() {
|
||||
// Allocate memory for the number text
|
||||
number_text_buffer = (u16*) malloc(0, 12);
|
||||
|
||||
// Assuming that 0x80342814 = HUD Module
|
||||
txtbox = print_number(0, number_text_buffer, counter_X_pos, counter_Y_pos, counter_number_of_digits, 0x08600000, GOLD_JEWEL_FONT, (void*) 0x80342814);
|
||||
}
|
||||
|
||||
void update_print(u8 i) {
|
||||
update_printed_number(txtbox, (s32) bytes[i], number_text_buffer, counter_number_of_digits, GOLD_JEWEL_FONT);
|
||||
}
|
||||
Reference in New Issue
Block a user