diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..843b158 --- /dev/null +++ b/Makefile @@ -0,0 +1,150 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif + +include $(DEVKITPPC)/wii_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 +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- + +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) +CXXFLAGS = $(CFLAGS) + +LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +# the order can-be/is critical +#--------------------------------------------------------------------------------- +LIBS := -lgrrlib -lfreetype -lbz2 -lpngu -lpng -ljpeg -lz -lfat +LIBS += -lwiiuse +#LIBS += -lmodplay -laesnd +LIBS += -lbte -logc -lm + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) + +#--------------------------------------------------------------------------------- +# 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 VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) + +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBOGC_INC) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol + +#--------------------------------------------------------------------------------- +run: + wiiload $(TARGET).dol + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).dol: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) + +$(OFILES_SOURCES) : $(HFILES) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .jpg extension +#--------------------------------------------------------------------------------- +%.jpg.o : %.jpg +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +#--------------------------------------------------------------------------------- +# This rule links in binary data with the .png extension +#--------------------------------------------------------------------------------- +%.png.o : %.png +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/README.md b/README.md index 0f4f0ba..721274e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,2 @@ -# FlappyBird-Wii - -A simple Flappy Bird port to the Wii device. \ No newline at end of file +# FlappyWii +A simple Flappy Bird port to the Wii device. diff --git a/data/background.png b/data/background.png new file mode 100644 index 0000000..59d4f58 Binary files /dev/null and b/data/background.png differ diff --git a/data/bird.png b/data/bird.png new file mode 100644 index 0000000..92abb54 Binary files /dev/null and b/data/bird.png differ diff --git a/data/ground.png b/data/ground.png new file mode 100644 index 0000000..944f908 Binary files /dev/null and b/data/ground.png differ diff --git a/data/pipes.png b/data/pipes.png new file mode 100644 index 0000000..e101469 Binary files /dev/null and b/data/pipes.png differ diff --git a/resources/Background/Background1.png b/resources/Background/Background1.png new file mode 100644 index 0000000..59d4f58 Binary files /dev/null and b/resources/Background/Background1.png differ diff --git a/resources/Background/Background2.png b/resources/Background/Background2.png new file mode 100644 index 0000000..c6a4c4e Binary files /dev/null and b/resources/Background/Background2.png differ diff --git a/resources/Background/Background3.png b/resources/Background/Background3.png new file mode 100644 index 0000000..91d4246 Binary files /dev/null and b/resources/Background/Background3.png differ diff --git a/resources/Background/Background4.png b/resources/Background/Background4.png new file mode 100644 index 0000000..f3b9917 Binary files /dev/null and b/resources/Background/Background4.png differ diff --git a/resources/Background/Background5.png b/resources/Background/Background5.png new file mode 100644 index 0000000..8523545 Binary files /dev/null and b/resources/Background/Background5.png differ diff --git a/resources/Background/Background6.png b/resources/Background/Background6.png new file mode 100644 index 0000000..36adcec Binary files /dev/null and b/resources/Background/Background6.png differ diff --git a/resources/Player/bird1.png b/resources/Player/bird1.png new file mode 100644 index 0000000..92abb54 Binary files /dev/null and b/resources/Player/bird1.png differ diff --git a/resources/Player/bird2.png b/resources/Player/bird2.png new file mode 100644 index 0000000..387250a Binary files /dev/null and b/resources/Player/bird2.png differ diff --git a/resources/Player/bird3.png b/resources/Player/bird3.png new file mode 100644 index 0000000..5841b43 Binary files /dev/null and b/resources/Player/bird3.png differ diff --git a/resources/Player/gif/bird1gif.gif b/resources/Player/gif/bird1gif.gif new file mode 100644 index 0000000..2ac5020 Binary files /dev/null and b/resources/Player/gif/bird1gif.gif differ diff --git a/resources/Player/gif/bird2gif.gif b/resources/Player/gif/bird2gif.gif new file mode 100644 index 0000000..9e7764e Binary files /dev/null and b/resources/Player/gif/bird2gif.gif differ diff --git a/resources/Player/gif/bird3gif.gif b/resources/Player/gif/bird3gif.gif new file mode 100644 index 0000000..e2ed0e5 Binary files /dev/null and b/resources/Player/gif/bird3gif.gif differ diff --git a/resources/Tileset/Style 1/OldS2.png b/resources/Tileset/Style 1/OldS2.png new file mode 100644 index 0000000..df1eb20 Binary files /dev/null and b/resources/Tileset/Style 1/OldS2.png differ diff --git a/resources/Tileset/Style 1/PipeStyle1.png b/resources/Tileset/Style 1/PipeStyle1.png new file mode 100644 index 0000000..e101469 Binary files /dev/null and b/resources/Tileset/Style 1/PipeStyle1.png differ diff --git a/resources/Tileset/Style 1/TileStyle1.png b/resources/Tileset/Style 1/TileStyle1.png new file mode 100644 index 0000000..944f908 Binary files /dev/null and b/resources/Tileset/Style 1/TileStyle1.png differ diff --git a/resources/Tileset/Style 2/OldS2.png b/resources/Tileset/Style 2/OldS2.png new file mode 100644 index 0000000..6640972 Binary files /dev/null and b/resources/Tileset/Style 2/OldS2.png differ diff --git a/resources/Tileset/Style 2/PipeStyle2.png b/resources/Tileset/Style 2/PipeStyle2.png new file mode 100644 index 0000000..281a0ca Binary files /dev/null and b/resources/Tileset/Style 2/PipeStyle2.png differ diff --git a/resources/Tileset/Style 2/TileStyle2.png b/resources/Tileset/Style 2/TileStyle2.png new file mode 100644 index 0000000..2916be0 Binary files /dev/null and b/resources/Tileset/Style 2/TileStyle2.png differ diff --git a/resources/Tileset/Style 3/OldS3.png b/resources/Tileset/Style 3/OldS3.png new file mode 100644 index 0000000..e68df1e Binary files /dev/null and b/resources/Tileset/Style 3/OldS3.png differ diff --git a/resources/Tileset/Style 3/PipeStyle3.png b/resources/Tileset/Style 3/PipeStyle3.png new file mode 100644 index 0000000..810d70e Binary files /dev/null and b/resources/Tileset/Style 3/PipeStyle3.png differ diff --git a/resources/Tileset/Style 3/TileStyle3.png b/resources/Tileset/Style 3/TileStyle3.png new file mode 100644 index 0000000..157fc30 Binary files /dev/null and b/resources/Tileset/Style 3/TileStyle3.png differ diff --git a/source/main.cpp b/source/main.cpp new file mode 100644 index 0000000..dce8c43 --- /dev/null +++ b/source/main.cpp @@ -0,0 +1,427 @@ +// Includes +/// System +#include +#include +/// Wii +#include +/// GRRLIB +#include + +// Images +#include "bird_png.h" +#include "pipes_png.h" +#include "background_png.h" +#include "ground_png.h" + +// Constants +#define SCR_WIDTH 640 +#define SCR_HEIGHT 480 + +#define PIPE_SPEED 2.5f +#define PIPE_SPACE 75 +#define PIPE_CHANCE 150 + +#define BIRD_GRAV 0.4f +#define BIRD_POWER 8 +#define BIRD_SIZE 2 + +#define CHNK_SIZE 5 + +// Variables +u32 wpad_input; +float game_time = 0; +int screen = 0; +int birdPresses = false; +bool running = true; +bool dead = false; + +// Classes +class Pipe{ +private: + // Variables + float bodyLength; + GRRLIB_texImg* sprite; + +public: + // Variables + float x, y; + + // Constructor + Pipe(int offset){ + // Loading texture + sprite = GRRLIB_LoadTexture(pipes_png); + GRRLIB_InitTileSet(sprite, 32, 29, 0); // 4x8 image scale + + // Setting position + x = SCR_WIDTH + 32 + (offset * 64 * 6); + + // What's our length? + bodyLength = 5; + newHeight(); + } + + // Functions + void newHeight(){ + // Random value + float randomHeightModi = ((float)(rand() % 10)) / 10.0f; + y = (randomHeightModi * PIPE_CHANCE) + (SCR_HEIGHT / 2) - (PIPE_CHANCE / 2); + } + void move(){ + // Dead? + if(dead) {return;} + + // Moving + x -= PIPE_SPEED; + + // Tiling + if(x < -64){ + x = SCR_WIDTH + 32; + newHeight(); + } + } + void draw(){ + // Drawing + // Higher End + /// Head + GRRLIB_DrawTile(x,y - PIPE_SPACE, sprite, 0, 2,-2, 0xFFFFFFFF, 2); + + /// Body + for(int i = 0; i < bodyLength; i++){ + GRRLIB_DrawTile(x,y-(58*(i+1)) - PIPE_SPACE, sprite, 0, 2,-2, 0xFFFFFFFF, 6); + } + + // Lower end + /// Head + GRRLIB_DrawTile(x,y + PIPE_SPACE, sprite, 0, 2,2, 0xFFFFFFFF, 2); + + /// Body + for(int i = 0; i < bodyLength; i++){ + GRRLIB_DrawTile(x,y+(58*(i+1)) + PIPE_SPACE, sprite, 0, 2,2, 0xFFFFFFFF, 6); + } + + } +}; +class Bird{ +private: + // Variables + float x, y; + float vx, vy; + float frame_time; + float r; + + int frame; + GRRLIB_texImg* sprite; + +public: + // Constructor + Bird(){ + + // Creating image + sprite = GRRLIB_LoadTexture(bird_png); + GRRLIB_InitTileSet(sprite, 16,16, 0); + + // Setting X and Y + x = SCR_WIDTH / 4; + y = 0; + + // Setting velocity + vx = 0; + vy = 0; + + // Setting rotation + r = 0; + + // Setting frame stuff + frame_time = 0; + frame = 0; + } + + // Functions + void falling(){ + // Falling + vy += BIRD_GRAV; + y += vy; + + // Rotation + if(vy > 0){ // Down + r = r+0.125f*((vy * 6)-r); + } + else{ // Up + r = -25; + } + } + void hover(){ + y = (sinf(game_time) * 10) + (SCR_HEIGHT / 2); + } + void move(){ + // Dead? + if(dead){ + if(y < SCR_HEIGHT - (16 * BIRD_SIZE)){ + falling(); + } + else{ + vy = 0; + y = SCR_HEIGHT - (16 * BIRD_SIZE); + } + return; + } + + // Falling + falling(); + + // Flapping + if((wpad_input & WPAD_BUTTON_A) + && birdPresses > 1){ + vy = -BIRD_POWER; + frame = 3; + } + + // Fell into ground? + if(y + (16 * BIRD_SIZE) > SCR_HEIGHT - 32){ + die(); + } + + // Inc Bird Presses + birdPresses++; + } + void draw(){ + // Switch frame? + switch(screen){ + case 0: // Waiting for bird to launch + if(frame_time > 1.5f){ + frame_time = 0; + if(frame >= 3) {frame = 0;} + else {frame += 1;} + } + else{ + frame_time += 0.1f; + } + break; + case 1: // Launching! + if(frame_time > 0.5f){ + frame_time = 0; + if(frame > 0) {frame--;} + else {frame = 0;} + } + else{ + frame_time += 0.1f; + } + break; + } + + // Drawing + GRRLIB_DrawTile(x,y, sprite, r, BIRD_SIZE,BIRD_SIZE, 0xFFFFFFFF, frame); + } + void die(){ + if(dead) {return;} + + dead = true; + vy = 0; + } + void collide(Pipe& pipe){ + if(x + 32 > pipe.x + && x < pipe.x + 32 + && (y + 32 > pipe.y + PIPE_SPACE + || y < pipe.y - PIPE_SPACE)){ + die(); + } + } +}; +class GroundChunk{ +private: + // Variables + GRRLIB_texImg* sprite; + +public: + // Variables + float x; + + // Constructor + GroundChunk(int index){ + // Setting position + x = (index * 32 * CHNK_SIZE); + + // Creating sprite + sprite = GRRLIB_LoadTexture(ground_png); + GRRLIB_InitTileSet(sprite, 16,16,0); + } + + // Functions + void move(){ + x -= PIPE_SPEED; + if(x + 32 * CHNK_SIZE <= 0){ + x = SCR_WIDTH; + } + } + void draw(){ + for(int i = 0; i < CHNK_SIZE; i++){ // Remember, 20 tiles == screen width + GRRLIB_DrawTile(x + i * 32,SCR_HEIGHT-32, sprite, 0, 2,2, 0xFFFFFFFF, 27); + } + } +}; +class BackgroundChunk{ +private: + // Variables + GRRLIB_texImg* sprite; + +public: + // Variables + float x; + + // Constructor + BackgroundChunk(int index){ + // Loading texture + sprite = GRRLIB_LoadTexture(background_png); + + // Setting position + x = index * 320; + } + + // Functions + void move(){ + // Moving left + x -= PIPE_SPEED / 2; + + // Tiling + if(x + 320 <= 0){ + x = SCR_WIDTH; + } + } + void draw(){ + GRRLIB_DrawImg(x,0, sprite, 0, 1.25f,1.875f, 0xFFFFFFFF); + } +}; + +// Functions +/// System +int init(){ + // Initialise the Graphics & Video subsystem + GRRLIB_Init(); + + // Initialise the Wiimotes + WPAD_Init(); + + // Random? + srand(time(NULL)); + + // Exit + return 0; +} +int update(){ + // Scan wiimote input + WPAD_ScanPads(); + WPAD_SetVRes(0, SCR_WIDTH, SCR_HEIGHT); + + // Get input + wpad_input = WPAD_ButtonsDown(0); + + // If [HOME] was pressed on the first Wiimote, break out of the loop + if (wpad_input & WPAD_BUTTON_HOME) {running = false;} + + // Exit + return 0; +} +/// Game +int restart(){ + if(!dead) {return 0;} + + if(wpad_input & WPAD_BUTTON_A){ + birdPresses = 0; + dead = false; + return 1; + } + return 0; +} + +// Entry point +int main(int argc, char **argv) { + init(); + + // Create bird + Bird bird; + + // Create pipes + Pipe pipes[2] = {Pipe(0), Pipe(1)}; + + // Background + BackgroundChunk backgrounds[3] = { + BackgroundChunk(0), + BackgroundChunk(1), + BackgroundChunk(2) + }; + + // Ground + GroundChunk chunks[5] = { + GroundChunk(0), + GroundChunk(1), + GroundChunk(2), + GroundChunk(3), + GroundChunk(4) + }; + + // Game loop + while(running) { + // Update + update(); + if(restart()){ + bird = Bird(); + pipes[0] = Pipe(0); + pipes[1] = Pipe(1); + for(int i = 0; i < 5; i++) {chunks[i].x = i * 32 * CHNK_SIZE;} + } + + // Drawing background + //GRRLIB_DrawImg(SCR_WIDTH/2,0, bckgrnd, 0, 1.25f,1.875f, 0xFFFFFFFF); + for(int i = 0; i < 3; i++){ + if(!dead) {backgrounds[i].move();} + backgrounds[i].draw(); + } + + // Screens? + switch(screen){ + case 0: // Bird waiting to launch + // Game code.. + game_time += 0.1f; + bird.hover(); + + /// Switching scenes + if(wpad_input & WPAD_BUTTON_A){ + screen = 1; + } + + // Render code.. + bird.draw(); + + break; + case 1: // Launching! + // Game code.. + bird.move(); + for(int i = 0; i < 2; i++){ + bird.collide(pipes[i]); + pipes[i].move(); + } + + // Render code.. + bird.draw(); + for(int i = 0; i < 2; i++){ + pipes[i].draw(); + } + break; + } + + // Ground + for(int i = 0; i < 5; i++) { + if(!dead) {chunks[i].move();} + chunks[i].draw(); + } + + // Render the frame buffer to the screen + GRRLIB_Render(); + } + + // Properly exiting GRRLIB + GRRLIB_Exit(); + + // Exit app + return 0; +}