-
Notifications
You must be signed in to change notification settings - Fork 12
Integrate map into chiventure gui split screen #1121
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
base: dev
Are you sure you want to change the base?
Changes from all 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,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 |
| 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) | ||
| { | ||
|
|
||
|
Contributor
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 |
||
|
|
||
| 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.
|
||
| /* 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 */ | ||
|
Contributor
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 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.
|
||
| { | ||
| 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); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.