-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcamera.cpp
More file actions
60 lines (45 loc) · 1.23 KB
/
camera.cpp
File metadata and controls
60 lines (45 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <splashkit/splashkit.h>
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
camera cam;
bitmap character;
float characterX, characterY;
void load_resources()
{
character = bitmap_named("character");
}
void update_character_position()
{
// Update character position here
characterX += 5;
}
void draw_game_objects()
{
clear_screen(COLOR_WHITE);
draw_bitmap(character, characterX, characterY);
}
int main()
{
open_window("Camera Example", SCREEN_WIDTH, SCREEN_HEIGHT);
// Set character initial position
characterX = 0;
characterY = SCREEN_HEIGHT / 2;
// Create camera object
cam = create_camera();
while (!window_close_requested("Camera Example"))
{
// Update character position
update_character_position();
// Update camera position to follow character
set_camera_position(cam, characterX - SCREEN_WIDTH / 2, characterY - SCREEN_HEIGHT / 2);
// Begin camera view
begin_camera(cam);
// Draw game objects
draw_game_objects();
// End camera view
end_camera();
// Update the screen
refresh_screen(60);
}
return 0;
}