#include "common.h" //#link "common.c" #include "scrolling.h" //#link "scrolling.c" #include "sprites.h" //#link "sprites.c" #include static void draw_cell(word ofs, byte x, byte y) { byte xx = x + origin_x; byte yy = y + origin_y; byte ch = xx ^ yy; hidbuf[ofs] = ch; // character colorbuf[ofs] = ch; // color } void scroll_draw_column(byte col) { byte y; word ofs = col; for (y=0; y>= 4; dy >>= 4; if (dx) { if (dx > 8) dx = 8; else if (dx < -8) dx = -8; camerax -= dx; } if (dy) { if (dy > 8) dy = 8; else if (dy < -8) dy = -8; cameray -= dy; } scroll_xy(dx, dy); } void main(void) { clrscr(); printf("\r\n\r\n\r\n Hello World!"); printf("\r\n\r\n\r\n Use the joystick to move"); printf("\r\n\r\n\r\n And the camera will follow"); // setup scrolling library scroll_setup(); VIC.bordercolor = 12; // setup sprite library and copy sprite to VIC bank sprite_clear(); sprite_set_shapes(SPRITE1, 192, 1); sprshad.spr_color[0] = 13; // install the joystick driver joy_install (joy_static_stddrv); // infinite loop while (1) { static char speed; static char joy; static bool slowframe = false; // get joystick bits joy = joy_read(0); // speed up scrolling while button pressed speed = JOY_BTN_1(joy) ? 3 : 1; // if we copied screen memory last frame, // double speed of player for this frame if (slowframe) speed *= 2; // move sprite based on arrow keys if (JOY_LEFT(joy)) playerx -= speed; if (JOY_RIGHT(joy)) playerx += speed; if (JOY_UP(joy)) playery -= speed; if (JOY_DOWN(joy)) playery += speed; // move the camera? camera_follow(joy); slowframe = swap_needed; // animate sprite in shadow sprite ram update_player(); // wait for end of frame wait_vblank(); // then update sprite registers sprite_update(visbuf); // update scroll registers // and swap screens if we must scroll_update(); } }