Tin học Phần giúp đỡ mik để dưới phần comment!

HauBright

Học sinh mới
20 Tháng tư 2023
72
36
11
14
Bến Tre
[TẶNG BẠN] TRỌN BỘ Bí kíp học tốt 08 môn
Chắc suất Đại học top - Giữ chỗ ngay!!

ĐĂNG BÀI NGAY để cùng trao đổi với các thành viên siêu nhiệt tình & dễ thương trên diễn đàn.

Program NO_NAME;
Uses Crt;

Const HeightJumping = 6;
Type
Position = Record
x,y: Integer;
JumpingStatus: Boolean;
End;
Var
Character: Position;
Height: Integer;
Gravity: Integer;
Procedure MapForGame;
Var
i,j : Byte;
Begin
For j := 21 To 29 Do
For i := 1 To 80 Do
Begin
TextColor(White);
GotoXY(i,1);
Write(Chr(178));
Gotoxy(i,j);
Write(Chr(178));
End;
End;

Procedure DrawCharacter(x,y: Integer);
Begin
Gotoxy(Character.x,Character.y);
Write(Chr(219));
End;

Procedure ClearCharacter(x,y: Integer);
Begin
Gotoxy(Character.x,Character.y);
Write(Chr(32));
End;

Procedure IsJumping;
Begin
ClearCharacter(Character.x,Character.y);
Character.y := Character.y - 1;
DrawCharacter(Character.x,Character.y);
End;

Procedure IsFalling;
Begin
ClearCharacter(Character.x,Character.y);
Character.y := Character.y + 1;
DrawCharacter(Character.x,Character.y);
End;

Procedure Jumping;
Begin
If (Not Character.JumpingStatus) Then
Begin
Character.JumpingStatus := True;
End;
Repeat
IsJumping;
Height := Height - 1;
Delay(Gravity);
Gravity := Gravity + 5;
Until Height = 0;
Delay(30);
Repeat
IsFalling;
Height := Height + 1;
Delay(Gravity);
Gravity := Gravity - 5;
Until Height = HeightJumping;
If (Height = HeightJumping) Then
Character.JumpingStatus := False;
End;

Procedure MoveRight;
Begin
// If right arrow key pressed
ClearCharacter(Character.x,Character.y);
Character.x := Character.x + 1;
DrawCharacter(Character.x,Character.y);
Delay(40);
End;

Procedure MoveLeft;
Begin
ClearCharacter(Character.x,Character.y);
Character.x := Character.x - 1;
DrawCharacter(Character.x,Character.y);
Delay(35);
End;
//====================The Main Program===================
Begin
TextBackGround(Black);
Clrscr;
MapForGame;
Gravity := 50;
Height := 6;
Character.x := 40;
Character.y := 20;
DrawCharacter(Character.x,Character.y);
Character.JumpingStatus := False;
While True Do
Begin
If (Not Character.JumpingStatus) Then
Begin
If Keypressed Then
Case Readkey Of
Chr(72): Jumping;
// If up arrow key Pressed
Chr(77): If (Character.x < 80) Then MoveRight;
// If right arrow key pressed
Chr(75): If (Character.x > 1) Then MoveLeft;
// If left arrow key pressed
End;
End;
End;
End.
 

HauBright

Học sinh mới
20 Tháng tư 2023
72
36
11
14
Bến Tre
Các pháp sư giúp mình làm sao để nhân vật đang trong trạng thái nhảy mà vẫn nhấn các phím mũi tên sang trái hoặc sang phải để điều khiển được, mik xin cảm ơn rất nhiều =))
 
  • Like
Reactions: colalake

Sói_Đơn_Độc

Học sinh mới
19 Tháng năm 2023
5
1
6
14
Bến Tre
Cái này chắc phải dùng đa luồng (multithread) trong thư viện system.classed rồi
 
Top Bottom