Snippet #1467

TTL: forever — WordwrapView raw

on 2021/05/26 16:42:57 (UTC) by Anonymous as C

1. `/*The edges of the play field*/`
2. `const int LEFT_EDGE = 0;`
3. `const int RIGHT_EDGE = 320;`
4. `const int TOP_EDGE = 0;`
5. `const int BOTTOM_EDGE = 224;`
6. ` `
7. `#include <genesis.h>`
8. `#include <resources.h>`
9. ` `
10. `Sprite* ball;`
11. ` `
12. `void moveBall()`
13. `{`
14. `	int ball_pos_x, ball_pos_y, ball_vel_x, ball_vel_y, ball_width, ball_height;`
15. `	//Check horizontal bounds`
16. `	if(ball_pos_x < LEFT_EDGE)`
17. `	{`
18. `		ball_pos_x = LEFT_EDGE;`
19. `		ball_vel_x = -ball_vel_x;`
20. `	} `
21. `	else if(ball_pos_x + ball_width > RIGHT_EDGE)`
22. `	{`
23. `		ball_pos_x = RIGHT_EDGE - ball_width;`
24. `		ball_vel_x = -ball_vel_x;`
25. `	}`
26. ` `
27. `	//Check vertical bounds`
28. `	if(ball_pos_y < TOP_EDGE)`
29. `	{`
30. `		ball_pos_y = TOP_EDGE;`
31. `		ball_vel_y = -ball_vel_y;`
32. `	} else if(ball_pos_y + ball_height > BOTTOM_EDGE)`
33. `	{`
34. `		ball_pos_y = BOTTOM_EDGE - ball_height;`
35. `		ball_vel_y = -ball_vel_y;`
36. `	}`
37. ` `
38. `	//Position the ball`
39. `	ball_pos_x += ball_vel_x;`
40. `	ball_pos_y += ball_vel_y;`
41. ` `
42. `	SPR_setPosition(ball,ball_pos_x,ball_pos_y);`
43. `}`
44. ` `
45. `int main()`
46. `{`
47. `	`
48. `	VDP_loadTileSet(bgtile.tileset,1,DMA);`
49. `	SPR_init(0,0,0);`
50. ` `
51. `	ball = SPR_addSprite(&imgball,100,100,TILE_ATTR(PAL1,0, FALSE, FALSE));`
52. `	int ball_pos_x = 100;`
53. `	int ball_pos_y = 100;`
54. `	int ball_vel_x = 1;`
55. `	int ball_vel_y = 1;`
56. `	int ball_width = 8;`
57. `	int ball_height = 8;`
58. ` `
59. `	VDP_setPalette(PAL1, bgtile.palette->data);`
60. `	VDP_fillTileMapRect(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,1),0,0,40,30);	`
61. ` `
62. `	//VDP_drawText("Hello Mega Drive World!", 8, 12);`
63. `    while(1)`
64. `    {`
65. `		moveBall();`
66. `		SPR_update();`
67. `        SYS_doVBlankProcess();`
68. `    }`
69. `    return (0);`
70. `}`