first commit
This commit is contained in:
commit
b07cee75ce
13 changed files with 12839 additions and 0 deletions
22
Makefile
Normal file
22
Makefile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
CC = gcc
|
||||
RAYLIB_PATH = /home/benag/Projects/C/raylib
|
||||
|
||||
CFLAGS = -Wall -O2 -I$(RAYLIB_PATH)/include
|
||||
LDFLAGS = -L$(RAYLIB_PATH)/lib -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 \
|
||||
-Wl,-rpath=$(RAYLIB_PATH)/lib
|
||||
|
||||
SRC = main.c
|
||||
TARGET = MyGame
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SRC)
|
||||
$(CC) $(CFLAGS) $(SRC) $(LDFLAGS) -o $(TARGET)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
|
||||
# Temporary LD_LIBRARY_PATH for one-off runs
|
||||
run: $(TARGET)
|
||||
LD_LIBRARY_PATH=$(RAYLIB_PATH)/lib:$$LD_LIBRARY_PATH ./$(TARGET)
|
||||
|
||||
BIN
MyGame
Executable file
BIN
MyGame
Executable file
Binary file not shown.
139
main.c
Normal file
139
main.c
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#include <stdlib.h>
|
||||
#include "raylib.h"
|
||||
|
||||
const float gravity = 0.25;
|
||||
const int bird_pos_x = 400;
|
||||
const float bird_radius = 10.0;
|
||||
const int pipe_vel = 3;
|
||||
const int pipe_width = 50;
|
||||
const int pipe_gap = 50;
|
||||
const int pipe_height = 900;
|
||||
|
||||
struct Birdie {
|
||||
float velocityY;
|
||||
int positionY;
|
||||
};
|
||||
|
||||
struct Pipe {
|
||||
int positionX;
|
||||
int positionY;
|
||||
};
|
||||
|
||||
struct DoublePipe {
|
||||
struct Pipe pipe1;
|
||||
struct Pipe pipe2;
|
||||
};
|
||||
|
||||
void Jump(float* vel) {
|
||||
if (IsKeyPressed(KEY_UP)) {
|
||||
*vel = -7;
|
||||
}
|
||||
}
|
||||
|
||||
void VelocityControl(float* vel) {
|
||||
if (*vel < -12) {
|
||||
*vel = -12;
|
||||
}
|
||||
}
|
||||
|
||||
void FlappyBird(struct Birdie* bird) {
|
||||
Jump(&bird->velocityY);
|
||||
VelocityControl(&bird->velocityY);
|
||||
|
||||
bird->velocityY += gravity;
|
||||
bird->positionY += (int)bird->velocityY;
|
||||
|
||||
if (bird->positionY > GetScreenHeight()) {
|
||||
bird->positionY = GetScreenHeight();
|
||||
bird->velocityY = 0;
|
||||
}
|
||||
|
||||
else if (bird->positionY < 0) {
|
||||
bird->positionY = 0;
|
||||
bird->velocityY = 0;
|
||||
}
|
||||
|
||||
DrawCircle(bird_pos_x, bird->positionY, bird_radius, YELLOW);
|
||||
}
|
||||
|
||||
struct DoublePipe CreateDoublePipe(int gap, int posY, int height) {
|
||||
struct DoublePipe double_pipe = {{GetScreenWidth(), posY - height - gap}, {GetScreenWidth(), posY + gap}};
|
||||
|
||||
return double_pipe;
|
||||
}
|
||||
|
||||
void DrawDoublePipe(struct DoublePipe* double_pipe) {
|
||||
DrawRectangle(double_pipe->pipe1.positionX, double_pipe->pipe1.positionY, pipe_width, pipe_height, GREEN);
|
||||
DrawRectangle(double_pipe->pipe2.positionX, double_pipe->pipe2.positionY, pipe_width, pipe_height, GREEN);
|
||||
}
|
||||
|
||||
void MoveDoublePipe(struct DoublePipe* double_pipe, int height, int gap) {
|
||||
if (double_pipe->pipe1.positionX + pipe_width < 0 && double_pipe->pipe2.positionX < 0) {
|
||||
double_pipe->pipe1.positionX = GetScreenWidth();
|
||||
double_pipe->pipe2.positionX = GetScreenWidth();
|
||||
|
||||
int randint = rand() % (GetScreenHeight() + 1);
|
||||
|
||||
double_pipe->pipe1.positionY = randint - height - gap;
|
||||
double_pipe->pipe2.positionY = randint + gap;
|
||||
|
||||
}
|
||||
|
||||
double_pipe->pipe1.positionX -= 6;
|
||||
double_pipe->pipe2.positionX -= 6;
|
||||
}
|
||||
|
||||
bool IsPlayerColliding(struct DoublePipe* double_pipe, struct Birdie* bird) {
|
||||
Rectangle rec1 = {double_pipe->pipe1.positionX, double_pipe->pipe1.positionY, pipe_width, pipe_height};
|
||||
Rectangle rec2 = {double_pipe->pipe2.positionX, double_pipe->pipe2.positionY, pipe_width, pipe_height};
|
||||
Vector2 center = {bird_pos_x, bird->positionY};
|
||||
|
||||
return CheckCollisionCircleRec(center, bird_radius, rec1) || CheckCollisionCircleRec(center, bird_radius, rec2);
|
||||
}
|
||||
|
||||
enum GameState MainGame(struct DoublePipe* double_pipe, struct Birdie* bird, int pipe_height, int pipe_gap) {
|
||||
if (!IsPlayerColliding(double_pipe, bird)) {
|
||||
ClearBackground(BLACK);
|
||||
} else {
|
||||
return Restart;
|
||||
}
|
||||
|
||||
FlappyBird(bird);
|
||||
|
||||
DrawDoublePipe(double_pipe);
|
||||
MoveDoublePipe(double_pipe, pipe_height, pipe_gap);
|
||||
|
||||
return Game;
|
||||
}
|
||||
|
||||
enum GameState {
|
||||
Start,
|
||||
Game,
|
||||
Restart
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
InitWindow(800, 600, "HELLO RAYLRIN!!!");
|
||||
SetTargetFPS(60);
|
||||
|
||||
enum GameState gs = Start;
|
||||
|
||||
struct Birdie bird = {0.0, 300};
|
||||
struct DoublePipe double_pipe = CreateDoublePipe(pipe_gap, 200, pipe_height);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
BeginDrawing();
|
||||
|
||||
switch (GameState) {
|
||||
case Game:
|
||||
MainGame(&double_pipe, &bird, pipe_height, pipe_gap);
|
||||
case Restart:
|
||||
//func for restart
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
2599
raylib/CHANGELOG
Normal file
2599
raylib/CHANGELOG
Normal file
File diff suppressed because it is too large
Load diff
16
raylib/LICENSE
Normal file
16
raylib/LICENSE
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
|
||||
|
||||
This software is provided "as-is", without any express or implied warranty. In no event
|
||||
will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
wrote the original software. If you use this software in a product, an acknowledgment
|
||||
in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
150
raylib/README.md
Normal file
150
raylib/README.md
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<img align="left" style="width:260px" src="https://github.com/raysan5/raylib/blob/master/logo/raylib_logo_animation.gif" width="288px">
|
||||
|
||||
**raylib is a simple and easy-to-use library to enjoy videogames programming.**
|
||||
|
||||
raylib is highly inspired by Borland BGI graphics lib and by XNA framework and it's especially well suited for prototyping, tooling, graphical applications, embedded systems and education.
|
||||
|
||||
*NOTE for ADVENTURERS: raylib is a programming library to enjoy videogames programming; no fancy interface, no visual helpers, no debug button... just coding in the most pure spartan-programmers way.*
|
||||
|
||||
Ready to learn? Jump to [code examples!](https://www.raylib.com/examples.html)
|
||||
|
||||
---
|
||||
|
||||
<br>
|
||||
|
||||
[](https://github.com/raysan5/raylib/releases)
|
||||
[](https://github.com/raysan5/raylib/stargazers)
|
||||
[](https://github.com/raysan5/raylib/commits/master)
|
||||
[](https://github.com/sponsors/raysan5)
|
||||
[](https://repology.org/project/raylib/versions)
|
||||
[](LICENSE)
|
||||
|
||||
[](https://discord.gg/raylib)
|
||||
[](https://www.reddit.com/r/raylib/)
|
||||
[](https://www.youtube.com/c/raylib)
|
||||
[](https://www.twitch.tv/raysan5)
|
||||
|
||||
[](https://github.com/raysan5/raylib/actions?query=workflow%3AWindows)
|
||||
[](https://github.com/raysan5/raylib/actions?query=workflow%3ALinux)
|
||||
[](https://github.com/raysan5/raylib/actions?query=workflow%3AmacOS)
|
||||
[](https://github.com/raysan5/raylib/actions?query=workflow%3AWebAssembly)
|
||||
|
||||
[](https://github.com/raysan5/raylib/actions?query=workflow%3ACMakeBuilds)
|
||||
[](https://github.com/raysan5/raylib/actions/workflows/windows_examples.yml)
|
||||
[](https://github.com/raysan5/raylib/actions/workflows/linux_examples.yml)
|
||||
|
||||
features
|
||||
--------
|
||||
- **NO external dependencies**, all required libraries are [bundled into raylib](https://github.com/raysan5/raylib/tree/master/src/external)
|
||||
- Multiple platforms supported: **Windows, Linux, MacOS, RPI, Android, HTML5... and more!**
|
||||
- Written in plain C code (C99) using PascalCase/camelCase notation
|
||||
- Hardware accelerated with OpenGL (**1.1, 2.1, 3.3, 4.3, ES 2.0, ES 3.0**)
|
||||
- **Unique OpenGL abstraction layer** (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h)
|
||||
- Multiple **Fonts** formats supported (TTF, OTF, FNT, BDF, sprite fonts)
|
||||
- Multiple texture formats supported, including **compressed formats** (DXT, ETC, ASTC)
|
||||
- **Full 3D support**, including 3D Shapes, Models, Billboards, Heightmaps and more!
|
||||
- Flexible Materials system, supporting classic maps and **PBR maps**
|
||||
- **Animated 3D models** supported (skeletal bones animation) (IQM, M3D, glTF)
|
||||
- Shaders support, including model shaders and **postprocessing** shaders
|
||||
- **Powerful math module** for Vector, Matrix and Quaternion operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h)
|
||||
- Audio loading and playing with streaming support (WAV, QOA, OGG, MP3, FLAC, XM, MOD)
|
||||
- **VR stereo rendering** support with configurable HMD device parameters
|
||||
- Huge examples collection with [+140 code examples](https://github.com/raysan5/raylib/tree/master/examples)!
|
||||
- Bindings to [+70 programming languages](https://github.com/raysan5/raylib/blob/master/BINDINGS.md)!
|
||||
- **Free and open source**
|
||||
|
||||
basic example
|
||||
--------------
|
||||
This is a basic raylib example, it creates a window and draws the text `"Congrats! You created your first window!"` in the middle of the screen. Check this example [running live on web here](https://www.raylib.com/examples/core/loader.html?name=core_basic_window).
|
||||
```c
|
||||
#include "raylib.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
InitWindow(800, 450, "raylib [core] example - basic window");
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
build and installation
|
||||
----------------------
|
||||
|
||||
raylib binary releases for Windows, Linux, macOS, Android and HTML5 are available at the [Github Releases page](https://github.com/raysan5/raylib/releases).
|
||||
|
||||
raylib is also available via multiple package managers on multiple OS distributions.
|
||||
|
||||
#### Installing and building raylib on multiple platforms
|
||||
|
||||
[raylib Wiki](https://github.com/raysan5/raylib/wiki#development-platforms) contains detailed instructions on building and usage on multiple platforms.
|
||||
|
||||
- [Working on Windows](https://github.com/raysan5/raylib/wiki/Working-on-Windows)
|
||||
- [Working on macOS](https://github.com/raysan5/raylib/wiki/Working-on-macOS)
|
||||
- [Working on GNU Linux](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux)
|
||||
- [Working on Chrome OS](https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS)
|
||||
- [Working on FreeBSD](https://github.com/raysan5/raylib/wiki/Working-on-FreeBSD)
|
||||
- [Working on Raspberry Pi](https://github.com/raysan5/raylib/wiki/Working-on-Raspberry-Pi)
|
||||
- [Working for Android](https://github.com/raysan5/raylib/wiki/Working-for-Android)
|
||||
- [Working for Web (HTML5)](https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5))
|
||||
- [Working anywhere with CMake](https://github.com/raysan5/raylib/wiki/Working-with-CMake)
|
||||
|
||||
*Note that the Wiki is open for edit, if you find some issues while building raylib for your target platform, feel free to edit the Wiki or open an issue related to it.*
|
||||
|
||||
#### Setup raylib with multiple IDEs
|
||||
|
||||
raylib has been developed on Windows platform using [Notepad++](https://notepad-plus-plus.org/) and [MinGW GCC](https://www.mingw-w64.org/) compiler but it can be used with other IDEs on multiple platforms.
|
||||
|
||||
[Projects directory](https://github.com/raysan5/raylib/tree/master/projects) contains several ready-to-use **project templates** to build raylib and code examples with multiple IDEs.
|
||||
|
||||
*Note that there are lots of IDEs supported, some of the provided templates could require some review, so please, if you find some issue with a template or you think they could be improved, feel free to send a PR or open a related issue.*
|
||||
|
||||
learning and docs
|
||||
------------------
|
||||
|
||||
raylib is designed to be learned using [the examples](https://github.com/raysan5/raylib/tree/master/examples) as the main reference. There is no standard API documentation but there is a [**cheatsheet**](https://www.raylib.com/cheatsheet/cheatsheet.html) containing all the functions available on the library a short description of each one of them, input parameters and result value names should be intuitive enough to understand how each function works.
|
||||
|
||||
Some additional documentation about raylib design can be found in [raylib GitHub Wiki](https://github.com/raysan5/raylib/wiki). Here are the relevant links:
|
||||
|
||||
- [raylib cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html)
|
||||
- [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture)
|
||||
- [raylib library design](https://github.com/raysan5/raylib/wiki)
|
||||
- [raylib examples collection](https://github.com/raysan5/raylib/tree/master/examples)
|
||||
- [raylib games collection](https://github.com/raysan5/raylib-games)
|
||||
|
||||
|
||||
contact and networks
|
||||
---------------------
|
||||
|
||||
raylib is present in several networks and raylib community is growing everyday. If you are using raylib and enjoying it, feel free to join us in any of these networks. The most active network is our [Discord server](https://discord.gg/raylib)! :)
|
||||
|
||||
- Webpage: [https://www.raylib.com](https://www.raylib.com)
|
||||
- Discord: [https://discord.gg/raylib](https://discord.gg/raylib)
|
||||
- Twitter: [https://www.twitter.com/raysan5](https://www.twitter.com/raysan5)
|
||||
- Twitch: [https://www.twitch.tv/raysan5](https://www.twitch.tv/raysan5)
|
||||
- Reddit: [https://www.reddit.com/r/raylib](https://www.reddit.com/r/raylib)
|
||||
- Patreon: [https://www.patreon.com/raylib](https://www.patreon.com/raylib)
|
||||
- YouTube: [https://www.youtube.com/channel/raylib](https://www.youtube.com/c/raylib)
|
||||
|
||||
contributors
|
||||
------------
|
||||
|
||||
<a href="https://github.com/raysan5/raylib/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=raysan5/raylib&max=500&columns=20&anon=1" />
|
||||
</a>
|
||||
|
||||
license
|
||||
-------
|
||||
|
||||
raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.
|
||||
|
||||
raylib uses internally some libraries for window/graphics/inputs management and also to support different file formats loading, all those libraries are embedded with and are available in [src/external](https://github.com/raysan5/raylib/tree/master/src/external) directory. Check [raylib dependencies LICENSES](https://github.com/raysan5/raylib/wiki/raylib-dependencies) on [raylib Wiki](https://github.com/raysan5/raylib/wiki) for details.
|
||||
1708
raylib/include/raylib.h
Normal file
1708
raylib/include/raylib.h
Normal file
File diff suppressed because it is too large
Load diff
2941
raylib/include/raymath.h
Normal file
2941
raylib/include/raymath.h
Normal file
File diff suppressed because it is too large
Load diff
5262
raylib/include/rlgl.h
Normal file
5262
raylib/include/rlgl.h
Normal file
File diff suppressed because it is too large
Load diff
BIN
raylib/lib/libraylib.a
Normal file
BIN
raylib/lib/libraylib.a
Normal file
Binary file not shown.
1
raylib/lib/libraylib.so
Symbolic link
1
raylib/lib/libraylib.so
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
libraylib.so.550
|
||||
BIN
raylib/lib/libraylib.so.5.5.0
Executable file
BIN
raylib/lib/libraylib.so.5.5.0
Executable file
Binary file not shown.
1
raylib/lib/libraylib.so.550
Symbolic link
1
raylib/lib/libraylib.so.550
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
libraylib.so.5.5.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue