Add Matrix texture animating. And prepare jet sprite.

main
sigonasr2 3 months ago
parent 5e66fd009e
commit d662b3d6a5
  1. 0
      New Text Document.txt
  2. BIN
      assets/hamster_jet.png
  3. 4
      hamster.vcxproj
  4. 3
      hamster.vcxproj.filters
  5. 63
      src/HamsterGame.cpp
  6. 10
      src/HamsterGame.h
  7. 47
      src/SpecialRenderable.h

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -382,6 +382,10 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="src\SpecialRenderable.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="src\Terrain.h">
<SubType>
</SubType>

@ -94,5 +94,8 @@
<ClInclude Include="src\Powerup.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\SpecialRenderable.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -2,6 +2,7 @@
#include "Hamster.h"
#include <stdexcept>
#include <ranges>
#include "util.h"
geom2d::rect<float>HamsterGame::SCREEN_FRAME{{96,0},{320,288}};
std::unordered_map<std::string,Animate2D::Animation<HamsterGame::AnimationState>>HamsterGame::ANIMATIONS;
@ -113,6 +114,7 @@ void HamsterGame::LoadLevel(const std::string_view mapName){
}
void HamsterGame::UpdateGame(const float fElapsedTime){
UpdateMatrixTexture();
camera.SetViewSize(tv.GetWorldVisibleArea());
camera.Update(fElapsedTime);
tv.SetWorldOffset(tv.ScaleToWorld(-SCREEN_FRAME.pos)+camera.GetViewPosition());
@ -156,8 +158,6 @@ void HamsterGame::DrawGame(){
GradientFillRectDecal(vf2d{12.f,240.f}+vf2d{12.f,5.f},vf2d{Hamster::GetPlayer().GetBurnRatio()*57.f,4.f},{250,177,163},{226,228,255},{226,228,255},{250,177,163});
}
#pragma endregion
tv.FillRectDecal(GetMousePos(),{2,2},GREEN);
}
const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const{
@ -224,6 +224,65 @@ const double HamsterGame::GetRuntime()const{
return runTime;
}
void HamsterGame::UpdateMatrixTexture(){
const auto result{GFX.insert({ASSETS_DIR+"MATRIX_TEXTURE",Renderable{}})};
Renderable&texture{(*result.first).second};
if(result.second){
texture.Create(64,64);
}
const std::array<char,10>matrixLetters{'0','1','2','3','4','5','6','7','8','9'};
if(matrixTimer==0){
activeLetters.emplace_back(vf2d{float(rand()%64),float(64)},util::random(-40)-20,matrixLetters[rand()%matrixLetters.size()]);
matrixTimer=util::random(0.125);
}
if(updatePixelsTimer==0){
SetDrawTarget(texture.Sprite());
Sprite*img=texture.Sprite();
for(int y=63;y>=0;y--){
for(int x=63;x>=0;x--){
Pixel col=img->GetPixel(x,y);
if(col.r>0){
if(x>0){
Pixel leftCol=img->GetPixel(x-1,y);
if(leftCol.r<col.r){
leftCol=PixelLerp(col,leftCol,0.125);
}
Draw(x-1,y,leftCol);
}
if(x<img->width-1){
Pixel rightCol=img->GetPixel(x+1,y);
if(rightCol.r<col.r){
rightCol=PixelLerp(col,rightCol,0.125);
}
Draw(x+1,y,rightCol);
}
col/=8;
Draw(x,y,col);
}
}
}
for(int y=0;y<64;y++){
Draw({0,y},img->GetPixel(1,y));
}
SetDrawTarget(nullptr);
updatePixelsTimer=0.1;
}
if(activeLetters.size()>0){
SetDrawTarget(texture.Sprite());
for(Letter&letter:activeLetters){
letter.pos.y+=letter.spd*GetElapsedTime();
DrawString(letter.pos,std::string(1,letter.c));
}
SetDrawTarget(nullptr);
texture.Decal()->Update();
}
matrixTimer=std::max(0.f,matrixTimer-GetElapsedTime());
updatePixelsTimer=std::max(0.f,updatePixelsTimer-GetElapsedTime());
std::erase_if(activeLetters,[](Letter&letter){return letter.pos.y<-32;});
}
int main()
{
HamsterGame game;

@ -46,6 +46,12 @@ All rights reserved.
#include "TSXParser.h"
#include "Terrain.h"
struct Letter{
vf2d pos;
float spd;
char c;
};
class HamsterGame : public olc::PixelGameEngine
{
const static std::string ASSETS_DIR;
@ -87,4 +93,8 @@ private:
double runTime{};
Camera2D camera;
Renderable mapImage;
void UpdateMatrixTexture();
float matrixTimer;
std::vector<Letter>activeLetters;
float updatePixelsTimer;
};

@ -0,0 +1,47 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2024 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#pragma once
#include "olcPixelGameEngine.h"
class SpecialRenderable{
Renderable originalImg;
Renderable modifiedImg;
public:
};
Loading…
Cancel
Save