944,131 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2334
  • C RSS
Oct 24th, 2004
0

How to use different colours?

Expand Post »
Hey guys,
For the snake game, I need to use different colours for the snake and food. At least two different colours must be used (other than white and black). How can I change the colours? I tried many ways but none did it properly !

This is the full code where I think it should go somewhere in here:
  1. static int map_board_x_to_screen_x(int board_x) {
  2. return BOARD_X_OFFSET + board_x;
  3. }
  4.  
  5. static int map_board_y_to_screen_y(int board_y) {
  6. return BOARD_Y_OFFSET + board_y;
  7. }
  8.  
  9. void init_screen() {
  10. /*
  11. ** Initialise the screen, by setting it to normal display mode
  12. ** and clear the screen.
  13. */
  14. normal_display_mode();
  15. clear_terminal();
  16.  
  17. draw_horizontal_line(map_board_y_to_screen_y(-1),
  18. map_board_x_to_screen_x(-1),
  19. map_board_x_to_screen_x(BOARD_WIDTH));
  20. draw_horizontal_line(map_board_y_to_screen_y(BOARD_ROWS),
  21. map_board_x_to_screen_x(-1),
  22. map_board_x_to_screen_x(BOARD_WIDTH));
  23. draw_vertical_line(map_board_x_to_screen_x(-1),
  24. map_board_y_to_screen_y(-1),
  25. map_board_y_to_screen_y(BOARD_ROWS));
  26. draw_vertical_line(map_board_x_to_screen_x(BOARD_WIDTH),
  27. map_board_y_to_screen_y(-1),
  28. map_board_y_to_screen_y(BOARD_ROWS));
  29.  
  30. move_cursor(SCORE_X_OFFSET, 5);
  31. printf_P(PSTR("SCORE"));
  32. output_score();
  33.  
  34. }
  35.  
  36. void output_score() {
  37. move_cursor(SCORE_X_OFFSET,6);
  38. printf_P(PSTR("%ld"), get_score());
  39. }
  40.  
  41. void display_character_at(int8_t x, int8_t y, char c) {
  42. move_cursor(map_board_x_to_screen_x(x),
  43. map_board_y_to_screen_y(y));
  44. putchar(c);
  45. }
  46.  
  47. void display_food_at(int8_t x, int8_t y) {
  48. display_character_at(x, y, '#');
  49. }
  50.  
  51. void display_snake_at(int8_t x, int8_t y) {
  52. reverse_video();
  53. display_character_at(x, y, 'O');
  54. normal_display_mode();
  55. }
  56.  
  57.  
  58. void display_blank_at(int8_t x, int8_t y) {
  59. display_character_at(x, y, ' ');
  60. }
  61.  
  62. void game_over_message(void) {
  63. move_cursor(SCORE_X_OFFSET, 7);
  64. printf("Game over");
  65. }
Help PLEASE :cry:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Simplicity is offline Offline
8 posts
since Oct 2004
Oct 24th, 2004
0

Re: How to use different colours?

One more thing changing colours has to be using escape sequences..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Simplicity is offline Offline
8 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: How can I write a program with 3 classes?
Next Thread in C Forum Timeline: evaluation of stacks





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC