-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: dev
Are you sure you want to change the base?
Changes from 38 commits
ce2d605
04c7f33
051f1df
645581c
b4d0b43
ad272d0
0f02cab
1159d77
7b26d8a
10ade90
af8c57a
39458b9
6c57e82
b47668e
313c00a
f2a12c8
36f182f
5d62089
22824ec
880bcc1
9a918bf
817a467
0c2d9e2
36ea2af
548d9c0
51e32d1
0c47273
f226cca
839178d
3cf8f90
f8be242
c0258cd
d802b3f
37c66a4
6488a24
db6850b
ddef478
75dfe35
21c1402
142129d
5e82d10
7919e61
3eb2a26
747e97a
f49b364
b6e2109
4708d07
5999c80
59120dd
a81db59
ff9132d
0ac878c
20b0206
bbaa0f7
5daf691
ad65adf
3971d65
cc74e79
bf74d76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
* | ||
* 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,4 @@ | |
*/ | ||
void run_gui(chiventure_ctx_t *ctx); | ||
|
||
#endif | ||
|
||
#endif |
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); | ||
} |
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/"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're using strcat, you should start by |
||
strcat(filename, ".png"); | ||
|
||
// snprintf(filename, MAX_FILENAME_LEN, "/home/grkapoor/cs220/chiventure/tests/wdl/examples/wdl/%s.png", room_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a block comment |
||
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 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
{ | ||
|
||
} |
There was a problem hiding this comment.
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