Pen Scrolling

Материал из Поле цифровой дидактики

A pen scrolling engine is a scrolling engine that uses the Pen Extension.

Setup

Create these variables:

(Scroll X)
(Scroll Y)
(X Vel)
(Y Vel)

Create these custom blocks:

draw stage::custom
draw player::custom
controls::custom
go to x: [] y: [] with scroll::custom

Scripts

To start off, create the main script.

when green flag clicked
hide
set [Scroll X v] to [0]
set [Scroll Y v] to [0]
set [X Vel v] to [0]
set [X Vel v] to [0]
forever
erase all // Reset the stage
draw stage :: custom // This will be explained later
draw player :: custom // This will be explained later
controls :: custom // This will be explained later
end

Now, add the control script.

define controls
change [X Vel v] by (<key (right arrow v) pressed?> - <key (left arrow v) pressed?>)
change [Y Vel v] by (<key (up arrow v) pressed?> - <key (down arrow v) pressed?>)
set [X Vel v] to ((X Vel) * [0.9])
set [Y Vel v] to ((Y Vel) * [0.9])
change [Scroll X v] by (X Vel)
change [Scroll Y v] by (Y Vel)

Now the important part, the stage.

define draw stage // Make sure this is "Run Without Screen Refresh".
set pen size to (5)
set pen color to [#32a852]
go to x: [50] y: [50] with scroll :: custom
pen down
go to x: [50] y: [-50] with scroll :: custom
go to x: [-50] y: [-50] with scroll :: custom
go to x: [-50] y: [50] with scroll :: custom
go to x: [50] y: [50] with scroll :: custom
pen up

define go to x: (x) y: (y) with scroll
go to x: ((x) - (Scroll X)) y: ((y) - (Scroll Y)

Now to draw the player:

define draw player // Make sure this is set to "Run Without Screen Refresh".
go to x: (0) y: (0)
set pen size to (40)
set pen color to [#0400ff]
pen down
pen up

Now the pen scrolling engine is complete.