Update/merge examples back into main repo (#192)
This commit is contained in:
parent
fa682b00ac
commit
bcdf8cec5b
320 changed files with 57965 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -9,6 +9,7 @@
|
||||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
.vscode/
|
.vscode/
|
||||||
|
*.data
|
||||||
|
|
||||||
# Binaries
|
# Binaries
|
||||||
![Bb]in/
|
![Bb]in/
|
||||||
|
|
|
||||||
193
Examples/Audio/ModulePlaying.cs
Normal file
193
Examples/Audio/ModulePlaying.cs
Normal file
|
|
@ -0,0 +1,193 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [audio] example - Module playing (streaming)
|
||||||
|
*
|
||||||
|
* NOTE: This example requires OpenAL Soft library installed
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.5 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Audio;
|
||||||
|
|
||||||
|
public class ModulePlaying
|
||||||
|
{
|
||||||
|
const int MaxCircles = 64;
|
||||||
|
|
||||||
|
struct CircleWave
|
||||||
|
{
|
||||||
|
public Vector2 Position;
|
||||||
|
public float Radius;
|
||||||
|
public float Alpha;
|
||||||
|
public float Speed;
|
||||||
|
public Color Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(ConfigFlags.FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)");
|
||||||
|
|
||||||
|
InitAudioDevice();
|
||||||
|
|
||||||
|
Color[] colors = new Color[14] {
|
||||||
|
Color.ORANGE,
|
||||||
|
Color.RED,
|
||||||
|
Color.GOLD,
|
||||||
|
Color.LIME,
|
||||||
|
Color.BLUE,
|
||||||
|
Color.VIOLET,
|
||||||
|
Color.BROWN,
|
||||||
|
Color.LIGHTGRAY,
|
||||||
|
Color.PINK,
|
||||||
|
Color.YELLOW,
|
||||||
|
Color.GREEN,
|
||||||
|
Color.SKYBLUE,
|
||||||
|
Color.PURPLE,
|
||||||
|
Color.BEIGE
|
||||||
|
};
|
||||||
|
|
||||||
|
// Creates ome circles for visual effect
|
||||||
|
CircleWave[] circles = new CircleWave[MaxCircles];
|
||||||
|
|
||||||
|
for (int i = MaxCircles - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
circles[i].Alpha = 0.0f;
|
||||||
|
circles[i].Radius = GetRandomValue(10, 40);
|
||||||
|
circles[i].Position.X = GetRandomValue((int)circles[i].Radius, screenWidth - (int)circles[i].Radius);
|
||||||
|
circles[i].Position.Y = GetRandomValue((int)circles[i].Radius, screenHeight - (int)circles[i].Radius);
|
||||||
|
circles[i].Speed = (float)GetRandomValue(1, 100) / 20000.0f;
|
||||||
|
circles[i].Color = colors[GetRandomValue(0, 13)];
|
||||||
|
}
|
||||||
|
|
||||||
|
Music music = LoadMusicStream("resources/audio/mini1111.Xm");
|
||||||
|
music.Looping = false;
|
||||||
|
float pitch = 1.0f;
|
||||||
|
|
||||||
|
PlayMusicStream(music);
|
||||||
|
|
||||||
|
float timePlayed = 0.0f;
|
||||||
|
bool pause = false;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
|
// Restart music playing (stop and play)
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_SPACE))
|
||||||
|
{
|
||||||
|
StopMusicStream(music);
|
||||||
|
PlayMusicStream(music);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause/Resume music playing
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_P))
|
||||||
|
{
|
||||||
|
pause = !pause;
|
||||||
|
|
||||||
|
if (pause)
|
||||||
|
{
|
||||||
|
PauseMusicStream(music);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ResumeMusicStream(music);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_DOWN))
|
||||||
|
{
|
||||||
|
pitch -= 0.01f;
|
||||||
|
}
|
||||||
|
else if (IsKeyDown(KeyboardKey.KEY_UP))
|
||||||
|
{
|
||||||
|
pitch += 0.01f;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetMusicPitch(music, pitch);
|
||||||
|
|
||||||
|
// Get timePlayed scaled to bar dimensions
|
||||||
|
timePlayed = GetMusicTimePlayed(music) / GetMusicTimeLength(music) * (screenWidth - 40);
|
||||||
|
|
||||||
|
// Color circles animation
|
||||||
|
for (int i = MaxCircles - 1; (i >= 0) && !pause; i--)
|
||||||
|
{
|
||||||
|
circles[i].Alpha += circles[i].Speed;
|
||||||
|
circles[i].Radius += circles[i].Speed * 10.0f;
|
||||||
|
|
||||||
|
if (circles[i].Alpha > 1.0f)
|
||||||
|
{
|
||||||
|
circles[i].Speed *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (circles[i].Alpha <= 0.0f)
|
||||||
|
{
|
||||||
|
circles[i].Alpha = 0.0f;
|
||||||
|
circles[i].Radius = GetRandomValue(10, 40);
|
||||||
|
circles[i].Position.X = GetRandomValue(
|
||||||
|
(int)circles[i].Radius,
|
||||||
|
screenWidth - (int)circles[i].Radius
|
||||||
|
);
|
||||||
|
circles[i].Position.Y = GetRandomValue(
|
||||||
|
(int)circles[i].Radius,
|
||||||
|
screenHeight - (int)circles[i].Radius
|
||||||
|
);
|
||||||
|
circles[i].Color = colors[GetRandomValue(0, 13)];
|
||||||
|
circles[i].Speed = (float)GetRandomValue(1, 100) / 2000.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
for (int i = MaxCircles - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
DrawCircleV(
|
||||||
|
circles[i].Position,
|
||||||
|
circles[i].Radius,
|
||||||
|
ColorAlpha(circles[i].Color, circles[i].Alpha)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw time bar
|
||||||
|
DrawRectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, Color.LIGHTGRAY);
|
||||||
|
DrawRectangle(20, screenHeight - 20 - 12, (int)timePlayed, 12, Color.MAROON);
|
||||||
|
DrawRectangleLines(20, screenHeight - 20 - 12, screenWidth - 40, 12, Color.GRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadMusicStream(music);
|
||||||
|
|
||||||
|
CloseAudioDevice();
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
106
Examples/Audio/MusicStreamDemo.cs
Normal file
106
Examples/Audio/MusicStreamDemo.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [audio] example - IntPtr playing (streaming)
|
||||||
|
*
|
||||||
|
* NOTE: This example requires OpenAL Soft library installed
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Audio;
|
||||||
|
|
||||||
|
public class MusicStreamDemo
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
|
||||||
|
InitAudioDevice();
|
||||||
|
|
||||||
|
Music music = LoadMusicStream("resources/audio/country.mp3");
|
||||||
|
PlayMusicStream(music);
|
||||||
|
|
||||||
|
float timePlayed = 0.0f;
|
||||||
|
bool pause = false;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateMusicStream(music); // Update music buffer with new stream data
|
||||||
|
|
||||||
|
// Restart music playing (stop and play)
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_SPACE))
|
||||||
|
{
|
||||||
|
StopMusicStream(music);
|
||||||
|
PlayMusicStream(music);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pause/Resume music playing
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_P))
|
||||||
|
{
|
||||||
|
pause = !pause;
|
||||||
|
|
||||||
|
if (pause)
|
||||||
|
{
|
||||||
|
PauseMusicStream(music);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ResumeMusicStream(music);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get timePlayed scaled to bar dimensions (400 pixels)
|
||||||
|
timePlayed = GetMusicTimePlayed(music) / GetMusicTimeLength(music) * 400;
|
||||||
|
|
||||||
|
if (timePlayed > 400)
|
||||||
|
{
|
||||||
|
StopMusicStream(music);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
DrawRectangle(200, 200, 400, 12, Color.LIGHTGRAY);
|
||||||
|
DrawRectangle(200, 200, (int)timePlayed, 12, Color.MAROON);
|
||||||
|
DrawRectangleLines(200, 200, 400, 12, Color.GRAY);
|
||||||
|
|
||||||
|
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, Color.LIGHTGRAY);
|
||||||
|
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadMusicStream(music);
|
||||||
|
|
||||||
|
CloseAudioDevice();
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
76
Examples/Audio/SoundLoading.cs
Normal file
76
Examples/Audio/SoundLoading.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [audio] example - Sound loading and playing
|
||||||
|
*
|
||||||
|
* NOTE: This example requires OpenAL Soft library installed
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Audio;
|
||||||
|
|
||||||
|
public class SoundLoading
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
|
||||||
|
InitAudioDevice();
|
||||||
|
|
||||||
|
Sound fxWav = LoadSound("resources/audio/sound.wav");
|
||||||
|
Sound fxOgg = LoadSound("resources/audio/target.ogg");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_SPACE))
|
||||||
|
{
|
||||||
|
PlaySound(fxWav);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_ENTER))
|
||||||
|
{
|
||||||
|
PlaySound(fxOgg);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, Color.LIGHTGRAY);
|
||||||
|
DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadSound(fxWav);
|
||||||
|
UnloadSound(fxOgg);
|
||||||
|
|
||||||
|
CloseAudioDevice();
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
175
Examples/Core/BasicScreenManager.cs
Normal file
175
Examples/Core/BasicScreenManager.cs
Normal file
|
|
@ -0,0 +1,175 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Basic window
|
||||||
|
*
|
||||||
|
* Welcome to raylib!
|
||||||
|
*
|
||||||
|
* To test examples, just press F6 and execute raylib_compile_execute script
|
||||||
|
* Note that compiled executable is placed in the same folder as .c file
|
||||||
|
*
|
||||||
|
* You can find all basic examples on C:\raylib\raylib\examples folder or
|
||||||
|
* raylib official webpage: www.raylib.com
|
||||||
|
*
|
||||||
|
* Enjoy using raylib. :)
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
enum GameScreen
|
||||||
|
{
|
||||||
|
Logo = 0,
|
||||||
|
Title,
|
||||||
|
Gameplay,
|
||||||
|
Ending
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BasicScreenManager
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic screen manager");
|
||||||
|
|
||||||
|
GameScreen currentScreen = GameScreen.Logo;
|
||||||
|
|
||||||
|
// TODO: Initialize all required variables and load all required data here!
|
||||||
|
|
||||||
|
// Useful to count frames
|
||||||
|
int framesCounter = 0;
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set desired framerate (frames-per-second)
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
switch (currentScreen)
|
||||||
|
{
|
||||||
|
case GameScreen.Logo:
|
||||||
|
{
|
||||||
|
// TODO: Update LOGO screen variables here!
|
||||||
|
|
||||||
|
// Count frames
|
||||||
|
framesCounter++;
|
||||||
|
|
||||||
|
// Wait for 2 seconds (120 frames) before jumping to TITLE screen
|
||||||
|
if (framesCounter > 120)
|
||||||
|
{
|
||||||
|
currentScreen = GameScreen.Title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GameScreen.Title:
|
||||||
|
{
|
||||||
|
// TODO: Update TITLE screen variables here!
|
||||||
|
|
||||||
|
// Press enter to change to GAMEPLAY screen
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_ENTER) || IsGestureDetected(Gesture.GESTURE_TAP))
|
||||||
|
{
|
||||||
|
currentScreen = GameScreen.Gameplay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GameScreen.Gameplay:
|
||||||
|
{
|
||||||
|
// TODO: Update GAMEPLAY screen variables here!
|
||||||
|
|
||||||
|
// Press enter to change to ENDING screen
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_ENTER) || IsGestureDetected(Gesture.GESTURE_TAP))
|
||||||
|
{
|
||||||
|
currentScreen = GameScreen.Ending;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GameScreen.Ending:
|
||||||
|
{
|
||||||
|
// TODO: Update ENDING screen variables here!
|
||||||
|
|
||||||
|
// Press enter to return to TITLE screen
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_ENTER) || IsGestureDetected(Gesture.GESTURE_TAP))
|
||||||
|
{
|
||||||
|
currentScreen = GameScreen.Title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
switch (currentScreen)
|
||||||
|
{
|
||||||
|
case GameScreen.Logo:
|
||||||
|
{
|
||||||
|
// TODO: Draw LOGO screen here!
|
||||||
|
DrawText("LOGO SCREEN", 20, 20, 40, Color.LIGHTGRAY);
|
||||||
|
DrawText("WAIT for 2 SECONDS...", 290, 220, 20, Color.GRAY);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GameScreen.Title:
|
||||||
|
{
|
||||||
|
// TODO: Draw TITLE screen here!
|
||||||
|
DrawRectangle(0, 0, screenWidth, screenHeight, Color.GREEN);
|
||||||
|
DrawText("TITLE SCREEN", 20, 20, 40, Color.DARKGREEN);
|
||||||
|
DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, Color.DARKGREEN);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GameScreen.Gameplay:
|
||||||
|
{
|
||||||
|
// TODO: Draw GAMEPLAY screen here!
|
||||||
|
DrawRectangle(0, 0, screenWidth, screenHeight, Color.PURPLE);
|
||||||
|
DrawText("GAMEPLAY SCREEN", 20, 20, 40, Color.MAROON);
|
||||||
|
DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, Color.MAROON);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GameScreen.Ending:
|
||||||
|
{
|
||||||
|
// TODO: Draw ENDING screen here!
|
||||||
|
DrawRectangle(0, 0, screenWidth, screenHeight, Color.BLUE);
|
||||||
|
DrawText("ENDING SCREEN", 20, 20, 40, Color.DARKBLUE);
|
||||||
|
DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, Color.DARKBLUE);
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// TODO: Unload all loaded data (textures, fonts, audio) here!
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
69
Examples/Core/BasicWindow.cs
Normal file
69
Examples/Core/BasicWindow.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Basic window
|
||||||
|
*
|
||||||
|
* Welcome to raylib!
|
||||||
|
*
|
||||||
|
* To test examples, just press F6 and execute raylib_compile_execute script
|
||||||
|
* Note that compiled executable is placed in the same folder as .c file
|
||||||
|
*
|
||||||
|
* You can find all basic examples on C:\raylib\raylib\examples folder or
|
||||||
|
* raylib official webpage: www.raylib.com
|
||||||
|
*
|
||||||
|
* Enjoy using raylib. :)
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class BasicWindow
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// TODO: Update your variables here
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("Congrats! You created your first window!", 190, 200, 20, Color.MAROON);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
175
Examples/Core/Camera2dDemo.cs
Normal file
175
Examples/Core/Camera2dDemo.cs
Normal file
|
|
@ -0,0 +1,175 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - 2d camera
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.5 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class Camera2dDemo
|
||||||
|
{
|
||||||
|
public const int MaxBuildings = 100;
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
|
||||||
|
|
||||||
|
Rectangle player = new(400, 280, 40, 40);
|
||||||
|
Rectangle[] buildings = new Rectangle[MaxBuildings];
|
||||||
|
Color[] buildColors = new Color[MaxBuildings];
|
||||||
|
|
||||||
|
int spacing = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < MaxBuildings; i++)
|
||||||
|
{
|
||||||
|
buildings[i].Width = GetRandomValue(50, 200);
|
||||||
|
buildings[i].Height = GetRandomValue(100, 800);
|
||||||
|
buildings[i].Y = screenHeight - 130 - buildings[i].Height;
|
||||||
|
buildings[i].X = -6000 + spacing;
|
||||||
|
|
||||||
|
spacing += (int)buildings[i].Width;
|
||||||
|
|
||||||
|
buildColors[i] = new Color(
|
||||||
|
GetRandomValue(200, 240),
|
||||||
|
GetRandomValue(200, 240),
|
||||||
|
GetRandomValue(200, 250),
|
||||||
|
255
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera2D camera = new();
|
||||||
|
camera.Target = new Vector2(player.X + 20, player.Y + 20);
|
||||||
|
camera.Offset = new Vector2(screenWidth / 2, screenHeight / 2);
|
||||||
|
camera.Rotation = 0.0f;
|
||||||
|
camera.Zoom = 1.0f;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Player movement
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_RIGHT))
|
||||||
|
{
|
||||||
|
player.X += 2;
|
||||||
|
}
|
||||||
|
else if (IsKeyDown(KeyboardKey.KEY_LEFT))
|
||||||
|
{
|
||||||
|
player.X -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera3D target follows player
|
||||||
|
camera.Target = new Vector2(player.X + 20, player.Y + 20);
|
||||||
|
|
||||||
|
// Camera3D rotation controls
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_A))
|
||||||
|
{
|
||||||
|
camera.Rotation--;
|
||||||
|
}
|
||||||
|
else if (IsKeyDown(KeyboardKey.KEY_S))
|
||||||
|
{
|
||||||
|
camera.Rotation++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit camera rotation to 80 degrees (-40 to 40)
|
||||||
|
if (camera.Rotation > 40)
|
||||||
|
{
|
||||||
|
camera.Rotation = 40;
|
||||||
|
}
|
||||||
|
else if (camera.Rotation < -40)
|
||||||
|
{
|
||||||
|
camera.Rotation = -40;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera3D zoom controls
|
||||||
|
camera.Zoom += ((float)GetMouseWheelMove() * 0.05f);
|
||||||
|
|
||||||
|
if (camera.Zoom > 3.0f)
|
||||||
|
{
|
||||||
|
camera.Zoom = 3.0f;
|
||||||
|
}
|
||||||
|
else if (camera.Zoom < 0.1f)
|
||||||
|
{
|
||||||
|
camera.Zoom = 0.1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera3D reset (zoom and rotation)
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_R))
|
||||||
|
{
|
||||||
|
camera.Zoom = 1.0f;
|
||||||
|
camera.Rotation = 0.0f;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode2D(camera);
|
||||||
|
|
||||||
|
DrawRectangle(-6000, 320, 13000, 8000, Color.DARKGRAY);
|
||||||
|
|
||||||
|
for (int i = 0; i < MaxBuildings; i++)
|
||||||
|
{
|
||||||
|
DrawRectangleRec(buildings[i], buildColors[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangleRec(player, Color.RED);
|
||||||
|
|
||||||
|
DrawRectangle((int)camera.Target.X, -500, 1, (int)(screenHeight * 4), Color.GREEN);
|
||||||
|
DrawLine(
|
||||||
|
(int)(-screenWidth * 10),
|
||||||
|
(int)camera.Target.Y,
|
||||||
|
(int)(screenWidth * 10),
|
||||||
|
(int)camera.Target.Y,
|
||||||
|
Color.GREEN
|
||||||
|
);
|
||||||
|
|
||||||
|
EndMode2D();
|
||||||
|
|
||||||
|
DrawText("SCREEN AREA", 640, 10, 20, Color.RED);
|
||||||
|
|
||||||
|
DrawRectangle(0, 0, (int)screenWidth, 5, Color.RED);
|
||||||
|
DrawRectangle(0, 5, 5, (int)screenHeight - 10, Color.RED);
|
||||||
|
DrawRectangle((int)screenWidth - 5, 5, 5, (int)screenHeight - 10, Color.RED);
|
||||||
|
DrawRectangle(0, (int)screenHeight - 5, (int)screenWidth, 5, Color.RED);
|
||||||
|
|
||||||
|
DrawRectangle(10, 10, 250, 113, ColorAlpha(Color.SKYBLUE, 0.5f));
|
||||||
|
DrawRectangleLines(10, 10, 250, 113, Color.BLUE);
|
||||||
|
|
||||||
|
DrawText("Free 2d camera controls:", 20, 20, 10, Color.BLACK);
|
||||||
|
DrawText("- Right/Left to move Offset", 40, 40, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- A / S to Rotate", 40, 80, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- R to reset Zoom and Rotation", 40, 100, 10, Color.DARKGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
402
Examples/Core/Camera2dPlatformer.cs
Normal file
402
Examples/Core/Camera2dPlatformer.cs
Normal file
|
|
@ -0,0 +1,402 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - 2d camera platformer
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Example contributed by arvyy (@arvyy) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 arvyy (@arvyy)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
using static Raylib_cs.Raymath;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class Camera2dPlatformer
|
||||||
|
{
|
||||||
|
const int G = 400;
|
||||||
|
const float PlayerJumpSpeed = 350.0f;
|
||||||
|
const float PlayerHorSpeed = 200.0f;
|
||||||
|
|
||||||
|
struct Player
|
||||||
|
{
|
||||||
|
public Vector2 Position;
|
||||||
|
public float Speed;
|
||||||
|
public bool CanJump;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct EnvItem
|
||||||
|
{
|
||||||
|
public Rectangle Rect;
|
||||||
|
public int Blocking;
|
||||||
|
public Color Color;
|
||||||
|
|
||||||
|
public EnvItem(Rectangle rect, int blocking, Color color)
|
||||||
|
{
|
||||||
|
this.Rect = rect;
|
||||||
|
this.Blocking = blocking;
|
||||||
|
this.Color = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate void CameraUpdaterCallback(
|
||||||
|
ref Camera2D camera,
|
||||||
|
ref Player player,
|
||||||
|
EnvItem[] envItems,
|
||||||
|
float delta,
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
);
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
|
||||||
|
|
||||||
|
Player player = new();
|
||||||
|
player.Position = new Vector2(400, 280);
|
||||||
|
player.Speed = 0;
|
||||||
|
player.CanJump = false;
|
||||||
|
|
||||||
|
EnvItem[] envItems = new EnvItem[]
|
||||||
|
{
|
||||||
|
new EnvItem(new Rectangle(0, 0, 1000, 400), 0, Color.LIGHTGRAY),
|
||||||
|
new EnvItem(new Rectangle(0, 400, 1000, 200), 1, Color.GRAY),
|
||||||
|
new EnvItem(new Rectangle(300, 200, 400, 10), 1, Color.GRAY),
|
||||||
|
new EnvItem(new Rectangle(250, 300, 100, 10), 1, Color.GRAY),
|
||||||
|
new EnvItem(new Rectangle(650, 300, 100, 10), 1, Color.GRAY)
|
||||||
|
};
|
||||||
|
|
||||||
|
Camera2D camera = new();
|
||||||
|
camera.Target = player.Position;
|
||||||
|
camera.Offset = new Vector2(screenWidth / 2, screenHeight / 2);
|
||||||
|
camera.Rotation = 0.0f;
|
||||||
|
camera.Zoom = 1.0f;
|
||||||
|
|
||||||
|
// Store callbacks to the multiple update camera functions
|
||||||
|
CameraUpdaterCallback[] cameraUpdaters = new CameraUpdaterCallback[]
|
||||||
|
{
|
||||||
|
UpdateCameraCenter,
|
||||||
|
UpdateCameraCenterInsideMap,
|
||||||
|
UpdateCameraCenterSmoothFollow,
|
||||||
|
UpdateCameraEvenOutOnLanding,
|
||||||
|
UpdateCameraPlayerBoundsPush
|
||||||
|
};
|
||||||
|
|
||||||
|
int cameraOption = 0;
|
||||||
|
int cameraUpdatersLength = cameraUpdaters.Length;
|
||||||
|
|
||||||
|
string[] cameraDescriptions = new string[]{
|
||||||
|
"Follow player center",
|
||||||
|
"Follow player center, but clamp to map edges",
|
||||||
|
"Follow player center; smoothed",
|
||||||
|
"Follow player center horizontally; update player center vertically after landing",
|
||||||
|
"Player push camera on getting too close to screen edge"
|
||||||
|
};
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
float deltaTime = GetFrameTime();
|
||||||
|
|
||||||
|
UpdatePlayer(ref player, envItems, deltaTime);
|
||||||
|
|
||||||
|
camera.Zoom += ((float)GetMouseWheelMove() * 0.05f);
|
||||||
|
|
||||||
|
if (camera.Zoom > 3.0f)
|
||||||
|
{
|
||||||
|
camera.Zoom = 3.0f;
|
||||||
|
}
|
||||||
|
else if (camera.Zoom < 0.25f)
|
||||||
|
{
|
||||||
|
camera.Zoom = 0.25f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_R))
|
||||||
|
{
|
||||||
|
camera.Zoom = 1.0f;
|
||||||
|
player.Position = new Vector2(400, 280);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_C))
|
||||||
|
{
|
||||||
|
cameraOption = (cameraOption + 1) % cameraUpdatersLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call update camera function by its pointer
|
||||||
|
cameraUpdaters[cameraOption](ref camera, ref player, envItems, deltaTime, screenWidth, screenHeight);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
BeginMode2D(camera);
|
||||||
|
|
||||||
|
for (int i = 0; i < envItems.Length; i++)
|
||||||
|
{
|
||||||
|
DrawRectangleRec(envItems[i].Rect, envItems[i].Color);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle playerRect = new(player.Position.X - 20, player.Position.Y - 40, 40, 40);
|
||||||
|
DrawRectangleRec(playerRect, Color.RED);
|
||||||
|
|
||||||
|
EndMode2D();
|
||||||
|
|
||||||
|
DrawText("Controls:", 20, 20, 10, Color.BLACK);
|
||||||
|
DrawText("- Right/Left to move", 40, 40, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- Space to jump", 40, 60, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- Mouse Wheel to Zoom in-out, R to reset zoom", 40, 80, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- C to change camera mode", 40, 100, 10, Color.DARKGRAY);
|
||||||
|
DrawText("Current camera mode:", 20, 120, 10, Color.BLACK);
|
||||||
|
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, Color.DARKGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdatePlayer(ref Player player, EnvItem[] envItems, float delta)
|
||||||
|
{
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_LEFT))
|
||||||
|
{
|
||||||
|
player.Position.X -= PlayerHorSpeed * delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_RIGHT))
|
||||||
|
{
|
||||||
|
player.Position.X += PlayerHorSpeed * delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_SPACE) && player.CanJump)
|
||||||
|
{
|
||||||
|
player.Speed = -PlayerJumpSpeed;
|
||||||
|
player.CanJump = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int hitObstacle = 0;
|
||||||
|
for (int i = 0; i < envItems.Length; i++)
|
||||||
|
{
|
||||||
|
EnvItem ei = envItems[i];
|
||||||
|
Vector2 p = player.Position;
|
||||||
|
if (ei.Blocking != 0 &&
|
||||||
|
ei.Rect.X <= p.X &&
|
||||||
|
ei.Rect.X + ei.Rect.Width >= p.X &&
|
||||||
|
ei.Rect.Y >= p.Y &&
|
||||||
|
ei.Rect.Y <= p.Y + player.Speed * delta)
|
||||||
|
{
|
||||||
|
hitObstacle = 1;
|
||||||
|
player.Speed = 0.0f;
|
||||||
|
player.Position.Y = ei.Rect.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hitObstacle == 0)
|
||||||
|
{
|
||||||
|
player.Position.Y += player.Speed * delta;
|
||||||
|
player.Speed += G * delta;
|
||||||
|
player.CanJump = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.CanJump = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateCameraCenter(
|
||||||
|
ref Camera2D camera,
|
||||||
|
ref Player player,
|
||||||
|
EnvItem[] envItems,
|
||||||
|
float delta,
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
)
|
||||||
|
{
|
||||||
|
camera.Offset = new Vector2(width / 2, height / 2);
|
||||||
|
camera.Target = player.Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateCameraCenterInsideMap(
|
||||||
|
ref Camera2D camera,
|
||||||
|
ref Player player,
|
||||||
|
EnvItem[] envItems,
|
||||||
|
float delta,
|
||||||
|
int width,
|
||||||
|
int height)
|
||||||
|
{
|
||||||
|
camera.Target = player.Position;
|
||||||
|
camera.Offset = new Vector2(width / 2, height / 2);
|
||||||
|
float minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;
|
||||||
|
|
||||||
|
for (int i = 0; i < envItems.Length; i++)
|
||||||
|
{
|
||||||
|
EnvItem ei = envItems[i];
|
||||||
|
minX = Math.Min(ei.Rect.X, minX);
|
||||||
|
maxX = Math.Max(ei.Rect.X + ei.Rect.Width, maxX);
|
||||||
|
minY = Math.Min(ei.Rect.Y, minY);
|
||||||
|
maxY = Math.Max(ei.Rect.Y + ei.Rect.Height, maxY);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 max = GetWorldToScreen2D(new Vector2(maxX, maxY), camera);
|
||||||
|
Vector2 min = GetWorldToScreen2D(new Vector2(minX, minY), camera);
|
||||||
|
|
||||||
|
if (max.X < width)
|
||||||
|
{
|
||||||
|
camera.Offset.X = width - (max.X - width / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max.Y < height)
|
||||||
|
{
|
||||||
|
camera.Offset.Y = height - (max.Y - height / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (min.X > 0)
|
||||||
|
{
|
||||||
|
camera.Offset.X = width / 2 - min.X;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (min.Y > 0)
|
||||||
|
{
|
||||||
|
camera.Offset.Y = height / 2 - min.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateCameraCenterSmoothFollow(
|
||||||
|
ref Camera2D camera,
|
||||||
|
ref Player player,
|
||||||
|
EnvItem[] envItems,
|
||||||
|
float delta,
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const float minSpeed = 30;
|
||||||
|
const float minEffectLength = 10;
|
||||||
|
const float fractionSpeed = 0.8f;
|
||||||
|
|
||||||
|
camera.Offset = new Vector2(width / 2, height / 2);
|
||||||
|
Vector2 diff = Vector2Subtract(player.Position, camera.Target);
|
||||||
|
float length = Vector2Length(diff);
|
||||||
|
|
||||||
|
if (length > minEffectLength)
|
||||||
|
{
|
||||||
|
float speed = Math.Max(fractionSpeed * length, minSpeed);
|
||||||
|
camera.Target = Vector2Add(camera.Target, Vector2Scale(diff, speed * delta / length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateCameraEvenOutOnLanding(
|
||||||
|
ref Camera2D camera,
|
||||||
|
ref Player player,
|
||||||
|
EnvItem[] envItems,
|
||||||
|
float delta,
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
)
|
||||||
|
{
|
||||||
|
float evenOutSpeed = 700;
|
||||||
|
int eveningOut = 0;
|
||||||
|
float evenOutTarget = 0.0f;
|
||||||
|
|
||||||
|
camera.Offset = new Vector2(width / 2, height / 2);
|
||||||
|
camera.Target.X = player.Position.X;
|
||||||
|
|
||||||
|
if (eveningOut != 0)
|
||||||
|
{
|
||||||
|
if (evenOutTarget > camera.Target.Y)
|
||||||
|
{
|
||||||
|
camera.Target.Y += evenOutSpeed * delta;
|
||||||
|
|
||||||
|
if (camera.Target.Y > evenOutTarget)
|
||||||
|
{
|
||||||
|
camera.Target.Y = evenOutTarget;
|
||||||
|
eveningOut = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
camera.Target.Y -= evenOutSpeed * delta;
|
||||||
|
|
||||||
|
if (camera.Target.Y < evenOutTarget)
|
||||||
|
{
|
||||||
|
camera.Target.Y = evenOutTarget;
|
||||||
|
eveningOut = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (player.CanJump && (player.Speed == 0) && (player.Position.Y != camera.Target.Y))
|
||||||
|
{
|
||||||
|
eveningOut = 1;
|
||||||
|
evenOutTarget = player.Position.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateCameraPlayerBoundsPush(
|
||||||
|
ref Camera2D camera,
|
||||||
|
ref Player player,
|
||||||
|
EnvItem[] envItems,
|
||||||
|
float delta,
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Vector2 bbox = new(0.2f, 0.2f);
|
||||||
|
|
||||||
|
Vector2 bboxWorldMin = GetScreenToWorld2D(
|
||||||
|
new Vector2((1 - bbox.X) * 0.5f * width, (1 - bbox.Y) * 0.5f * height),
|
||||||
|
camera
|
||||||
|
);
|
||||||
|
Vector2 bboxWorldMax = GetScreenToWorld2D(
|
||||||
|
new Vector2((1 + bbox.X) * 0.5f * width,
|
||||||
|
(1 + bbox.Y) * 0.5f * height),
|
||||||
|
camera
|
||||||
|
);
|
||||||
|
camera.Offset = new Vector2((1 - bbox.X) * 0.5f * width, (1 - bbox.Y) * 0.5f * height);
|
||||||
|
|
||||||
|
if (player.Position.X < bboxWorldMin.X)
|
||||||
|
{
|
||||||
|
camera.Target.X = player.Position.X;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.Position.Y < bboxWorldMin.Y)
|
||||||
|
{
|
||||||
|
camera.Target.Y = player.Position.Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.Position.X > bboxWorldMax.X)
|
||||||
|
{
|
||||||
|
camera.Target.X = bboxWorldMin.X + (player.Position.X - bboxWorldMax.X);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.Position.Y > bboxWorldMax.Y)
|
||||||
|
{
|
||||||
|
camera.Target.Y = bboxWorldMin.Y + (player.Position.Y - bboxWorldMax.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
186
Examples/Core/Camera3dFirstPerson.cs
Normal file
186
Examples/Core/Camera3dFirstPerson.cs
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - 3d camera first person
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class Camera3dFirstPerson
|
||||||
|
{
|
||||||
|
public const int MaxColumns = 20;
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world (position, target, up vector)
|
||||||
|
Camera3D camera = new();
|
||||||
|
camera.Position = new Vector3(4.0f, 2.0f, 4.0f);
|
||||||
|
camera.Target = new Vector3(0.0f, 1.8f, 0.0f);
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
camera.FovY = 60.0f;
|
||||||
|
camera.Projection = CameraProjection.CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
|
// Generates some random columns
|
||||||
|
float[] heights = new float[MaxColumns];
|
||||||
|
Vector3[] positions = new Vector3[MaxColumns];
|
||||||
|
Color[] colors = new Color[MaxColumns];
|
||||||
|
|
||||||
|
for (int i = 0; i < MaxColumns; i++)
|
||||||
|
{
|
||||||
|
heights[i] = (float)GetRandomValue(1, 12);
|
||||||
|
positions[i] = new Vector3(GetRandomValue(-15, 15), heights[i] / 2, GetRandomValue(-15, 15));
|
||||||
|
colors[i] = new Color(GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraMode cameraMode = CameraMode.CAMERA_FIRST_PERSON;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Switch camera mode
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_ONE))
|
||||||
|
{
|
||||||
|
cameraMode = CameraMode.CAMERA_FREE;
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_TWO))
|
||||||
|
{
|
||||||
|
cameraMode = CameraMode.CAMERA_FIRST_PERSON;
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_THREE))
|
||||||
|
{
|
||||||
|
cameraMode = CameraMode.CAMERA_THIRD_PERSON;
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_FOUR))
|
||||||
|
{
|
||||||
|
cameraMode = CameraMode.CAMERA_ORBITAL;
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch camera projection
|
||||||
|
if (IsKeyPressed(KeyboardKey.KEY_P))
|
||||||
|
{
|
||||||
|
if (camera.Projection == CameraProjection.CAMERA_PERSPECTIVE)
|
||||||
|
{
|
||||||
|
// Create isometric view
|
||||||
|
cameraMode = CameraMode.CAMERA_THIRD_PERSON;
|
||||||
|
// Note: The target distance is related to the render distance in the orthographic projection
|
||||||
|
camera.Position = new Vector3(0.0f, 2.0f, -100.0f);
|
||||||
|
camera.Target = new Vector3(0.0f, 2.0f, 0.0f);
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
camera.Projection = CameraProjection.CAMERA_ORTHOGRAPHIC;
|
||||||
|
camera.FovY = 20.0f; // near plane width in CAMERA_ORTHOGRAPHIC
|
||||||
|
// CameraYaw(&camera, -135 * DEG2RAD, true);
|
||||||
|
// CameraPitch(&camera, -45 * DEG2RAD, true, true, false);
|
||||||
|
}
|
||||||
|
else if (camera.Projection == CameraProjection.CAMERA_ORTHOGRAPHIC)
|
||||||
|
{
|
||||||
|
// Reset to default view
|
||||||
|
cameraMode = CameraMode.CAMERA_THIRD_PERSON;
|
||||||
|
camera.Position = new Vector3(0.0f, 2.0f, 10.0f);
|
||||||
|
camera.Target = new Vector3(0.0f, 2.0f, 0.0f);
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
camera.Projection = CameraProjection.CAMERA_PERSPECTIVE;
|
||||||
|
camera.FovY = 60.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update camera computes movement internally depending on the camera mode
|
||||||
|
// Some default standard keyboard/mouse inputs are hardcoded to simplify use
|
||||||
|
// For advance camera controls, it's reecommended to compute camera movement manually
|
||||||
|
UpdateCamera(ref camera, CameraMode.CAMERA_CUSTOM);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
// Draw ground
|
||||||
|
DrawPlane(new Vector3(0.0f, 0.0f, 0.0f), new Vector2(32.0f, 32.0f), Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
// Draw a blue wall
|
||||||
|
DrawCube(new Vector3(-16.0f, 2.5f, 0.0f), 1.0f, 5.0f, 32.0f, Color.BLUE);
|
||||||
|
|
||||||
|
// Draw a green wall
|
||||||
|
DrawCube(new Vector3(16.0f, 2.5f, 0.0f), 1.0f, 5.0f, 32.0f, Color.LIME);
|
||||||
|
|
||||||
|
// Draw a yellow wall
|
||||||
|
DrawCube(new Vector3(0.0f, 2.5f, 16.0f), 32.0f, 5.0f, 1.0f, Color.GOLD);
|
||||||
|
|
||||||
|
// Draw some cubes around
|
||||||
|
for (int i = 0; i < MaxColumns; i++)
|
||||||
|
{
|
||||||
|
DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]);
|
||||||
|
DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, Color.MAROON);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw player cube
|
||||||
|
if (cameraMode == CameraMode.CAMERA_THIRD_PERSON)
|
||||||
|
{
|
||||||
|
DrawCube(camera.Target, 0.5f, 0.5f, 0.5f, Color.PURPLE);
|
||||||
|
DrawCubeWires(camera.Target, 0.5f, 0.5f, 0.5f, Color.DARKPURPLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
// Draw info boxes
|
||||||
|
DrawRectangle(5, 5, 330, 100, ColorAlpha(Color.SKYBLUE, 0.5f));
|
||||||
|
DrawRectangleLines(10, 10, 330, 100, Color.BLUE);
|
||||||
|
|
||||||
|
DrawText("Camera controls:", 15, 15, 10, Color.BLACK);
|
||||||
|
DrawText("- Move keys: W, A, S, D, Space, Left-Ctrl", 15, 30, 10, Color.BLACK);
|
||||||
|
DrawText("- Look around: arrow keys or mouse", 15, 45, 10, Color.BLACK);
|
||||||
|
DrawText("- Camera mode keys: 1, 2, 3, 4", 15, 60, 10, Color.BLACK);
|
||||||
|
DrawText("- Zoom keys: num-plus, num-minus or mouse scroll", 15, 75, 10, Color.BLACK);
|
||||||
|
DrawText("- Camera projection key: P", 15, 90, 10, Color.BLACK);
|
||||||
|
|
||||||
|
DrawRectangle(600, 5, 195, 100, Fade(Color.SKYBLUE, 0.5f));
|
||||||
|
DrawRectangleLines(600, 5, 195, 100, Color.BLUE);
|
||||||
|
|
||||||
|
DrawText("Camera status:", 610, 15, 10, Color.BLACK);
|
||||||
|
DrawText($"- Mode: {cameraMode}", 610, 30, 10, Color.BLACK);
|
||||||
|
DrawText($"- Projection: {camera.Projection}", 610, 45, 10, Color.BLACK);
|
||||||
|
DrawText($"- Position: {camera.Position}", 610, 60, 10, Color.BLACK);
|
||||||
|
DrawText($"- Target: {camera.Target}", 610, 75, 10, Color.BLACK);
|
||||||
|
DrawText($"- Up: {camera.Up}", 610, 90, 10, Color.BLACK);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
89
Examples/Core/Camera3dFree.cs
Normal file
89
Examples/Core/Camera3dFree.cs
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Initialize 3d camera free
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class Camera3dFree
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
Camera3D camera;
|
||||||
|
camera.Position = new Vector3(10.0f, 10.0f, 10.0f);
|
||||||
|
camera.Target = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
camera.FovY = 45.0f;
|
||||||
|
camera.Projection = CameraProjection.CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
|
Vector3 cubePosition = new(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(ref camera, CameraMode.CAMERA_FREE);
|
||||||
|
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_Z))
|
||||||
|
{
|
||||||
|
camera.Target = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, Color.RED);
|
||||||
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, Color.MAROON);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
DrawRectangle(10, 10, 320, 133, ColorAlpha(Color.SKYBLUE, 0.5f));
|
||||||
|
DrawRectangleLines(10, 10, 320, 133, Color.BLUE);
|
||||||
|
|
||||||
|
DrawText("Free camera default controls:", 20, 20, 10, Color.BLACK);
|
||||||
|
DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, Color.DARKGRAY);
|
||||||
|
DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, Color.DARKGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
78
Examples/Core/Camera3dMode.cs
Normal file
78
Examples/Core/Camera3dMode.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Initialize 3d camera mode
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class Camera3dMode
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera mode");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
Camera3D camera = new();
|
||||||
|
camera.Position = new Vector3(0.0f, 10.0f, 10.0f);
|
||||||
|
camera.Target = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
|
camera.Up = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
|
camera.FovY = 45.0f;
|
||||||
|
camera.Projection = CameraProjection.CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
|
Vector3 cubePosition = new(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// TODO: Update your variables here
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, Color.RED);
|
||||||
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, Color.MAROON);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
DrawText("Welcome to the third dimension!", 10, 40, 20, Color.DARKGRAY);
|
||||||
|
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
87
Examples/Core/Customlogging.cs
Normal file
87
Examples/Core/Customlogging.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Custom logging
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 2.1 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Example contributed by Pablo Marcos Oltra (@pamarcos) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Pablo Marcos Oltra (@pamarcos) and Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public unsafe class CustomLogging
|
||||||
|
{
|
||||||
|
[UnmanagedCallersOnly(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||||
|
private static void LogCustom(int logLevel, sbyte* text, sbyte* args)
|
||||||
|
{
|
||||||
|
var message = Logging.GetLogMessage(new IntPtr(text), new IntPtr(args));
|
||||||
|
|
||||||
|
/*Console.ForegroundColor = (TraceLogLevel)logLevel switch
|
||||||
|
{
|
||||||
|
TraceLogLevel.LOG_ALL => ConsoleColor.White,
|
||||||
|
TraceLogLevel.LOG_TRACE => ConsoleColor.Black,
|
||||||
|
TraceLogLevel.LOG_DEBUG => ConsoleColor.Blue,
|
||||||
|
TraceLogLevel.LOG_INFO => ConsoleColor.Black,
|
||||||
|
TraceLogLevel.LOG_WARNING => ConsoleColor.DarkYellow,
|
||||||
|
TraceLogLevel.LOG_ERROR => ConsoleColor.Red,
|
||||||
|
TraceLogLevel.LOG_FATAL => ConsoleColor.Red,
|
||||||
|
TraceLogLevel.LOG_NONE => ConsoleColor.White,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null)
|
||||||
|
};*/
|
||||||
|
|
||||||
|
Console.WriteLine($"Custom " + message);
|
||||||
|
// Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
// First thing we do is setting our custom logger to ensure everything raylib logs
|
||||||
|
// will use our own logger instead of its internal one
|
||||||
|
Raylib.SetTraceLogCallback(&LogCustom);
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - custom logging");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// TODO: Update your variables here
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("Check out the console output to see the custom logger in action!", 60, 200, 20, Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
Raylib.SetTraceLogCallback(&Logging.LogConsole);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
85
Examples/Core/DropFiles.cs
Normal file
85
Examples/Core/DropFiles.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Windows drop files
|
||||||
|
*
|
||||||
|
* This example only works on platforms that support drag ref drop (Windows, Linux, OSX, Html5?)
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class DropFiles
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files");
|
||||||
|
|
||||||
|
string[] files = new string[0];
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsFileDropped())
|
||||||
|
{
|
||||||
|
files = Raylib.GetDroppedFiles();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
if (files.Length == 0)
|
||||||
|
{
|
||||||
|
DrawText("Drop your files to this window!", 100, 40, 20, Color.DARKGRAY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText("Dropped files:", 100, 40, 20, Color.DARKGRAY);
|
||||||
|
|
||||||
|
for (int i = 0; i < files.Length; i++)
|
||||||
|
{
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 85 + 40 * i, screenWidth, 40, ColorAlpha(Color.LIGHTGRAY, 0.5f));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 85 + 40 * i, screenWidth, 40, ColorAlpha(Color.LIGHTGRAY, 0.3f));
|
||||||
|
}
|
||||||
|
DrawText(files[i], 120, 100 + 40 * i, 10, Color.GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText("Drop new files...", 100, 110 + 40 * files.Length, 20, Color.DARKGRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
324
Examples/Core/InputGamepad.cs
Normal file
324
Examples/Core/InputGamepad.cs
Normal file
|
|
@ -0,0 +1,324 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Gamepad input
|
||||||
|
*
|
||||||
|
* NOTE: This example requires a Gamepad connected to the system
|
||||||
|
* raylib is configured to work with the following gamepads:
|
||||||
|
* - Xbox 360 Controller (Xbox 360, Xbox One)
|
||||||
|
* - PLAYSTATION(R)3 Controller
|
||||||
|
* Check raylib.h for buttons configuration
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.6 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class InputGamepad
|
||||||
|
{
|
||||||
|
// NOTE: Gamepad name ID depends on drivers and OS
|
||||||
|
// public const string XBOX360_NAME_ID = "Microsoft;
|
||||||
|
// public const string PS3_NAME_ID = "PLAYSTATION(R)3;
|
||||||
|
public const string XBOX360_NAME_ID = "Xbox";
|
||||||
|
public const string PS3_NAME_ID = "PLAYSTATION(R)3";
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
// Set MSAA 4X hint before windows creation
|
||||||
|
SetConfigFlags(ConfigFlags.FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
||||||
|
|
||||||
|
Texture2D texPs3Pad = LoadTexture("resources/ps3.png");
|
||||||
|
Texture2D texXboxPad = LoadTexture("resources/xbox.png");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// ...
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
if (IsGamepadAvailable(0))
|
||||||
|
{
|
||||||
|
string gamepadName = GetGamepadName_(0);
|
||||||
|
DrawText($"GP1: {gamepadName}", 10, 10, 10, Color.BLACK);
|
||||||
|
|
||||||
|
if (gamepadName == XBOX360_NAME_ID)
|
||||||
|
{
|
||||||
|
DrawTexture(texXboxPad, 0, 0, Color.DARKGRAY);
|
||||||
|
|
||||||
|
// Draw buttons: xbox home
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE))
|
||||||
|
{
|
||||||
|
DrawCircle(394, 89, 19, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_RIGHT))
|
||||||
|
{
|
||||||
|
DrawCircle(436, 150, 9, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_LEFT))
|
||||||
|
{
|
||||||
|
DrawCircle(352, 150, 9, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||||
|
{
|
||||||
|
DrawCircle(501, 151, 15, Color.BLUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
|
||||||
|
{
|
||||||
|
DrawCircle(536, 187, 15, Color.LIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||||
|
{
|
||||||
|
DrawCircle(572, 151, 15, Color.MAROON);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_UP))
|
||||||
|
{
|
||||||
|
DrawCircle(536, 115, 15, Color.GOLD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw buttons: d-pad
|
||||||
|
DrawRectangle(317, 202, 19, 71, Color.BLACK);
|
||||||
|
DrawRectangle(293, 228, 69, 19, Color.BLACK);
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_UP))
|
||||||
|
{
|
||||||
|
DrawRectangle(317, 202, 19, 26, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_DOWN))
|
||||||
|
{
|
||||||
|
DrawRectangle(317, 202 + 45, 19, 26, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_LEFT))
|
||||||
|
{
|
||||||
|
DrawRectangle(292, 228, 25, 19, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_RIGHT))
|
||||||
|
{
|
||||||
|
DrawRectangle(292 + 44, 228, 26, 19, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw buttons: left-right back
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_TRIGGER_1))
|
||||||
|
{
|
||||||
|
DrawCircle(259, 61, 20, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_TRIGGER_1))
|
||||||
|
{
|
||||||
|
DrawCircle(536, 61, 20, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw axis: left joystick
|
||||||
|
DrawCircle(259, 152, 39, Color.BLACK);
|
||||||
|
DrawCircle(259, 152, 34, Color.LIGHTGRAY);
|
||||||
|
DrawCircle(
|
||||||
|
259 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||||
|
152 - (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||||
|
25,
|
||||||
|
Color.BLACK
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw axis: right joystick
|
||||||
|
DrawCircle(461, 237, 38, Color.BLACK);
|
||||||
|
DrawCircle(461, 237, 33, Color.LIGHTGRAY);
|
||||||
|
DrawCircle(
|
||||||
|
461 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||||
|
237 - (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||||
|
25, Color.BLACK
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw axis: left-right triggers
|
||||||
|
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_TRIGGER);
|
||||||
|
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||||
|
DrawRectangle(170, 30, 15, 70, Color.GRAY);
|
||||||
|
DrawRectangle(604, 30, 15, 70, Color.GRAY);
|
||||||
|
DrawRectangle(170, 30, 15, (int)(((1.0f + leftTriggerX) / 2.0f) * 70), Color.RED);
|
||||||
|
DrawRectangle(604, 30, 15, (int)(((1.0f + rightTriggerX) / 2.0f) * 70), Color.RED);
|
||||||
|
}
|
||||||
|
else if (gamepadName == PS3_NAME_ID)
|
||||||
|
{
|
||||||
|
DrawTexture(texPs3Pad, 0, 0, Color.DARKGRAY);
|
||||||
|
|
||||||
|
// Draw buttons: ps
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE))
|
||||||
|
{
|
||||||
|
DrawCircle(396, 222, 13, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw buttons: basic
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_LEFT))
|
||||||
|
{
|
||||||
|
DrawRectangle(328, 170, 32, 13, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_MIDDLE_RIGHT))
|
||||||
|
{
|
||||||
|
DrawTriangle(
|
||||||
|
new Vector2(436, 168),
|
||||||
|
new Vector2(436, 185),
|
||||||
|
new Vector2(464, 177),
|
||||||
|
Color.RED
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_UP))
|
||||||
|
{
|
||||||
|
DrawCircle(557, 144, 13, Color.LIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
|
||||||
|
{
|
||||||
|
DrawCircle(586, 173, 13, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
|
||||||
|
{
|
||||||
|
DrawCircle(557, 203, 13, Color.VIOLET);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_FACE_LEFT))
|
||||||
|
{
|
||||||
|
DrawCircle(527, 173, 13, Color.PINK);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw buttons: d-pad
|
||||||
|
DrawRectangle(225, 132, 24, 84, Color.BLACK);
|
||||||
|
DrawRectangle(195, 161, 84, 25, Color.BLACK);
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_UP))
|
||||||
|
{
|
||||||
|
DrawRectangle(225, 132, 24, 29, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_DOWN))
|
||||||
|
{
|
||||||
|
DrawRectangle(225, 132 + 54, 24, 30, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_LEFT))
|
||||||
|
{
|
||||||
|
DrawRectangle(195, 161, 30, 25, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_FACE_RIGHT))
|
||||||
|
{
|
||||||
|
DrawRectangle(195 + 54, 161, 30, 25, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw buttons: left-right back buttons
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_LEFT_TRIGGER_1))
|
||||||
|
{
|
||||||
|
DrawCircle(239, 82, 20, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsGamepadButtonDown(0, GamepadButton.GAMEPAD_BUTTON_RIGHT_TRIGGER_1))
|
||||||
|
{
|
||||||
|
DrawCircle(557, 82, 20, Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw axis: left joystick
|
||||||
|
DrawCircle(319, 255, 35, Color.BLACK);
|
||||||
|
DrawCircle(319, 255, 31, Color.LIGHTGRAY);
|
||||||
|
DrawCircle(
|
||||||
|
319 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_X) * 20),
|
||||||
|
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_Y) * 20),
|
||||||
|
25,
|
||||||
|
Color.BLACK
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw axis: right joystick
|
||||||
|
DrawCircle(475, 255, 35, Color.BLACK);
|
||||||
|
DrawCircle(475, 255, 31, Color.LIGHTGRAY);
|
||||||
|
DrawCircle(
|
||||||
|
475 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_X) * 20),
|
||||||
|
255 + (int)(GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_Y) * 20),
|
||||||
|
25,
|
||||||
|
Color.BLACK
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw axis: left-right triggers
|
||||||
|
float leftTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_LEFT_TRIGGER);
|
||||||
|
float rightTriggerX = GetGamepadAxisMovement(0, GamepadAxis.GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||||
|
DrawRectangle(169, 48, 15, 70, Color.GRAY);
|
||||||
|
DrawRectangle(611, 48, 15, 70, Color.GRAY);
|
||||||
|
DrawRectangle(169, 48, 15, (int)(((1.0f - leftTriggerX) / 2.0f) * 70), Color.RED);
|
||||||
|
DrawRectangle(611, 48, 15, (int)(((1.0f - rightTriggerX) / 2.0f) * 70), Color.RED);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText("- GENERIC GAMEPAD -", 280, 180, 20, Color.GRAY);
|
||||||
|
// TODO: Draw generic gamepad
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText($"DETECTED AXIS [{GetGamepadAxisCount(0)}]:", 10, 50, 10, Color.MAROON);
|
||||||
|
|
||||||
|
for (int i = 0; i < GetGamepadAxisCount(0); i++)
|
||||||
|
{
|
||||||
|
DrawText(
|
||||||
|
$"AXIS {i}: {GetGamepadAxisMovement(0, (GamepadAxis)i)}",
|
||||||
|
20,
|
||||||
|
70 + 20 * i,
|
||||||
|
10,
|
||||||
|
Color.DARKGRAY
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetGamepadButtonPressed() != (int)GamepadButton.GAMEPAD_BUTTON_UNKNOWN)
|
||||||
|
{
|
||||||
|
DrawText($"DETECTED BUTTON: {GetGamepadButtonPressed()}", 10, 430, 10, Color.RED);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText("DETECTED BUTTON: NONE", 10, 430, 10, Color.GRAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText("GP1: NOT DETECTED", 10, 10, 10, Color.GRAY);
|
||||||
|
DrawTexture(texXboxPad, 0, 0, Color.LIGHTGRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(texPs3Pad);
|
||||||
|
UnloadTexture(texXboxPad);
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
158
Examples/Core/InputGestures.cs
Normal file
158
Examples/Core/InputGestures.cs
Normal file
|
|
@ -0,0 +1,158 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Gestures Detection
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.4 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class InputGestures
|
||||||
|
{
|
||||||
|
public const int MaxGestureStrings = 20;
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection");
|
||||||
|
|
||||||
|
Vector2 touchPosition = new(0, 0);
|
||||||
|
Rectangle touchArea = new(220, 10, screenWidth - 230, screenHeight - 20);
|
||||||
|
|
||||||
|
int gesturesCount = 0;
|
||||||
|
string[] gestureStrings = new string[MaxGestureStrings];
|
||||||
|
|
||||||
|
Gesture currentGesture = Gesture.GESTURE_NONE;
|
||||||
|
Gesture lastGesture = Gesture.GESTURE_NONE;
|
||||||
|
|
||||||
|
// SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
lastGesture = currentGesture;
|
||||||
|
currentGesture = GetGestureDetected();
|
||||||
|
touchPosition = GetTouchPosition(0);
|
||||||
|
|
||||||
|
if (CheckCollisionPointRec(touchPosition, touchArea) && (currentGesture != Gesture.GESTURE_NONE))
|
||||||
|
{
|
||||||
|
if (currentGesture != lastGesture)
|
||||||
|
{
|
||||||
|
// Store gesture string
|
||||||
|
switch ((Gesture)currentGesture)
|
||||||
|
{
|
||||||
|
case Gesture.GESTURE_TAP:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE TAP";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_DOUBLETAP:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE DOUBLETAP";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_HOLD:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE HOLD";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_DRAG:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE DRAG";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_SWIPE_RIGHT:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE SWIPE RIGHT";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_SWIPE_LEFT:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE SWIPE LEFT";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_SWIPE_UP:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE SWIPE UP";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_SWIPE_DOWN:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE SWIPE DOWN";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_PINCH_IN:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE PINCH IN";
|
||||||
|
break;
|
||||||
|
case Gesture.GESTURE_PINCH_OUT:
|
||||||
|
gestureStrings[gesturesCount] = "GESTURE PINCH OUT";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
gesturesCount++;
|
||||||
|
|
||||||
|
// Reset gestures strings
|
||||||
|
if (gesturesCount >= MaxGestureStrings)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < MaxGestureStrings; i++)
|
||||||
|
{
|
||||||
|
gestureStrings[i] = " ";
|
||||||
|
}
|
||||||
|
gesturesCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawRectangleRec(touchArea, Color.GRAY);
|
||||||
|
DrawRectangle(225, 15, screenWidth - 240, screenHeight - 30, Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("GESTURES TEST AREA", screenWidth - 270, screenHeight - 40, 20, ColorAlpha(Color.GRAY, 0.5f));
|
||||||
|
|
||||||
|
for (int i = 0; i < gesturesCount; i++)
|
||||||
|
{
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
DrawRectangle(10, 30 + 20 * i, 200, 20, ColorAlpha(Color.LIGHTGRAY, 0.5f));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawRectangle(10, 30 + 20 * i, 200, 20, ColorAlpha(Color.LIGHTGRAY, 0.3f));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < gesturesCount - 1)
|
||||||
|
{
|
||||||
|
DrawText(gestureStrings[i], 35, 36 + 20 * i, 10, Color.DARKGRAY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText(gestureStrings[i], 35, 36 + 20 * i, 10, Color.MAROON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangleLines(10, 29, 200, screenHeight - 50, Color.GRAY);
|
||||||
|
DrawText("DETECTED GESTURES", 50, 15, 10, Color.GRAY);
|
||||||
|
|
||||||
|
if (currentGesture != Gesture.GESTURE_NONE)
|
||||||
|
{
|
||||||
|
DrawCircleV(touchPosition, 30, Color.MAROON);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
79
Examples/Core/InputKeys.cs
Normal file
79
Examples/Core/InputKeys.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Keyboard input
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class InputKeys
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
|
||||||
|
|
||||||
|
Vector2 ballPosition = new((float)screenWidth / 2, (float)screenHeight / 2);
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set target frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_RIGHT))
|
||||||
|
{
|
||||||
|
ballPosition.X += 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_LEFT))
|
||||||
|
{
|
||||||
|
ballPosition.X -= 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_UP))
|
||||||
|
{
|
||||||
|
ballPosition.Y -= 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyDown(KeyboardKey.KEY_DOWN))
|
||||||
|
{
|
||||||
|
ballPosition.Y += 2.0f;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("move the ball with arrow keys", 10, 10, 20, Color.DARKGRAY);
|
||||||
|
|
||||||
|
DrawCircleV(ballPosition, 50, Color.MAROON);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
75
Examples/Core/InputMouse.cs
Normal file
75
Examples/Core/InputMouse.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Mouse input
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class InputMouse
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
|
||||||
|
|
||||||
|
Vector2 ballPosition = new(-100.0f, -100.0f);
|
||||||
|
Color ballColor = Color.DARKBLUE;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
ballPosition = GetMousePosition();
|
||||||
|
|
||||||
|
if (IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON))
|
||||||
|
{
|
||||||
|
ballColor = Color.MAROON;
|
||||||
|
}
|
||||||
|
else if (IsMouseButtonPressed(MouseButton.MOUSE_MIDDLE_BUTTON))
|
||||||
|
{
|
||||||
|
ballColor = Color.LIME;
|
||||||
|
}
|
||||||
|
else if (IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON))
|
||||||
|
{
|
||||||
|
ballColor = Color.DARKBLUE;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawCircleV(ballPosition, 40, ballColor);
|
||||||
|
|
||||||
|
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, Color.DARKGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
64
Examples/Core/InputMouseWheel.cs
Normal file
64
Examples/Core/InputMouseWheel.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] examples - Mouse wheel input
|
||||||
|
*
|
||||||
|
* This test has been created using raylib 1.1 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class InputMouseWheel
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");
|
||||||
|
|
||||||
|
int boxPositionY = screenHeight / 2 - 40;
|
||||||
|
|
||||||
|
// Scrolling speed in pixels
|
||||||
|
int scrollSpeed = 4;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
boxPositionY -= (int)(GetMouseWheelMove() * scrollSpeed);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
DrawRectangle(screenWidth / 2 - 40, boxPositionY, 80, 80, Color.MAROON);
|
||||||
|
|
||||||
|
DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, Color.GRAY);
|
||||||
|
DrawText($"Box position Y: {boxPositionY}", 10, 40, 20, Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
91
Examples/Core/InputMultitouch.cs
Normal file
91
Examples/Core/InputMultitouch.cs
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Input multitouch
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 2.1 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
public class InputMultitouch
|
||||||
|
{
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - input multitouch");
|
||||||
|
|
||||||
|
const int MaxTouchPoints = 10;
|
||||||
|
Vector2[] touchPositions = new Vector2[MaxTouchPoints];
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Get the touch point count (h ow many fingers are touching the screen )
|
||||||
|
int tCount = GetTouchPointCount();
|
||||||
|
|
||||||
|
// Clamp touch points available (set the maximum touch points allowed )
|
||||||
|
if (tCount > MaxTouchPoints)
|
||||||
|
{
|
||||||
|
tCount = MaxTouchPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get touch points positions
|
||||||
|
for (int i = 0; i < tCount; i++)
|
||||||
|
{
|
||||||
|
touchPositions[i] = GetTouchPosition(i);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Color.RAYWHITE);
|
||||||
|
|
||||||
|
for (int i = 0; i < tCount; i++)
|
||||||
|
{
|
||||||
|
// Make sure point is not (0, 0) as this means there is no touch for it
|
||||||
|
if ((touchPositions[i].X > 0) && (touchPositions[i].Y > 0))
|
||||||
|
{
|
||||||
|
// Draw circle and touch index number
|
||||||
|
DrawCircleV(touchPositions[i], 34, Color.ORANGE);
|
||||||
|
DrawText(i.ToString(),
|
||||||
|
(int)touchPositions[i].X - 10,
|
||||||
|
(int)touchPositions[i].Y - 70,
|
||||||
|
40,
|
||||||
|
Color.BLACK
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText("touch the screen at multiple locations to get multiple balls", 10, 10, 20, Color.DARKGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
161
Examples/Core/LoadingThread.cs
Normal file
161
Examples/Core/LoadingThread.cs
Normal file
|
|
@ -0,0 +1,161 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib example - loading thread
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 2.5 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
using System.Threading;
|
||||||
|
using static Raylib_cs.Raylib;
|
||||||
|
using static Raylib_cs.Color;
|
||||||
|
using static Raylib_cs.KeyboardKey;
|
||||||
|
|
||||||
|
namespace Examples.Core;
|
||||||
|
|
||||||
|
enum State
|
||||||
|
{
|
||||||
|
STATE_WAITING,
|
||||||
|
STATE_LOADING,
|
||||||
|
STATE_FINISHED
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LoadingThread
|
||||||
|
{
|
||||||
|
// C# bool is atomic. Used for synchronization
|
||||||
|
// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/variables#atomicity-of-variable-references
|
||||||
|
// Data Loaded completion indicator
|
||||||
|
static bool dataLoaded = false;
|
||||||
|
|
||||||
|
// Data progress accumulator
|
||||||
|
static int dataProgress = 0;
|
||||||
|
|
||||||
|
public static int Main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - loading thread");
|
||||||
|
|
||||||
|
// Loading data thread id
|
||||||
|
Thread thread = new(new ThreadStart(LoadDataThread));
|
||||||
|
|
||||||
|
State state = State.STATE_WAITING;
|
||||||
|
int framesCounter = 0;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case State.STATE_WAITING:
|
||||||
|
{
|
||||||
|
if (IsKeyPressed(KEY_ENTER))
|
||||||
|
{
|
||||||
|
thread.Start();
|
||||||
|
//int error = pthread_create(ref, NULL, ref, NULL);
|
||||||
|
//if (error != 0) TraceLog(TraceLogLevel.LOG_ERROR, "Error creating loading thread");
|
||||||
|
//else TraceLog(TraceLogLevel.LOG_INFO, "Loading thread initialized successfully");
|
||||||
|
|
||||||
|
state = State.STATE_LOADING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case State.STATE_LOADING:
|
||||||
|
{
|
||||||
|
framesCounter++;
|
||||||
|
if (dataLoaded)
|
||||||
|
{
|
||||||
|
framesCounter = 0;
|
||||||
|
state = State.STATE_FINISHED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case State.STATE_FINISHED:
|
||||||
|
{
|
||||||
|
if (IsKeyPressed(KEY_ENTER))
|
||||||
|
{
|
||||||
|
// Reset everything to launch again
|
||||||
|
// atomic_store(ref, false);
|
||||||
|
dataProgress = 0;
|
||||||
|
state = State.STATE_WAITING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case State.STATE_WAITING:
|
||||||
|
DrawText("PRESS ENTER to START LOADING DATA", 150, 170, 20, DARKGRAY);
|
||||||
|
break;
|
||||||
|
case State.STATE_LOADING:
|
||||||
|
{
|
||||||
|
DrawRectangle(150, 200, dataProgress, 60, SKYBLUE);
|
||||||
|
if ((framesCounter / 15) % 2 == 0) DrawText("LOADING DATA...", 240, 210, 40, DARKBLUE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case State.STATE_FINISHED:
|
||||||
|
{
|
||||||
|
DrawRectangle(150, 200, 500, 60, LIME);
|
||||||
|
DrawText("DATA LOADED!", 250, 210, 40, GREEN);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangleLines(150, 200, 500, 60, DARKGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loading data thread function definition
|
||||||
|
static void LoadDataThread()
|
||||||
|
{
|
||||||
|
int timeCounter = 0; // Time counted in ms
|
||||||
|
// clock_t prevTime = clock(); // Previous time
|
||||||
|
|
||||||
|
// We simulate data loading with a time counter for 5 seconds
|
||||||
|
while (timeCounter < 5000)
|
||||||
|
{
|
||||||
|
//clock_t currentTime = clock() - prevTime;
|
||||||
|
//timeCounter = currentTime*1000/CLOCKS_PER_SEC;
|
||||||
|
timeCounter += 1;
|
||||||
|
|
||||||
|
// We accumulate time over a global variable to be used in
|
||||||
|
// main thread as a progress bar
|
||||||
|
dataProgress = timeCounter / 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When data has finished loading, we set global variable
|
||||||
|
dataLoaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue