Restoring blinking
This commit is contained in:
		@@ -23,4 +23,6 @@ void pokerCharacterJennyInit(vncharacter_t *vnc) {
 | 
				
			|||||||
    608, 250,
 | 
					    608, 250,
 | 
				
			||||||
    280, 123
 | 
					    280, 123
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  vnc->breathing = false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,19 +12,19 @@ void pokerCharacterJulieInit(vncharacter_t *vnc) {
 | 
				
			|||||||
  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 1053, 1961);
 | 
					  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 1053, 1961);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Layers
 | 
					  // Layers
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 4,
 | 
					  vnc->layerEyes = vnCharacterLayerAdd(vnc, 4,
 | 
				
			||||||
    1053, 0,
 | 
					    1053, 0,
 | 
				
			||||||
    353, 119,
 | 
					    353, 119,
 | 
				
			||||||
    344, 351
 | 
					    344, 351
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 12,
 | 
					  vnc->layerMouth = vnCharacterLayerAdd(vnc, 12,
 | 
				
			||||||
    1053, 351,
 | 
					    1053, 351,
 | 
				
			||||||
    353, 119,
 | 
					    353, 119,
 | 
				
			||||||
    344, 351
 | 
					    344, 351
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 4,
 | 
					  vnc->layerEyebrows = vnCharacterLayerAdd(vnc, 4,
 | 
				
			||||||
    1053, 702,
 | 
					    1053, 702,
 | 
				
			||||||
    353, 119,
 | 
					    353, 119,
 | 
				
			||||||
    344, 351
 | 
					    344, 351
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,20 +13,19 @@ void pokerCharacterLucyInit(vncharacter_t *vnc) {
 | 
				
			|||||||
  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 1440, 2240);
 | 
					  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 1440, 2240);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Layers
 | 
					  // Layers
 | 
				
			||||||
  
 | 
					  vnc->layerEyes = vnCharacterLayerAdd(vnc, 5,
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 5,
 | 
					 | 
				
			||||||
    1440, 0,
 | 
					    1440, 0,
 | 
				
			||||||
    675, 327,
 | 
					    675, 327,
 | 
				
			||||||
    295, 235
 | 
					    295, 235
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 12,
 | 
					  vnc->layerMouth = vnCharacterLayerAdd(vnc, 12,
 | 
				
			||||||
    1440, 235,
 | 
					    1440, 235,
 | 
				
			||||||
    675, 327,
 | 
					    675, 327,
 | 
				
			||||||
    295, 235
 | 
					    295, 235
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 5,
 | 
					  vnc->layerEyebrows = vnCharacterLayerAdd(vnc, 5,
 | 
				
			||||||
    1440, 470,
 | 
					    1440, 470,
 | 
				
			||||||
    675, 327,
 | 
					    675, 327,
 | 
				
			||||||
    295, 235
 | 
					    295, 235
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,19 +12,19 @@ void pokerCharacterPennyInit(vncharacter_t *vnc) {
 | 
				
			|||||||
  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 1000, 1920);
 | 
					  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 1000, 1920);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Layers
 | 
					  // Layers
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 5,
 | 
					  vnc->layerEyebrows = vnCharacterLayerAdd(vnc, 5,
 | 
				
			||||||
    1000, 0,
 | 
					    1000, 0,
 | 
				
			||||||
    367, 256,
 | 
					    367, 256,
 | 
				
			||||||
    280, 280
 | 
					    280, 280
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 4,
 | 
					  vnc->layerEyes = vnCharacterLayerAdd(vnc, 4,
 | 
				
			||||||
    1000, 280,
 | 
					    1000, 280,
 | 
				
			||||||
    367, 256,
 | 
					    367, 256,
 | 
				
			||||||
    280, 280
 | 
					    280, 280
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 12,
 | 
					  vnc->layerMouth = vnCharacterLayerAdd(vnc, 12,
 | 
				
			||||||
    1000, 560,
 | 
					    1000, 560,
 | 
				
			||||||
    367, 256,
 | 
					    367, 256,
 | 
				
			||||||
    280, 280
 | 
					    280, 280
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,19 +12,19 @@ void pokerCharacterSammyInit(vncharacter_t *vnc) {
 | 
				
			|||||||
  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 731, 2122);
 | 
					  vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, 731, 2122);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Layers
 | 
					  // Layers
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 4,
 | 
					  vnc->layerEyes = vnCharacterLayerAdd(vnc, 4,
 | 
				
			||||||
    731, 0,
 | 
					    731, 0,
 | 
				
			||||||
    215, 264,
 | 
					    215, 264,
 | 
				
			||||||
    307, 213
 | 
					    307, 213
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 12,
 | 
					  vnc->layerMouth = vnCharacterLayerAdd(vnc, 12,
 | 
				
			||||||
    731, 213,
 | 
					    731, 213,
 | 
				
			||||||
    215, 264,
 | 
					    215, 264,
 | 
				
			||||||
    307, 213
 | 
					    307, 213
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  vnCharacterLayerAdd(vnc, 5,
 | 
					  vnc->layerEyebrows = vnCharacterLayerAdd(vnc, 5,
 | 
				
			||||||
    731, 426,
 | 
					    731, 426,
 | 
				
			||||||
    215, 264,
 | 
					    215, 264,
 | 
				
			||||||
    307, 213
 | 
					    307, 213
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,6 @@ void pokerGameUpdate(pokergame_t *game) {
 | 
				
			|||||||
    game->poker.players
 | 
					    game->poker.players
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Bind the shader.
 | 
					  // Bind the shader.
 | 
				
			||||||
  shaderUse(&game->assets.shader);
 | 
					  shaderUse(&game->assets.shader);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,6 +51,6 @@
 | 
				
			|||||||
#define randRange(n, min, max) (mathMod(n, (max-min)) + min)
 | 
					#define randRange(n, min, max) (mathMod(n, (max-min)) + min)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define randInt32Range(min, max) randRange(randInt32(), min, max)
 | 
					#define randInt32Range(min, max) randRange(randInt32(), min, max)
 | 
				
			||||||
#define randFloatRange(min, max) (fmod(randFloat(), max- min) + min)
 | 
					#define randFloatRange(min, max) ((float)fmod(randFloat(), max- min) + min)
 | 
				
			||||||
#define randUint32Range(min, max) randRange(randUint32(), min, max)
 | 
					#define randUint32Range(min, max) randRange(randUint32(), min, max)
 | 
				
			||||||
#define randUint8Range(min, max) randRange(randUint8(), min, max)
 | 
					#define randUint8Range(min, max) randRange(randUint8(), min, max)
 | 
				
			||||||
@@ -7,7 +7,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "vncharacter.h"
 | 
					#include "vncharacter.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void vnCharacterInit(vncharacter_t *character, texture_t *texture) {
 | 
					void vnCharacterInit(vncharacter_t *character, texture_t *texture) {
 | 
				
			||||||
  character->x = 0;
 | 
					  character->x = 0;
 | 
				
			||||||
  character->y = 0;
 | 
					  character->y = 0;
 | 
				
			||||||
@@ -22,6 +21,12 @@ void vnCharacterInit(vncharacter_t *character, texture_t *texture) {
 | 
				
			|||||||
  character->layerCount = 0;
 | 
					  character->layerCount = 0;
 | 
				
			||||||
  character->texture = texture;
 | 
					  character->texture = texture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  character->layerEyes = 0xFF;
 | 
				
			||||||
 | 
					  character->layerMouth = 0xFF;
 | 
				
			||||||
 | 
					  character->layerEyebrows = 0xFF;
 | 
				
			||||||
 | 
					  character->breathing = true;
 | 
				
			||||||
 | 
					  character->blinkStart = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Init the primitive.
 | 
					  // Init the primitive.
 | 
				
			||||||
  primitiveInit(&character->primitive,
 | 
					  primitiveInit(&character->primitive,
 | 
				
			||||||
    QUAD_VERTICE_COUNT * VN_CHARACTER_LAYERS_MAX,
 | 
					    QUAD_VERTICE_COUNT * VN_CHARACTER_LAYERS_MAX,
 | 
				
			||||||
@@ -30,10 +35,25 @@ void vnCharacterInit(vncharacter_t *character, texture_t *texture) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine) {
 | 
					void vnCharacterUpdate(vncharacter_t *character, engine_t *engine) {
 | 
				
			||||||
  float t;
 | 
					  float t, n;
 | 
				
			||||||
  float speed, amount;
 | 
					  float speed, amount;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Setup frames based on the emotion.
 | 
					  // Setup frames based on the emotion.
 | 
				
			||||||
 | 
					  if(character->layerEyes != 0xFF) {
 | 
				
			||||||
 | 
					    n = (engine->time.current-character->blinkStart)*VN_CHARACTER_BLINK_SPEED;
 | 
				
			||||||
 | 
					    if(n > 1.0f) {
 | 
				
			||||||
 | 
					      character->blinkStart = engine->time.current + randFloatRange(
 | 
				
			||||||
 | 
					        1, VN_CHARACTER_BLINK_TIME_RANGE_MAX
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    } else if(n > 0) {
 | 
				
			||||||
 | 
					      n = (
 | 
				
			||||||
 | 
					        easeInQuad(animForwardAndBackwardScaled(n)) *
 | 
				
			||||||
 | 
					        character->layers[character->layerEyes].frames
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      vnCharacterLayerSetFrame(character, character->layerEyes, (int32_t)n);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // mouth = character->emotion % 0x04;
 | 
					  // mouth = character->emotion % 0x04;
 | 
				
			||||||
  // eyes = (character->emotion/0x04) % 0x04;
 | 
					  // eyes = (character->emotion/0x04) % 0x04;
 | 
				
			||||||
  // eyebrows = ((character->emotion/0x04)/0x04) % 0x05;
 | 
					  // eyebrows = ((character->emotion/0x04)/0x04) % 0x05;
 | 
				
			||||||
@@ -76,14 +96,19 @@ void vnCharacterUpdate(vncharacter_t *character, engine_t *engine) {
 | 
				
			|||||||
  // }
 | 
					  // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Update the scale frames for breathing / talk breathing
 | 
					  // Update the scale frames for breathing / talk breathing
 | 
				
			||||||
  speed = 0.2f;
 | 
					  if(character->breathing) {
 | 
				
			||||||
  amount = 90.0f;
 | 
					    speed = 0.2f;
 | 
				
			||||||
  t = animForwardAndBackwardScaled(
 | 
					    amount = 90.0f;
 | 
				
			||||||
    mathModFloat(engine->time.current, 1 / speed) * speed
 | 
					    t = animForwardAndBackwardScaled(
 | 
				
			||||||
  );
 | 
					      mathModFloat(engine->time.current, 1 / speed) * speed
 | 
				
			||||||
  t = easeInOutQuad(t) / amount - (1/(amount*2));
 | 
					    );
 | 
				
			||||||
  character->scaleX = 1 + t;
 | 
					    t = easeInOutQuad(t) / amount - (1/(amount*2));
 | 
				
			||||||
  character->scaleY = 1 - t;
 | 
					    character->scaleX = 1 + t;
 | 
				
			||||||
 | 
					    character->scaleY = 1 - t;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    character->scaleX = 1;
 | 
				
			||||||
 | 
					    character->scaleY = 1;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,10 +17,11 @@
 | 
				
			|||||||
#include "../display/animation/easing.h"
 | 
					#include "../display/animation/easing.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define VN_CHARACTER_BLINK_TIME_RANGE_MAX 6
 | 
					#define VN_CHARACTER_BLINK_TIME_RANGE_MAX 6
 | 
				
			||||||
 | 
					#define VN_CHARACTER_BLINK_SPEED 3.0f
 | 
				
			||||||
#define VN_CHARACTER_LAYERS_MAX 6
 | 
					#define VN_CHARACTER_LAYERS_MAX 6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
  int32_t lx, ly, x, y, width, height;
 | 
					  int16_t lx, ly, x, y, width, height;
 | 
				
			||||||
  uint8_t frames;
 | 
					  uint8_t frames;
 | 
				
			||||||
} vncharacterlayer_t;
 | 
					} vncharacterlayer_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,18 +36,24 @@ typedef struct {
 | 
				
			|||||||
  /** Texture sheet for the character */
 | 
					  /** Texture sheet for the character */
 | 
				
			||||||
  texture_t *texture;
 | 
					  texture_t *texture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** Count of layers */
 | 
					  /** Layer Information */
 | 
				
			||||||
  vncharacterlayer_t layers[VN_CHARACTER_LAYERS_MAX];
 | 
					  vncharacterlayer_t layers[VN_CHARACTER_LAYERS_MAX];
 | 
				
			||||||
  uint8_t layerCount;
 | 
					  uint8_t layerCount;
 | 
				
			||||||
 | 
					  uint8_t layerEyes;
 | 
				
			||||||
 | 
					  uint8_t layerMouth;
 | 
				
			||||||
 | 
					  uint8_t layerEyebrows;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bool breathing;
 | 
				
			||||||
 | 
					  float blinkStart;
 | 
				
			||||||
} vncharacter_t; 
 | 
					} vncharacter_t; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void vnCharacterInit(vncharacter_t *character, texture_t *texture);
 | 
					void vnCharacterInit(vncharacter_t *character, texture_t *texture);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint8_t vnCharacterLayerAdd(vncharacter_t *character,
 | 
					uint8_t vnCharacterLayerAdd(vncharacter_t *character,
 | 
				
			||||||
  uint8_t frames,
 | 
					  uint8_t frames,
 | 
				
			||||||
  int32_t lx, int32_t ly,
 | 
					  int16_t lx, int16_t ly,
 | 
				
			||||||
  int32_t x, int32_t y,
 | 
					  int16_t x, int16_t y,
 | 
				
			||||||
  int32_t width, int32_t height
 | 
					  int16_t width, int16_t height
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f);
 | 
					void vnCharacterLayerSetFrame(vncharacter_t *character, uint8_t l, uint8_t f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user