From 422f720e65e7505dac76d1b20e1497a8943cf46d Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Mon, 11 Mar 2019 19:27:13 -0400 Subject: More prep work for sprite --- bounce.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'bounce.cpp') diff --git a/bounce.cpp b/bounce.cpp index 6f5e66a..7c7e362 100644 --- a/bounce.cpp +++ b/bounce.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,8 @@ __chip WORD ballSprite[] = { 0x0000, 0x0000, WORD ballColors[] = { 0x0000, 0x00F0, 0x0F00 }; +// sprite struct + /** * WindowPos @@ -108,6 +111,8 @@ class AmigaWindow { struct BallPos ballpos; int bounceDirX; int bounceDirY; + struct VSprite *vsprite; + struct GelsInfo *ginfo; struct WindowPos winposition; struct WindowSize winsize; @@ -135,10 +140,35 @@ class AmigaWindow { rp = window->RPort; if(rp == nullptr) { bad = true; + } else { + initSprite(); } } } + /** + * Sets up sprite + */ + void initSprite() { + if(!bad) { + if(NULL == (vsprite = makeVSprite(&vsprite))) { + bad = true; + } else { + AddVSprite(vsprite, rp); + spriteDrawList(); + } + } + } + + /** + * Sprite redrawing routines + */ + void spriteDrawList() { + SortGList(rp); + DrawGList(rp, ViewPortAddress(window)); + RethinkDisplay(); + } + /** * Draws the bouncing ball on screen */ @@ -195,6 +225,13 @@ class AmigaWindow { * Cleans up window */ ~AmigaWindow() { + if(vsprite != nullptr) { + RemVSprite(vsprite); + freeVSprite(vsprite); + vsprite = nullptr; + spriteDrawList(); + cleanupGelSys(ginfo, rp); + } if(window != nullptr) { CloseWindow(window); window = nullptr; -- cgit v1.2.3