Advertisement
Guest User

hero.c

a guest
May 23rd, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <avr/io.h>
  5. #include <util/delay.h>
  6. #include <graphics.h>
  7. #include "cpu_speed.h"
  8. #include "friendly_ports.h"
  9. #include "sprite.h"
  10. #include "graphics.h"
  11. #include "hero.h"
  12.  
  13. void update_hero( Sprite * hero );
  14.  
  15. void play_hero(void){
  16.  
  17.  
  18. byte bitmap1[] = {
  19. BYTE( 10100000 ),
  20. BYTE( 11100000 ),
  21. BYTE( 10100000 ),
  22. BYTE( 00000000 ),
  23. BYTE( 00000000 ),
  24. BYTE( 00000000 ),
  25. BYTE( 00000000 ),
  26. BYTE( 00000000 )
  27. };
  28.  
  29. Sprite hero;
  30. init_sprite( &hero, 40, 23, 3, 3, bitmap1 );
  31. hero.is_visible = 1;
  32. //srandom( 5198985 );
  33. //double angle = ((double)random()) * 2 * M_PI / RANDOM_MAX;
  34. hero.dx = 1;
  35. hero.dy = 0;
  36.  
  37. //while(1){
  38. update_hero ( &hero);
  39. draw_sprite( &hero);
  40.  
  41. refresh();
  42.  
  43. // move forward 1 pixel until hit walls
  44.  
  45. }
  46.  
  47.  
  48.  
  49. /* void turn_hero (Sprite * hero, double degrees){
  50. double angle = degrees * 3.1416 / 180;
  51. double c = cos (angle);
  52. double s = sin (angle);
  53.  
  54. float newdx = c * hero->dx - s * hero->dy;
  55. float newdy = s * hero->dx + c * hero->dy;
  56. hero->dx = round(newdx);
  57. hero->dy = round(newdy);
  58. } */
  59.  
  60.  
  61.  
  62. void update_hero( Sprite * hero ) {
  63. hero->x += hero->dx;
  64. hero->y += hero->dy;
  65.  
  66. if ( hero->x >= LCD_X - hero->width || hero->x < 40 ) {
  67. hero->dx = -hero->dx;
  68. }
  69.  
  70. if ( hero->y >= LCD_Y - hero->height || hero->y < 0 ) {
  71. hero->dy = -hero->dy;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement