Răsfoiți Sursa

More examples.

Brucey 5 ani în urmă
părinte
comite
336d76846d

+ 4 - 0
lib.mod/common.bmx

@@ -750,3 +750,7 @@ Const FILTER_TRILINEAR:Int = 2
 Const FILTER_ANISOTROPIC_4X:Int = 3
 Const FILTER_ANISOTROPIC_8X:Int = 4
 Const FILTER_ANISOTROPIC_16X:Int = 5
+
+Const MOUSE_LEFT_BUTTON:Int   = 0
+Const MOUSE_RIGHT_BUTTON:Int  = 1
+Const MOUSE_MIDDLE_BUTTON:Int = 2

+ 90 - 0
lib.mod/examples/shapes/shapes_draw_ring.bmx

@@ -0,0 +1,90 @@
+SuperStrict
+
+Framework Ray.GUI
+
+' Initialization
+'--------------------------------------------------------------------------------------
+Const screenWidth:Int = 800
+Const screenHeight:Int = 450
+
+InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw ring")
+
+Local center:RVector2 = New RVector2((GetScreenWidth() - 300)/2, GetScreenHeight()/2)
+
+Local innerRadius:Float = 80.0
+Local outerRadius:Float = 190.0
+
+Local startAngle:Int = 0
+Local endAngle:Int = 360
+Local segments:Int = 0
+
+Local shouldDrawRing:Int = True
+Local shouldDrawRingLines:Int = False
+Local shouldDrawCircleLines:Int = False
+
+SetTargetFPS(60)               ' Set our game to run at 60 frames-per-second
+'--------------------------------------------------------------------------------------
+
+' Main game loop
+While Not WindowShouldClose()    ' Detect window close button or ESC key
+	' Update
+	'----------------------------------------------------------------------------------
+	' NOTE: All variables update happens inside GUI control functions
+	'----------------------------------------------------------------------------------
+
+	' Draw
+	'----------------------------------------------------------------------------------
+	BeginDrawing()
+
+		ClearBackground(RAYWHITE)
+
+		DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6))
+		DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3))
+
+		If shouldDrawRing Then
+			DrawRing(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.3))
+		End If
+		If shouldDrawRingLines Then
+			DrawRingLines(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4))
+		End If
+		If shouldDrawCircleLines Then
+			DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4))
+		End If
+
+		' Draw GUI controls
+		'------------------------------------------------------------------------------
+		startAngle = GuiSliderBar(New RRectangle(600, 40, 120, 20), "StartAngle", "", startAngle, -450, 450)
+		endAngle = GuiSliderBar(New RRectangle(600, 70, 120, 20), "EndAngle", "", endAngle, -450, 450)
+
+		innerRadius = GuiSliderBar(New RRectangle(600, 140, 120, 20), "InnerRadius", "", innerRadius, 0, 100)
+		outerRadius = GuiSliderBar(New RRectangle(600, 170, 120, 20), "OuterRadius", "", outerRadius, 0, 200)
+
+		segments = GuiSliderBar(New RRectangle(600, 240, 120, 20), "Segments", "", segments, 0, 100)
+
+		shouldDrawRing = GuiCheckBox(New RRectangle(600, 320, 20, 20), "Draw Ring", shouldDrawRing)
+		shouldDrawRingLines = GuiCheckBox(New RRectangle(600, 350, 20, 20), "Draw RingLines", shouldDrawRingLines)
+		shouldDrawCircleLines = GuiCheckBox(New RRectangle(600, 380, 20, 20), "Draw CircleLines", shouldDrawCircleLines)
+		'------------------------------------------------------------------------------
+
+		Local col:RColor
+		Local txt:String
+		If segments >= 4 Then
+			txt = "MODE: MANUAL"
+			col = MAROON
+		Else
+			txt = "MODE: AUTO"
+			col = DARKGRAY
+		End If
+		
+		DrawText(txt, 600, 270, 10, col)
+
+		DrawFPS(10, 10)
+
+	EndDrawing()
+	'----------------------------------------------------------------------------------
+Wend
+
+' De-Initialization
+'--------------------------------------------------------------------------------------
+CloseWindow()        ' Close window and OpenGL context
+'--------------------------------------------------------------------------------------

+ 41 - 0
lib.mod/examples/shapes/shapes_logo_raylib.bmx

@@ -0,0 +1,41 @@
+SuperStrict
+
+Framework Ray.Lib
+
+' Initialization
+'--------------------------------------------------------------------------------------
+Const screenWidth:Int = 800
+Const screenHeight:Int = 450
+
+InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes")
+
+SetTargetFPS(60)               ' Set our game to run at 60 frames-per-second
+'--------------------------------------------------------------------------------------
+
+' Main game loop
+While Not WindowShouldClose()    ' Detect window close button or ESC key
+	' Update
+	'----------------------------------------------------------------------------------
+	' TODO: Update your variables here
+	'----------------------------------------------------------------------------------
+
+	' Draw
+	'----------------------------------------------------------------------------------
+	BeginDrawing()
+
+		ClearBackground(RAYWHITE)
+
+		DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, BLACK)
+		DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE)
+		DrawText("raylib", screenWidth/2 - 44, screenHeight/2 + 48, 50, BLACK)
+
+		DrawText("this is NOT a texture!", 350, 370, 10, GRAY)
+
+	EndDrawing()
+	'----------------------------------------------------------------------------------
+Wend
+
+' De-Initialization
+'--------------------------------------------------------------------------------------
+CloseWindow()        ' Close window and OpenGL context
+'--------------------------------------------------------------------------------------

+ 130 - 0
lib.mod/examples/shapes/shapes_logo_raylib_anim.bmx

@@ -0,0 +1,130 @@
+SuperStrict
+
+Framework Ray.Lib
+
+' Initialization
+'--------------------------------------------------------------------------------------
+Const screenWidth:Int = 800
+Const screenHeight:Int = 450
+
+InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
+
+Local logoPositionX:Int = screenWidth/2 - 128
+Local logoPositionY:Int = screenHeight/2 - 128
+
+Local framesCounter:Int = 0
+Local lettersCount:Int = 0
+
+Local topSideRecWidth:Int = 16
+Local leftSideRecHeight:Int = 16
+
+Local bottomSideRecWidth:Int = 16
+Local rightSideRecHeight:Int = 16
+
+Local state:Int = 0                  ' Tracking animation states (State Machine)
+Local alpha:Float = 1.0              ' Useful for fading
+
+SetTargetFPS(60)               ' Set our game to run at 60 frames-per-second
+'--------------------------------------------------------------------------------------
+
+' Main game loop
+While Not WindowShouldClose()    ' Detect window close button or ESC key
+	' Update
+	'----------------------------------------------------------------------------------
+	If state = 0 Then                 ' State 0: Small box blinking
+		framesCounter:+ 1
+
+		If framesCounter = 120 Then
+			state = 1
+			framesCounter = 0      ' Reset counter... will be used later...
+		End If
+	Else If state = 1 Then           ' State 1: Top and left bars growing
+		topSideRecWidth :+ 4
+		leftSideRecHeight :+ 4
+
+		If topSideRecWidth = 256
+			state = 2
+		End If
+	Else If state = 2 Then            ' State 2: Bottom and right bars growing
+		bottomSideRecWidth :+ 4
+		rightSideRecHeight :+ 4
+
+		If bottomSideRecWidth = 256 Then
+			state = 3
+		End If
+		
+	Else If state = 3 Then            ' State 3: Letters appearing (one by one)
+		framesCounter :+ 1
+
+		If framesCounter/12 Then       ' Every 12 frames, one more letter!
+			lettersCount :+ 1
+			framesCounter = 0
+		End If
+
+		If lettersCount >= 10 Then     ' When all letters have appeared, just fade out everything
+			alpha :- 0.02
+
+			If alpha <= 0.0 Then
+				alpha = 0.0
+				state = 4
+			End If
+		End If
+	Else If state = 4            ' State 4: Reset and Replay
+		If IsKeyPressed(Asc("R"))
+			framesCounter = 0
+			lettersCount = 0
+
+			topSideRecWidth = 16
+			leftSideRecHeight = 16
+
+			bottomSideRecWidth = 16
+			rightSideRecHeight = 16
+
+			alpha = 1.0
+			state = 0          ' Return to State 0
+		End If
+	End If
+	'----------------------------------------------------------------------------------
+
+	' Draw
+	'----------------------------------------------------------------------------------
+	BeginDrawing()
+
+		ClearBackground(RAYWHITE)
+
+		If state = 0 Then
+			If (framesCounter / 15) Mod 2 Then
+				DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK)
+			End If
+		Else If state = 1 Then
+			DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK)
+			DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK)
+		Else If state = 2 Then
+			DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK)
+			DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK)
+
+			DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK)
+			DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK)
+		Else If state = 3 Then
+			DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha))
+			DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha))
+
+			DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha))
+			DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha))
+
+			DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha))
+
+			DrawText("raylib"[..lettersCount], screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha))
+
+		Else If state = 4 Then
+			DrawText("[R] REPLAY", 340, 200, 20, GRAY)
+		End If
+
+	EndDrawing()
+	'----------------------------------------------------------------------------------
+Wend
+
+' De-Initialization
+'--------------------------------------------------------------------------------------
+CloseWindow()        ' Close window and OpenGL context
+'--------------------------------------------------------------------------------------

+ 83 - 0
lib.mod/examples/shapes/shapes_rectangle_scaling.bmx

@@ -0,0 +1,83 @@
+SuperStrict
+
+Framework Ray.Lib
+
+Const MOUSE_SCALE_MARK_SIZE:Int = 12
+
+' Initialization
+'--------------------------------------------------------------------------------------
+Const screenWidth:Int = 800
+Const screenHeight:Int = 450
+
+InitWindow(screenWidth, screenHeight, "raylib [shapes] example - rectangle scaling mouse")
+
+Local rec:RRectangle = New RRectangle(100, 100, 200, 80)
+
+Local mousePosition:RVector2
+
+Local mouseScaleReady:Int = False
+Local mouseScaleMode:Int = False
+
+SetTargetFPS(60)               ' Set our game to run at 60 frames-per-second
+'--------------------------------------------------------------------------------------
+
+' Main game loop
+While Not WindowShouldClose()    ' Detect window close button or ESC key
+	' Update
+	'----------------------------------------------------------------------------------
+	mousePosition = GetMousePosition()
+
+	If CheckCollisionPointRec(mousePosition, rec) And ..
+			CheckCollisionPointRec(mousePosition, New RRectangle(rec.x + rec.width - MOUSE_SCALE_MARK_SIZE, rec.y + rec.height - MOUSE_SCALE_MARK_SIZE, MOUSE_SCALE_MARK_SIZE, MOUSE_SCALE_MARK_SIZE)) Then
+		mouseScaleReady = True
+		If IsMouseButtonPressed(MOUSE_LEFT_BUTTON) Then
+			mouseScaleMode = True
+		End If
+	Else
+		mouseScaleReady = False
+	End If
+
+	If mouseScaleMode Then
+		mouseScaleReady = True
+
+		rec.width = (mousePosition.x - rec.x)
+		rec.height = (mousePosition.y - rec.y)
+
+		If rec.width < MOUSE_SCALE_MARK_SIZE Then
+			rec.width = MOUSE_SCALE_MARK_SIZE
+		End If
+		If rec.height < MOUSE_SCALE_MARK_SIZE Then
+			rec.height = MOUSE_SCALE_MARK_SIZE
+		End If
+
+		If IsMouseButtonReleased(MOUSE_LEFT_BUTTON) Then
+			mouseScaleMode = False
+		End If
+	End If
+	'----------------------------------------------------------------------------------
+
+	' Draw
+	'----------------------------------------------------------------------------------
+	BeginDrawing()
+
+		ClearBackground(RAYWHITE)
+
+		DrawText("Scale rectangle dragging from bottom-right corner!", 10, 10, 20, GRAY)
+
+		DrawRectangleRec(rec, Fade(GREEN, 0.5))
+
+		If mouseScaleReady Then
+			DrawRectangleLinesEx(rec, 1, RED)
+			DrawTriangle(New RVector2(rec.x + rec.width - MOUSE_SCALE_MARK_SIZE, rec.y + rec.height), ..
+						 New RVector2(rec.x + rec.width, rec.y + rec.height), ..
+						 New RVector2(rec.x + rec.width, rec.y + rec.height - MOUSE_SCALE_MARK_SIZE), RED)
+		End If
+
+	EndDrawing()
+	'----------------------------------------------------------------------------------
+Wend
+
+' De-Initialization
+'--------------------------------------------------------------------------------------
+CloseWindow()        ' Close window and OpenGL context
+'--------------------------------------------------------------------------------------