diff --git a/.gitignore b/.gitignore index e52e292..c678cad 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,9 @@ *.map *.lst +# Wii U files +*.rpx + # Switch files *.nro *.nacp diff --git a/README.md b/README.md index 7fe4fa3..6c76cac 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ Compiling for GameCube requires the same libogc libraries from [devkitPro](https ### Original Xbox Clone [this fork of nxdk](https://github.com/dracc/nxdk/tree/xgu) directly next to the Terri-Fried folder, then [install the nxdk prerequisites](https://github.com/XboxDev/nxdk/wiki/Getting-Started). Follow the instructions [here](https://github.com/Voxel9/xbox-xgu-examples#quick-guide) to fix the XGU headers in nxdk. This is a temporary fix for some duplicate symbol linker errors. Now `cd` to the `Terri-fried/xbox` folder and run `make`. An XBE file should be built in the `bin` folder. Copy the contents of the `bin` folder to your Xbox and run `default.xbe`. +### Wii U +Requires devkitpro, devkitPPC, [wut](https://github.com/devkitPro/wut), [libromfs-wiiu](https://github.com/yawut/libromfs-wiiu) and the following packages to be installed with dkp-pacman: +`wiiu-pkg-config`, `wiiu-sdl2`, `wiiu-sdl2_mixer`, `wiiu-sdl2_image` `wiiu-sdl2_ttf` +Once installed `cd` to `Terri-Fried/wiiu` and run `make`. Create a folder on your SD card with any name in the directory `/wiiu/apps` and copy the file(s) `Terri-Fried.rpx` (`icon.png` and `meta.xml` *optional*) into that folder. You will also need to create a folder on the root of your SD card named `Terri-Fried`. You can then launch via the Homebrew Launcher. ### Nintendo Switch Requires devkitpro, devkitARM, libNX and the following packages to be installed via dkp-pacman: `switch-pkg-config`, `switch-SDL2`, `switch-SDL2_mixer`, `switch-SDL2_image` `switch-SDL2_ttf` diff --git a/wiiu/Makefile b/wiiu/Makefile new file mode 100644 index 0000000..23c3650 --- /dev/null +++ b/wiiu/Makefile @@ -0,0 +1,134 @@ +#------------------------------------------------------------------------------- +.SUFFIXES: +#------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) + +include $(DEVKITPRO)/wut/share/wut_rules + +#------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +# ROMFS is a folder to generate app's romfs +#------------------------------------------------------------------------------- +TARGET := Terri-Fried +BUILD := build +SOURCES := source +INCLUDES := include +ROMFS := romfs + +#------------------------------------------------------------------------------- +# options for code generation +#------------------------------------------------------------------------------- +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(MACHDEP) + +CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ + +CFLAGS += `powerpc-eabi-pkg-config --libs sdl2 SDL2_mixer SDL2_image SDL2_ttf` -lwut -lm + +CXXFLAGS := $(CFLAGS) + +ASFLAGS := -g $(MACHDEP) +LDFLAGS := -g $(MACHDEP) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) + +LIBS := `powerpc-eabi-pkg-config --libs sdl2 SDL2_mixer SDL2_image SDL2_ttf` -lwut -lm + +#------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level +# containing include and lib +#------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(WUT_ROOT) + + +#------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) + +#------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#------------------------------------------------------------------------------- + export LD := $(CC) +#------------------------------------------------------------------------------- +else +#------------------------------------------------------------------------------- + export LD := $(CXX) +#------------------------------------------------------------------------------- +endif +#------------------------------------------------------------------------------- + +export SRCFILES := $(CPPFILES) $(CFILES) $(SFILES) +export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean all + +#------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): $(SRCFILES) + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).rpx $(TARGET).elf + +#------------------------------------------------------------------------------- +else +.PHONY: all + +#------------------------------------------------------------------------------- +# romfs +#------------------------------------------------------------------------------- +include $(PORTLIBS_PATH)/wiiu/share/romfs-wiiu.mk +CFLAGS += $(ROMFS_CFLAGS) +CXXFLAGS += $(ROMFS_CFLAGS) +LIBS += $(ROMFS_LIBS) +OFILES += $(ROMFS_TARGET) +#------------------------------------------------------------------------------- + +DEPENDS := $(OFILES:.o=.d) + +#------------------------------------------------------------------------------- +# main targets +#------------------------------------------------------------------------------- +all : $(OUTPUT).rpx + +$(OUTPUT).rpx : $(OUTPUT).elf + +$(OUTPUT).elf : $(OFILES) + +-include $(DEPENDS) + +#------------------------------------------------------------------------------- +endif +#------------------------------------------------------------------------------- \ No newline at end of file diff --git a/wiiu/icon.png b/wiiu/icon.png new file mode 100644 index 0000000..380f3e5 Binary files /dev/null and b/wiiu/icon.png differ diff --git a/wiiu/meta.xml b/wiiu/meta.xml new file mode 100644 index 0000000..f92f732 --- /dev/null +++ b/wiiu/meta.xml @@ -0,0 +1,15 @@ + + + Terri-Fried + PolyMars (Port by Fangal) + 1.0 + 20200505000000 + A Ludum Dare 46 Game + Everyone is dead except for... an egg. Humanity is depending on you to make sure this egg survives. Balance power and precision in Terri-Fried, a game made in 72 hours for Ludum Dare 46 + +Hold the A button and move the left stick or use your fingers to form a trajectory for the egg, and release to send it flying! + + + + + diff --git a/wiiu/romfs/resources/click.wav b/wiiu/romfs/resources/click.wav new file mode 100644 index 0000000..09a3124 Binary files /dev/null and b/wiiu/romfs/resources/click.wav differ diff --git a/wiiu/romfs/resources/coin.png b/wiiu/romfs/resources/coin.png new file mode 100644 index 0000000..2ac238e Binary files /dev/null and b/wiiu/romfs/resources/coin.png differ diff --git a/wiiu/romfs/resources/coin.wav b/wiiu/romfs/resources/coin.wav new file mode 100644 index 0000000..ac728c2 Binary files /dev/null and b/wiiu/romfs/resources/coin.wav differ diff --git a/wiiu/romfs/resources/die.wav b/wiiu/romfs/resources/die.wav new file mode 100644 index 0000000..63cf89b Binary files /dev/null and b/wiiu/romfs/resources/die.wav differ diff --git a/wiiu/romfs/resources/egg.png b/wiiu/romfs/resources/egg.png new file mode 100644 index 0000000..5d23d9d Binary files /dev/null and b/wiiu/romfs/resources/egg.png differ diff --git a/wiiu/romfs/resources/font.otf b/wiiu/romfs/resources/font.otf new file mode 100644 index 0000000..5fc0706 Binary files /dev/null and b/wiiu/romfs/resources/font.otf differ diff --git a/wiiu/romfs/resources/launch.wav b/wiiu/romfs/resources/launch.wav new file mode 100644 index 0000000..b85c109 Binary files /dev/null and b/wiiu/romfs/resources/launch.wav differ diff --git a/wiiu/romfs/resources/lava.png b/wiiu/romfs/resources/lava.png new file mode 100644 index 0000000..4e78ff2 Binary files /dev/null and b/wiiu/romfs/resources/lava.png differ diff --git a/wiiu/romfs/resources/logo.png b/wiiu/romfs/resources/logo.png new file mode 100644 index 0000000..4c60c38 Binary files /dev/null and b/wiiu/romfs/resources/logo.png differ diff --git a/wiiu/romfs/resources/platform.png b/wiiu/romfs/resources/platform.png new file mode 100644 index 0000000..d70474e Binary files /dev/null and b/wiiu/romfs/resources/platform.png differ diff --git a/wiiu/romfs/resources/scorebox.png b/wiiu/romfs/resources/scorebox.png new file mode 100644 index 0000000..556eeae Binary files /dev/null and b/wiiu/romfs/resources/scorebox.png differ diff --git a/wiiu/romfs/resources/select.wav b/wiiu/romfs/resources/select.wav new file mode 100644 index 0000000..b39de7e Binary files /dev/null and b/wiiu/romfs/resources/select.wav differ diff --git a/wiiu/romfs/resources/splash.wav b/wiiu/romfs/resources/splash.wav new file mode 100644 index 0000000..56320a8 Binary files /dev/null and b/wiiu/romfs/resources/splash.wav differ diff --git a/wiiu/romfs/resources/splash_egg.png b/wiiu/romfs/resources/splash_egg.png new file mode 100644 index 0000000..2de1557 Binary files /dev/null and b/wiiu/romfs/resources/splash_egg.png differ diff --git a/wiiu/source/main.cpp b/wiiu/source/main.cpp new file mode 100644 index 0000000..50d1687 --- /dev/null +++ b/wiiu/source/main.cpp @@ -0,0 +1,442 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#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 LoadHighScore() { + FILE *scorefile = fopen("fs:/vol/external01/Terri-Fried/terri-fried-score.bin", "rb"); + + if (!scorefile) + return 0; + + int ret; + fread(&ret, sizeof(int), 1, scorefile); + fclose(scorefile); + + return ret; +} + +void SaveHighScore(int val) { + FILE *scorefile = fopen("fs:/vol/external01/Terri-Fried/terri-fried-score.bin", "wb"); + + fwrite(&val, sizeof(int), 1, scorefile); + fclose(scorefile); +} + +int scoreInt = 0; +int highscoreInt = LoadHighScore(); +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); + SaveHighScore(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); +} + +void Draw_Font(SDL_Renderer *renderer, const char *str, int x, int y, int width, int height, int size, SDL_Color color) { + TTF_Font* font = TTF_OpenFont("resources/font.otf", size); + + SDL_Surface* message_surf = TTF_RenderText_Blended(font, str, color); + SDL_Texture* Message = SDL_CreateTextureFromSurface(renderer, message_surf); + SDL_Rect Message_rect = {x, y, width, height}; + SDL_RenderCopy(renderer, Message, NULL, &Message_rect); + + SDL_DestroyTexture(Message); + SDL_FreeSurface(message_surf); + TTF_CloseFont(font); +} + +void Draw_Trajectory(SDL_Renderer *renderer, int playerX, int playerY, double velocityX, double velocityY) { + double XvelStep = velocityX; + double YvelStep = velocityY; + + double XStep = playerX; + double YStep = playerY; + + double XStepPrev, YStepPrev; + + for(int i = 0; i < 32; i++) { + if(i != 0) { + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); + SDL_RenderDrawLine(renderer, XStep, YStep, XStepPrev, YStepPrev); + } + + XStepPrev = XStep; + YStepPrev = YStep; + + XStep += XvelStep; + YStep += YvelStep; + + YvelStep += gravity; + + if (XStep < 16) { + XvelStep *= -1; + } + if (XStep + 16 > 1280) { + XvelStep *= -1; + } + } +} + +int main(int argc, char **argv) { + WHBProcInit(); + romfsInit(); + chdir("romfs:/"); + + srand(time(NULL)); + + resetScore(); + sprintf(highscore, "BEST: %d", highscoreInt); + + const int screenWidth = 1280; + const int screenHeight = 720; + + int mouseDownX = 0; + int mouseDownY = 0; + + double lavaY = screenHeight - 64; + double timer = 0; + double splashTimer = 0; + + bool firstTime = true; + bool playedSplash = false; + bool playedSelect = false; + + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); + IMG_Init(IMG_INIT_PNG); + TTF_Init(); + + SDL_Window* window = SDL_CreateWindow("Terri-Fried", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenWidth, screenHeight, SDL_WINDOW_FULLSCREEN_DESKTOP); + + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); + + Mix_AllocateChannels(5); + Mix_OpenAudio(48000, AUDIO_S16, 2, 4096); + + SDL_InitSubSystem(SDL_INIT_JOYSTICK); + SDL_JoystickEventState(SDL_ENABLE); + SDL_JoystickOpen(0); + + SDL_Surface* playerSprite_surf = IMG_Load("resources/egg.png"); + SDL_Surface* lavaSprite_surf = IMG_Load("resources/lava.png"); + SDL_Surface* platformSprite_surf = IMG_Load("resources/platform.png"); + SDL_Surface* coinSprite_surf = IMG_Load("resources/coin.png"); + SDL_Surface* scoreBoxSprite_surf = IMG_Load("resources/scorebox.png"); + SDL_Surface* logo_surf = IMG_Load("resources/logo.png"); + SDL_Surface* splashEggSprite_surf = IMG_Load("resources/splash_egg.png"); + + SDL_Texture* playerSprite = SDL_CreateTextureFromSurface(renderer, playerSprite_surf); + SDL_Texture* lavaSprite = SDL_CreateTextureFromSurface(renderer, lavaSprite_surf); + SDL_Texture* platformSprite = SDL_CreateTextureFromSurface(renderer, platformSprite_surf); + SDL_Texture* coinSprite = SDL_CreateTextureFromSurface(renderer, coinSprite_surf); + SDL_Texture* scoreBoxSprite = SDL_CreateTextureFromSurface(renderer, scoreBoxSprite_surf); + SDL_Texture* logo = SDL_CreateTextureFromSurface(renderer, logo_surf); + SDL_Texture* splashEggSprite = SDL_CreateTextureFromSurface(renderer, splashEggSprite_surf); + + // Gives platform texture a brown color + SDL_SetTextureColorMod(platformSprite, 0.698*255, 0.588*255, 0.49*255); + + Mix_Chunk* fxLaunch = Mix_LoadWAV("resources/launch.wav"); + Mix_Chunk* fxClick = Mix_LoadWAV("resources/click.wav"); + Mix_Chunk* fxDeath = Mix_LoadWAV("resources/die.wav"); + Mix_Chunk* fxCoin = Mix_LoadWAV("resources/coin.wav"); + Mix_Chunk* fxSplash = Mix_LoadWAV("resources/splash.wav"); + Mix_Chunk* fxSelect = Mix_LoadWAV("resources/select.wav"); + + bool mouse_down = false; + + int mouse_x = 0, mouse_y = 0; + + int joy_offsetX = 0, joy_offsetY = 0; + + while (WHBProcIsRunning()) { + SDL_Event e; + bool mouse_released = false; + bool mouse_pressed = false; + + while(SDL_PollEvent(&e)) { + switch(e.type) { + case SDL_QUIT: { + WHBProcStopRunning(); + } break; + case SDL_FINGERDOWN: { + mouse_x = e.tfinger.x * screenWidth; + mouse_y = e.tfinger.y * screenHeight; + + mouseDownX = mouse_x; + mouseDownY = mouse_y; + + joy_offsetX = 0; + joy_offsetY = 0; + + mouse_down = true; + mouse_pressed = true; + } break; + case SDL_FINGERMOTION: { + mouse_x = e.tfinger.x * screenWidth; + mouse_y = e.tfinger.y * screenHeight; + } break; + case SDL_FINGERUP: { + mouse_down = false; + mouse_released = true; + } break; + case SDL_JOYBUTTONDOWN: { + if(e.jbutton.button == SDL_CONTROLLER_BUTTON_A) { + mouse_x = e.tfinger.x * screenWidth; + mouse_y = e.tfinger.y * screenHeight; + + mouseDownX = mouse_x; + mouseDownY = mouse_y; + + joy_offsetX = 0; + joy_offsetY = 0; + + mouse_down = true; + mouse_pressed = true; + } + } break; + case SDL_JOYBUTTONUP: { + if(e.jbutton.button == SDL_CONTROLLER_BUTTON_A) { + mouse_down = false; + mouse_released = true; + } + } break; + case SDL_JOYAXISMOTION: { + if(e.jaxis.which == 0) { + if(e.jaxis.axis == 0) + joy_offsetX = e.jaxis.value; + else if(e.jaxis.axis == 1) + joy_offsetY = e.jaxis.value; + } + } break; + } + } + + mouse_x += joy_offsetX/2000; + mouse_y += joy_offsetY/2000; + + if (titleScreen) { + if (splashTimer > 120) { + if (!playedSelect) { + Mix_PlayChannel(-1, fxSelect, 0); + playedSelect = true; + } + + SDL_SetRenderDrawColor(renderer, 0.933 * 255, 0.894 * 255, 0.882 * 255, 1.0 * 255); + SDL_RenderClear(renderer); + + SDL_Rect logo_rect = { screenWidth/2 - 200, screenHeight/2 - 45 - 30, 400, 90 }; + SDL_RenderCopy(renderer, logo, NULL, &logo_rect); + + Draw_Font(renderer, highscore, screenWidth/2 - 37, screenHeight/2 + 10, 74, 32, 32, {0, 0, 0}); + Draw_Font(renderer, "CLICK ANYWHERE TO BEGIN", screenWidth/2 - 134, screenHeight/2 + 50, 268, 32, 32, {178, 150, 125}); + + SDL_RenderPresent(renderer); + + if (mouse_pressed) { + Mix_PlayChannel(-1, fxSelect, 0); + titleScreen = false; + mouseDownX = mouse_x; + mouseDownY = mouse_y; + } + } + else { + if (!playedSplash) { + Mix_PlayChannel(-1, fxSplash, 0); + playedSplash = true; + } + + SDL_SetRenderDrawColor(renderer, 0.933 * 255, 0.894 * 255, 0.882 * 255, 1.0 * 255); + SDL_RenderClear(renderer); + + Draw_Font(renderer, "POLYMARS", screenWidth/2 - 54, screenHeight/2 + 3, 108, 32, 32, {213, 128, 90}); + + SDL_Rect splashEggSprite_rect = { screenWidth/2 - 16, screenHeight/2 - 16 - 23, 32, 32 }; + SDL_RenderCopy(renderer, splashEggSprite, NULL, &splashEggSprite_rect); + + SDL_RenderPresent(renderer); + + splashTimer += 1; + } + } + else { + if (playCoinFX) { + Mix_PlayChannel(-1, fxCoin, 0); + playCoinFX = false; + } + + if (mouse_pressed && player.isOnGround()) { + Mix_PlayChannel(-1, fxClick, 0); + mouseDownX = mouse_x; + mouseDownY = mouse_y; + } + + int velocityX = mouse_x - mouseDownX; + int velocityY = mouse_y - mouseDownY; + + if (mouse_released && player.isOnGround()) { + if (firstTime) { + firstTime = false; + } + else { + Mix_PlayChannel(-1, fxLaunch, 0); + + if(player.isOnPlatform()) + player.setY(player.getY() - 1); + + player.setVelocity((double)velocityX*.08, (double)velocityY*.08); + } + } + + checkPlayerCollision(); + player.updatePosition(); + + if (player.getY() > screenHeight) { + Mix_PlayChannel(-1, fxDeath, 0); + resetGame(); + } + for (int i = 0; i < 4; i++) { + platforms[i].updatePosition(); + } + + lavaY = screenHeight - 43 - sin(timer) * 5; + timer += 0.05; + + SDL_SetRenderDrawColor(renderer, 0.933 * 255, 0.894 * 255, 0.882 * 255, 1.0 * 255); + SDL_RenderClear(renderer); + + if (mouse_down && player.isOnGround()) { + Draw_Trajectory(renderer, player.getX() + 16, player.getY() + 16, (double)velocityX*.08, (double)velocityY*.08); + } + + for (int i = 0; i < 4; i++) { + SDL_Rect platformSprite_rect = { platforms[i].getX(), platforms[i].getY(), 100, 32 }; + SDL_RenderCopy(renderer, platformSprite, NULL, &platformSprite_rect); + + if (platforms[i].getHasCoin()) { + SDL_Rect coinSprite_rect = { platforms[i].getCoinX(), platforms[i].getCoinY(), 24, 24 }; + SDL_RenderCopy(renderer, coinSprite, NULL, &coinSprite_rect); + } + } + + SDL_Rect playerSprite_rect = { player.getX(), player.getY(), 32, 32 }; + SDL_RenderCopy(renderer, playerSprite, NULL, &playerSprite_rect); + + SDL_Rect lavaSprite_rect = { 0, lavaY, 1280, 48 }; + SDL_RenderCopy(renderer, lavaSprite, NULL, &lavaSprite_rect); + + SDL_Rect scoreBoxSprite_rect = { 17, 17, 102, 70 }; + SDL_RenderCopy(renderer, scoreBoxSprite, NULL, &scoreBoxSprite_rect); + + Draw_Font(renderer, score, 28, 20, 75, 64, 64, {0, 0, 0}); + Draw_Font(renderer, highscore, 17, 90, 74, 32, 32, {0, 0, 0}); + + SDL_RenderPresent(renderer); + } + + } + + SDL_DestroyTexture(playerSprite); + SDL_DestroyTexture(lavaSprite); + SDL_DestroyTexture(platformSprite); + SDL_DestroyTexture(coinSprite); + SDL_DestroyTexture(scoreBoxSprite); + SDL_DestroyTexture(logo); + SDL_DestroyTexture(splashEggSprite); + + SDL_FreeSurface(playerSprite_surf); + SDL_FreeSurface(lavaSprite_surf); + SDL_FreeSurface(platformSprite_surf); + SDL_FreeSurface(coinSprite_surf); + SDL_FreeSurface(scoreBoxSprite_surf); + SDL_FreeSurface(logo_surf); + SDL_FreeSurface(splashEggSprite_surf); + + Mix_FreeChunk(fxClick); + Mix_FreeChunk(fxLaunch); + Mix_FreeChunk(fxDeath); + Mix_FreeChunk(fxCoin); + Mix_FreeChunk(fxSplash); + Mix_FreeChunk(fxSelect); + + Mix_CloseAudio(); + TTF_Quit(); + IMG_Quit(); + SDL_Quit(); + romfsExit(); + WHBProcShutdown(); + return 0; +} diff --git a/wiiu/source/platform.cpp b/wiiu/source/platform.cpp new file mode 100644 index 0000000..ef51856 --- /dev/null +++ b/wiiu/source/platform.cpp @@ -0,0 +1,74 @@ +#include "platform.h" +#include + +const int screenWidth = 1280; +const int screenHeight = 720; + +Platform::Platform(int index) { + width = 100; + height = 32; + + x = rand()% 1140 + 20; + y = 0 - height - (index * 135); + + 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; + } +} diff --git a/wiiu/source/platform.h b/wiiu/source/platform.h new file mode 100644 index 0000000..3d4c66b --- /dev/null +++ b/wiiu/source/platform.h @@ -0,0 +1,26 @@ +#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 diff --git a/wiiu/source/player.cpp b/wiiu/source/player.cpp new file mode 100644 index 0000000..a4b7c9a --- /dev/null +++ b/wiiu/source/player.cpp @@ -0,0 +1,78 @@ +#include "player.h" + +#include +#include + +const double pi = 3.1415926535897; +const int gravity = 1; +const int screenWidth = 1280; +const int screenHeight = 720; + +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){x, 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 > 1280) + velocity.x *= -1; +} + diff --git a/wiiu/source/player.h b/wiiu/source/player.h new file mode 100644 index 0000000..ebd41ca --- /dev/null +++ b/wiiu/source/player.h @@ -0,0 +1,35 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include + +typedef struct { + int x; + int y; +} Vector2; + +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