block_part2.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "raylib.h"
  2. #include <math.h>
  3. int map[100][100] = {0};
  4. // Get our angle between two points.
  5. static float getangle(float x1,float y1,float x2,float y2);
  6. int main(void)
  7. {
  8. // Initialization
  9. //--------------------------------------------------------------------------------------
  10. const int screenWidth = 800;
  11. const int screenHeight = 450;
  12. InitWindow(screenWidth, screenHeight, "raylib example.");
  13. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  14. //--------------------------------------------------------------------------------------
  15. for(int i=0;i<100;i++){
  16. map[i][0]=1;
  17. }
  18. float posx = 320;
  19. float posy = 400;
  20. // Main game loop
  21. while (!WindowShouldClose()) // Detect window close button or ESC key
  22. {
  23. // Update
  24. //----------------------------------------------------------------------------------
  25. //----------------------------------------------------------------------------------
  26. // Draw
  27. //----------------------------------------------------------------------------------
  28. BeginDrawing();
  29. ClearBackground(RAYWHITE);
  30. for(int y=0;y<10;y++){
  31. for(int x=0;x<100;x++){
  32. if(map[x][y]==1){
  33. DrawRectangle(x*32,y*32,32,32,RED);
  34. DrawRectangle(x*32+1,y*32+1,32-2,32-2,BLUE);
  35. }
  36. }}
  37. float x = GetMouseX()/32;
  38. float y = GetMouseY()/32;
  39. if(map[(int)x][(int)y]==0){
  40. if( map[(int)x][(int)y-1]==1 || map[(int)x-1][(int)y]==1 || map[(int)x+1][(int)y]==1){
  41. DrawRectangle(x*32,y*32,32,32,DARKGRAY);
  42. }}
  43. float an = getangle(posx,posy,x*32,y*32);
  44. DrawLine(posx,posy,posx+cos(an)*32,posy+sin(an)*32,DARKGRAY);
  45. EndDrawing();
  46. //----------------------------------------------------------------------------------
  47. }
  48. // De-Initialization
  49. //--------------------------------------------------------------------------------------
  50. CloseWindow(); // Close window and OpenGL context
  51. //--------------------------------------------------------------------------------------
  52. return 0;
  53. }
  54. // Return the angle from - to in float
  55. float getangle(float x1,float y1,float x2,float y2){
  56. return (float)atan2(y2-y1, x2-x1);
  57. }