This page was last updated on March 13th, 2020(UTC) and it is currently August 10th, 2020(UTC).
That means this page is 150 days, 1 hours, 18 minutes and 23 seconds old. Please keep that in mind.

45 - Sprites Now that we're getting a little less functional and more visual, I want to start by changing "emplace()" so that we can have transparency. There are other black colors in the palette, and we can also change the palette if we need.

void drawable::emplace(){ //This could really, really benefit from rewriting into assembly. offscreen = true; int rx = x - (xs >> 1), ry = y - (ys >> 1); for(int i = 0; i < ys; i++) for(int j = 0; j < xs; j++){ int px = rx + j; //We're declaring here hoping the compiler doesn't actually create the variables int py = (ry + i)*xsize; unsigned char pixel = bitmap[(xs*i)+j]; if(py < 0 || py >= ysize * xsize) break; //Push up Y, since the whole row's dead. if(pixel && px >= 0 && px <= xsize){ offscreen = false; //Lots of memory ops in a loop. buffer[py+px] = pixel; } } }

Next we've done the following files, which you should be figuring out the name to.

#ifndef _ENEMY_H #include "COLLIDAB.H" #include "PLAYER.H" class enemy: public collidable { protected: int ticks; player *target; public: enemy(int x, int y, player &target); virtual void draw(); //Virtual, incase you want to make less generec enemies. }; #endif #define _ENEMY_H true

//Note, you probably want to turnoff wordwrap while editing this file if you're stuck using vim: vim c:\vim\_vimrc, set nowrap, or do it temporarily with ":set nowrap" #include "ENEMY.H" //------------------------------------------------------------------------- unsigned char enemy_bitmap[2][225]={ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x17, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x17, 0x17, 0x17, 0x17, 0x17, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x17, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x17, 0x17, 0x17, 0x17, 0x17, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x28, 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00 } }; //------------------------------------------------------------------------- enemy::enemy(int x, int y, player &target):collidable(x, y){ dmg = 100; //Incase the player's dumb enough to try to ram it. xs = 15; ys = 15; radius = (xs+ys)/(float)4; ticks = 0; this->target = &target; } //------------------------------------------------------------------------- void enemy::draw(){ ticks++; if(x < (xsize >> 1)) x = xsize >> 1; if(x > (xsize - 20)) x = xsize - 20; if(y < 20) y = 20; else if (y > (ysize - 20)) y = ysize - 20; x += rand() % 7 - 3; y += rand() % 7 - 3; bitmap = enemy_bitmap[(ticks/60) % 2]; emplace(); } //-------------------------------------------------------------------------

#ifndef _PLAYER_H #include "COLLIDAB.H" class player: public collidable{ int ticks; public: player(int x, int y); void draw(); }; #endif #define _PLAYER_H true

#include "PLAYER.H" //------------------------------------------------------------------------- unsigned char player_draw_buffer[15*15]; unsigned char player_bitmap[]={ " TT " " TTT " " XXFX " " EEE XFFFX " "EEEEEXXFXXX " " EEE XFXFXXX " " XXXWWWXY " " XXWWWWWYYY" " XXXWWWXY " " EEE XFXFXXX " "EEEEEXXFXXX " " EEE XFFFX " " XXFX " " TTT " " TT " }; //------------------------------------------------------------------------- player::player(int x, int y):collidable(x, y){ xs = 15; ys = 15; radius = (xs+ys)/(float)4; bitmap = player_draw_buffer; ticks = 0; }; //------------------------------------------------------------------------- void player::draw(){ if(rdmg){ x = -1000; y = -1000; return; } for(int i = 0; i < 15*15; i++){ player_draw_buffer[i] = 0; switch(player_bitmap[i]){ case 'X': player_draw_buffer[i] = 0x1c; break; case 'E': if((ticks / 5) % 2) player_draw_buffer[i] = 0x2b; break; case 'F': player_draw_buffer[i] = 0x0f; break; case 'T': player_draw_buffer[i] = 0x09; break; case 'W': player_draw_buffer[i] = 0xfb; break; case 'Y': player_draw_buffer[i] = 0x27; break; }; } emplace(); ticks++; if(x < 0) x = 0; else if(x > xsize) x = xsize; if(y < 0) y = 0; else if(y > ysize) y = ysize; } //-------------------------------------------------------------------------

Nothing here should be particularly new here, but you'll start to see some of my personal techniques coming out more than before. At this point, I just wanted to get more structure in. Next, we need to work on bullets, which will have a bit of new stuff to them.

Get your own web kitty here!
┬ęCopyright 2010-2020. All rights reserved.