diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d1d96e7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,405 @@
+# Created by https://www.toptal.com/developers/gitignore/api/visualstudio
+# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio
+
+### VisualStudio ###
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.tlog
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio 6 auto-generated project file (contains which files were open etc.)
+*.vbp
+
+# Visual Studio 6 workspace and project file (working project files containing files to include in project)
+*.dsw
+*.dsp
+
+# Visual Studio 6 technical files
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# Visual Studio History (VSHistory) files
+.vshistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+# VS Code files for those working on multiple tools
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+*.code-workspace
+
+# Local History for Visual Studio Code
+.history/
+
+# Windows Installer files from build outputs
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# JetBrains Rider
+*.sln.iml
+
+### VisualStudio Patch ###
+# Additional files built by Visual Studio
+
+# End of https://www.toptal.com/developers/gitignore/api/visualstudio
\ No newline at end of file
diff --git a/MiniGolfPro.sln b/MiniGolfPro.sln
new file mode 100644
index 0000000..3ab5538
--- /dev/null
+++ b/MiniGolfPro.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33516.290
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MiniGolfPro", "MiniGolfPro.vcxproj", "{E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Debug|x64.ActiveCfg = Debug|x64
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Debug|x64.Build.0 = Debug|x64
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Debug|x86.ActiveCfg = Debug|Win32
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Debug|x86.Build.0 = Debug|Win32
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Release|x64.ActiveCfg = Release|x64
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Release|x64.Build.0 = Release|x64
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Release|x86.ActiveCfg = Release|Win32
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A2AAA7EE-EACB-4984-973C-E5026077B816}
+ EndGlobalSection
+EndGlobal
diff --git a/MiniGolfPro.vcxproj b/MiniGolfPro.vcxproj
new file mode 100644
index 0000000..0686708
--- /dev/null
+++ b/MiniGolfPro.vcxproj
@@ -0,0 +1,114 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ {E57F8D7A-E7A2-4C39-A16A-2E446E6A92E0}
+ Win32Proj
+
+
+
+ Application
+ true
+ v143
+
+
+ Application
+ false
+ v143
+
+
+ Application
+ true
+ v143
+
+
+ Application
+ false
+ v143
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ true
+
+
+
+ WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)
+ MultiThreadedDebugDLL
+ Level3
+ ProgramDatabase
+ Disabled
+
+
+ MachineX86
+ true
+ Windows
+
+
+
+
+ WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)
+ MultiThreadedDLL
+ Level3
+ ProgramDatabase
+
+
+ MachineX86
+ true
+ Windows
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MiniGolfPro.vcxproj.filters b/MiniGolfPro.vcxproj.filters
new file mode 100644
index 0000000..7f4c36c
--- /dev/null
+++ b/MiniGolfPro.vcxproj.filters
@@ -0,0 +1,34 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main.cpp b/main.cpp
index e654d21..7c2c9ff 100644
--- a/main.cpp
+++ b/main.cpp
@@ -22,8 +22,11 @@ struct Line{
float bounceFactor=0.8;
float bumperLeft=0;
float bumperRight=0;
+ bool oneWay=false;
};
+const float PI=3.14159f;
+
class MiniGolfPro : public olc::PixelGameEngine
{
@@ -35,6 +38,12 @@ public:
std::vector>collidingPairs;
std::vectorfakeBalls;
bool selectedLineStart=false;
+ float friction=0.9f;
+ float gravity=200.f;
+ float limit=500.f;
+ Line*leftFlipperLine,*rightFlipperLine;
+ float leftFlipper=PI/4;
+ float rightFlipper=3*PI/4;
MiniGolfPro()
{
@@ -46,18 +55,26 @@ public:
b.pos=pos;
b.radius=r;
b.mass=r*10;
+ b.vel.y=rand()%1000-17000;
balls.emplace_back(b);
}
- void AddLine(vf2d pos1,vf2d pos2,float r,float bounceFactor){
+ void AddLine(vf2d pos1,vf2d pos2,float r,float bounceFactor,bool oneway=false){
Line l;
l.startPos=pos1;
l.endPos=pos2;
l.radius=r;
l.bounceFactor=bounceFactor;
+ l.oneWay=oneway;
lines.push_back(l);
}
+ void AddTriangle(vf2d center,float size,float radius,float bounceFactor,bool flip=false){
+ AddLine(center+vf2d{-size,size}*(flip?-1:1),center+vf2d{0,-size}*(flip?-1:1),radius,bounceFactor);
+ AddLine(center+vf2d{0,-size}*(flip?-1:1),center+vf2d{size,size}*(flip?-1:1),radius,bounceFactor);
+ AddLine(center+vf2d{size,size}*(flip?-1:1),center+vf2d{-size,size}*(flip?-1:1),radius,bounceFactor);
+ }
+
bool isLeft(Line line, vf2d point) {
return (line.endPos.x - line.startPos.x)*(point.y - line.startPos.y) - (line.endPos.y - line.startPos.y)*(point.x - line.startPos.x) > 0;
}
@@ -65,10 +82,8 @@ public:
public:
bool OnUserCreate() override
{
- for (int i=0;i<20;i++){
- AddBall({float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},rand()%16+2);
- }
- AddLine({0,450},{640,450},10,0.8);
+ AddBall({610,620},rand()%4+8);
+ AddLine({0,630},{640,630},10,0.8);
ConsoleCaptureStdOut(true);
for(int x=0;x<320;x+=20){
AddLine({float(x+320),(1.f/18000)*std::abs(powf(float(x),2.6f))},{x+20+320.f,(1.f/18000)*std::abs(powf(float(x+20),2.6f))},10,0.4);
@@ -82,9 +97,25 @@ public:
AddLine({float(-x+320),(1.f/12000)*std::abs(powf(float(x),2.6f))+60},{float(-x-20+320),(1.f/12000)*std::abs(powf(float(x+20),2.6f))+60},10,0.4);
}
}
- AddLine({640,190},{640,480},10,0.4);
- AddLine({580,220},{580,480},10,0.4);
- AddLine({60,100},{90,290},15,1.5);
+ AddLine({640,190},{640,640},10,0.8);
+ AddLine({580,220},{580,640},10,0.8);
+ AddLine({60,100},{100,290},15,1.5);
+ AddLine({110,290},{120,560},5,0.8);
+ AddLine({158,392},{196,503},5,0.8);
+ AddLine({196,503},{258,545},5,0.8);
+ AddLine({161,104},{81,86},2,0.4,true);
+
+ AddTriangle({250,220},40,10,1.5);
+ AddTriangle({350,160},40,10,1.5,true);
+ AddTriangle({450,220},40,10,1.5);
+
+
+ AddLine({535,392},{497,503},5,0.8);
+ AddLine({497,503},{435,545},5,0.8);
+ AddLine({258,545},{258,545},8,0.4);
+ AddLine({435,545},{435,545},8,0.4);
+ leftFlipperLine=&lines[lines.size()-2];
+ rightFlipperLine=&lines[lines.size()-1];
return true;
}
@@ -132,6 +163,9 @@ public:
}
}
if(GetMouse(0).bReleased){
+ if(selectedLine!=nullptr){
+ std::cout<startPos<<"/"<endPos<vel.x=5*((selectedBall->pos.x)-GetMouseX());
selectedBall->vel.y=5*((selectedBall->pos.y)-GetMouseY());
@@ -157,6 +191,37 @@ public:
int maxSimulationSteps=15;
float simElapsedTime=fElapsedTime/(float)simulationUpdates;
+ leftFlipperLine->endPos=vf2d{std::cosf(leftFlipper)*64,std::sinf(leftFlipper)*64}+leftFlipperLine->startPos;
+ rightFlipperLine->endPos=vf2d{std::cosf(rightFlipper)*64,std::sinf(rightFlipper)*64}+rightFlipperLine->startPos;
+
+ if(GetKey(SPACE).bPressed){
+ AddBall({610,620},rand()%4+8);
+ }
+
+ if(GetKey(A).bHeld){
+ leftFlipper=std::max(-PI/4,leftFlipper-8*PI*fElapsedTime);
+ if(leftFlipper!=-PI/4){
+ leftFlipperLine->bounceFactor=2;
+ } else {
+ leftFlipperLine->bounceFactor=std::max(0.4f,leftFlipperLine->bounceFactor-2*fElapsedTime);
+ }
+ } else {
+ leftFlipper=std::min(PI/4,leftFlipper+8*PI*fElapsedTime);
+ leftFlipperLine->bounceFactor=0.4;
+ }
+
+ if(GetKey(L).bHeld){
+ rightFlipper=std::min(5*PI/4,rightFlipper+8*PI*fElapsedTime);
+ if(rightFlipper!=5*PI/4){
+ rightFlipperLine->bounceFactor=2;
+ } else {
+ rightFlipperLine->bounceFactor=std::max(0.4f,rightFlipperLine->bounceFactor-2*fElapsedTime);
+ }
+ } else {
+ rightFlipper=std::max(3*PI/4,rightFlipper-8*PI*fElapsedTime);
+ rightFlipperLine->bounceFactor=0.4;
+ }
+
for(int i=0;i0){
b.originalPos.x=b.pos.x;
b.originalPos.y=b.pos.y;
- b.acc.x=-b.vel.x*0.8f;
- b.acc.y=-b.vel.y*0.8f+100.f; //Gravity constant;
+ b.acc.x=-b.vel.x*friction;
+ b.acc.y=-b.vel.y*friction+gravity; //Gravity constant;
b.vel.x+=b.acc.x*b.simTimeRemaining;
b.vel.y+=b.acc.y*b.simTimeRemaining;
b.pos.x+=b.vel.x*b.simTimeRemaining;
@@ -196,27 +261,29 @@ public:
for(Ball&b:balls){
float deltaTime=b.simTimeRemaining;
for(Line&l:lines){
- vf2d line1={l.endPos.x-l.startPos.x,l.endPos.y-l.startPos.y};
- vf2d line2={b.pos.x-l.startPos.x,b.pos.y-l.startPos.y};
- float edgeLength=line1.x*line1.x+line1.y*line1.y;
- float t=std::max(0.f,std::min(edgeLength,(line1.x*line2.x+line1.y*line2.y)))/edgeLength;
- vf2d closestPoint={l.startPos.x+t*line1.x,l.startPos.y+t*line1.y};
- float dist=sqrtf((b.pos.x-closestPoint.x)*(b.pos.x-closestPoint.x)+(b.pos.y-closestPoint.y)*(b.pos.y-closestPoint.y));
- if(dist<=b.radius+l.radius){
- Ball*fakeBall=new Ball();
- fakeBall->radius=l.radius;
- fakeBall->mass=b.mass*l.bounceFactor;
- fakeBall->pos={closestPoint.x,closestPoint.y};
- fakeBall->vel={-b.vel.x,-b.vel.y};
- fakeBalls.push_back(fakeBall);
- collidingPairs.push_back({&b,fakeBall});
- float overlap=1.1f*(dist-b.radius-fakeBall->radius);
- b.pos.x-=overlap*(b.pos.x-fakeBall->pos.x)/dist;
- b.pos.y-=overlap*(b.pos.y-fakeBall->pos.y)/dist;
- if(isLeft(l,b.pos)){
- l.bumperLeft=1;
- } else {
- l.bumperRight=1;
+ if(!l.oneWay||l.oneWay&&b.vel.y<0){
+ vf2d line1={l.endPos.x-l.startPos.x,l.endPos.y-l.startPos.y};
+ vf2d line2={b.pos.x-l.startPos.x,b.pos.y-l.startPos.y};
+ float edgeLength=line1.x*line1.x+line1.y*line1.y;
+ float t=std::max(0.f,std::min(edgeLength,(line1.x*line2.x+line1.y*line2.y)))/edgeLength;
+ vf2d closestPoint={l.startPos.x+t*line1.x,l.startPos.y+t*line1.y};
+ float dist=sqrtf((b.pos.x-closestPoint.x)*(b.pos.x-closestPoint.x)+(b.pos.y-closestPoint.y)*(b.pos.y-closestPoint.y));
+ if(dist<=b.radius+l.radius){
+ Ball*fakeBall=new Ball();
+ fakeBall->radius=l.radius;
+ fakeBall->mass=b.mass*l.bounceFactor;
+ fakeBall->pos={closestPoint.x,closestPoint.y};
+ fakeBall->vel={std::min(limit,std::max(-limit,-b.vel.x)),std::min(limit,std::max(-limit,-b.vel.y))};
+ fakeBalls.push_back(fakeBall);
+ collidingPairs.push_back({&b,fakeBall});
+ float overlap=1.1f*(dist-b.radius-fakeBall->radius);
+ b.pos.x-=overlap*(b.pos.x-fakeBall->pos.x)/dist;
+ b.pos.y-=overlap*(b.pos.y-fakeBall->pos.y)/dist;
+ if(isLeft(l,b.pos)){
+ l.bumperLeft=1;
+ } else {
+ l.bumperRight=1;
+ }
}
}
}
@@ -278,8 +345,24 @@ public:
normal/=dist;
l.bumperLeft=std::max(0.f,l.bumperLeft-fElapsedTime);
l.bumperRight=std::max(0.f,l.bumperRight-fElapsedTime);
- DrawLine(l.startPos.x+normal.x*l.radius,l.startPos.y+normal.y*l.radius,l.endPos.x+normal.x*l.radius,l.endPos.y+normal.y*l.radius,l.bumperLeft?RED:WHITE);
- DrawLine(l.startPos.x-normal.x*l.radius,l.startPos.y-normal.y*l.radius,l.endPos.x-normal.x*l.radius,l.endPos.y-normal.y*l.radius,l.bumperRight?BLUE:WHITE);
+ if(l.bumperLeft){
+ SetPixelMode(Pixel::ALPHA);
+ for(int i=0;i<3;i++){
+ DrawLine(l.startPos.x+normal.x*(l.radius+i),l.startPos.y+normal.y*(l.radius+i),l.endPos.x+normal.x*(l.radius+i),l.endPos.y+normal.y*(l.radius+i),{255,0,0,uint8_t((4-i)/4.f*255)});
+ }
+ SetPixelMode(Pixel::NORMAL);
+ } else {
+ DrawLine(l.startPos.x+normal.x*l.radius,l.startPos.y+normal.y*l.radius,l.endPos.x+normal.x*l.radius,l.endPos.y+normal.y*l.radius,l.oneWay?DARK_YELLOW:WHITE);
+ }
+ if(l.bumperRight){
+ SetPixelMode(Pixel::ALPHA);
+ for(int i=0;i<3;i++){
+ DrawLine(l.startPos.x-normal.x*(l.radius+i),l.startPos.y-normal.y*(l.radius+i),l.endPos.x-normal.x*(l.radius+i),l.endPos.y-normal.y*(l.radius+i),{0,0,255,uint8_t((4-i)/4.f*255)});
+ }
+ SetPixelMode(Pixel::NORMAL);
+ } else {
+ DrawLine(l.startPos.x-normal.x*l.radius,l.startPos.y-normal.y*l.radius,l.endPos.x-normal.x*l.radius,l.endPos.y-normal.y*l.radius,l.oneWay?DARK_YELLOW:WHITE);
+ }
}
return true;
}
@@ -293,7 +376,7 @@ public:
int main()
{
MiniGolfPro demo;
- if (demo.Construct(640, 480, 4, 4))
+ if (demo.Construct(640, 640, 4, 4))
demo.Start();
return 0;