this is a light that turns around with the mouse
// Includes
#include "template.h"
// Namespace
using namespace AGK;
app App;
/*
setVirtualResolution(1280, 720)
setSyncRate(30, 0)
initShader()
loadAGKlogo()
loadTorch()
x1 = 0
y1 = 0
angle1 = 0
rad1 = 100
x2 = 0
y2 = 0
angle2 = 0
rad2 = 150
x3 = 0
y3 = 0
angle3 = 0
rad3 = 150
spotX = 640
spotY = 360
rem A Wizard Did It!
do
inc angle1
if angle1 = 360 then angle1 = 0
x1 = 640 + sin(angle1)*rad1
y1 = 360 + cos(angle1)*rad1
dec angle2
if angle2 = 0 then angle2 = 360
x2 = 640 + sin(angle2)*rad2
y2 = 360 + cos(angle2)*rad2
dec angle3
if angle3 = 0 then angle3 = 360
x3 = 440 + sin(angle3)*rad3
y3 = 360 + cos(angle3)*rad3
setShaderConstantByName(shader, "PLightPos1", getPointerX(), getPointerY(), abs(sin(angle1)*rad1), 0)
setShaderConstantByName(shader, "PLightPos2", x1, y1, 100, 0)
setShaderConstantByName(shader, "PLightPos3", x2, y2, 100, 0)
setShaderConstantByName(shader, "PLightPos4", x3, y3, 200, 0)
dx1 = torchIntensity * sin(torchA)
dy1 = torchIntensity * cos(torchA)
tx1 = torchX + dx1
ty1 = torchY - dy1
setShaderConstantByName(shader, "spotLightPos1", torchX, torchY, 0, 0)
setShaderConstantByName(shader, "spotLightDir1", tx1, ty1, torchRadius, 0)
controlTorch()
sync()
loop
function initShader()
global shader = 1
loadShader(shader, "sprite.vs", "sprite_2spot_8newpoint_amb.ps" )
setShaderConstantByName(shader, "PLightPos1", 640, 360, 200, 0)
setShaderConstantByName(shader, "PLightCol1", 255, 255, 0, 0)
setShaderConstantByName(shader, "PLightPos2", 800, 200, 200, 0)
setShaderConstantByName(shader, "PLightCol2", 0, 255, 0, 0)
setShaderConstantByName(shader, "PLightPos3", 800, 550, 200, 0)
setShaderConstantByName(shader, "PLightCol3", 0, 0, 255, 0)
setShaderConstantByName(shader, "PLightPos4", 300, 200, 200, 0)
setShaderConstantByName(shader, "PLightCol4", 255, 0, 0, 0)
setShaderConstantByName(shader, "ambient", 0.1, 0, 0, 0)
setShaderConstantByName(shader, "spotLightPos1", 600, 360, 250, 0)
setShaderConstantByName(shader, "spotLightDir1", 800, 360, 20, 0)
setShaderConstantByName(shader, "spotLightCol1", 255, 0, 0, 0)
endFunction
function loadAGKlogo()
global logo as integer
logo = loadSprite("Made-With-AGK-White-512px.png")
setSpriteSize(logo, 512, 512)
setSpritePositionByOffset(logo, 640, 360)
SetSpriteShader(logo, shader)
SetSpriteTransparency(logo, 2)
endFunction
// ***********************************************************************************
// ***********************************************************************************
function controlTorch()
torchX = getSpriteXbyOffset(torchSpr)
torchY = getSpriteYbyOffset(torchSpr)
torchA = getSpriteAngle(torchSpr)
speed# = 0 - getJoystickY() * 75
vx#=cos(torchA - 90)*speed#
vy#=sin(torchA - 90)*speed#
inc torchA, getJoystickX() * 3
setSpriteAngle(torchSpr, torchA)
endFunction
function loadTorch()
global torchSpr as integer
torchSpr = loadSprite("torch.png")
setSpriteSize(torchSpr, 50, 150)
setSpriteOffset(torchSpr, 25, 30)
setSpritePosition(torchSpr, 500, 400)
SetSpriteShader(torchSpr, shader)
SetSpriteTransparency(torchSpr, 1)
global torchX = 500
global torchY = 400
global torchA = 0
global torchRadius = 25
global torchIntensity = 200 // essentially setting the length of the light cone
endFunction
*/
int ImageID;
int SpriteID;
int ShaderID;
float Time = 0;
int shader;
int logo;
int torchSpr;
int torchX;
int torchY;
int torchA;
int torchRadius = 25;
int torchIntensity = 200; // essentially setting the length of the light cone
int speed;
int vx;
int vy;
int x1;
int y1a;
int angle1;
int rad1a;
int x2;
int y2;
int angle2;
int rad2a;
int x3;
int y3;
int angle3;
int rad3a;
int spotX;
int spotY;
void controlTorch()
{
torchX = agk::GetSpriteXByOffset(torchSpr);
torchY = agk::GetSpriteYByOffset(torchSpr);
torchA = agk::GetSpriteAngle(torchSpr);
speed = 0 - agk::GetJoystickY() * 75;
vx = agk::Cos(torchA - 90)*speed;
vy = agk::Sin(torchA - 90)*speed;
torchA = torchA + agk::GetJoystickX() * 3;
agk::SetSpriteAngle(torchSpr, torchA);
}
void loadAGKlogo()
{
logo = agk::LoadSprite("media/Made-With-AGK-White-512px.png");
agk::SetSpriteSize(logo, 512, 512);
agk::SetSpritePositionByOffset(logo, 640, 360);
agk::SetSpriteShader(logo, shader);
agk::SetSpriteTransparency(logo, 2);
}
void loadtorch()
{
torchSpr = agk::LoadSprite("media/torch.png");
agk::SetSpriteSize(torchSpr, 50, 150);
agk::SetSpriteOffset(torchSpr, 25, 30);
agk::SetSpritePosition(torchSpr, 500, 400);
agk::SetSpriteShader(torchSpr, shader);
agk::SetSpriteTransparency(torchSpr, 1);
torchX = 500;
torchY = 400;
torchA = 0;
torchRadius = 25;
torchIntensity = 200; // essentially setting the length of the light cone
}
void initShader()
{
shader = 1;
agk::LoadShader(shader, "media/sprite.vs", "media/sprite_1spot_4newpoint_amb.ps");
/*
agk::SetShaderConstantByName(shader, "PLightPos1", 640, 360, 200, 0);
agk::SetShaderConstantByName(shader, "PLightCol1", 255, 255, 0, 0);
/*
agk::SetShaderConstantByName(shader, "PLightPos2", 800, 200, 200, 0);
agk::SetShaderConstantByName(shader, "PLightCol2", 0, 255, 0, 0);
agk::SetShaderConstantByName(shader, "PLightPos3", 800, 550, 200, 0);
agk::SetShaderConstantByName(shader, "PLightCol3", 0, 0, 255, 0);
agk::SetShaderConstantByName(shader, "PLightPos4", 300, 200, 200, 0);
agk::SetShaderConstantByName(shader, "PLightCol4", 255, 0, 0, 0);
*/
agk::SetShaderConstantByName(shader, "ambient", 0.1, 100, 100, 100);
agk::SetShaderConstantByName(shader, "spotLightPos1", 600, 360, 250, 0);
agk::SetShaderConstantByName(shader, "spotLightDir1", 800, 360, 20, 0);
agk::SetShaderConstantByName(shader, "spotLightCol1", 255, 0, 0, 0);
}
void app::Begin(void)
{
agk::SetVirtualResolution(1280, 720);
agk::SetSyncRate(30, 0);
initShader();
loadAGKlogo();
loadtorch();
x1 = 0;
y1a = 0;
angle1 = 0;
rad1a = 100;
x2 = 0;
y2 = 0;
angle2 = 0;
rad2a = 150;
x3 = 0;
y3 = 0;
angle3 = 0;
rad3a = 150;
spotX = 640;
spotY = 360;
/*agk::SetClearColor(151, 170, 204); // light blue
agk::SetSyncRate(60, 0);
agk::SetScissor(0, 0, 0, 0);
ImageID = agk::LoadImage("grid.jpg");
SpriteID = agk::CreateSprite(ImageID);
agk::SetSpriteSize(SpriteID, 1024, 798);
//ShaderID=LoadSpriteShader("pixel.ps" )
ShaderID = agk::LoadShader("media/shader.vs", "media/shader.ps");
agk::SetShaderConstantByName(ShaderID, "PLightPos1", Time, 0, 0, 0);*/
}
void app::Loop (void)
{
angle1++;
if (angle1 == 360)
{
angle1 = 0;
}
x1 = 640 + agk::Sin(angle1)*rad1a;
y1a = 360 + agk::Cos(angle1)*rad1a;
angle2--;
if (angle2 == 0)
{
angle2 = 360;
}
x2 = 640 + agk::Sin(angle2)*rad2a;
y2 = 360 + agk::Cos(angle2)*rad2a;
angle3--;
if (angle3 == 0)
{
angle3 = 360;
}
x3 = 440 + agk::Sin(angle3)*rad3a;
y3 = 360 + agk::Cos(angle3)*rad3a;
// agk::SetShaderConstantByName(shader, "PLightPos1", agk::GetPointerX(), agk::GetPointerY(), agk::Abs(agk::Sin(angle1)*rad1a), 0);
//agk::SetShaderConstantByName(shader, "PLightPos2", x1, y1a, 100, 0);
//agk::SetShaderConstantByName(shader, "PLightPos3", x2, y2, 100, 0);
//agk::SetShaderConstantByName(shader, "PLightPos4", x3, y3, 200, 0);
//
float dx1 = torchIntensity * agk::Sin(torchA);
float dy1 = torchIntensity * agk::Cos(torchA);
float tx1 = torchX + dx1;
float ty1 = torchY - dy1;
agk::SetShaderConstantByName(shader, "spotLightPos1", torchX, torchY, 0, 0);
agk::SetShaderConstantByName(shader, "spotLightDir1", agk::GetPointerX(), agk::GetPointerY(), torchRadius, 0);
controlTorch();
agk::Sync();
}
void app::End (void)
{
}
Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.