Бывалый
Регистрация: 22.12.2011
Сообщений: 844
Написано 150 полезных сообщений (для 275 пользователей)
|
Ответ: Vivo

Graphics DesktopWidth(),DesktopHeight()
Global R1=GraphicsWidth()
Global R2=GraphicsHeight()
SeedRnd MilliSecs()
Global player_image=LoadImage("images\player.png")
SetImageHandle player_image,15,32
Global dx,dy,camera_x,camera_y,g#,mouse_block_x,mouse_block_y
Global speed=5
camera_x=4000
camera_y=200
Global map_width,map_height
map_width=500
map_height=500
Global block[100]
block[0]=LoadImage("images\blocks\sky.png")
block[1]=LoadImage("images\blocks\ground.png")
Global map[map_width+1,map_height+1]
Global key_hit_1,key_hit_2
Global fps,lfps,tfps
Function Create_world()
For i=0 To 500
For i1=0 To 500
If i1>50
map[i,i1]=1
Else
map[i,i1]=0
EndIf
Next
Next
End Function
Create_world()
Function Update_camera()
dx=KeyDown(KEY_D)-KeyDown(KEY_A)
If map[(camera_x+R1/2)/16,(camera_y+R2/2)/16+1]=1
g=0
If KeyDown(KEY_SPACE) g=5
camera_y=Int(camera_y/16+1)*16-6-g
Else
g=g-0.4
If g<-3 g=-3
If g>0
If Not collision()
camera_y=camera_y-g
EndIf
Else
If map[(camera_x+R1/2)/16,(camera_y+R2/2)/16+1]=0
camera_y=camera_y-g
EndIf
EndIf
EndIf
If Not collision()
camera_x=camera_x+dx*speed
EndIf
End Function
Function collision()
For i=(camera_x+dx*5*speed+R1/2)/16-2 To (camera_x+dx*5*speed+R1/2)/16+2
For i1=(camera_y+R2/2)/16-2 To (camera_y+R2/2)/16
If map[i,i1]=1
If ImagesCollide(player_image,R1/2,R2/2,0,block[map[i,i1]],i*16-camera_x,i1*16-camera_y,0)
Return True
EndIf
EndIf
Next
Next
End Function
Function Draw_world()
mouse_block_x=(camera_x+MouseX())/16
mouse_block_y=(camera_y+MouseY())/16
For i=camera_x/16 To (camera_x+R1)/16
For i1=camera_y/16 To (camera_y+R2)/16
DrawImage block[map[i,i1]],i*16-camera_x,i1*16-camera_y
If key_hit_1
If mouse_block_x=i And mouse_block_y=i1 map[i,i1]=1
EndIf
If key_hit_2
If mouse_block_x=i And mouse_block_y=i1 map[i,i1]=0
EndIf
Next
Next
DrawImage player_image,R1/2,R2/2
End Function
Function Update_HUD()
If MilliSecs()-tfps<1000 fps=fps+1
If MilliSecs()-tfps>1000 Then
lfps=fps
tfps=MilliSecs()
fps=0
EndIf
SetColor 255,255,255
SetAlpha 1
DrawText "FPS: "+lfps,0,0
DrawText "mouse_block_x: "+mouse_block_x+" mouse_block_y: "+mouse_block_y+" g: "+g,0,24
End Function
While Not KeyHit(KEY_ESCAPE)
key_hit_1=MouseHit(1)
key_hit_2=MouseHit(2)
Update_camera()
Draw_world()
Update_HUD()
Flip(1)
Cls
Wend
Блин, что-то вконец ничего не получается. С осью y разобрался, а вот с x вообще лажа  Помогите найти ошибку, пожалуйста. Проблема в том, что игрок всё равно может проникнуть через блок. Хотя я думаю что у меня подход неверный, коллизии в тайловой игре как-то не очень.
З.Ы. код jimon'a посмотреть не смог, файл удалили.
|