1 /* 2 Copyright © 2022, Inochi2D Project 3 Distributed under the 2-Clause BSD License, see LICENSE file. 4 5 Authors: Luna Nielsen 6 */ 7 module creator.core.egg; 8 import creator.core; 9 import inochi2d; 10 import bindbc.sdl; 11 import bindbc.opengl; 12 import std.stdio; 13 import std.random; 14 15 version(InBranding) { 16 private { 17 int logoClickCounter; 18 vec2 adaOffset; 19 vec2 adaVelocity; 20 enum ADA_SIZE = 396; 21 enum CLICK_THRESH = 25; 22 23 enum JUMP_SPEED_X = 500; 24 enum JUMP_SPEED_Y = 700; 25 bool lhs; 26 Camera cam; 27 28 Shader adaShader; 29 } 30 31 void incAdaTickOne() { 32 logoClickCounter++; 33 if (logoClickCounter == CLICK_THRESH) { 34 lhs = !lhs; 35 36 float uiScale = incGetUIScale(); 37 int w, h; 38 SDL_GetWindowSize(incGetWindowPtr(), &w, &h); 39 40 float adaHalf = (ADA_SIZE*uiScale)/2; 41 float hws = (w/2)/uiScale; 42 43 // Alternate jumping from left and right 44 float spawnX = lhs ? uniform(-(hws+adaHalf), -adaHalf) : uniform(adaHalf, hws-adaHalf); 45 float dirX = (lhs ? uniform(-JUMP_SPEED_X, -100) : uniform(100, JUMP_SPEED_X))*uiScale; 46 adaVelocity = vec2(dirX, -JUMP_SPEED_Y*uiScale); 47 adaOffset = vec2(spawnX, 0); 48 } 49 } 50 51 // UwU 52 void incAdaUpdate() { 53 if (logoClickCounter >= CLICK_THRESH) { 54 float uiScale = incGetUIScale(); 55 56 int w, h; 57 int ww, wh; 58 inGetViewport(ww, wh); 59 SDL_GetWindowSize(incGetWindowPtr(), &w, &h); 60 61 glDisable(GL_DEPTH_TEST); 62 glDisable(GL_CULL_FACE); 63 glEnable(GL_BLEND); 64 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 65 66 float halfWidth = w/2; 67 float halfHeight = h/2; 68 69 adaOffset -= adaVelocity*deltaTime(); 70 adaVelocity.y += 500.0*deltaTime(); 71 72 inSetViewport(w, h); 73 inDrawTextureAtRect( 74 incGetAda(), 75 rect(adaOffset.x, halfHeight-adaOffset.y, ADA_SIZE*uiScale, ADA_SIZE*uiScale), 76 rect(0, 0, 1, 1), 77 1, 78 vec3(1, 1, 1), 79 vec3(0, 0, 0), 80 adaShader, 81 cam 82 ); 83 84 inSetViewport(ww, wh); 85 86 // Animation is over 87 if (adaOffset.y < -((ADA_SIZE+32)*uiScale)) { 88 logoClickCounter = 0; 89 } 90 } 91 } 92 93 void incInitAda() { 94 adaShader = new Shader(import("shaders/ada.vert"), import("shaders/ada.frag")); 95 96 cam = new Camera(); 97 cam.position = vec2(0, 0); 98 cam.scale = vec2(1, 1); 99 cam.rotation = 0; 100 } 101 }