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 38 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
32 changes: 32 additions & 0 deletions include/ui/draw_images.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef DRAW_IMAGES_H
#define DRAW_IMAGES_H

#include "common/ctx.h"
#include "ui/ui_ctx.h"


/* draw_room
* Draws a room based on its room number for the split screen in chiventure
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it now draws based on room id; please update this header accordingly

*
* Parameters:
* - 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
* - room_number: integer that defines the room
* - room_number: integer that defines the room
*
* No value is returned
*/
void draw_room_gui(int width, int height, int pos_x, int pos_y, 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.

nit: add a line break after line 19

/* draw_object
* Draws an object based on its item ID
*
* Parameters:
* - item_id: a string that defines each item
*
* No value is returned
*/
void draw_object(char *item_id);

void draw_map(int width, int height, room_t *curr_room);

#endif
3 changes: 1 addition & 2 deletions include/ui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
*/
void run_gui(chiventure_ctx_t *ctx);

#endif

#endif
4 changes: 3 additions & 1 deletion src/ui/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
if (raylib_FOUND)
set(UI_EXAMPLES map_raylib_example split_screen_example split_screen_map_example)
set(UI_EXAMPLES map_raylib_example split_screen_example split_screen_map_example gui_sample_game)

add_executable(map_raylib_example
map_raylib_example.c)
add_executable(split_screen_example
split_screen_example.c)
add_executable(split_screen_map_example
split_screen_map_example.c)
add_executable(gui_sample_game
gui_sample_game.c)

# Link with chiventure libraries
foreach(example ${UI_EXAMPLES})
Expand Down
36 changes: 36 additions & 0 deletions src/ui/examples/gui_sample_game.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "action_management/actionmanagement.h"
#include "ui/gui.h"
#include "raylib.h"
#include "game-state/game.h"
#include "game-state/room.h"


chiventure_ctx_t *create_sample_ctx()
MaxineK36 marked this conversation as resolved.
Show resolved Hide resolved
{
game_t *game = game_new("Welcome to Chiventure!");
room_t *room1 = room_new("room1", "This is room 1", "Verily, this is the first room.");
room_t *room2 = room_new("room2", "This is room 2", "Truly, this is the second room.");
room_t *room3 = room_new("room3", "This is room 3", "Wow, this is the final room.");

add_room_to_game(game, room1);
add_room_to_game(game, room2);
add_room_to_game(game, room3);

game->curr_room = room1;
create_connection(game, "room1", "room2", "NORTH");
create_connection(game, "room2", "room3", "EAST");

/* Create context */
chiventure_ctx_t *ctx = chiventure_ctx_new(game);

return ctx;
}

int main() {
chiventure_ctx_t *ctx = create_sample_ctx();

run_gui(ctx);
}
193 changes: 193 additions & 0 deletions src/ui/src/draw_images.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#include <stdio.h>
#include <stdlib.h>
#include "raylib.h"

#include "ui/draw_images.h"
#include "game-state/room.h"
#include "game-state/game.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, room_t *curr_room)
{
// BeginDrawing();

char filename[MAX_FILENAME_LEN] = "/home/grkapoor/cs220/chiventure/tests/wdl/examples/wdl/";
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't be a hardcoded value, especially not one that references someone's home directory. It should be generalized before merging to dev.


strcat(filename, curr_room->room_id);

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")

strcat(filename, ".png");

// snprintf(filename, MAX_FILENAME_LEN, "/home/grkapoor/cs220/chiventure/tests/wdl/examples/wdl/%s.png", room_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

all extra commented out code should be removed before merging


// filename = “/home/grkapoor/cs220/chiventure/tests/wdl/examples/wdl/%s.png”, ctx->game->curr_room->room_id);

Image room = LoadImage(filename);

ImageResize(&room, width, height);

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

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

DrawTexture(texture, pos_x, pos_y, WHITE);

Copy link
Contributor

Choose a reason for hiding this comment

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

please delete extra lines here

// EndDrawing();

}

MaxineK36 marked this conversation as resolved.
Show resolved Hide resolved
// Color* colors_list()
// {
// 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;

// return colors;
// }

// bool in_array(room_t room, room_t *list, int len)
// {
// bool ret = false;
// for (int i = 0; i < len; i++)
// {
// if (room == list[i])
// {
// return true;
// }
// }
// return ret;
// }

// int num_rooms(game_t *game)
// {
// int count = 0;
// room_list_t *rooms = get_all_rooms(game);
// while(rooms->next != NULL)
// {
// count++;
// rooms = rooms->next;
// }
// return count;
// }

void draw_map(int width, int height, room_t *curr_room)
{
int map_width, map_height, map_room_width, map_room_height, map_centX, map_centY, ball_rad;
map_width = width / 10;
map_height = height / 5;
map_room_width = map_width / 3;
map_room_height = map_height / 3;
map_centX = map_width/2;
map_centY = -1 * (map_height/2);
ball_rad = map_room_width / 5;

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
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a block comment /* Map background */ as should all other comments that take up a whole line

DrawRectangle(map_centX, map_centY, map_width, map_height, BLACK);

int posX = map_centX;
int posY = map_centY;
// 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)
{
posX = map_centX + map_room_width;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[1]);

room_t *east = find_room_from_dir(curr_room, "EAST");
if (find_room_from_dir(east, "NORTH") != NULL)
MaxineK36 marked this conversation as resolved.
Show resolved Hide resolved
{
posY = map_centX + map_room_height;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[5]);
}
if (find_room_from_dir(east, "SOUTH") != NULL)
{
posY = map_centY - map_room_height;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[6]);
}

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

room_t *west = find_room_from_dir(curr_room, "WEST");
if (find_room_from_dir(west, "NORTH") != NULL)
{
posY = map_centX + map_room_height;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[7]);
}
if (find_room_from_dir(west, "SOUTH") != NULL)
{
posY = map_centX - map_room_height;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[8]);
}
}
if (find_room_from_dir(curr_room, "SOUTH") != NULL)
{
posY = map_centX - map_room_height;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[3]);

room_t *south = find_room_from_dir(curr_room, "SOUTH");
if (find_room_from_dir(south, "EAST") != NULL)
{
posX = map_centX + map_room_width;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[6]);
}
if (find_room_from_dir(south, "WEST") != NULL)
{
posX = map_centX - map_room_width;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[8]);
}
}
if (find_room_from_dir(curr_room, "NORTH") != NULL)
{
posY = map_centX + map_room_height;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[4]);

room_t *north = find_room_from_dir(curr_room, "NORTH");
if (find_room_from_dir(north, "WEST") != NULL)
{
posX = map_centX - map_room_width;
DrawRectangle(posX, posY, map_room_width, map_room_height, colors[7]);
}
if (find_room_from_dir(north, "EAST") != NULL)
{
posX = map_centX + map_room_width;
DrawRectangle(posX, posY, 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_centX, map_centY, ball_rad, WHITE);

}

/* See draw_images.h for documentation */
Copy link
Contributor

Choose a reason for hiding this comment

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

This function should be removed or completed before merging

void draw_object(char *item_id)
{

}
Loading