News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

accelerate sprite movement in mode 2?

Started by funkheld, 15:20, 03 January 21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

funkheld



Hi there.

I created a sprite with pain.net for mode 2 here 96x48.
with: cpct_img2tileset -m 2 -tw 96 -th 48 -oph sprite.png edited.
i put three sprite pictures in the background to play.
you can move the sprite with the q / w / e / s keys.

the sprite is moved transparently in mode 2.
this sprite need not be rectangular.
the background is brought to the front in sprite size when moving,
background is in 0x4000


how can you set the movement for : setze_hintergr() and  setze_spr()  accelerate ?


greeting.







#include <cpctelera.h>


#define spr_w 12
#define spr_h 48
#define SCR_W  80
#define SCR_H  200


const u8 g_tile_sprite[12 * 48] = {
   0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00,
   0x00, 0x00, 0x7e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
   0x00, 0x01, 0xf0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00,
   0x00, 0x07, 0xc0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00,
   0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00,
   0x00, 0x38, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00,
   0x00, 0xf0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00,
   0x01, 0xc0, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x07, 0x00,
   0x03, 0x80, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x03, 0x80,
   0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x01, 0xc0,
   0x0e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0xe0,
   0x1c, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x70,
   0x38, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x38,
   0x30, 0x18, 0x60, 0x0c, 0x00, 0x06, 0xc0, 0x00, 0x00, 0x00, 0x18, 0x18,
   0x60, 0x18, 0xf0, 0x1e, 0x00, 0x06, 0xc0, 0x00, 0x00, 0x00, 0x18, 0x0c,
   0x60, 0x19, 0xf8, 0x3f, 0x00, 0x06, 0xc0, 0x00, 0x00, 0x00, 0x18, 0x0c,
   0x60, 0x19, 0xdc, 0x77, 0x00, 0x06, 0xc0, 0x00, 0x00, 0x00, 0x18, 0x0e,
   0xc0, 0x18, 0xe6, 0xee, 0x00, 0x06, 0xe0, 0x00, 0x00, 0x00, 0x18, 0x06,
   0xc0, 0x18, 0x73, 0x9c, 0x00, 0x1c, 0x70, 0x00, 0x00, 0x00, 0x18, 0x06,
   0xc0, 0x18, 0x39, 0x38, 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x18, 0x06,
   0xc0, 0x18, 0x1c, 0x70, 0x00, 0x71, 0x1c, 0x00, 0x00, 0x00, 0x18, 0x06,
   0xc0, 0x18, 0x1c, 0x70, 0x00, 0xe7, 0xce, 0x00, 0x00, 0x00, 0x18, 0x06,
   0xc0, 0x18, 0x39, 0x38, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0x18, 0x06,
   0xe0, 0x18, 0x73, 0x9c, 0x03, 0xf8, 0x3f, 0x80, 0x00, 0x00, 0x18, 0x0e,
   0x60, 0x18, 0xe7, 0xce, 0x07, 0xc0, 0x07, 0xc0, 0x00, 0x00, 0x18, 0x0c,
   0x60, 0x19, 0xcc, 0x77, 0x0f, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x18, 0x0c,
   0x30, 0x19, 0xf8, 0x3f, 0x18, 0x00, 0x00, 0x30, 0x00, 0x00, 0x18, 0x18,
   0x38, 0x18, 0xf0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38,
   0x1c, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x70,
   0x0c, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x60,
   0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0,
   0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80,
   0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
   0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00,
   0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00,
   0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00,
   0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00,
   0x00, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00,
   0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
   0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00,
   0x00, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00
};
const u16 line_c0[8 * 25] = {
  0xC000, 0xC800, 0xD000, 0xD800, 0xE000, 0xE800, 0xF000, 0xF800,
  0xC050, 0xC850, 0xD050, 0xD850, 0xE050, 0xE850, 0xF050, 0xF850,
  0xC0A0, 0xC8A0, 0xD0A0, 0xD8A0, 0xE0A0, 0xE8A0, 0xF0A0, 0xF8A0,
  0xC0F0, 0xC8F0, 0xD0F0, 0xD8F0, 0xE0F0, 0xE8F0, 0xF0F0, 0xF8F0,
  0xC140, 0xC940, 0xD140, 0xD940, 0xE140, 0xE940, 0xF140, 0xF940,
  0xC190, 0xC990, 0xD190, 0xD990, 0xE190, 0xE990, 0xF190, 0xF990,
  0xC1E0, 0xC9E0, 0xD1E0, 0xD9E0, 0xE1E0, 0xE9E0, 0xF1E0, 0xF9E0,
  0xC230, 0xCA30, 0xD230, 0xDA30, 0xE230, 0xEA30, 0xF230, 0xFA30,
  0xC280, 0xCA80, 0xD280, 0xDA80, 0xE280, 0xEA80, 0xF280, 0xFA80,
  0xC2D0, 0xCAD0, 0xD2D0, 0xDAD0, 0xE2D0, 0xEAD0, 0xF2D0, 0xFAD0,
  0xC320, 0xCB20, 0xD320, 0xDB20, 0xE320, 0xEB20, 0xF320, 0xFB20,
  0xC370, 0xCB70, 0xD370, 0xDB70, 0xE370, 0xEB70, 0xF370, 0xFB70,
  0xC3C0, 0xCBC0, 0xD3C0, 0xDBC0, 0xE3C0, 0xEBC0, 0xF3C0, 0xFBC0,
  0xC410, 0xCC10, 0xD410, 0xDC10, 0xE410, 0xEC10, 0xF410, 0xFC10,
  0xC460, 0xCC60, 0xD460, 0xDC60, 0xE460, 0xEC60, 0xF460, 0xFC60,
  0xC4B0, 0xCCB0, 0xD4B0, 0xDCB0, 0xE4B0, 0xECB0, 0xF4B0, 0xFCB0,
  0xC500, 0xCD00, 0xD500, 0xDD00, 0xE500, 0xED00, 0xF500, 0xFD00,
  0xC550, 0xCD50, 0xD550, 0xDD50, 0xE550, 0xED50, 0xF550, 0xFD50,
  0xC5A0, 0xCDA0, 0xD5A0, 0xDDA0, 0xE5A0, 0xEDA0, 0xF5A0, 0xFDA0,
  0xC5F0, 0xCDF0, 0xD5F0, 0xDDF0, 0xE5F0, 0xEDF0, 0xF5F0, 0xFDF0,
  0xC640, 0xCE40, 0xD640, 0xDE40, 0xE640, 0xEE40, 0xF640, 0xFE40,
  0xC690, 0xCE90, 0xD690, 0xDE90, 0xE690, 0xEE90, 0xF690, 0xFE90,
  0xC6E0, 0xCEE0, 0xD6E0, 0xDEE0, 0xE6E0, 0xEEE0, 0xF6E0, 0xFEE0,
  0xC730, 0xCF30, 0xD730, 0xDF30, 0xE730, 0xEF30, 0xF730, 0xFF30,
  0xC780, 0xCF80, 0xD780, 0xDF80, 0xE780, 0xEF80, 0xF780, 0xFF80};


u8 *scradrc0;
u8 *scradr40;
u16 nx,ny,x,y,w,h,ya,xa,xscr,yscr;
u8* pvideomem; 


setze_hintergr()
{
  for(ny= 0; ny < spr_h; ny++)
  {
     scradrc0=line_c0[ya+ny];
     scradr40=scradrc0 - 0x8000;
     for(nx= 0; nx < spr_w; nx++)
     {
       *(scradrc0+xa+nx)=*(scradr40+xa+nx);
     }
  }
}


setze_spr()

  w=0;
  for(ny= 0; ny < spr_h; ny++)
  {   
     scradrc0=line_c0[y+ny];
     scradr40=scradrc0 - 0x8000;
     for(nx= 0; nx < spr_w; nx++)
     {
        *(scradrc0+x+nx)=*(scradr40+x+nx) | g_tile_sprite[nx+w];
     }
     w=w+spr_w;
  } 
  ya=y;
  xa=x;     
}


void main(void) {
  cpct_disableFirmware();
  cpct_setVideoMode(2);
 
  xscr=10;
  yscr=60;
  pvideomem = cpct_getScreenPtr(0xc000, xscr, yscr);
  cpct_drawSprite(g_tile_sprite, pvideomem, spr_w, spr_h);
  xscr=30;
  yscr=120;
  pvideomem = cpct_getScreenPtr(0xc000, xscr, yscr);
  cpct_drawSprite(g_tile_sprite, pvideomem, spr_w, spr_h);
  xscr=60;
  yscr=20;
  pvideomem = cpct_getScreenPtr(0xc000, xscr, yscr);
  cpct_drawSprite(g_tile_sprite, pvideomem, spr_w, spr_h);
 
  cpct_memcpy(0x4000,0xc000,0x4000);
   
  x=30;
  y=60;
 
  setze_spr();
  ya=y;
  xa=x;

   while(1) {
      cpct_scanKeyboard_f();


      if(cpct_isKeyPressed(Key_E) && x < (SCR_W - spr_w) )
      {       
        ++x;
        setze_hintergr();
        setze_spr();
      } 
      else if (cpct_isKeyPressed(Key_Q)  && x > 0)
      {       
        --x;
       setze_hintergr();
       setze_spr();
      } 
      if(cpct_isKeyPressed(Key_W)    && y > 0)
      {
        y=y-4;
        setze_hintergr();
        setze_spr();
      }
      else if (cpct_isKeyPressed(Key_S)  && y < (SCR_H - spr_h) )
      {
        y=y+4;
        setze_hintergr();
        setze_spr();
      }     
   }
}

andycadley

I'm not sure I understand your question. Your code appears to be entirely responsible for handling the position of things, if you want them to move by a greater amount, then why not just do so? Or are you asking a more general question about how to mimic acceleration to give a more realistic sense that things move the way they would normally?

funkheld

#2

how can one write the setze_spr() in asm please?


greeting

freemac

#3
cpct_drawSpriteBlended() with CPCT_BLEND_OR parameter ? For that you need to get same color per sprite or else manage a palette so 0x08 | 0x07=addition color you want (no problem with mode 2 :doh: )

A good approach is setting a struct per sprite, with values like "x, y, speed, acceleration"

I suggest also using VSYNC at begin of while :
while (1) {
cpct_waitVSYNC();
...
}

funkheld


funkheld


if I write it like this, you can leave out the table for the screen addresses.
I had not thought about that.

scradrc0=cpct_getScreenPtr(0xc000, 0,ya+ny);
scradrc0=cpct_getScreenPtr(0xc000, 0,y+ny);


greeting

Powered by SMFPacks Menu Editor Mod