Skip to content

Commit

Permalink
俺はがんばったよ……
Browse files Browse the repository at this point in the history
  • Loading branch information
jnc-explosion committed Jan 15, 2024
1 parent 542bc5b commit 7a6ef36
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/engine/GameObject.d
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GameObject: Loggable {

package void realSetup(Context* ctx) {
this._ctx = ctx;
SDL_SetRenderDrawBlendMode(ctx.r, SDL_BLENDMODE_BLEND);
debug {
layer++;
debugSetupPre;
Expand Down Expand Up @@ -118,6 +119,7 @@ class GameObject: Loggable {
}

void color(ubyte r, ubyte g, ubyte b, ubyte a = 255) {
//dbg("僕は皇帝Hikakin: ", r, ", ", g, ", ", b, ", ", a);
ctx.layers[layer] ~= {
SDL_SetRenderDrawColor(ctx.r, r, g, b, a);
};
Expand Down
1 change: 1 addition & 0 deletions src/engine/components/SpriteRenderer.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SpriteRenderer: Component {
this.colorArr = colorArr;
this.invisdraw = invisdraw;
}

// Vec3
this(Vec2 psize, ubyte[3] colorArr = [255, 255, 255], bool invisdraw = false){
this.psize = psize;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/core/package.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module engine.core;

public import engine.core.media;
public import engine.core.physics;
//public import engine.core.physics;

public import engine.core.Nullpo;
public import engine.core.Vec2;
6 changes: 2 additions & 4 deletions src/engine/extra/Timer.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import sdl;
class Timer {
ulong started = 0;

this(bool autostart = true) {
if(autostart) start;
}
this() { reset; }

auto start() => started = SDL_GetTicks64;
auto reset() => started = SDL_GetTicks64;
auto cur() => SDL_GetTicks64 - started;
}
8 changes: 8 additions & 0 deletions src/engine/extra/WindowParam.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module engine.extra.WindowParam;

import std;
import engine;

class WindowParam: GameObject {
Vec2 size() => ctx.windowSize;
}
1 change: 1 addition & 0 deletions src/engine/extra/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ public import engine.extra.ui;
public import engine.extra.DebugView;
public import engine.extra.Router;
public import engine.extra.Timer;
public import engine.extra.WindowParam;
71 changes: 71 additions & 0 deletions src/game/effects/Fade.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module game.effects.Fade;

import std;
import game;
import engine;

class Fade: GameObject {
Transform tform;
SpriteRenderer sr;

WindowParam win;
Timer tmr;

bool isDisplay = false, isChanging = false;
uint fadetime;
ubyte[3] color;
private ubyte tp = 255, changeTo = 0;

bool display(bool d){
changeTo = d ? 0 : 255;
isChanging = true;
return (changeTo == 255);
}

bool swap(){
changeTo = (changeTo == 255) ? 0 : 255;
isChanging = true;
return (changeTo == 255);
}

void show(){
changeTo = 0;
isChanging = true;
}

void hide(){
changeTo = 255;
isChanging = true;
}

this(ubyte[3] color = [0, 0, 0], uint fadetime = 1) {
this.color = color;
this.fadetime = fadetime;
tmr = new Timer;
}

override void setup() {
tform = register(new Transform);
win = register(new WindowParam);
ubyte[4] ubyuf = color ~ 255;
dbg(ubyuf, ", ", ubyuf.length);
sr = register(new SpriteRenderer(win.size, ubyuf));

//win = register(new WindowParam);
//tmr = register(new Timer);
}

override void loop() {
if(tmr.cur >= fadetime){
if(!isChanging) goto afterfade; // 表示と変化先が等しい(変化済み)
(changeTo == 0) ? tp-=4 : tp+=4;
if(changeTo == tp){
isChanging = false;
}
tmr.reset;
}
sr.colorArr = color ~ tp;
dbg(sr.colorArr);
afterfade:
}
}
3 changes: 3 additions & 0 deletions src/game/effects/package.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module game.effects;

public import game.effects.Fade;
2 changes: 1 addition & 1 deletion src/game/entities/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public import game.entities.Missile;
public import game.entities.Point;
public import game.entities.TimeLimitClock;
public import game.entities.UI;
public import game.entities.Title;
public import game.entities.Title;
1 change: 1 addition & 0 deletions src/game/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module game;
public import game.entities;
public import game.stages;
public import game.ui;
public import game.effects;

public import game.Game;
4 changes: 4 additions & 0 deletions src/game/stages/title/TitleScene.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TitleScene: RouteObject {
AudioSource audio;
Transform tform;
Timer hoge; // gomi
Fade fd;

this() {
hoge = new Timer;
Expand All @@ -24,9 +25,12 @@ class TitleScene: RouteObject {
audio.play(-1);
audio.volume(15);
auto title = register(new TextBox("Hello"));
fd = register(new Fade([255, 0, 0]));
}

override void loop() {
if(hoge.cur > 5_000) router.go(Routes.Home);
if(!fd.isChanging) {dbg("ゲッHikamaniya…"); fd.swap;}
dbg("生きてるね。");
}
}

0 comments on commit 7a6ef36

Please sign in to comment.