<> Introduction

Last time, I only did the third step , I can't believe the speed ! My programming work has reached the seventh step ( Now it's stuck because of technical problems …) I'll speed up next .( More code will be posted next , And the interval between each code block is very short , Please understand )
These articles suggest that those who have not read them should read them from the beginning , Otherwise you may not know what I'm doing
I've been watching it lately Appgamekit Official document of , There has been no update , I'm so ashamed , The article came out immediately ! Let's get started ,Link start!!!

<> code 4. Realize random generation 1 Or 2 A draggable number grid

This is a very simple step .
Open as usual Appgamkekit

<> preparation

First of all, we know , To randomly generate one or two number grids , So we're going to need a random variable . When it comes to 1 When I was young , generate 1 A grid , When it comes to 2 When I was young , Generate two lattices . So first of all main.agc A file named ORT Variable of .

in addition , In the first article, we defined a sprite1 Variable of , Some may wonder why there should be one 1, Here's the answer . It means this is the first lattice . When we need two squares , We can't just use 1,2 To represent them , So we need to define another one sprite2.
ORT as integer sprite1=1 sprite2=2
<> Main programming

I don't need to give it here for the time being ORT assignment . come Load.agc Start the operation in the file . stay ORT by 1 When I was young , Code unchanged . When ORT by 2 Add the following code when you start
LOAD2: ORT=random(1,2) // to ORT random assignment ,1 or 2 CreateImageColor(1,0,255,255,255)
CreateImageColor(255,255,255,0,255)// When you need to create two lattices , We'll need two different color squares if ORT=2
CreateSprite(sprite1,1) CreateSprite(sprite2,255) SetSpriteSize(sprite1,50,50)
SetSpriteSize(sprite2,50,50) SetSpritePosition(sprite1,blockX/2-30,blockY)
// Set the position of the two cells SetSpritePosition(sprite2,blockX/2+30,blockY) endif if ORT=1
CreateSprite(sprite1,1) // These are the original code SetSpriteSize(sprite1,50,50)
SetSpritePosition(sprite1,blockX/2,blockY) endif return
Notice that there's one at the beginning here “LOAD2:”, That is to say, at the end, you need one return, And in LOAD2 Do not include last build in 25 A code that can place blocks .

At this time, if the compiler runs, an error will be reported , Why? ? Because in our generation 25 When a block can be placed , We are from 2 Created from

So here we have to modify it , hold i The value of is from 2 Amend to read 3, Loop to 26 Amend to read 27
for i=3 to 27
At this time, the operation will be successful . If ORT The value of is 2 Then there will be such a running situation ‘

<> code 5. To achieve the use of the mouse while dragging two digital lattice

This is complicated . You can see the figure below ( This is mine Movesprite.agc file , It may be different from yours )

But don't worry , It's easy to penetrate here bit by bit . When you write these codes successfully, you will feel very proud .

No more nonsense , Start programming .

First of all Movesprite.agc The following variables are defined in the file ( Change color, change mood )
mouseX1 as float mouseY1 as float mouseX2 as float mouseY2 as float jiange =

above 4 It's a variable. It's easy to understand , Two digit grid XY coordinate , This needs to be distinguished from the case of a grid , Or you'll get mixed up later . the last one jiange It's easy to understand what it means , The space between two number grids ( Chinese Pinyin …)

After getting these variables , We will need to modify the previous code , We've been here before Movesprite.agc I've written the code to move a lattice , Here we put one on it if Statement to detect whether a lattice is currently generated ( If two lattices are generated, the code here will be invalid )
if GetRawMouseLeftState()=1 if ORT = 1 if GetRawMouseX()>=getspriteX(sprite1)-
20 and GetRawMouseX()<=GetSpriteX(sprite1)+GetSpriteWidth(sprite1)+20 if
GetRawMouseY()>=GetSpriteY(sprite1)-20 and getrawmousey()<=GetSpriteY(sprite1)+
GetSpriteHeight(sprite1)+20 . . endif endif endif endif /* Pay attention to endif ending */
After doing this well , stay if
getrawmouseleftstate()=1 One more inside if sentence , But this one if We need to write it ourselves . In fact, the logic of dragging two lattices with the mouse is very simple , It's just updating the coordinates of the two spirits at the same time . So we need to write down here …
. . if ORT = 2 if GetRawMouseX()>=getspriteX(sprite1)-20 and GetRawMouseX()<=
GetSpriteX(sprite2)+GetSpriteWidth(sprite2)+20 if GetRawMouseY()>=GetSpriteY(
sprite1)-20 and getrawmousey()<=GetSpriteY(sprite1)+GetSpriteHeight(sprite1)+20
/* be careful , The detection statement here is different from that of a lattice , So don't copy and paste */ mouseX1 = getrawmouseX() - jiange /*
Update coordinates , Using the previously defined jiange variable */ mouseY1 = getrawmouseY() - GetSpriteHeight(sprite1)/2
mouseX2 = getrawmouseX() + jiange mouseY2 = getrawmouseY() - GetSpriteHeight(
sprite1)/2 if mouseX2 > blockX /* frame */ mouseX2 =blockX endif if mouseY1 >blockY
mouseY1 =blockY endif if mouseX1 < 0 mouseX1 = 0 endif if mouseY2<0 mouseY2=0
endif setspriteposition(sprite1,mouseX1,mouseY1)/* Update coordinates */ setspriteposition(
sprite2,mouseX2,mouseY2) endif . .
If there's nothing wrong with the program , Then click Run , You can see that when two lattices are generated , We can drag them around !!! It was a big success !!

But after it's written, someone might find out , There are more codes on the pictures I posted than here , In fact, the extra code is what I have been reading in the official documents these two days , These things are animations , Chain animation ( I like to call it that way ).

After the current code is written, you can find that , Whether it's a single or two grid , I'm dragging it ( People ) It's always a blink when it's time ( That is to say, at the moment when the left mouse button is pressed, the location of the grid is located to the coordinates we set , It's not good .) I've been looking for solutions to transition , If used inc
Command or order for Statement to increment coordinates, then the amount of computation will explode , If you use direct animation, then the production cost is very high , So I found this , Chain animation !

Because this involves a lot of things , Interested can go through the official documents ( stay Appgamekit Press F1) I'll just talk about what I use here .

To use chain animation , First you have to create a chain . We are here load.agc Create it in the library
chain = createtweenchain()
CreateTweenChain() // Create a chain, That's the chain

Please note that , The chain animation I'm talking about here is not its real name , It's just a translation of official documents that I read myself .

After creating the chain , We will also need to create Tween spirit ( Sprites using animation )
Also in Load.agc in , Where we create the grid , Add the following code
. . if ORT=2 CreateSprite(sprite1,1) CreateSprite(sprite2,255) SetSpriteSize(
sprite1,50,50) SetSpriteSize(sprite2,50,50) SetSpritePosition(sprite1,blockX/2-
30,blockY) SetSpritePosition(sprite2,blockX/2+30,blockY) CreateTweenSprite(
sprite1#,sprite1)// This is the code I added CreateTweenSprite(sprite2#,sprite2) endif if ORT=1
CreateSprite(sprite1,1) SetSpriteSize(sprite1,50,50) SetSpritePosition(sprite1,
blockX/2,blockY) CreateTweenSprite(sprite1#,sprite1)// ditto endif . .

You can see that , establish Tween The use of Sprite functions is the same as creating ordinary sprites , But here we use two new variables sprite1# and sprite2#, So we're here main.agc It's defined in a function ( In fact, it's OK without definition )
sprite1#=1 sprite2#=2
We have it Tween, There is also a chain , Next, in the Movesprite.agc Use them in the library

come Movesprite.agc in , We have to delete something here , that is setspriteposition() function , We don't love it anymore TAT! Then replace it with a new one SetTweenSpriteX() and SetTweenSpriteY(). Write the following code …
. . if ORT = 1 . . SetTweenSpriteX(sprite1#,GetSpriteX(sprite1),mouseX,0.1)
// hinder 0.1 It's animation time ,0.1 second SetTweenSpriteY(sprite1#,GetSpriteY(sprite1),mouseY,0.1)
//SetSpritePosition(sprite1,mouseX,mouseY) PlayTweenSprite(sprite1#,sprite1,0.1)
// Start animation , The time is 0.1 second AddTweenChainSprite(chain,sprite1#,sprite1,0)
// hold Tween Given to ordinary spirits , And add to the chain , The time is 0 second PlayTweenChain(chain) // Start play chain UpdateAllTweens(
GetFrameTime())// to update Tween spirit sync() endif . if ORT = 2 . . SetTweenSpriteX(
sprite1#,GetSpriteX(sprite1),mouseX1,0.1) SetTweenSpriteY(sprite1#,GetSpriteY(
sprite1),mouseY1,0.1) SetTweenSpriteX(sprite2#,GetSpriteX(sprite2),mouseX2,0.1)
//SetSpritePosition(sprite2,mouseX2,mouseY2) PlayTweenSprite(sprite1#,sprite1,
0.1) PlayTweenSprite(sprite2#,sprite2,0.1) AddTweenChainSprite(chain,sprite1#,
sprite1,0) addtweenchainsprite(chain,sprite2#,sprite2,1)// The following numbers also refer to the animation time ,1 Seconds and 0 second
PlayTweenChain(chain) //SetSpritePosition(sprite1,mouseX1,mouseY1)
//PlayTweenChain(chain) UpdateAllTweens(GetFrameTime())
//SetSpritePosition(sprite2,mouseX2,mouseY2) sync() endif . .
After all this is done , It's ready to compile and run . After running, you can find that the drag color block is no longer blinking like before , It will now have a transition animation . It's like this

<> epilogue

The next part is going to be the hard part . We need to keep going , It won't work if it's just three minutes hot , I've been out 3 This is an article , But the real main programming part has not been involved .

School is about to start recently , I'm still a student . After the beginning of school, the frequency of updating may be smaller , Maybe it's one in January , But it won't break , No matter what the situation is, I will not break more ! After this xiaoxiaole game is finished, I may go to make illusions 4 My article , But I'm not interested in fantasy 4 I know very little about it , I hope you won't laugh .

I am XresKing Howard!