Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------
- // Program Name:
- // Author:
- // License:
- // Description:
- //--------------------------------------
- /* Keep these headers */
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <tice.h>
- /* Standard headers - it's recommended to leave them included */
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* Other available headers */
- // stdarg.h, setjmp.h, assert.h, ctype.h, float.h, iso646.h, limits.h, errno.h, debug.h, intce.h
- #include <graphx.h>
- #include "gfx/sprite_gfx.h"
- /* Put your function prototypes here */
- void waitForKey();
- void infobar(int score);
- void update();
- /* Put all your globals here. */
- #define INFOBAR_HEIGHT 16
- #define BORDER 4
- #define ROADS_X 7
- #define ROADS_Y 7
- #define ROAD_LENGTH 24
- #define ROAD_WIDTH 6
- #define TAXI_LENGTH 8
- #define TAXI_WIDTH 8
- enum direction {NORTH, EAST, WEST, SOUTH};
- typedef enum direction direction_t;
- void main(void) {
- /* Fill in the body of the main function here */
- uint8_t xPos;
- uint8_t yPos;
- gfx_TempSprite(sprite_buffer, 24, 6);
- prgm_CleanUp();
- gfx_Begin(gfx_8bpp);
- gfx_SetPalette(sprite_gfx_pal, sizeof sprite_gfx_pal, 0);
- /* Background color */
- gfx_FillScreen(74);
- /* Populate roads */
- for( xPos = 0; xPos < (ROADS_X + 1); xPos++ ) {
- for( yPos = 0; yPos < ROADS_Y; yPos++ ) {
- gfx_Sprite(street, (ROAD_LENGTH + ROAD_WIDTH) * xPos + BORDER, (ROAD_LENGTH + ROAD_WIDTH) * yPos + INFOBAR_HEIGHT + BORDER + ROAD_WIDTH);
- }
- }
- for( xPos = 0; xPos < ROADS_X; xPos++ ) {
- for( yPos = 0; yPos < (ROADS_Y + 1); yPos++ ) {
- gfx_Sprite(gfx_RotateSpriteC(street, sprite_buffer), (ROAD_LENGTH + ROAD_WIDTH) * xPos + ROAD_WIDTH + BORDER, (ROAD_LENGTH + ROAD_WIDTH) * yPos + INFOBAR_HEIGHT + BORDER);
- }
- }
- gfx_Blit(gfx_screen);
- gfx_SetDrawBuffer();
- infobar(0);
- while (!os_GetCSC()) {
- update();
- }
- gfx_End();
- prgm_CleanUp();
- }
- /* Put other functions here */
- void waitForKey() {
- while (!os_GetCSC()){}
- }
- void infobar(int score) {
- /* White infobar */
- gfx_SetColor(255);
- gfx_FillRectangle(0, 0, LCD_WIDTH, INFOBAR_HEIGHT);
- /* Populate infobar */
- gfx_SetTextFGColor(255);
- gfx_SetTextFGColor(8);
- gfx_PrintStringXY("Taxi Sim", 4, 4);
- gfx_SetTextXY(128,4);
- gfx_PrintString("Score: ");
- gfx_PrintUInt(score,3);
- }
- void update() {
- static uint16_t score = 0;
- static uint8_t xPos;
- static uint8_t yPos;
- static uint8_t intersection_x = 3; //taxi is approaching this
- static uint8_t intersection_y = 3; //taxi is approaching this
- static uint8_t progress = 0; //how far along the road the taxi is
- static direction_t rotation = NORTH;
- static gfx_image_t *behind_sprite;
- static uint16_t iterations = 0;
- int8_t offset_x = 0;
- int8_t offset_y = 0;
- gfx_TempSprite(taxi, 8, 8);
- behind_sprite = gfx_MallocSprite(TAXI_LENGTH, TAXI_WIDTH);
- //update traffic
- //process taxi movement
- progress++;
- if(progress > (ROAD_LENGTH + ROAD_WIDTH)) {
- progress = 0;
- switch(rotation) {
- case NORTH:
- intersection_y--;
- break;
- case SOUTH:
- intersection_y++;
- break;
- case EAST:
- intersection_x++;
- break;
- case WEST:
- intersection_x--;
- break;
- }
- }
- //render taxi
- if (iterations == 0) {
- gfx_GetSprite(behind_sprite, xPos, yPos);
- }
- gfx_Sprite(behind_sprite, 300, 40);
- switch(rotation) {
- case NORTH:
- offset_y = -1;
- taxi = taxi_rear;
- break;
- case SOUTH:
- offset_y = 1;
- taxi = taxi_front;
- break;
- case EAST:
- offset_x = 1;
- taxi = taxi_right;
- break;
- case WEST:
- offset_x = -1;
- gfx_FlipSpriteY(taxi_right, taxi);
- break;
- }
- offset_x *= progress;
- offset_y *= progress;
- xPos = offset_x + (ROAD_LENGTH + ROAD_WIDTH) * intersection_x + BORDER - 1;
- yPos = offset_y + (ROAD_LENGTH + ROAD_WIDTH) * intersection_y + INFOBAR_HEIGHT + BORDER + ROAD_LENGTH;
- //gfx_GetSprite(behind_sprite, xPos, yPos);
- gfx_TransparentSprite(taxi, xPos, yPos);
- //update infobar
- score++;
- infobar(score);
- gfx_BlitBuffer();
- iterations++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement