CanadianMachines / MachineLib / Pipe.cpp
Pipe.cpp
Raw
/**
 * @file Pipe.cpp
 * @author sriram
 */

#include "pch.h"
#include "Pipe.h"

/// The pipe base image
const std::wstring PipeBaseImage = L"/images/pipe-base.png";

/// The pipe image
const std::wstring PipeImage = L"/images/pipe.png";

/// The pipe top image
const std::wstring PipeTopImage = L"/images/pipe-top.png";

/// The pipe puff image
const std::wstring PuffImage = L"/images/puff.png";

/// Pipe images width in pixels
const int PipeWidth = 20;

/// Pipe base height
const int PipeBaseHeight = 20;

/// Puff image width in pixels
const int PuffWidth = 65;

/**
 * constructor
 * @param resourcesDir
 * @param audioEngine
 * @param sound
 * @param length
 */
Pipe::Pipe(std::wstring resourcesDir, ma_engine *audioEngine, std::wstring sound, int length):
			mLength(length), Instrument(resourcesDir, audioEngine, sound)
{
	mSink.SetComponent(this);

	// Instrument base class polygon
	mBase.SetImage(resourcesDir + PipeBaseImage);
	mBase.Rectangle(-PipeWidth / 2, 0, PipeWidth, PipeWidth);

	// Polygons for the other components
	mBody.SetImage(resourcesDir + PipeImage);
	mBody.Rectangle(-PipeWidth / 2, -PipeBaseHeight, PipeWidth, length);

	mTop.SetImage(resourcesDir + PipeTopImage);
	mTop.Rectangle(-PipeWidth / 2, -PipeBaseHeight - length, PipeWidth);

	mPuff.SetImage(resourcesDir + PuffImage);
	mPuff.Rectangle(-PuffWidth / 2, -PipeBaseHeight - length, PuffWidth);
}

/**
 * draw graphics
 * @param graphics
 * @param x
 * @param y
 */
void Pipe::Draw(std::shared_ptr<wxGraphicsContext> graphics,double x, double y)
{
	if (mPressure>0)
	{
		mPuff.DrawPolygon(graphics, x + GetComponentLocation().x, y + GetComponentLocation().y);
	}
	mBase.DrawPolygon(graphics,x+GetComponentLocation().x,y+GetComponentLocation().y);
	mBody.DrawPolygon(graphics,x+GetComponentLocation().x,y+GetComponentLocation().y);
	mTop.DrawPolygon(graphics,x+GetComponentLocation().x,y+GetComponentLocation().y);
}

/**
 * display puff when pressure was sent
 * @param pressure
 */
void Pipe::SendPressure(double pressure)
{
	if(mPressure==0 && pressure>0)
	{
		Instrument::PlaySound();
	}
	mPressure=pressure;
}