Skip to content

Commit 18c4375

Browse files
committed
player limits with camera established
1 parent 7143dce commit 18c4375

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

ModulePlayer.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,21 @@ update_status ModulePlayer::Update()
145145

146146
if (enable_movement) {
147147

148-
if (App->input->keyboard[SDL_SCANCODE_D] == KEY_STATE::KEY_REPEAT)
148+
if (App->input->keyboard[SDL_SCANCODE_D] == KEY_STATE::KEY_REPEAT && position.x < App->render->camera.x / SCREEN_SIZE + SCREEN_WIDTH-40)
149149
{
150-
position.x += speed;
150+
position.x += speed;
151151
}
152-
if (App->input->keyboard[SDL_SCANCODE_A] == KEY_STATE::KEY_REPEAT &&position.x>App->render->camera.x/SCREEN_SIZE)
152+
if (App->input->keyboard[SDL_SCANCODE_A] == KEY_STATE::KEY_REPEAT && position.x > App->render->camera.x / SCREEN_SIZE)
153153
{
154154
position.x -= speed;
155155
}
156-
if (App->input->keyboard[SDL_SCANCODE_W] == KEY_STATE::KEY_DOWN)
156+
if (App->input->keyboard[SDL_SCANCODE_W] == KEY_STATE::KEY_DOWN && position.y > App->render->camera.y/SCREEN_SIZE)
157157
{
158158
position.y -= speed;
159159
current_animation = &upward;
160160
current_animation->Reset();
161-
162161
}
163-
if (App->input->keyboard[SDL_SCANCODE_W] == KEY_STATE::KEY_REPEAT && position.y>App->render->camera.y)
162+
if (App->input->keyboard[SDL_SCANCODE_W] == KEY_STATE::KEY_REPEAT && position.y > App->render->camera.y/SCREEN_SIZE)
164163
{
165164
position.y -= speed;
166165
current_animation = &upward;
@@ -171,14 +170,14 @@ update_status ModulePlayer::Update()
171170
current_animation = &upwardreturn;
172171
}
173172
}
174-
if (App->input->keyboard[SDL_SCANCODE_S] == KEY_STATE::KEY_DOWN)
173+
if (App->input->keyboard[SDL_SCANCODE_S] == KEY_STATE::KEY_DOWN && position.y < App->render->camera.y /SCREEN_SIZE + SCREEN_HEIGHT-50)
175174
{
176175
position.y += speed * 1.5f;
177176
current_animation = &downward;
178177
current_animation->Reset();
179178

180179
}
181-
if (App->input->keyboard[SDL_SCANCODE_S] == KEY_STATE::KEY_REPEAT)
180+
if (App->input->keyboard[SDL_SCANCODE_S] == KEY_STATE::KEY_REPEAT && position.y < App->render->camera.y /SCREEN_SIZE + SCREEN_HEIGHT - 50)
182181
{
183182
position.y += speed * 1.5f;
184183
current_animation = &downward;

0 commit comments

Comments
 (0)