diff --git a/linux/raylib/Makefile b/linux/raylib/Makefile new file mode 100644 index 0000000..05551f2 --- /dev/null +++ b/linux/raylib/Makefile @@ -0,0 +1,408 @@ +#************************************************************************************************** +# +# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 +# +# Copyright (c) 2013-2020 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. +# +#************************************************************************************************** + +.PHONY: all clean + +# Define required raylib variables +PROJECT_NAME ?= Terri-Fried +RAYLIB_VERSION ?= 3.0.0 +RAYLIB_API_VERSION ?= 3 +RAYLIB_PATH ?= ../.. + +# Define default options + +# One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB +PLATFORM ?= PLATFORM_DESKTOP + +# Locations of your newly installed library and associated headers. See ../src/Makefile +# On Linux, if you have installed raylib but cannot compile the examples, check that +# the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations. +# To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED. +# To enable compile-time linking to a special version of libraylib.so, change these variables here. +# To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below. +# If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime, +# the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH. +# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths. +DESTDIR ?= /usr/local +RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib +# RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files. +RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include + +# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll) +RAYLIB_LIBTYPE ?= STATIC + +# Build mode for project: DEBUG or RELEASE +BUILD_MODE ?= RELEASE + +# Use external GLFW library instead of rglfw module +# TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3 +USE_EXTERNAL_GLFW ?= FALSE + +# Use Wayland display server protocol on Linux desktop +# by default it uses X11 windowing system +USE_WAYLAND_DISPLAY ?= FALSE + +# Determine PLATFORM_OS in case PLATFORM_DESKTOP selected +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + # No uname.exe on MinGW!, but OS=Windows_NT on Windows! + # ifeq ($(UNAME),Msys) -> Windows + ifeq ($(OS),Windows_NT) + PLATFORM_OS=WINDOWS + else + UNAMEOS=$(shell uname) + ifeq ($(UNAMEOS),Linux) + PLATFORM_OS=LINUX + endif + ifeq ($(UNAMEOS),FreeBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),OpenBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),NetBSD) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),DragonFly) + PLATFORM_OS=BSD + endif + ifeq ($(UNAMEOS),Darwin) + PLATFORM_OS=OSX + endif + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + UNAMEOS=$(shell uname) + ifeq ($(UNAMEOS),Linux) + PLATFORM_OS=LINUX + endif +endif + +# RAYLIB_PATH adjustment for different platforms. +# If using GNU make, we can get the full path to the top of the tree. Windows? BSD? +# Required for ldconfig or other tools that do not perform path expansion. +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + RAYLIB_PREFIX ?= .. + RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX)) + endif +endif +# Default path for raylib on Raspberry Pi, if installed in different path, update it! +# This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki. +# TODO: update install: target in src/Makefile for RPI, consider relation to LINUX. +ifeq ($(PLATFORM),PLATFORM_RPI) + RAYLIB_PATH ?= /home/pi/raylib +endif + +ifeq ($(PLATFORM),PLATFORM_WEB) + # Emscripten required variables + EMSDK_PATH ?= C:/emsdk + EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/fastcomp/emscripten + CLANG_PATH = $(EMSDK_PATH)/fastcomp/bin + PYTHON_PATH = $(EMSDK_PATH)/python/3.7.4_64bit + NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin + export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH) +endif + +# Define raylib release directory for compiled library. +# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version +RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src + +# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries +# into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH +# so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux +# without formal installation from ../src/Makefile. It aids portability and is useful if you have +# multiple versions of raylib, have raylib installed to a non-standard location, or want to +# bundle libraylib.so with your game. Change it to your liking. +# NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, +# The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH, +# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) +# To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute. +# To see which libraries a built example is linking to, ldd core/core_basic_window; +# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing. +EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH) + +# Define default C compiler: gcc +# NOTE: define g++ compiler if using C++ +CC = g++ + +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),OSX) + # OSX default compiler + CC = clang + endif + ifeq ($(PLATFORM_OS),BSD) + # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler + CC = clang + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + ifeq ($(USE_RPI_CROSS_COMPILER),TRUE) + # Define RPI cross-compiler + #CC = armv6j-hardfloat-linux-gnueabi-gcc + CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc + endif +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + # HTML5 emscripten compiler + # WARNING: To compile to HTML5, code must be redesigned + # to use emscripten.h and emscripten_set_main_loop() + CC = emcc +endif + +# Define default make program: Mingw32-make +MAKE = make + +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + MAKE = make + endif +endif + +# Define compiler flags: +# -O1 defines optimization level +# -g include debug information on compilation +# -s strip unnecessary data from build +# -Wall turns on most, but not all, compiler warnings +# -std=c99 defines C language mode (standard C from 1999 revision) +# -std=gnu99 defines C language mode (GNU C from 1999 revision) +# -Wno-missing-braces ignore invalid warning (GCC bug 53119) +# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec +CFLAGS += -Wall -std=c++11 -D_DEFAULT_SOURCE -Wno-missing-braces + +ifeq ($(BUILD_MODE),DEBUG) + CFLAGS += -g + ifeq ($(PLATFORM),PLATFORM_WEB) + CFLAGS += -s ASSERTIONS=1 --profiling + endif +else + ifeq ($(PLATFORM),PLATFORM_WEB) + CFLAGS += -Os + else + CFLAGS += -s -O1 + endif +endif + +# Additional flags for compiler (if desired) +#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(RAYLIB_LIBTYPE),STATIC) + CFLAGS += -D_DEFAULT_SOURCE + endif + ifeq ($(RAYLIB_LIBTYPE),SHARED) + # Explicitly enable runtime link to libraylib.so + CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) + endif + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + CFLAGS += -std=gnu99 +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + # -Os # size optimization + # -O2 # optimization level 2, if used, also set --memory-init-file 0 + # -s USE_GLFW=3 # Use glfw3 library (context/input management) + # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL! + # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) + # -s USE_PTHREADS=1 # multithreading support + # -s WASM=0 # disable Web Assembly, emitted by default + # -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow) + # -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter + # -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data + # -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off) + # --profiling # include information for code profiling + # --memory-init-file 0 # to avoid an external memory initialization code file (.mem) + # --preload-file resources # specify a resources folder for data compilation + CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 + #-s + #EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 + + # NOTE: Simple raylib examples are compiled to be interpreter by emterpreter, that way, + # we can compile same code for ALL platforms with no change required, but, working on bigger + # projects, code needs to be refactored to avoid a blocking while() loop, moving Update and Draw + # logic to a self contained function: UpdateDrawFrame(), check core_basic_window_web.c for reference. + + # Define a custom shell .html and output extension + CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html + EXT = .html +endif + +# Define include paths for required headers +# NOTE: Several external required libraries (stb and others) +INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external + +# Define additional directories containing required header files +ifeq ($(PLATFORM),PLATFORM_RPI) + # RPI required libraries + INCLUDE_PATHS += -I/opt/vc/include + INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux + INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads +endif +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),BSD) + # Consider -L$(RAYLIB_H_INSTALL_PATH) + INCLUDE_PATHS += -I/usr/local/include + endif + ifeq ($(PLATFORM_OS),LINUX) + # Reset everything. + # Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include + INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external + endif +endif + +# Define library paths containing required libs. +LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src + +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),WINDOWS) + # resource file contains windows executable icon and properties + LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data + # -Wl,--subsystem,windows hides the console window + ifeq ($(BUILD_MODE), RELEASE) + LDFLAGS += -Wl,--subsystem,windows + endif + endif + ifeq ($(PLATFORM_OS),BSD) + # Consider -L$(RAYLIB_INSTALL_PATH) + LDFLAGS += -L. -Lsrc -L/usr/local/lib + endif + ifeq ($(PLATFORM_OS),LINUX) + # Reset everything. + # Precedence: immediately local, installed version, raysan5 provided libs + LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) + endif +endif + +ifeq ($(PLATFORM),PLATFORM_RPI) + LDFLAGS += -L/opt/vc/lib +endif + +# Define any libraries required on linking +# if you want to link libraries (libname.so or libname.a), use the -lname +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),WINDOWS) + # Libraries for Windows desktop compilation + # NOTE: WinMM library required to set high-res timer resolution + LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm + # Required for physac examples + LDLIBS += -static -lpthread + endif + ifeq ($(PLATFORM_OS),LINUX) + # Libraries for Debian GNU/Linux desktop compiling + # NOTE: Required packages: libegl1-mesa-dev + LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt + + # On X11 requires also below libraries + LDLIBS += -lX11 + # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them + #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor + + # On Wayland windowing system, additional libraries requires + ifeq ($(USE_WAYLAND_DISPLAY),TRUE) + LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon + endif + # Explicit link to libc + ifeq ($(RAYLIB_LIBTYPE),SHARED) + LDLIBS += -lc + endif + endif + ifeq ($(PLATFORM_OS),OSX) + # Libraries for OSX 10.9 desktop compiling + # NOTE: Required packages: libopenal-dev libegl1-mesa-dev + LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo + endif + ifeq ($(PLATFORM_OS),BSD) + # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling + # NOTE: Required packages: mesa-libs + LDLIBS = -lraylib -lGL -lpthread -lm + + # On XWindow requires also below libraries + LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor + endif + ifeq ($(USE_EXTERNAL_GLFW),TRUE) + # NOTE: It could require additional packages installed: libglfw3-dev + LDLIBS += -lglfw + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + # Libraries for Raspberry Pi compiling + # NOTE: Required packages: libasound2-dev (ALSA) + LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + # Libraries for web (HTML5) compiling + LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc +endif + +# Define all source files required +PROJECT_SOURCE_FILES ?= main.cpp player.cpp platform.cpp + +# Define all object files from source files +OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES)) + +# For Android platform we call a custom Makefile.Android +ifeq ($(PLATFORM),PLATFORM_ANDROID) + MAKEFILE_PARAMS = -f Makefile.Android + export PROJECT_NAME + export PROJECT_SOURCE_FILES +else + MAKEFILE_PARAMS = $(PROJECT_NAME) +endif + +# Default target entry +# NOTE: We call this Makefile target or Makefile.Android target +all: + $(MAKE) $(MAKEFILE_PARAMS) + +# Project target defined by PROJECT_NAME +$(PROJECT_NAME): $(OBJS) + $(CC) -o $(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) + +# Compile source files +# NOTE: This pattern will compile every module defined on $(OBJS) +%.o: %.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) + +# Clean everything +clean: +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),WINDOWS) + del *.o *.exe /s + endif + ifeq ($(PLATFORM_OS),LINUX) + find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable|x-pie-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv + endif + ifeq ($(PLATFORM_OS),OSX) + find . -type f -perm +ugo+x -delete + rm -f *.o + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + find . -type f -executable -delete + rm -fv *.o +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + del *.o *.html *.js +endif + @echo Cleaning done + diff --git a/linux/raylib/main.cpp b/linux/raylib/main.cpp new file mode 100644 index 0000000..8b6bf4a --- /dev/null +++ b/linux/raylib/main.cpp @@ -0,0 +1,260 @@ +#include "raylib.h" +#include +#include +#include +#include "player.h" +#include "platform.h" + +const double pi = 3.1415926535897; + + +const int gravity = 1; + + + +Platform platforms[4] = {{0}, {1}, {2}, {3}}; +Player player(platforms[0].getX() + platforms[0].getWidth()/2 - 26/2, platforms[0].getY() - player.getHeight(), 26, 32); + +int scoreInt = 0; +int highscoreInt = LoadStorageValue(0); +char score[32]; +char highscore[32]; + +bool titleScreen = true; +bool playCoinFX = false; + +void addScore(int amount) +{ + scoreInt += amount; + if (scoreInt < 10) + { + sprintf(score, "00%d", scoreInt); + } else if (scoreInt < 100) + { + sprintf(score, "0%d", scoreInt); + } else { + sprintf(score, "%d", scoreInt); + } + if (scoreInt > highscoreInt) + { + highscoreInt = scoreInt; + sprintf(highscore, "BEST: %d", highscoreInt); + } +} +void resetScore() +{ + scoreInt = 0; + sprintf(score, "00%d", scoreInt); + SaveStorageValue(0, highscoreInt); +} +void resetGame() +{ + resetScore(); + for (int i = 0; i < 4; i++) + { + platforms[i] = Platform(i); + } + player.setVelocity(0, 0); + player.setX(platforms[0].getX() + platforms[0].getWidth()/2 - 26/2); + player.setY(platforms[0].getY() - player.getHeight()); +} + + +void checkPlayerCollision() +{ + bool onPlatform = false; + for (int i = 0; i < 4; i++) + { + if (platforms[i].getHasCoin() && player.getX() + player.getWidth() - 3 > platforms[i].getCoinX() && player.getX() + 3 < platforms[i].getCoinX() + 24 && player.getY() + player.getHeight() - 3 > platforms[i].getCoinY() && player.getY() + 3 < platforms[i].getCoinY() + 24) + { + addScore(1); + platforms[i].setHasCoin(false); + playCoinFX = true; + } + if (player.getX() + 1 < platforms[i].getX() + platforms[i].getWidth() && player.getX() + player.getWidth() > platforms[i].getX() && player.getY() + player.getHeight() >= platforms[i].getY() && player.getY() < platforms[i].getY() + platforms[i].getHeight()) + { + if (player.getY() > platforms[i].getY() + platforms[i].getHeight()/2) + { + player.setVelocity(player.getVelocity().x, 5); + } + else if (player.getY() + player.getHeight() < platforms[i].getY() + platforms[i].getHeight()) + { + onPlatform = true; + player.setY(platforms[i].getY() - player.getHeight()); + player.setY(player.getY() + 1); + } + } + + } + player.setOnPlatform(onPlatform); +} + + +int main(void) +{ + srand (time(NULL)); + resetScore(); + sprintf(highscore, "BEST: %d", highscoreInt); + const int screenWidth = 800; + const int screenHeight = 450; + + int mouseDownX = 0; + int mouseDownY = 0; + double lavaY = screenHeight - 32; + double timer = 0; + double splashTimer = 0; + bool firstTime = true; + bool playedSplash = false; + bool playedSelect = false; + Image egg = LoadImage("resources/egg.png"); + InitWindow(screenWidth, screenHeight, "Terri-Fried"); + SetWindowIcon(egg); + InitAudioDevice(); + SetMasterVolume(0.3f); + + Texture2D playerSprite = LoadTexture("resources/egg.png"); + Texture2D lavaSprite = LoadTexture("resources/lava.png"); + Texture2D platformSprite = LoadTexture("resources/platform.png"); + Texture2D coinSprite = LoadTexture("resources/coin.png"); + Texture2D scoreBoxSprite = LoadTexture("resources/scorebox.png"); + Texture2D logo = LoadTexture("resources/logo.png"); + Texture2D splashEggSprite = LoadTexture("resources/splash_egg.png"); + + Sound fxLaunch = LoadSound("resources/launch.wav"); + Sound fxClick = LoadSound("resources/click.wav"); + Sound fxDeath = LoadSound("resources/die.wav"); + Sound fxCoin = LoadSound("resources/coin.wav"); + Sound fxSplash = LoadSound("resources/splash.wav"); + Sound fxSelect = LoadSound("resources/select.wav"); + Font font = LoadFontEx("resources/font.otf", 64, 0, NULL); + SetTargetFPS(60); + while (!WindowShouldClose()) + { + if (titleScreen) + { if (splashTimer > 120) + { + if (!playedSelect) + { + PlaySound(fxSelect); + playedSelect = true; + } + BeginDrawing(); + ClearBackground(ColorFromNormalized((Vector4){0.933, 0.894, 0.882, 1.0})); + DrawTexture(logo, screenWidth/2 - 200, screenHeight/2 - 45 - 30, WHITE); + DrawTextEx(font, highscore,Vector2{screenWidth/2 - 37, screenHeight/2 + 10}, 32, 0, BLACK); + DrawTextEx(font, "CLICK ANYWHERE TO BEGIN",Vector2{screenWidth/2 - 134, screenHeight/2 + 50}, 32, 0, ColorFromNormalized((Vector4){.698, .588, .49, 0.4})); + EndDrawing(); + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + PlaySound(fxSelect); + titleScreen = false; + mouseDownX = GetMouseX(); + mouseDownY = GetMouseY(); + } + } else { + if (!playedSplash) + { + PlaySound(fxSplash); + playedSplash = true; + } + BeginDrawing(); + ClearBackground(ColorFromNormalized((Vector4){0.933, 0.894, 0.882, 1.0})); + DrawTextEx(font, "POLYMARS",Vector2{screenWidth/2 - 54, screenHeight/2 + 3}, 32, 0, ColorFromNormalized((Vector4){.835, .502, .353, 1.0})); + DrawTexture(splashEggSprite, screenWidth/2 - 16, screenHeight/2 - 16 - 23, WHITE); + EndDrawing(); + splashTimer += 1; + } + } + else + { + + + if (playCoinFX) + { + PlaySound(fxCoin); + playCoinFX = false; + } + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && player.isOnGround()) + { + PlaySound(fxClick); + mouseDownX = GetMouseX(); + mouseDownY = GetMouseY(); + } + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON) && player.isOnGround()) + { + if (firstTime) + { + firstTime = false; + } else { + PlaySound(fxLaunch); + if (player.isOnPlatform()) + { + player.setY(player.getY() - 1); + } + int velocityX = GetMouseX() - mouseDownX; + + int velocityY = GetMouseY() - mouseDownY; + + player.setVelocity((double)velocityX*.08, (double)velocityY*.08); + } + } + checkPlayerCollision(); + player.updatePosition(); + if (player.getY() > screenHeight) + { + PlaySound(fxDeath); + resetGame(); + } + for (int i = 0; i < 4; i++) + { + platforms[i].updatePosition(); + } + + lavaY = screenHeight - 43 - sin(timer) * 5; + timer += 0.05; + BeginDrawing(); + + ClearBackground(ColorFromNormalized((Vector4){0.933, 0.894, 0.882, 1.0})); + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && player.isOnGround()) + { + DrawLineEx((Vector2){static_cast(mouseDownX + (player.getX() - mouseDownX) + (player.getWidth()/2)), static_cast(mouseDownY + (player.getY() - mouseDownY) + (player.getHeight()/2))}, (Vector2){static_cast(GetMouseX() + (player.getX() - mouseDownX) + (player.getWidth()/2)), static_cast(GetMouseY() + (player.getY() - mouseDownY) + (player.getHeight()/2))}, 3.0f, ColorFromNormalized((Vector4){.906, .847, .788, 1.0})); + } + //DrawRectangle(player.getX(), player.getY(), player.getWidth(), player.getHeight(), WHITE); + for (int i = 0; i < 4; i++) + { + DrawTexture(platformSprite, platforms[i].getX(), platforms[i].getY(), ColorFromNormalized((Vector4){.698, .588, .49, 1.0})); + if (platforms[i].getHasCoin()) + { + DrawTexture(coinSprite, platforms[i].getCoinX(), platforms[i].getCoinY(), WHITE); + } + } + DrawTexture(playerSprite, player.getX(), player.getY(), WHITE); + DrawTexture(lavaSprite, 0, lavaY, WHITE); + DrawTexture(scoreBoxSprite, 17, 17, WHITE); + DrawTextEx(font, score,Vector2{28, 20},64, 0, BLACK); + DrawTextEx(font, highscore,Vector2{17, 90}, 32, 0, BLACK); + + EndDrawing(); + } + + } + + UnloadTexture(playerSprite); + UnloadTexture(lavaSprite); + UnloadTexture(platformSprite); + UnloadTexture(coinSprite); + UnloadTexture(scoreBoxSprite); + UnloadTexture(logo); + UnloadTexture(splashEggSprite); + UnloadSound(fxClick); + UnloadSound(fxLaunch); + UnloadSound(fxDeath); + UnloadSound(fxCoin); + UnloadSound(fxSplash); + UnloadSound(fxSelect); + UnloadFont(font); + CloseAudioDevice(); + CloseWindow(); + + return 0; +} diff --git a/linux/raylib/platform.cpp b/linux/raylib/platform.cpp new file mode 100644 index 0000000..abb418b --- /dev/null +++ b/linux/raylib/platform.cpp @@ -0,0 +1,78 @@ +#include "raylib.h" +#include "platform.h" +#include +const int screenWidth = 800; +const int screenHeight = 450; +Platform::Platform(int index) +{ + width = 100; + height = 32; + x = rand()% 660 + 20; + y = 0 - height - (index * 100); + int coinInt = rand()% 4; + if (coinInt == 0 || index == 0) + { + hasCoin = false; + } else { + hasCoin = true; + } + coinX = x + width/2 - 24/2; + coinY = y - 24 - 5; + +} + +double Platform::getX() +{ + return x; +} + +double Platform::getY() +{ + return y; +} + +int Platform::getWidth() +{ + return width; +} + +int Platform::getHeight() +{ + return height; +} + +bool Platform::getHasCoin() +{ + return hasCoin; +} +void Platform::setHasCoin(bool value) +{ + hasCoin = value; +} +int Platform::getCoinX() +{ + return coinX; +} +int Platform::getCoinY() +{ + return coinY; +} + +void Platform::updatePosition() +{ + y+=1; + coinX = x + width/2 - 24/2; + coinY = y - 24 - 5; + if (y > screenHeight) + { + x = rand()% 660 + 20; + y = 0 - height; + int coinInt = rand()% 4; + if (coinInt == 0) + { + hasCoin = false; + } else { + hasCoin = true; + } + } +} \ No newline at end of file diff --git a/linux/raylib/platform.h b/linux/raylib/platform.h new file mode 100644 index 0000000..b25bc1d --- /dev/null +++ b/linux/raylib/platform.h @@ -0,0 +1,27 @@ +#ifndef PLATFORM_H +#define PLATFORM_H +class Platform +{ + private: + double x; + double y; + int width; + int height; + bool hasCoin; + int coinX; + int coinY; + + public: + Platform(int index); + double getX(); + double getY(); + int getWidth(); + int getHeight(); + bool getHasCoin(); + void setHasCoin(bool value); + int getCoinX(); + int getCoinY(); + void updatePosition(); + +}; +#endif \ No newline at end of file diff --git a/linux/raylib/player.cpp b/linux/raylib/player.cpp new file mode 100644 index 0000000..baf1e21 --- /dev/null +++ b/linux/raylib/player.cpp @@ -0,0 +1,94 @@ +#include "raylib.h" +#include "player.h" +#include +#include + +const double pi = 3.1415926535897; +const int gravity = 1; +const int screenWidth = 800; +const int screenHeight = 450; + +Player::Player(double x, double y, int width, int height) +{ + this->x = x; + this->y = y; + this->width = width; + this->height = height; + onPlatform = false; +} + +double Player::getX() +{ + return x; +} + +double Player::getY() +{ + return y; +} + +void Player::setX(int x) +{ + this->x = x; +} + +void Player::setY(int y) +{ + this->y = y; +} + +int Player::getWidth() +{ + return width; +} + +int Player::getHeight() +{ + return height; +} + +bool Player::isOnGround() +{ + return onPlatform; +} +bool Player::isOnPlatform() +{ + return onPlatform; +} + +void Player::setOnPlatform(bool result) +{ + onPlatform = result; +} + +void Player::setVelocity(double x, double y) +{ + velocity = (Vector2){static_cast(x), static_cast(y)}; +} + +Vector2 Player::getVelocity() +{ + return velocity; +} + +void Player::updatePosition() +{ + x += velocity.x; + y += velocity.y; + if (!isOnGround()) + { + velocity.y += gravity; + } else + { + velocity = (Vector2){0, 0}; + } + if (x < 0) + { + velocity.x *= -1; + } + if (x + width > 800) + { + velocity.x *= -1; + } +} + diff --git a/linux/raylib/player.h b/linux/raylib/player.h new file mode 100644 index 0000000..116699a --- /dev/null +++ b/linux/raylib/player.h @@ -0,0 +1,30 @@ +#ifndef PLAYER_H +#define PLAYER_H +#include +class Player +{ + private: + double x; + double y; + int width; + int height; + bool onPlatform; + Vector2 velocity; + + public: + Player(double x, double y, int width, int height); + double getX(); + double getY(); + void setX(int x); + void setY(int y); + int getWidth(); + int getHeight(); + bool isOnGround(); + bool isOnPlatform(); + void setOnPlatform(bool result); + void setVelocity(double x, double y); + Vector2 getVelocity(); + void updatePosition(); + +}; +#endif \ No newline at end of file diff --git a/linux/resources/click.wav b/linux/raylib/resources/click.wav similarity index 100% rename from linux/resources/click.wav rename to linux/raylib/resources/click.wav diff --git a/linux/resources/coin.png b/linux/raylib/resources/coin.png similarity index 100% rename from linux/resources/coin.png rename to linux/raylib/resources/coin.png diff --git a/linux/resources/coin.wav b/linux/raylib/resources/coin.wav similarity index 100% rename from linux/resources/coin.wav rename to linux/raylib/resources/coin.wav diff --git a/linux/resources/die.wav b/linux/raylib/resources/die.wav similarity index 100% rename from linux/resources/die.wav rename to linux/raylib/resources/die.wav diff --git a/linux/resources/egg.png b/linux/raylib/resources/egg.png similarity index 100% rename from linux/resources/egg.png rename to linux/raylib/resources/egg.png diff --git a/linux/resources/font.otf b/linux/raylib/resources/font.otf similarity index 100% rename from linux/resources/font.otf rename to linux/raylib/resources/font.otf diff --git a/linux/resources/launch.wav b/linux/raylib/resources/launch.wav similarity index 100% rename from linux/resources/launch.wav rename to linux/raylib/resources/launch.wav diff --git a/linux/resources/lava.png b/linux/raylib/resources/lava.png similarity index 100% rename from linux/resources/lava.png rename to linux/raylib/resources/lava.png diff --git a/linux/resources/logo.png b/linux/raylib/resources/logo.png similarity index 100% rename from linux/resources/logo.png rename to linux/raylib/resources/logo.png diff --git a/linux/resources/platform.png b/linux/raylib/resources/platform.png similarity index 100% rename from linux/resources/platform.png rename to linux/raylib/resources/platform.png diff --git a/linux/resources/scorebox.png b/linux/raylib/resources/scorebox.png similarity index 100% rename from linux/resources/scorebox.png rename to linux/raylib/resources/scorebox.png diff --git a/linux/resources/select.wav b/linux/raylib/resources/select.wav similarity index 100% rename from linux/resources/select.wav rename to linux/raylib/resources/select.wav diff --git a/linux/resources/splash.wav b/linux/raylib/resources/splash.wav similarity index 100% rename from linux/resources/splash.wav rename to linux/raylib/resources/splash.wav diff --git a/linux/resources/splash_egg.png b/linux/raylib/resources/splash_egg.png similarity index 100% rename from linux/resources/splash_egg.png rename to linux/raylib/resources/splash_egg.png diff --git a/linux/Makefile b/linux/sdl2/Makefile similarity index 100% rename from linux/Makefile rename to linux/sdl2/Makefile diff --git a/linux/main.cpp b/linux/sdl2/main.cpp similarity index 100% rename from linux/main.cpp rename to linux/sdl2/main.cpp diff --git a/linux/platform.cpp b/linux/sdl2/platform.cpp similarity index 100% rename from linux/platform.cpp rename to linux/sdl2/platform.cpp diff --git a/linux/platform.h b/linux/sdl2/platform.h similarity index 100% rename from linux/platform.h rename to linux/sdl2/platform.h diff --git a/linux/player.cpp b/linux/sdl2/player.cpp similarity index 100% rename from linux/player.cpp rename to linux/sdl2/player.cpp diff --git a/linux/player.h b/linux/sdl2/player.h similarity index 100% rename from linux/player.h rename to linux/sdl2/player.h diff --git a/linux/sdl2/resources/click.wav b/linux/sdl2/resources/click.wav new file mode 100644 index 0000000..09a3124 Binary files /dev/null and b/linux/sdl2/resources/click.wav differ diff --git a/linux/sdl2/resources/coin.png b/linux/sdl2/resources/coin.png new file mode 100644 index 0000000..2ac238e Binary files /dev/null and b/linux/sdl2/resources/coin.png differ diff --git a/linux/sdl2/resources/coin.wav b/linux/sdl2/resources/coin.wav new file mode 100644 index 0000000..ac728c2 Binary files /dev/null and b/linux/sdl2/resources/coin.wav differ diff --git a/linux/sdl2/resources/die.wav b/linux/sdl2/resources/die.wav new file mode 100644 index 0000000..63cf89b Binary files /dev/null and b/linux/sdl2/resources/die.wav differ diff --git a/linux/sdl2/resources/egg.png b/linux/sdl2/resources/egg.png new file mode 100644 index 0000000..5d23d9d Binary files /dev/null and b/linux/sdl2/resources/egg.png differ diff --git a/linux/sdl2/resources/font.otf b/linux/sdl2/resources/font.otf new file mode 100644 index 0000000..5fc0706 Binary files /dev/null and b/linux/sdl2/resources/font.otf differ diff --git a/linux/sdl2/resources/launch.wav b/linux/sdl2/resources/launch.wav new file mode 100644 index 0000000..b85c109 Binary files /dev/null and b/linux/sdl2/resources/launch.wav differ diff --git a/linux/sdl2/resources/lava.png b/linux/sdl2/resources/lava.png new file mode 100644 index 0000000..4e78ff2 Binary files /dev/null and b/linux/sdl2/resources/lava.png differ diff --git a/linux/sdl2/resources/logo.png b/linux/sdl2/resources/logo.png new file mode 100644 index 0000000..4c60c38 Binary files /dev/null and b/linux/sdl2/resources/logo.png differ diff --git a/linux/sdl2/resources/platform.png b/linux/sdl2/resources/platform.png new file mode 100644 index 0000000..d70474e Binary files /dev/null and b/linux/sdl2/resources/platform.png differ diff --git a/linux/sdl2/resources/scorebox.png b/linux/sdl2/resources/scorebox.png new file mode 100644 index 0000000..556eeae Binary files /dev/null and b/linux/sdl2/resources/scorebox.png differ diff --git a/linux/sdl2/resources/select.wav b/linux/sdl2/resources/select.wav new file mode 100644 index 0000000..b39de7e Binary files /dev/null and b/linux/sdl2/resources/select.wav differ diff --git a/linux/sdl2/resources/splash.wav b/linux/sdl2/resources/splash.wav new file mode 100644 index 0000000..56320a8 Binary files /dev/null and b/linux/sdl2/resources/splash.wav differ diff --git a/linux/sdl2/resources/splash_egg.png b/linux/sdl2/resources/splash_egg.png new file mode 100644 index 0000000..2de1557 Binary files /dev/null and b/linux/sdl2/resources/splash_egg.png differ diff --git a/linux/winres/TF-icon.ico b/linux/sdl2/winres/TF-icon.ico similarity index 100% rename from linux/winres/TF-icon.ico rename to linux/sdl2/winres/TF-icon.ico diff --git a/linux/winres/TF-icon.rc b/linux/sdl2/winres/TF-icon.rc similarity index 100% rename from linux/winres/TF-icon.rc rename to linux/sdl2/winres/TF-icon.rc diff --git a/linux/winres/TF-icon.res b/linux/sdl2/winres/TF-icon.res similarity index 100% rename from linux/winres/TF-icon.res rename to linux/sdl2/winres/TF-icon.res