I made a test thingy (From the sample small games) that saves the velocity and if the difference in velocity over a frame is more than 1.5 it takes the last velocity and applies it.
Dunno if it will fix a lag but it seems to work when i drag the window
Click/Drag the ball to start
// Project: Angry Blocks
// Created: 2017-03-02
// By Easter Bunny
/*
Hacks you should totally do
1. Infinite shots
2. Player doesn't reset position on level restart
3. Design your own levels!
4. Add some sort of scoring system
*/
SetErrorMode(2)
//init stuff
SetWindowTitle( "Angry Blocks" )
SetWindowSize( 1000,625, 0 ) //use 16:10 aspect ratio
SetVirtualResolution( 160,100 )
SetOrientationAllowed( 0, 0, 1, 1 )
SetSyncRate( 0,1 ) //unlimited framerate
UseNewDefaultFonts( 1 )
SetPhysicsDebugOn()
//by default these 4 walls are on anyway so these lines are redundant
//however if you move the viewport (using SetViewOffset(x,y), the walls will automtically be removed
//so if you ever intend to move the viewport around, you should use static physics sprites for walls at the bounds of your level
SetPhysicsWallBottom(0)
SetPhysicsWallTop(0)
SetPhysicsWallLeft(0)
SetPhysicsWallRight(0)
//I'm not sure what the default gravity is set to
//so it's best practice to manually set the gravity so you have full control over it (ie if you change it, you can change it back since you know what it is)
SetPhysicsGravity(0,0)
//it's best practice to declare your variables as this will prepare you for using more advanced languages like C++
startPad as integer
firingState as integer
levelBlocks as integer[99]
ix as float
iy as float
plr as tPlayer //set up type for player. Includes player sprite, shots remaining and firing state. Check out the type declaration at the bottom of the code
rw = CreateSprite(0)
setspritesize(rw, 10, GetVirtualHeight())
SetSpritePosition(rw, GetVirtualWidth() - 10, 0)
SetSpriteShape(rw, 2)
SetSpritePhysicsOn(rw, 1)
SetSpritePhysicsRestitution(rw, 1)
lw = CreateSprite(0)
setspritesize(lw, 10, GetVirtualHeight())
SetSpritePosition(lw, 0, 0)
SetSpriteShape(lw, 2)
SetSpritePhysicsOn(lw, 1)
SetSpritePhysicsRestitution(lw, 1)
tw = CreateSprite(0)
setspritesize(tw, GetVirtualWidth(), 10)
SetSpritePosition(tw, 0, 0)
SetSpriteShape(tw, 2)
SetSpritePhysicsOn(tw, 1)
SetSpritePhysicsRestitution(tw, 1)
bw = CreateSprite(0)
setspritesize(bw, GetVirtualWidth(), 10)
SetSpritePosition(bw, 0, GetVirtualHeight() - 10)
SetSpriteShape(bw, 2)
SetSpritePhysicsOn(bw, 1)
plr.sprite=CreateSprite(0) //use blank [white square] image
SetSpriteSize(plr.sprite,5,5)
SetSpritePosition(plr.sprite,30,73) //75=80-5 [top of startPad]-[height of player sprite]
SetSpriteShape(plr.sprite,1) //0=no shape, 1=circle, 2=box, 3=polygon
SetSpritePhysicsOn(plr.sprite,2) //1=static, 2=dynamic, 3= kinematic
SetSpritePhysicsFriction(plr.sprite,0)
SetSpritePhysicsRestitution(plr.sprite,1) //the 'bounciness' of the sprite
SetSpritePhysicsDamping(plr.sprite, 0)
SetSpritePhysicsAngularDamping(plr.sprite, 0)
plr.shots=3
plr.firingState=0
type speed
x as float
y as float
v as float
endtype
speed as speed
lastspeed as speed
do
//print(ScreenFPS())
print("Shots remaining: "+str(plr.shots))
if plr.firingState=0
Print("Click anywhere and hold")
if GetPointerPressed()
ix=GetPointerX()
iy=GetPointerY()
plr.firingState=1
endif
elseif plr.firingState=1
Print("Drag then release to fire!")
DrawLine(GetPointerX(),GetPointerY(),ix,iy,200,200,200)
if GetPointerReleased()
dec plr.shots,1
SetSpritePhysicsVelocity(plr.sprite,(ix-GetPointerX())*10,(iy-GetPointerY())*10)
plr.firingState=2
endif
elseif plr.firingState=2
if plr.shots>0
print("Click to reset")
if GetPointerReleased()
SetSpritePosition(plr.sprite,2,75)
SetSpritePhysicsVelocity(plr.sprite,0,0)
SetSpritePhysicsAngularVelocity(plr.sprite,0)
plr.firingState=0
endif
else
print("")
print("Game over")
print("Click to restart game")
if GetPointerReleased()
f=OpenToRead("level.abl")
ReadLine(f)
n=val(ReadLine(f))
for k=1 to n
ReadLine(f) //blank line between each block for formatting
x#=valFloat(ReadLine(f))
y#=valFloat(ReadLine(f))
xs#=valFloat(ReadLine(f))
ys#=valFloat(ReadLine(f))
typ=val(ReadLine(f))
SetSpritePosition(levelBlocks[k],x#,y#)
SetSpriteAngle(levelBlocks[k],0)
SetSpritePhysicsVelocity(levelBlocks[k],0,0)
SetSpritePhysicsAngularVelocity(levelBlocks[k],0)
next
CloseFile(f)
SetSpritePosition(plr.sprite,2,75)
SetSpritePhysicsVelocity(plr.sprite,0,0)
SetSpritePhysicsAngularVelocity(plr.sprite,0)
plr.shots=3
plr.firingState=0
endif
endif
endif
speed.x = GetSpritePhysicsVelocityX(plr.sprite)
speed.y = GetSpritePhysicsVelocityY(plr.sprite)
speed.v = Distance2D(speed.x, speed.y)
if lastspeed.v / speed.v > 1.5
SetSpritePhysicsVelocity(plr.sprite,lastspeed.x,lastspeed.y)
speed = lastspeed
endif
Print("Speed="+str(speed.v)+")")
Sync()
lastspeed = speed
loop
function Distance2D(x as float, y as float)
dist as float
dist=sqrt((x)^2 + (y)^2)
endfunction dist
type tPlayer
sprite
shots
firingState
endtype