Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. //--------------------------------------
  2. // Program Name:
  3. // Author:
  4. // License:
  5. // Description:
  6. //--------------------------------------
  7.  
  8. /* Keep these headers */
  9. #include <stdbool.h>
  10. #include <stddef.h>
  11. #include <stdint.h>
  12. #include <tice.h>
  13.  
  14. /* Standard headers - it's recommended to leave them included */
  15. #include <math.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. /* Other available headers */
  21. // stdarg.h, setjmp.h, assert.h, ctype.h, float.h, iso646.h, limits.h, errno.h, debug.h, intce.h
  22. #include <graphx.h>
  23.  
  24. #include "gfx/sprite_gfx.h"
  25.  
  26. /* Put your function prototypes here */
  27. void waitForKey();
  28. void infobar(int score);
  29. void update();
  30.  
  31. /* Put all your globals here. */
  32. #define INFOBAR_HEIGHT 16
  33. #define BORDER 4
  34. #define ROADS_X 7
  35. #define ROADS_Y 7
  36. #define ROAD_LENGTH 24
  37. #define ROAD_WIDTH 6
  38. #define TAXI_LENGTH 8
  39. #define TAXI_WIDTH 8
  40.  
  41. enum direction {NORTH, EAST, WEST, SOUTH};
  42. typedef enum direction direction_t;
  43.  
  44. void main(void) {
  45. /* Fill in the body of the main function here */
  46. uint8_t xPos;
  47. uint8_t yPos;
  48. gfx_TempSprite(sprite_buffer, 24, 6);
  49.  
  50. prgm_CleanUp();
  51. gfx_Begin(gfx_8bpp);
  52. gfx_SetPalette(sprite_gfx_pal, sizeof sprite_gfx_pal, 0);
  53.  
  54. /* Background color */
  55. gfx_FillScreen(74);
  56.  
  57. /* Populate roads */
  58. for( xPos = 0; xPos < (ROADS_X + 1); xPos++ ) {
  59. for( yPos = 0; yPos < ROADS_Y; yPos++ ) {
  60. gfx_Sprite(street, (ROAD_LENGTH + ROAD_WIDTH) * xPos + BORDER, (ROAD_LENGTH + ROAD_WIDTH) * yPos + INFOBAR_HEIGHT + BORDER + ROAD_WIDTH);
  61. }
  62. }
  63.  
  64. for( xPos = 0; xPos < ROADS_X; xPos++ ) {
  65. for( yPos = 0; yPos < (ROADS_Y + 1); yPos++ ) {
  66. gfx_Sprite(gfx_RotateSpriteC(street, sprite_buffer), (ROAD_LENGTH + ROAD_WIDTH) * xPos + ROAD_WIDTH + BORDER, (ROAD_LENGTH + ROAD_WIDTH) * yPos + INFOBAR_HEIGHT + BORDER);
  67. }
  68. }
  69. gfx_Blit(gfx_screen);
  70. gfx_SetDrawBuffer();
  71.  
  72. infobar(0);
  73.  
  74. while (!os_GetCSC()) {
  75. update();
  76. }
  77.  
  78. gfx_End();
  79. prgm_CleanUp();
  80. }
  81.  
  82. /* Put other functions here */
  83. void waitForKey() {
  84. while (!os_GetCSC()){}
  85. }
  86. void infobar(int score) {
  87. /* White infobar */
  88. gfx_SetColor(255);
  89. gfx_FillRectangle(0, 0, LCD_WIDTH, INFOBAR_HEIGHT);
  90. /* Populate infobar */
  91. gfx_SetTextFGColor(255);
  92. gfx_SetTextFGColor(8);
  93. gfx_PrintStringXY("Taxi Sim", 4, 4);
  94. gfx_SetTextXY(128,4);
  95. gfx_PrintString("Score: ");
  96. gfx_PrintUInt(score,3);
  97. }
  98. void update() {
  99. static uint16_t score = 0;
  100. static uint8_t xPos;
  101. static uint8_t yPos;
  102. static uint8_t intersection_x = 3; //taxi is approaching this
  103. static uint8_t intersection_y = 3; //taxi is approaching this
  104. static uint8_t progress = 0; //how far along the road the taxi is
  105. static direction_t rotation = NORTH;
  106. static gfx_image_t *behind_sprite;
  107. static uint16_t iterations = 0;
  108. int8_t offset_x = 0;
  109. int8_t offset_y = 0;
  110.  
  111. gfx_TempSprite(taxi, 8, 8);
  112. behind_sprite = gfx_MallocSprite(TAXI_LENGTH, TAXI_WIDTH);
  113. //update traffic
  114. //process taxi movement
  115. progress++;
  116. if(progress > (ROAD_LENGTH + ROAD_WIDTH)) {
  117. progress = 0;
  118. switch(rotation) {
  119. case NORTH:
  120. intersection_y--;
  121. break;
  122. case SOUTH:
  123. intersection_y++;
  124. break;
  125. case EAST:
  126. intersection_x++;
  127. break;
  128. case WEST:
  129. intersection_x--;
  130. break;
  131. }
  132. }
  133. //render taxi
  134. if (iterations == 0) {
  135. gfx_GetSprite(behind_sprite, xPos, yPos);
  136. }
  137. gfx_Sprite(behind_sprite, 300, 40);
  138. switch(rotation) {
  139. case NORTH:
  140. offset_y = -1;
  141. taxi = taxi_rear;
  142. break;
  143. case SOUTH:
  144. offset_y = 1;
  145. taxi = taxi_front;
  146. break;
  147. case EAST:
  148. offset_x = 1;
  149. taxi = taxi_right;
  150. break;
  151. case WEST:
  152. offset_x = -1;
  153. gfx_FlipSpriteY(taxi_right, taxi);
  154. break;
  155. }
  156. offset_x *= progress;
  157. offset_y *= progress;
  158. xPos = offset_x + (ROAD_LENGTH + ROAD_WIDTH) * intersection_x + BORDER - 1;
  159. yPos = offset_y + (ROAD_LENGTH + ROAD_WIDTH) * intersection_y + INFOBAR_HEIGHT + BORDER + ROAD_LENGTH;
  160. //gfx_GetSprite(behind_sprite, xPos, yPos);
  161. gfx_TransparentSprite(taxi, xPos, yPos);
  162. //update infobar
  163. score++;
  164. infobar(score);
  165. gfx_BlitBuffer();
  166. iterations++;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement