/* * Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "f256.h" #define SPRITE_COUNT 4 #define SPRITE_SIZE 32 #define SPRITE_WIDTH 5 #define SPRITE_HEIGHT 2 #define SPR_LEFT 0 #define SPR_LEFT_ADDR 0x10000 #define SPR_LEFT_FRONT 1 #define SPR_LEFT_FRONT_ADDR 0x12800 #define SPR_RIGHT_FRONT 2 #define SPR_RIGHT_FRONT_ADDR 0x15000 #define SPR_RIGHT 3 #define SPR_RIGHT_ADDR 0x17800 #define SPR_CLUT 0x1a000 #define SPR_CLUT_COLORS 32 #define TURN_SPEED 25 static byte sprites[SPRITE_COUNT] = { SPR_LEFT, SPR_LEFT_FRONT, SPR_RIGHT_FRONT, SPR_RIGHT }; static uint32_t spriteStartAddrs[SPRITE_COUNT] = { SPR_LEFT_ADDR, SPR_LEFT_FRONT_ADDR, SPR_RIGHT_FRONT_ADDR, SPR_RIGHT_ADDR }; static uint32_t spriteAddrs[SPRITE_COUNT][SPRITE_WIDTH][SPRITE_HEIGHT]; static byte spriteIds[SPRITE_COUNT][SPRITE_WIDTH][SPRITE_HEIGHT]; static byte anyJoy; void drawHelicopter(void) { static byte last = SPR_RIGHT; // Last frame used, can be anything other than "frame". static byte frame = SPR_RIGHT_FRONT; static byte lag = 0; static uint16_t xSize = (SPRITE_WIDTH * SPRITE_SIZE); static uint16_t ySize = (SPRITE_HEIGHT * SPRITE_SIZE); static uint16_t xPos = 96; // (352 / 2) - (xSize / 2); static uint16_t yPos = 104; // (272 / 2) - (ySize / 2); byte i; byte j; // New frame? if (last != frame) { for (j=0; j 32) yPos--; } if (anyJoy & JOY_DOWN) { if (yPos + ySize < 271) yPos++; } if (anyJoy & JOY_LEFT) { if (xPos > 32) xPos--; if (frame > SPR_LEFT) { if (lag == 0) { lag = TURN_SPEED; } else { lag--; if (lag == 0) frame--; } } } if (anyJoy & JOY_RIGHT) { if (xPos + xSize < 351) xPos++; if (frame < SPR_RIGHT) { if (lag == 0) { lag = TURN_SPEED; } else { lag--; if (lag == 0) frame++; } } } // Update sprite positions. for (j=0; j