Snippet #1467
on 2021/05/26 16:42:57 (UTC) by Anonymous as C
-
/*The edges of the play field*/
-
const int LEFT_EDGE = 0;
-
const int RIGHT_EDGE = 320;
-
const int TOP_EDGE = 0;
-
const int BOTTOM_EDGE = 224;
-
-
#include <genesis.h>
-
#include <resources.h>
-
-
Sprite* ball;
-
-
void moveBall()
-
{
-
int ball_pos_x, ball_pos_y, ball_vel_x, ball_vel_y, ball_width, ball_height;
-
//Check horizontal bounds
-
if(ball_pos_x < LEFT_EDGE)
-
{
-
ball_pos_x = LEFT_EDGE;
-
ball_vel_x = -ball_vel_x;
-
}
-
else if(ball_pos_x + ball_width > RIGHT_EDGE)
-
{
-
ball_pos_x = RIGHT_EDGE - ball_width;
-
ball_vel_x = -ball_vel_x;
-
}
-
-
//Check vertical bounds
-
if(ball_pos_y < TOP_EDGE)
-
{
-
ball_pos_y = TOP_EDGE;
-
ball_vel_y = -ball_vel_y;
-
} else if(ball_pos_y + ball_height > BOTTOM_EDGE)
-
{
-
ball_pos_y = BOTTOM_EDGE - ball_height;
-
ball_vel_y = -ball_vel_y;
-
}
-
-
//Position the ball
-
ball_pos_x += ball_vel_x;
-
ball_pos_y += ball_vel_y;
-
-
SPR_setPosition(ball,ball_pos_x,ball_pos_y);
-
}
-
-
int main()
-
{
-
-
VDP_loadTileSet(bgtile.tileset,1,DMA);
-
SPR_init(0,0,0);
-
-
ball = SPR_addSprite(&imgball,100,100,TILE_ATTR(PAL1,0, FALSE, FALSE));
-
int ball_pos_x = 100;
-
int ball_pos_y = 100;
-
int ball_vel_x = 1;
-
int ball_vel_y = 1;
-
int ball_width = 8;
-
int ball_height = 8;
-
-
VDP_setPalette(PAL1, bgtile.palette->data);
-
VDP_fillTileMapRect(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,1),0,0,40,30);
-
-
//VDP_drawText("Hello Mega Drive World!", 8, 12);
-
while(1)
-
{
-
moveBall();
-
SPR_update();
-
SYS_doVBlankProcess();
-
}
-
return (0);
-
}
Recent Snippets
- #157071 by Anonymous (471 days ago)
- #156876 by Anonymous (471 days ago)
- #154030 by Anonymous (476 days ago)
- #140524 by Anonymous (495 days ago)
- #137907 by rotense (498 days ago)
- #131892 by Anonymous (506 days ago)