Author Topic: Scrolling Engine  (Read 4341 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Scrolling Engine
« on: January 13, 2011, 11:02:52 am »
I've been trying to make a scrolling engine but I'm not having much luck :S



Code: [Select]
.SCROLL
ClrDraw
[003C7E7E7E7E3C00]->Pic1
[FF818181818181FF]->Pic2
Pt-On(40,40,Pic2
Repeat getKey(15)
Pt-On(X,Y,Pic1
If getKey(1)
Y+1->Y
Vertical -
End
If getKey(2)
X-1->X
Horizontal +
End
If getKey(3)
X+1->X
Horizontal -
End
If getKey(4)
Y-1->Y
Vertical +
End
DispGraph
End

That is my code and what is happening, attached is the source code.

My problem is that the scrolling is not working like, for example, in a RPG, and I want it for each time the ball moves 1 pxl, that little square moves one pxl too in a controlled way, isntead of what is happening (everything is crazy)















Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: Scrolling Engine
« Reply #1 on: January 13, 2011, 01:06:44 pm »
First you need make a tilemap. Next you can do a scrolling engine to display a tilemap in function of your sprite position.
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Scrolling Engine
« Reply #2 on: January 13, 2011, 01:53:47 pm »
I've been trying to make a scrolling engine but I'm not having much luck :S



Code: [Select]
.SCROLL
ClrDraw
[003C7E7E7E7E3C00]->Pic1
[FF818181818181FF]->Pic2
Pt-On(40,40,Pic2
Repeat getKey(15)
Pt-On(X,Y,Pic1
If getKey(1)
Y+1->Y
Vertical -
End
If getKey(2)
X-1->X
Horizontal +
End
If getKey(3)
X+1->X
Horizontal -
End
If getKey(4)
Y-1->Y
Vertical +
End
DispGraph
End

That is my code and what is happening, attached is the source code.

My problem is that the scrolling is not working like, for example, in a RPG, and I want it for each time the ball moves 1 pxl, that little square moves one pxl too in a controlled way, isntead of what is happening (everything is crazy)

I think the problem is that each time you use vertical or horizontal, you also increment the position of the black ball, effectively doubling the distance that you move?  Try using either horizontal/vertical, or incrementing X and Y.  Using both might cause problems.

Assuming you want to continue using horizontal and vertical, and assuming you don't want the black trail, try this:
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Scrolling Engine
« Reply #3 on: January 14, 2011, 05:43:23 pm »
Michael, your code isn't showing up...

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Scrolling Engine
« Reply #4 on: January 14, 2011, 05:56:29 pm »
Michael, your code isn't showing up...

Yeah it isn't :S

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Scrolling Engine
« Reply #5 on: January 14, 2011, 06:11:02 pm »
Michael, your code isn't showing up...

Yeah it isn't :S

Bizarre.  Here it is:

Code: [Select]
.SCROLL

[003C7E7E7E7E3C00]->Pic1
[FF818181818181FF]->Pic2

10->X->Y

Repeat getKey(15)
    ClrDraw
    Pt-On(35,35,Pic1)
    Pt-On(X,Y,Pic2)
    DispGraph

    If getKey(1)
        Y-1->Y
    End
    If getKey(2)
        X+1->X
    End
    If getKey(3)
        X-1->X
    End
    If getKey(4)
        Y+1->Y
    End
End

Disclaimer: This hasn't been tested, so you might have to fiddle with it slightly to get it to work the way you want.
I assumed that you wanted the black ball to move, and not leave behind a trail.
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Scrolling Engine
« Reply #6 on: January 14, 2011, 06:15:15 pm »
Thanks much!

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: Scrolling Engine
« Reply #7 on: January 15, 2011, 09:36:30 am »
Here a scroll engine with tilemapping :

Code :
Code: [Select]
:.RPG
:
:0→A→B
:.Position of tilemap
:
:4→V+1→U
:.V and U are position of cross
:
:Repeat getKey(15)
:If getKey(3) and (sub(ZIP,A+U+1,B+V)=0
: If A<24 and (U=5)
: +A→A
: ElseIf U<11
: +U→U
: End
:ElseIf getKey(2) and (sub(ZIP,A+U-1,B+V)=0
: If (U=5) and (A>0)
: A-1→A
: ElseIf U>0
: U-1→U
: End
:End
:If getKey(1) and (sub(ZIP,A+U,B+V+1)=0
: If B<8 and (V=4)
: +B→B
: ElseIf V<7
: +V→V
: End
:ElseIf getKey(4) and (sub(ZIP,A+U,B+V-1)=0
: If B>0 and (V=4)
: B-1→B
: ElseIf V>0
: V-1→V
: End
:End
:DispGraphClrDraw
:sub(TLM)
:Pt-On(U*8,V*8,[181818FFFF181818]
:End
:Return
:
:.Subroutine to wait no key pressed
:Lbl NOG
:While getKey(0)
: Pause 5
:End
:Return
:
:.Tile
:[0000000000000000]→Pic1
:.Tile n°0
:[FFFFFFFFFFFFFFFF]
:.Tile n°1
:[55AA55AA55AA55AA]
:.Tile n°2
:[7FBFDFEFF7FBFDFE]
:.Tile n°3
:
:.You can up to 16 tiles
:
:.Map
:[111111111111111111111111111111111111]→GDB1
:.Line 1
:[100000000000000000000000000000000001]
:.Line 2
:[100000000000000000333333000000000001]
:.Line 3
:[100000000000000000333333000000000001]
:.Line 4
:[100000000000000000333333000000000001]
:.Line 5
:[100000000000000000330033000000000001]
:.Line 6
:[100000000000000000330033000000000001]
:.Line 7
:[100000000000000000333033000000000001]
:.Line 8
:[100000000000000000330033000000000001]
:.Line 9
:[100000000000000000330333000000000001]
:.Line 10
:[100000000000000000330333000000000001]
:.Line 11
:[100000000000000000000000000000000001]
:.Line 12
:[100000000000000000000000000000002221]
:.Line 13
:[100000000000000000000000000000002221]
:.Line 14
:[100000000000000000000000000000002221]
:.Line 15
:[111111111111111111111111111111111111]
:.Line 16
:
:.Subroutine to display each tile on screen
:Lbl TLM
:For(Y,0,7)
: For(X,0,11)
: sub(ZIP,X+A,Y+B)→r1
: Pt-On(X*8,Y*8,r1*8+Pic1
: End
:End
:Return
:
:.Subroutine to extract byte from map (GDB1)
:Lbl ZIP
:r2*36+r1→r1
:{r1/2+GDB1}→r2
:If r1^2
: r2^16
:Else
: r2/16
:End

1200 byte source, 1300 byte.
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%