Tournament tracker continued work

This commit is contained in:
AMay 2026-10-16 18:21:47 -05:00
parent 4099951fee
commit e7f766732f
3 changed files with 211 additions and 7 deletions

View File

@ -3,5 +3,5 @@
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Project Path="TournamentTracker/TournamentTracker.vcxproj" />
<Project Path="TournamentTracker/TournamentTracker.vcxproj" Id="56676c02-056a-49ff-b510-3f1d6fae0b29" />
</Solution>

View File

@ -12,6 +12,76 @@
#define OLC_PGE3_APPLICATION
#include "olcPixelGameEngine3.h"
using namespace olc;
using namespace olc::Colour;
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2026 Amy 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
class DynamicCounter{
public:
DynamicCounter();
void Initialize(const int*number,float tickRate=0.01f,Pixel originalCol=WHITE,Pixel increaseCol=WHITE,Pixel decreaseCol=WHITE,float colorChangeTime=0.4f);
void Update();
const int&GetDisplayValue()const;
const Pixel&GetDisplayColor()const;
void UpdateNumberPointer(const int*newPtr);
private:
int displayNumber;
const int*targetNumber=nullptr;
int lastTargetNumber;
float targetChangedTimer;
float colorChangeTime;
float tickRate;
float tickTimer;
Pixel originalCol;
Pixel displayCol;
Pixel adjustedCol;
Pixel increaseCol;
Pixel decreaseCol;
};
class Example_Pixels;
Example_Pixels*game;
// Example application demonstrating pixel drawing. This class
// overrides the olc::PixelGameEngine base class by implementing
// the OnUserCreate() and OnUserUpdate() functions
@ -21,41 +91,175 @@ public:
Example_Pixels()
{
sAppName = "Example - Pixels ...lots of pixels";
game=this;
}
DynamicCounter score1;
DynamicCounter score2;
Image img;
int ex1{0};
int ex2{0};
float fadeTimer{0.f};
public:
// Called once at the start, so create things here
bool OnUserCreate() override
{
// Nothing to do here, so return true
score1.Initialize(&ex1,0.01);
score2.Initialize(&ex2,0.01);
CreateImageFromFile(img,"wingradient.png");
return true;
}
// Called every frame, so update things here
bool OnUserUpdate(float fElapsedTime) override
{
// Clear screen to dark blue
draw.Clear(olc::Colour::VERY_DARK_BLUE);
draw.FilledRoundedRect(ScreenSize()/8,vd2d{ScreenSize().x*(2/8.),ScreenSize().y*(6/8.)},8,olc::Colour::WHITE,olc::Colour::WHITE,8);
draw.FilledRoundedRect(vf2d{ScreenSize().x-ScreenSize().x*(3/8.f),ScreenSize().y/8.f},vd2d{ScreenSize().x*(2/8.),ScreenSize().y*(6/8.)},8,olc::Colour::WHITE,olc::Colour::WHITE,8);
score1.Update();
score2.Update();
if(score1.GetDisplayValue()>score2.GetDisplayValue()){
fadeTimer=std::max(0.f,fadeTimer-0.7f*fElapsedTime);
}else if(score2.GetDisplayValue()>score1.GetDisplayValue()){
fadeTimer=std::min(1.f,fadeTimer+0.7f*fElapsedTime);
}else{
if(fadeTimer>0.5f){
fadeTimer=std::max(0.5f,fadeTimer-0.7f*fElapsedTime);
}else{
fadeTimer=std::min(0.5f,fadeTimer+0.7f*fElapsedTime);
}
}
if(keyboard.GetKey(Key::D).bHeld)ex1+=1;
if(keyboard.GetKey(Key::A).bHeld)ex1=std::max(0,ex1-1);
if(keyboard.GetKey(Key::RIGHT).bHeld)ex2+=1;
if(keyboard.GetKey(Key::LEFT).bHeld)ex2=std::max(0,ex2-1);
int maxBar{std::max(500,std::max(score1.GetDisplayValue(),score2.GetDisplayValue()))};
draw.Clear(olc::Colour::VERY_DARK_BLUE);
olc::Pixel myCol{ olc::Pixel{255, 0, 0, 255} }; //255 R, 0 G, 0 B, 255 A
float maxBarHeight{float(ScreenSize().y*(6/8.))};
float midpoint{(float(score1.GetDisplayValue())+float(score2.GetDisplayValue()))/2.f};
float halfWidth{5.5f*sqrtf(abs(score1.GetDisplayValue()-score2.GetDisplayValue()))};
float boundMin{midpoint-halfWidth};
float boundMax{midpoint+halfWidth};
float bar1Height{std::clamp((score1.GetDisplayValue()-boundMin)/(halfWidth*2)*maxBarHeight,0.1f*maxBarHeight,0.9f*maxBarHeight)};
float bar2Height{std::clamp((score2.GetDisplayValue()-boundMin)/(halfWidth*2)*maxBarHeight,0.1f*maxBarHeight,0.9f*maxBarHeight)};
if(score1.GetDisplayValue()==score2.GetDisplayValue()){bar1Height=bar2Height=0.5f*maxBarHeight;}
Pixel bar1Col{64,180,145};
Pixel bar2Col{237,39,147};
Pixel leadingCol{250,164,34};
draw.FilledRoundedRect(ScreenSize()/8+vf2d{0,(maxBarHeight-bar1Height)},vd2d{ScreenSize().x*(2/8.),bar1Height},8,WHITE,bar1Col,8);
draw.FilledRoundedRect(vf2d{ScreenSize().x-ScreenSize().x*(3/8.f),ScreenSize().y/8.f+(maxBarHeight-bar2Height)},vd2d{ScreenSize().x*(2/8.),bar2Height},8,WHITE,bar2Col,8);
draw.Image(img,ScreenSize()/8+vf2d{-16,(maxBarHeight-bar1Height)},{0.003f*ScreenSize().x,bar1Height*0.0079f},{255,255,255,uint8_t(255-fadeTimer*255)});
draw.Image(img,vf2d{ScreenSize().x-ScreenSize().x*(3/8.f)-16.f,(maxBarHeight-bar2Height)+ScreenSize().y/8.f},{0.003f*ScreenSize().x,bar2Height*0.0079f},{255,255,255,uint8_t(fadeTimer*255)});
std::string ex1{std::to_string(score1.GetDisplayValue())};
vf2d textSize1{draw.GetTextSize(ex1,false,{3,6})};
std::string ex2{std::to_string(score2.GetDisplayValue())};
vf2d textSize2{draw.GetTextSize(ex2,false,{3,6})};
draw.String(ScreenSize()/8+vf2d{28,maxBarHeight+1+32}-textSize1/2,ex1,BLACK,{3.f,6.f});
draw.String(ScreenSize()/8+vf2d{28,maxBarHeight+32}-textSize1/2,ex1,score1.GetDisplayValue()>score2.GetDisplayValue()?leadingCol:WHITE,{3.f,6.f});
draw.String(vf2d{ScreenSize().x-ScreenSize().x*(3/8.f)+28-textSize2.x/2,ScreenSize().y/8.f+8}+vf2d{1,maxBarHeight+1},ex2,BLACK,{3.f,6.f});
draw.String(vf2d{ScreenSize().x-ScreenSize().x*(3/8.f)+28-textSize2.x/2,ScreenSize().y/8.f+8}+vf2d{0,maxBarHeight},ex2,score2.GetDisplayValue()>score1.GetDisplayValue()?leadingCol:WHITE,{3.f,6.f});
// Successful frame
return true;
}
};
// Main entry point for the application
int main()
{
// Construct demo application
Example_Pixels demo;
if (demo.Construct({ 640, 480 }, { 1, 1 }))
if (demo.Construct({ 249, 568 }, { 1, 1 }))
{
// Start the application
demo.Start();
}
return 0;
}
DynamicCounter::DynamicCounter(){}
void DynamicCounter::Initialize(const int*number,float tickRate,Pixel originalCol,Pixel increaseCol,Pixel decreaseCol,float colorChangeTime){
this->targetNumber=number;
this->displayNumber=*number;
this->tickRate=tickRate;
this->originalCol=originalCol;
this->increaseCol=increaseCol;
this->decreaseCol=decreaseCol;
this->colorChangeTime=colorChangeTime;
}
void DynamicCounter::Update(){
if(targetNumber==nullptr)throw new std::exception{"WARNING! This dynamic counter has not been properly initialized! Call Initialize() first!"};
targetChangedTimer=std::max(0.f,targetChangedTimer-game->FrameTimeElapsed());
bool targetNumberChanged=*targetNumber!=lastTargetNumber;
tickTimer+=game->FrameTimeElapsed();
bool tickOccurred=false;
while(tickTimer>tickRate){
tickTimer-=tickRate;
if(displayNumber!=int(*targetNumber)){
if(displayNumber>int(*targetNumber)){
int incrementAmt=int(abs(*targetNumber-displayNumber)/(1/tickRate))+1;
displayNumber=std::max(displayNumber-incrementAmt,*targetNumber);
if(targetNumberChanged){
adjustedCol=decreaseCol;
targetChangedTimer=colorChangeTime;
}
}else{
int incrementAmt=int(abs(*targetNumber-displayNumber)/(1/tickRate))+1;
displayNumber=std::min(displayNumber+incrementAmt,*targetNumber);
if(targetNumberChanged){
adjustedCol=increaseCol;
targetChangedTimer=colorChangeTime;
}
}
}
tickOccurred=true;
}
if(tickOccurred&&targetNumberChanged){
lastTargetNumber=int(*targetNumber);
}
displayCol=PixelLerp(adjustedCol,originalCol,1-(targetChangedTimer/colorChangeTime));
}
const int&DynamicCounter::GetDisplayValue()const{
return displayNumber;
}
const Pixel&DynamicCounter::GetDisplayColor()const{
return displayCol;
}
void DynamicCounter::UpdateNumberPointer(const int*newPtr){
targetNumber=newPtr;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB