TGC Codebase Backup



Simple Curve Painter by Markus

25th Nov 2016 13:14
Summary

Paint Curve for Sprite movement



Description

Painting a Curve with Mouse for using as sprite movement.
For Jump,Bounce,Fall,Effects,...



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem AGK 2.0.21
rem Curve Paint
rem MR

SetVirtualResolution(100,100)

type Pos
	x as float
	y as float
endtype

Main()
End

Function Main()

	local Nr as integer 
	Nr=1
	
	#constant CurveMax=180
	
	local Curve as Pos[CurveMax,1]
	local CurvePos as integer
	CurvePos=0
	
	spr = CreateSprite(0)
	SetSpriteSize(spr,5.0,5.0)

	sprx=50.0
	spry=50.0

	SetSpritePositionByOffset(spr,sprx,spry)

	
	Do
		Print("Hold Left Mouse Button and Move Mouse to Paint a Curve")
		Print("C=Clear")
		Print("X=Ignore X,Y=Ignore Y")
		
		mx=GetPointerX()
		my=GetPointerY()

		if GetRawKeyState( 88 ) //X
			mx=50.0
		endif
		
		if GetRawKeyState( 89 ) //Y
			my=50.0
		endif

		//Clear Curve Data
		if GetRawKeyPressed( 67 ) //C
			for i=1 to CurveMax
				Curve[i,Nr].x=0
				Curve[i,Nr].y=0
			next		
			CurvePos=0
			CurvePosSpr=0
		endif

		//Draw Cross
		DrawLine(0,50,100,50,128,128,128)
		DrawLine(50,0,50,100,128,128,128)
		
		//Collect
		if GetPointerState()=1 and CurvePos<CurveMax
			CurvePos=CurvePos+1
			Curve[CurvePos,Nr].x=mx-50.0
			Curve[CurvePos,Nr].y=my-50.0
			CurvePosSpr=0
		else
			//Sprite Animation
			CurvePosSpr=CurvePosSpr+1
			if CurvePosSpr>CurvePos then CurvePosSpr=CurvePosSpr-CurvePos
			SetSpritePositionByOffset(spr,sprx+Curve[CurvePosSpr,Nr].x,spry+Curve[CurvePosSpr,Nr].y)
		endif

		//Draw Curve
		for i=1 to CurvePos
			DrawEllipse(50.0+Curve[i,Nr].x,50.0+Curve[i,Nr].y,0.5,0.5,255,255,0)
		next

		//... Save / Load
		
		Sync()
	Loop

EndFunction