News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Sprite with key move at ccz80 ++?

Started by cpcuser, 09:36, 20 November 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cpcuser


Hi good afternoon.
I would like to please a sprite with the the key down / up / left / right control at ccz80 ++.
"Sprite1.xIncrement = 1", so a sprite is assigned a speed.
When I press the "up" button, the sprite continues to move and when I do not stop the button.


How can I stop the sprite when I release the "up" button?


thank you.
greeting

arnoldemu


cpcuser

#2
At the keyboard up,down,left,right the sprite should move by 1 pixel.

how does it work ?


greeting.



include Indirections6128.ccz80++
include GameScreen.ccz80++
include GameSprite.ccz80++
include GameKeyboard.ccz80++

class Test
{
  static void main()
  {
    static short image[] = {
      18, 9, 6, 54,

      #0F, #0C, #00, #00, #00, #00,
      #34, #C2, #00, #00, #00, #00,
      #12, #E1, #0F, #0E, #00, #00,
      #01, #FF, #FF, #EF, #08, #00,
      #00, #78, #F0, #F0, #84, #00,
      #01, #FF, #FF, #EF, #08, #00,
      #12, #E1, #0F, #0E, #00, #00,
      #34, #C2, #00, #00, #00, #00,
      #0F, #0C, #00, #00, #00, #00,

      #07, #0E, #00, #00, #00, #00,
      #12, #E1, #00, #00, #00, #00,
      #01, #F0, #0F, #0F, #00, #00,
      #00, #7F, #FF, #FF, #0C, #00,
      #00, #34, #F0, #F0, #C2, #00,
      #00, #7F, #FF, #FF, #0C, #00,
      #01, #F0, #0F, #0F, #00, #00,
      #12, #E1, #00, #00, #00, #00,
      #07, #0E, #00, #00, #00, #00,


      #03, #0F, #00, #00, #00, #00,
      #01, #F0, #08, #00, #00, #00,
      #00, #78, #87, #0F, #08, #00,
      #00, #37, #FF, #FF, #8E, #00,
      #00, #12, #F0, #F0, #E1, #00,
      #00, #37, #FF, #FF, #8E, #00,
      #00, #78, #87, #0F, #08, #00,
      #01, #F0, #08, #00, #00, #00,
      #03, #0F, #00, #00, #00, #00,

      #01, #0F, #08, #00, #00, #00,
      #00, #78, #84, #00, #00, #00,
      #00, #34, #C3, #0F, #0C, #00,
      #00, #13, #FF, #FF, #CF, #00,
      #00, #01, #F0, #F0, #F0, #08,
      #00, #13, #FF, #FF, #CF, #00,
      #00, #34, #C3, #0F, #0C, #00,
      #00, #78, #84, #00, #00, #00,
      #01, #0F, #08, #00, #00, #00
    };
   
    GameScreen.SetMode(1);
     
    GameSprite sprite1;
      sprite1.Create(0, 50, &image);
     
      while(1){
         sprite1.keyUp = GameKeyboard.keyUp;   
         sprite1.keyDown = GameKeyboard.keyDown;
         sprite1.keyLeft = GameKeyboard.keyLeft;
         sprite1.keyRight = GameKeyboard.keyRight;
         sprite1.xSpeedKeys = 1;
         sprite1.UpdateAuto();   
         GameScreen.WaitFlyback();
      }
  }
}

arnoldemu

Try this:

Use "UpdateByKeys". :)

UpdateAuto if you want to make movement by CPU (e.g. for AI/Enemy) and not keyboard.

Also, do not need to set keys each loop. Only set 1 time.




include Indirections6128.ccz80++
include GameScreen.ccz80++
include GameSprite.ccz80++
include GameKeyboard.ccz80++

class Test
{
  static void main()
  {
    static short image[] = {
      18, 9, 6, 54,

      #0F, #0C, #00, #00, #00, #00,
      #34, #C2, #00, #00, #00, #00,
      #12, #E1, #0F, #0E, #00, #00,
      #01, #FF, #FF, #EF, #08, #00,
      #00, #78, #F0, #F0, #84, #00,
      #01, #FF, #FF, #EF, #08, #00,
      #12, #E1, #0F, #0E, #00, #00,
      #34, #C2, #00, #00, #00, #00,
      #0F, #0C, #00, #00, #00, #00,

      #07, #0E, #00, #00, #00, #00,
      #12, #E1, #00, #00, #00, #00,
      #01, #F0, #0F, #0F, #00, #00,
      #00, #7F, #FF, #FF, #0C, #00,
      #00, #34, #F0, #F0, #C2, #00,
      #00, #7F, #FF, #FF, #0C, #00,
      #01, #F0, #0F, #0F, #00, #00,
      #12, #E1, #00, #00, #00, #00,
      #07, #0E, #00, #00, #00, #00,


      #03, #0F, #00, #00, #00, #00,
      #01, #F0, #08, #00, #00, #00,
      #00, #78, #87, #0F, #08, #00,
      #00, #37, #FF, #FF, #8E, #00,
      #00, #12, #F0, #F0, #E1, #00,
      #00, #37, #FF, #FF, #8E, #00,
      #00, #78, #87, #0F, #08, #00,
      #01, #F0, #08, #00, #00, #00,
      #03, #0F, #00, #00, #00, #00,

      #01, #0F, #08, #00, #00, #00,
      #00, #78, #84, #00, #00, #00,
      #00, #34, #C3, #0F, #0C, #00,
      #00, #13, #FF, #FF, #CF, #00,
      #00, #01, #F0, #F0, #F0, #08,
      #00, #13, #FF, #FF, #CF, #00,
      #00, #34, #C3, #0F, #0C, #00,
      #00, #78, #84, #00, #00, #00,
      #01, #0F, #08, #00, #00, #00
    };
   
    GameScreen.SetMode(1);
     
    GameSprite sprite1;
      sprite1.Create(0, 50, &image);
         sprite1.keyUp = GameKeyboard.keyUp;   
         sprite1.keyDown = GameKeyboard.keyDown;
         sprite1.keyLeft = GameKeyboard.keyLeft;
         sprite1.keyRight = GameKeyboard.keyRight;
         sprite1.xSpeedKeys = 1;
     
      while(1){
         sprite1.UpdateByKeys();   
         GameScreen.WaitFlyback();
      }
  }
}


cpcuser

#4

hello,works now.
If collision, then disappear the square.
taste: up/down/left/right.


greeting




include Indirections6128.ccz80++
include Screen.ccz80++
include Graphics.ccz80++
include GameSystem.ccz80++
include GameScreen.ccz80++
include GameSprite.ccz80++
include Keyboard.ccz80++
include Text.ccz80++


class Test
{
    static short image[] = {
      18, 9, 6, 54,


      #0F, #0C, #00, #00, #00, #00,
      #34, #C2, #00, #00, #00, #00,
      #12, #E1, #0F, #0E, #00, #00,
      #01, #FF, #FF, #EF, #08, #00,
      #00, #78, #F0, #F0, #84, #00,
      #01, #FF, #FF, #EF, #08, #00,
      #12, #E1, #0F, #0E, #00, #00,
      #34, #C2, #00, #00, #00, #00,
      #0F, #0C, #00, #00, #00, #00,


      #07, #0E, #00, #00, #00, #00,
      #12, #E1, #00, #00, #00, #00,
      #01, #F0, #0F, #0F, #00, #00,
      #00, #7F, #FF, #FF, #0C, #00,
      #00, #34, #F0, #F0, #C2, #00,
      #00, #7F, #FF, #FF, #0C, #00,
      #01, #F0, #0F, #0F, #00, #00,
      #12, #E1, #00, #00, #00, #00,
      #07, #0E, #00, #00, #00, #00,




      #03, #0F, #00, #00, #00, #00,
      #01, #F0, #08, #00, #00, #00,
      #00, #78, #87, #0F, #08, #00,
      #00, #37, #FF, #FF, #8E, #00,
      #00, #12, #F0, #F0, #E1, #00,
      #00, #37, #FF, #FF, #8E, #00,
      #00, #78, #87, #0F, #08, #00,
      #01, #F0, #08, #00, #00, #00,
      #03, #0F, #00, #00, #00, #00,


      #01, #0F, #08, #00, #00, #00,
      #00, #78, #84, #00, #00, #00,
      #00, #34, #C3, #0F, #0C, #00,
      #00, #13, #FF, #FF, #CF, #00,
      #00, #01, #F0, #F0, #F0, #08,
      #00, #13, #FF, #FF, #CF, #00,
      #00, #34, #C3, #0F, #0C, #00,
      #00, #78, #84, #00, #00, #00,
      #01, #0F, #08, #00, #00, #00
    };
     
      static short image1[] = {
         16, 16, 5, 80,


         #FF, #FF, #FF, #FF, #00,
         #F8, #F0, #F0, #F1, #00,
         #CB, #0F, #0F, #3D, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CA, #00, #00, #35, #00,
         #CB, #0F, #0F, #3D, #00,
         #F8, #F0, #F0, #F1, #00,
         #FF, #FF, #FF, #FF, #00,


         #77, #FF, #FF, #FF, #88,
         #74, #F0, #F0, #F0, #88,
         #65, #0F, #0F, #1E, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #00, #00, #12, #88,
         #65, #0F, #0F, #1E, #88,
         #74, #F0, #F0, #F0, #88,
         #77, #FF, #FF, #FF, #88,


         #33, #FF, #FF, #FF, #CC,
         #32, #F0, #F0, #F0, #C4,
         #32, #0F, #0F, #0F, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #08, #00, #01, #C4,
         #32, #0F, #0F, #0F, #C4,
         #32, #F0, #F0, #F0, #C4,
         #33, #FF, #FF, #FF, #CC,


         #11, #FF, #FF, #FF, #EE,
         #11, #F0, #F0, #F0, #E2,
         #11, #87, #0F, #0F, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #84, #00, #00, #6A,
         #11, #87, #0F, #0F, #6A,
         #11, #F0, #F0, #F0, #E2,
         #11, #FF, #FF, #FF, #EE
       };
       
      static void main()
      {
         GameSystem.SetStack(#A6FC);
         Game();
         GameSystem.RestoreStack();
      }
     
      static void Game()
    {
         GameScreen.SetMode(1);
           
         GameSprite sprite1;
         GameSprite hin1, hin2, hin3;
         
         sprite1.Create(0, 50, &image);
         hin1.Create(100, 80, &image1);
         hin2.Create(150, 110, &image1);
         hin3.Create(170, 150, &image1);
         
         sprite1.keyUp = GameKeyboard.keyUp;   
         sprite1.keyDown = GameKeyboard.keyDown;
         sprite1.keyLeft = GameKeyboard.keyLeft;
         sprite1.keyRight = GameKeyboard.keyRight;
         
         sprite1.xSpeedKeys = 2;
         sprite1.ySpeedKeys = 2;
         
         Graphics.Move(0, 200);
         Graphics.Draw(640, 200);
           
         while(1){
            if(Keyboard.Inkey())
            {         
               sprite1.UpdateByKeys();
               sprite1.xIncrement=0;
               sprite1.yIncrement=0;       
            }
           
            if (sprite1.IsCollision())
            {     
               if (hin1.IsCollision() & hin1.IsActive())
               {
                  hin1.Remove();
                  Text.PrintString("\n\rhindernis1 weg....");
               }
               else if (hin2.IsCollision() & hin2.IsActive())
               {
                  hin2.Remove();
                  Text.PrintString("\n\rhindernis2 weg....");
               }
               else if (hin3.IsCollision() & hin3.IsActive())
               {
                  hin3.Remove();
                  Text.PrintString("\n\rhindernis3 weg....");
               }
            }
            GameScreen.WaitFlyback();
         }
     }
}



Powered by SMFPacks Menu Editor Mod