So far I have this code
Code:
that allows me to make a sprite, when go off screen, return back to the screen, on the right vertical edge of the screen and the bottom edge of the screen. How can I make it work for all the borders?
Code:
/*
*--------------------------------------
* Program Name:
* Author:
* License:
* Description:
*--------------------------------------
*/
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>
/* Standard headers (recommended) */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphx.h>
#include <keypadc.h>
#include "gfx/logo_gfx.h"
/* Put your function prototypes here */
void draw_sprite(int x, int y);
/* Put all your globals here */
void main(void) {
bool right;
bool left;
bool up;
bool down;
kb_key_t arrows;
int x, y;
gfx_Begin();
gfx_SetPalette(logo_gfx_pal, sizeof_logo_gfx_pal, 0);
x = 0;
y = 0;
gfx_SetDrawBuffer();
draw_sprite(x, y);
do {
kb_Scan();
arrows = kb_Data[7];
right = arrows & kb_Right;
left = arrows & kb_Left;
up = arrows & kb_Up;
down = arrows & kb_Down;
if(arrows) {
if(right) {
x++;
}
if(left) {
x--;
}
if(up) {
y--;
}
if(down) {
y++;
}
draw_sprite(x, y);
}
if (x >= 320) {
x = 320 - 60;
}
if (y >= 240) {
y = 240 - 87;
}
} while (kb_Data[6] != kb_Clear);
gfx_End();
}
/* Put other functions here */
void draw_sprite(int x, int y) {
gfx_FillScreen(0);
gfx_Sprite(assad, x, y);
gfx_BlitBuffer();
}
that allows me to make a sprite, when go off screen, return back to the screen, on the right vertical edge of the screen and the bottom edge of the screen. How can I make it work for all the borders?