Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate map into chiventure gui split screen #1121

Open
wants to merge 59 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ce2d605
Created ui_enhancement.h and draw_images.h
May 1, 2021
04c7f33
Delted ui_enhancement.h
May 2, 2021
051f1df
Removed draw_images.h
May 2, 2021
645581c
Added draw_images.h and .c
May 6, 2021
b4d0b43
Added draw_images
May 17, 2021
ad272d0
Added some comments on potential modifications
May 17, 2021
0f02cab
Added starting description from ctx
May 17, 2021
1159d77
Fixed descriptions
May 17, 2021
7b26d8a
Changed gui.c
May 17, 2021
10ade90
Changed gui.c
May 17, 2021
af8c57a
Merged dev branch
May 17, 2021
39458b9
Changed cmake
May 17, 2021
6c57e82
Some minor diagnostic changes to gui.c
May 18, 2021
b47668e
Removing the draw_images.h include fixed textbox behavior
May 19, 2021
313c00a
Removed draw room
May 19, 2021
f2a12c8
Removed draw_room
May 19, 2021
36f182f
Removed extra BeginDrawing and EndDrawing function calls
May 19, 2021
5d62089
No bugs
May 19, 2021
22824ec
draw_images.c with the map not the ball
May 20, 2021
880bcc1
Merge remote-tracking branch 'refs/remotes/origin/gui/split_screen_up…
May 20, 2021
9a918bf
Add files via upload
grkapoor17 May 20, 2021
817a467
Updated gui
May 20, 2021
0c2d9e2
Updated chiventure.c to call run_gui
May 20, 2021
36ea2af
Removed include draw_images
May 21, 2021
548d9c0
Updated header comment
May 21, 2021
51e32d1
Removed draw_images from CMake
May 21, 2021
0c47273
Changed
May 21, 2021
f226cca
Updated gui.c
May 26, 2021
839178d
update draw_images
May 26, 2021
3cf8f90
Updated draw_images
May 26, 2021
f8be242
Updates
May 26, 2021
c0258cd
created sample game
May 26, 2021
d802b3f
created sample game
May 26, 2021
37c66a4
Merge branch 'dev' into gui/split_screen_update
MaxineK36 May 26, 2021
6488a24
made changes
May 27, 2021
db6850b
Merge branch 'gui/split_screen_update' of https://github.com/uchicago…
May 27, 2021
ddef478
added example executable
May 27, 2021
75dfe35
finished gui_sample_game and completed draw map inside gui
May 27, 2021
21c1402
Merge branch 'dev' into gui/split_screen_update
MaxineK36 May 28, 2021
142129d
Add files via upload
grkapoor17 May 28, 2021
5e82d10
Updated gui.c and added images to examples
May 28, 2021
7919e61
Updated gui_sample_game
May 28, 2021
3eb2a26
Reverted draw_room in gui.c
May 28, 2021
747e97a
added comments to gui.c
May 28, 2021
f49b364
moving sample game to separate branch
May 28, 2021
b6e2109
moving sample game
May 28, 2021
4708d07
removing room images
May 28, 2021
5999c80
moving sample game to branch gui/sample_game
May 28, 2021
59120dd
trying to fix draw_images module
May 28, 2021
a81db59
fixed styling of comments
May 28, 2021
ff9132d
fixed key range
Jun 1, 2021
0ac878c
Updated draw_images
Jun 2, 2021
20b0206
Updated CMake
Jun 2, 2021
bbaa0f7
Integrated draw_images with sample game
Jun 2, 2021
5daf691
Merge branch 'dev' into gui/split_screen_update
MaxineK36 Jun 2, 2021
ad65adf
final commits to draw_images
Jun 3, 2021
3971d65
Merge branch 'dev' into gui/split_screen_update
MaxineK36 Jun 3, 2021
cc74e79
typo
MaxineK36 Jun 3, 2021
bf74d76
Update draw_images.c
MaxineK36 Jun 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/ui/draw_images.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef DRAW_IMAGES_H
#define DRAW_IMAGES_H

#include "game-state/room.h"

/* draw_room_gui
* Draws a room based on its room id for the split screen in chiventure
*
* Parameters:
* - width: integer that defines the width of the split screen
* - height: integer that defines the height of the split screen
* - pos_x: integer that defines the x-coordinate of the center of the image
* - pos_y: integer that defines the x-coordinate of the center of the image
* - filepath: string that contains the filepath to the directory containing the images
* - curr_room: room_t that defines the current room the player is in
*
* No value is returned
*/
void draw_room_gui(int width, int height, int pos_x, int pos_y, char *filepath, room_t *curr_room);

/* draw_map
* Draws the map in the top left corner of the split screen that updates the center room
* when the player moves rooms
*
* Parameters:
* - width: integer that defines the width of the split screen
* - height: integer that defines the height of the split screen
* - curr_room: room_t that defines the current room the player is in
*
* No value is returned
*/
void draw_map(int width, int height, room_t *curr_room);

#endif
3 changes: 2 additions & 1 deletion src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ add_library(ui
src/print_functions.c
src/ui.c
src/ui_ctx.c
src/window.c)
src/window.c
src/draw_images.c)

if (raylib_FOUND)
target_sources(ui PRIVATE src/gui.c)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (raylib_FOUND)
add_executable(split_screen_example
split_screen_example.c)
add_executable(split_screen_map_example
split_screen_map_example.c)
split_screen_map_example.c)
add_executable(gui_sample_game
gui_sample_game.c)

Expand Down
137 changes: 7 additions & 130 deletions src/ui/examples/gui_sample_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "raylib.h"
#include "game-state/game.h"
#include "game-state/room.h"
#include "ui/draw_images.h"


chiventure_ctx_t *create_sample_ctx()
MaxineK36 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -134,27 +135,10 @@ int main() {
int height = SCREEN_HEIGHT/2;
int pos_x = SCREEN_WIDTH/4;
int pos_y = SCREEN_HEIGHT/10;
room_t *curr_room = ctx->game->curr_room;
char *filepath = strdup("../../../../src/ui/examples/");

/* Loading just one image is a temporary solution
In the future, we will use a more generic path so that we can load
game-specific images */
char filename[100] = "../../../../src/ui/examples/";

strcat(filename, ctx->game->curr_room->room_id);

strcat(filename, ".png");

Image room = LoadImage(filename);

ImageResize(&room, width, height);

/* Image converted to texture, uploaded to GPU memory (VRAM) */
Texture2D texture = LoadTextureFromImage(room);

/* Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM */
UnloadImage(room);

DrawTexture(texture, pos_x, pos_y, WHITE);
draw_room_gui(width, height, pos_x, pos_y, filepath, curr_room);

DrawRectangleRec(textBox, WHITE);
DrawRectangle(POS_ZERO, SCREEN_HEIGHT - heightbuf2, SCREEN_WIDTH, rectHeight, WHITE);
Expand All @@ -180,117 +164,10 @@ int main() {
Font test = GetFontDefault();
DrawTextRec(test, output_text, output, fontSize, fontSpacing, true, BLACK);

int map_width, map_height, map_room_width, map_room_height, map_topX, map_topY, ball_rad;
map_width = height / 2;
map_height = width / 5;
map_room_width = map_width / 3;
map_room_height = map_height / 3;
map_topX = 5;
map_topY = 5;
ball_rad = map_room_width / 10;
room_t *curr_room = ctx->game->curr_room;

Color colors[8];

colors[0] = RED;
colors[1] = PINK;
colors[2] = PURPLE;
colors[3] = BLUE;
colors[4] = YELLOW;
colors[5] = GREEN;
colors[6] = ORANGE;
colors[7] = DARKGREEN;

// map background
DrawRectangle(map_topX, map_topY, map_width, map_height, BLACK);

int posX = map_topX + map_width/2 - map_room_width/2;
int posY = map_topY + map_height/2 - map_room_height/2;
// current room
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[0]);

//draw surrounding rooms around current room
if (find_room_from_dir(curr_room, "EAST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, posY, map_room_width, map_room_height, colors[1]);

room_t *east = find_room_from_dir(curr_room, "EAST");
// draw rooms above and below the room that is east of the current room
// northeast and southeast rooms to the current room
if (find_room_from_dir(east, "NORTH") != NULL)
{
int tempY = posY - map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[5]);
}
if (find_room_from_dir(east, "SOUTH") != NULL)
{
int tempY = posY + map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[6]);
}

}
if (find_room_from_dir(curr_room, "WEST") != NULL)
{
int tempX = posX - map_room_width;
DrawRectangle(tempX, posY, map_room_width, map_room_height, colors[2]);

room_t *west = find_room_from_dir(curr_room, "WEST");
// draw rooms above and below the room that is west of the current room
// northwest and southwest rooms to the current room
if (find_room_from_dir(west, "NORTH") != NULL)
{
int tempY = posY - map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[7]);
}
if (find_room_from_dir(west, "SOUTH") != NULL)
{
int tempY = posY + map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[8]);
}
}
if (find_room_from_dir(curr_room, "SOUTH") != NULL)
{
int tempY = posY + map_room_height;
DrawRectangle(posX, tempY, map_room_width, map_room_height, colors[3]);

room_t *south = find_room_from_dir(curr_room, "SOUTH");
// draw rooms next to the room that is south of the current room
// southeast and southwest rooms to the current room
if (find_room_from_dir(south, "EAST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[6]);
}
if (find_room_from_dir(south, "WEST") != NULL)
{
int tempX = posX - map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[8]);
}
}
if (find_room_from_dir(curr_room, "NORTH") != NULL)
{
int tempY = posY - map_room_height;
DrawRectangle(posX, tempY, map_room_width, map_room_height, colors[4]);

room_t *north = find_room_from_dir(curr_room, "NORTH");
// draw rooms next to the room that is north of the current room
// northeast and northwest rooms to the current room
if (find_room_from_dir(north, "WEST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[7]);
}
if (find_room_from_dir(north, "EAST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[5]);
}
}
/* Drawing the Map for the upper half of the split screen */

draw_map(width, height, curr_room);

//draws player position as ball in the middle of map screen and inside current room
DrawCircle(map_topX + map_width/2, map_topY + map_height/2, ball_rad, WHITE);

EndDrawing();
}

Expand Down
144 changes: 144 additions & 0 deletions src/ui/src/draw_images.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#include <stdio.h>
#include <stdlib.h>
#include "raylib.h"
#include "ui/draw_images.h"


#define MAX_FILENAME_LEN (100)

/* See draw_images.h for documentation */
void draw_room_gui(int width, int height, int pos_x, int pos_y, char *filepath, room_t *curr_room)
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're using strcat, you should start by callocing a new string of sufficient length, and the strcat'ing onto that.
You can also do this via sprintf: if your new string is called image_filename and has been calloced, you should be able to do sprintf(image_filename, "%s%s.%s", filepath, curr_room, ".png")


char *image_filename = calloc(100, sizeof(char));
sprintf(image_filename, "%s%s.%s", filepath, curr_room->room_id, "png");

Image room = LoadImage(filepath);

ImageResize(&room, width, height);

/* Image converted to texture, uploaded to GPU memory (VRAM) */
Texture2D texture = LoadTextureFromImage(room);

/* Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM */
UnloadImage(room);

DrawTexture(texture, pos_x, pos_y, WHITE);
}

MaxineK36 marked this conversation as resolved.
Show resolved Hide resolved
/* See draw_images.h for documentation */
void draw_map(int width, int height, room_t *curr_room)
{
int map_width, map_height, map_room_width, map_room_height, map_topX, map_topY, ball_rad;
map_width = height / 2;
map_height = width / 5;
map_room_width = map_width / 3;
map_room_height = map_height / 3;
map_topX = 5;
map_topY = 5;
ball_rad = map_room_width / 10;

Color colors[8];

colors[0] = RED;
colors[1] = PINK;
colors[2] = PURPLE;
colors[3] = BLUE;
colors[4] = YELLOW;
colors[5] = GREEN;
colors[6] = ORANGE;
colors[7] = DARKGREEN;

/* map background */
DrawRectangle(map_topX, map_topY, map_width, map_height, BLACK);

int posX = map_topX + map_width / 2 - map_room_width / 2;
int posY = map_topY + map_height / 2 - map_room_height / 2;

/* draw current room */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a blank line between lines 59 and 60

DrawRectangle(posX, posY, map_room_width, map_room_height, colors[0]);

/* draw surrounding rooms around current room */
if (find_room_from_dir(curr_room, "EAST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, posY, map_room_width, map_room_height, colors[1]);

room_t *east = find_room_from_dir(curr_room, "EAST");
/* draw rooms above and below the room that is east of the current room
northeast and southeast rooms to the current room */
if (find_room_from_dir(east, "NORTH") != NULL)
MaxineK36 marked this conversation as resolved.
Show resolved Hide resolved
{
int tempY = posY - map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[5]);
}
if (find_room_from_dir(east, "SOUTH") != NULL)
{
int tempY = posY + map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[6]);
}
}
if (find_room_from_dir(curr_room, "WEST") != NULL)
{
int tempX = posX - map_room_width;
DrawRectangle(tempX, posY, map_room_width, map_room_height, colors[2]);

room_t *west = find_room_from_dir(curr_room, "WEST");
/* draw rooms above and below the room that is west of the current room
northwest and southwest rooms to the current room */
if (find_room_from_dir(west, "NORTH") != NULL)
{
int tempY = posY - map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[7]);
}
if (find_room_from_dir(west, "SOUTH") != NULL)
{
int tempY = posY + map_room_height;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[8]);
}
}
if (find_room_from_dir(curr_room, "SOUTH") != NULL)
{
int tempY = posY + map_room_height;
DrawRectangle(posX, tempY, map_room_width, map_room_height, colors[3]);

room_t *south = find_room_from_dir(curr_room, "SOUTH");
/* draw rooms next to the room that is south of the current room
southeast and southwest rooms to the current room */
if (find_room_from_dir(south, "EAST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[6]);
}
if (find_room_from_dir(south, "WEST") != NULL)
{
int tempX = posX - map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[8]);
}
}
if (find_room_from_dir(curr_room, "NORTH") != NULL)
{
int tempY = posY - map_room_height;
DrawRectangle(posX, tempY, map_room_width, map_room_height, colors[4]);

room_t *north = find_room_from_dir(curr_room, "NORTH");
/* draw rooms next to the room that is north of the current room
northeast and northwest rooms to the current room */
if (find_room_from_dir(north, "WEST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[7]);
}
if (find_room_from_dir(north, "EAST") != NULL)
{
int tempX = posX + map_room_width;
DrawRectangle(tempX, tempY, map_room_width, map_room_height, colors[5]);
}
}

/* draws player position as ball in the middle of map screen and inside current room */
DrawCircle(map_topX + map_width / 2, map_topY + map_height / 2, ball_rad, WHITE);
}


Loading