heres kinda what I was thinking still lots to do
// set window properties
SetWindowTitle( "thingy" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate(30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#constant thingyShd =1
#constant white = MakeColor(255,255,255)
createShaderFile()
thingySpr=CreateSprite(0)
SetSpriteSize(thingySpr,1024,768)
SetSpritePosition(thingySpr,0,0)
LoadSpriteShader(thingyShd,"thingy.ps")
SetSpriteShader(thingySpr,thingyShd)
SetSpriteDepth(thingySpr,20)
SetSpriteActive(thingySpr,0)
type objType
ID as integer
xDir as float
yDir as float
Time as float
enemy as integer
endtype
global objSpr as objType[]
global enemyLeft=0
createBoxes(20)
thingyWidth as float
thingyWidth=0.015
SetShaderConstantByName(thingyShd,"resolution",1024,768 ,0,0)
SetShaderConstantByName(thingyShd,"speed",1.0,0,0,0)
SetShaderConstantByName(thingyShd,"color",0.8,0.5,0.5,0)
SetShaderConstantByName(thingyShd,"width",thingyWidth,0,0,0)
colWidth as float
colWidth=10.0
colSpr=createSprite(0)
SetSpriteSize(colSpr,colWidth,300)
SetSpriteOffset(colSpr,colWidth*0.5,300)
SetSpriteShape(colSpr,3)
SetSpriteDepth(colSpr,10)
SetSpriteVisible(colSpr,0)
SetSpritePositionByOffset(colSpr,512,384)
score=0
do
SetSpriteAngle(colSpr,360-getAngle(GetSpriteXByOffset(colSpr),GetSpriteYByOffset(colSpr),GetPointerX(),getPointerY()) )
SetSpriteSize(colSpr,colWidth,distance(512,384,getPointerX(),getPointerY()))
for num = objSpr.length to 0 step -1
SetSpritePositionByOffset(objSpr[num].ID,objSpr[num].xDir+GetSpriteXByOffset(objSpr[num].ID),objSpr[num].yDir+GetSpriteYByOffset(objSpr[num].ID))
//check if need to randomly change direction
if timer() > objSpr[num].time+2
objSpr[num].xDir=random2(-1.5,1.5)
objSpr[num].yDir=random2(-1.5,1.5)
objSpr[num].time=Timer()
endif
//screen bounds
if GetSpriteXByOffset(objSpr[num].ID)<0 then SetSpritePositionByOffset(objSpr[num].ID,1024,GetSpriteYByOffset(objSpr[num].ID))
if GetSpriteXByOffset(objSpr[num].ID)>1024 then SetSpritePositionByOffset(objSpr[num].ID,0,GetSpriteYByOffset(objSpr[num].ID))
if GetSpriteYByOffset(objSpr[num].ID)<0 then SetSpritePositionByOffset(objSpr[num].ID,GetSpriteXByOffset(objSpr[num].ID),768)
if GetSpriteYByOffset(objSpr[num].ID)>768 then SetSpritePositionByOffset(objSpr[num].ID,GetSpriteXByOffset(objSpr[num].ID),0)
hit= GetSpriteCollision(objSpr[num].ID,colSpr )
if hit=1
if objSpr[num].enemy=1
thingyWidth=thingyWidth+0.0025:colWidth=colWidth+0.75
SetShaderConstantByName(thingyShd,"width",thingyWidth,0,0,0)
inc score,10:dec enemyLeft,1
else
thingyWidth=thingyWidth-0.0025:colWidth=colWidth-0.75
SetShaderConstantByName(thingyShd,"width",thingyWidth,0,0,0)
dec score,10
endif
DeleteSprite(objSpr[num].ID)
objSpr.remove(num)
endif
next
if enemyLeft <=0
deleteBoxes()
createBoxes(20)
endif
print(score)
print(ScreenFPS())
SetShaderConstantByName(thingyShd,"time",timer(),0,0,0)
SetShaderConstantByName(thingyShd,"mouse",GetPointerX(),getPointery(),0,0)
sync()
loop
function deleteBoxes()
for num = objSpr.length to 0 step -1
DeleteSprite(objSpr[num].ID)
objSpr.remove(num)
next
endfunction
function createBoxes(num as integer)
newSpr as objType
for t =1 to num
newSpr.ID=createSprite(0)
SetSpriteSize(newSpr.ID,20,20)
SetSpritePosition(newSpr.ID,Random(100,924),Random(100,668))
SetSpriteShape(newSpr.ID,3)
SetSpriteDepth(newSpr.ID,10)
newSpr.xDir=random2(-1.5,1.5)
newSpr.yDir=random2(-1.5,1.5)
newSpr.time=0
if random(1,2)=1
newSpr.enemy=1:inc enemyLeft,1
SetSpriteColor(newSpr.ID,200,0,0,255)
else
newSpr.enemy=0
SetSpriteColor(newSpr.ID,0,200,0,255)
endif
objSpr.insert(newSpr)
next t
endfunction
function distance(x1#,y1#,x2#,y2#)
dx# = x2#-x1#
dy# = y2#-y1#
D# = sqrt(dx#*dx# + dy#*dy#)
endfunction d#
function getAngle(x1#, y1#, x2#, y2#)
result# = ATan2(x1# - x2#,y1# - y2#)
endfunction result#
function createShaderFile()
fw=OpenToWrite("thingy.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"")
WriteLine(fw,"uniform float speed; ")
WriteLine(fw,"uniform vec3 color; ")
WriteLine(fw,"uniform float width; ")
WriteLine(fw,"uniform float time; ")
WriteLine(fw,"uniform vec2 mouse; // mouse pixel coords. xy:")
WriteLine(fw,"uniform vec2 resolution; // viewport resolution (in pixels)")
WriteLine(fw,"uniform sampler2D backbuffer;")
WriteLine(fw,"float Hash( vec2 p, float s)")
WriteLine(fw,"{")
WriteLine(fw," vec3 p2 = vec3(p.xy,10.0 * abs(sin(s)));")
WriteLine(fw," return fract(sin(dot(p2,vec3(27.1,61.7, 12.4)))*273758.5453123);")
WriteLine(fw,"}")
WriteLine(fw,"float noise(vec2 p, float s)")
WriteLine(fw,"{")
WriteLine(fw," vec2 i = floor(p);")
WriteLine(fw," vec2 f = fract(p);")
WriteLine(fw," f *= f * f * (3.0-2.0*f);")
WriteLine(fw," return mix(mix(Hash(i + vec2(0.,0.), s), Hash(i + vec2(1.,0.), s),f.x),")
WriteLine(fw," mix(Hash(i + vec2(0.,1.), s), Hash(i + vec2(1.,1.), s),f.x),")
WriteLine(fw," f.y) * s;")
WriteLine(fw,"}")
WriteLine(fw,"float factor(float len, float s, float e){")
WriteLine(fw," float v1 = 1.0 - 1.0 / exp(pow((s-len) * 6.0,2.0));")
WriteLine(fw," v1 = clamp(v1, 0.0, 1.0);")
WriteLine(fw," float v2 = 1.0 - 1.0 / exp(pow((len-e) * 6.0,2.0));")
WriteLine(fw," v2 = clamp(v2, 0.0, 1.0);")
WriteLine(fw," return (1.0-step(len,s))*v1 * (step(len,e))*v2;")
WriteLine(fw,"}")
WriteLine(fw,"float fbm(vec2 uv,float t,float len){")
WriteLine(fw," float v = 0.0;")
WriteLine(fw," vec2 p = uv+t;")
WriteLine(fw," v += noise(p*.5, 0.35);")
WriteLine(fw," v -= noise(p*2., 0.25);")
WriteLine(fw," v -= noise(p*4., 0.125);")
WriteLine(fw," v += noise(p*8., 0.0625);")
WriteLine(fw," return v*factor(length(uv),0.0,len);")
WriteLine(fw,"}")
WriteLine(fw,"vec2 rotate(vec2 uv,float degree){")
WriteLine(fw," mat2 rot = mat2(cos(degree),-sin(degree),sin(degree),cos(degree));")
WriteLine(fw," return rot*uv;")
WriteLine(fw,"}")
WriteLine(fw,"void main( void ) {")
WriteLine(fw," float size = min(resolution.x, resolution.y);")
WriteLine(fw," vec2 uv = gl_FragCoord.xy / size * 2.0 - resolution/size;")
WriteLine(fw," uv.x *= resolution.y/ resolution.x;")
WriteLine(fw," vec2 touch = vec2(1.0) - 2.0 * mouse/resolution;")
WriteLine(fw," uv = rotate(uv,atan(touch.y,-touch.x));")
WriteLine(fw," float t = width / distance(uv, vec2(clamp(uv.x,0.0,length(touch)),fbm(uv,time*speed,length(touch))));")
WriteLine(fw," vec3 finalColor = 0.3 * texture2D(backbuffer,gl_FragCoord.xy).rgb + t * color;")
WriteLine(fw," gl_FragColor = vec4( finalColor, 1.0 );")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
collect red squares by colliding with them avoid the green ones
fubar