Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Is there a easier way to do this code for sprite falling?

Author
Message
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 5th Jul 2020 23:09 Edited at: 6th Jul 2020 00:17
I have full sprites falling on empty sprites to fill them with there info.

I have tested my code and it works, but it is for only two sprites

if I do it for all sprites nothing happens as only one sprite is above the other.

I cant get my mind around it.

Do i have to write 64 lines of code?

Sorry, Im still learning



this is how im doing it now, to many lines of code, over 64 times

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 6th Jul 2020 10:58 Edited at: 6th Jul 2020 11:03
Is this still the match3 game?
If so, you're really making this difficult for yourself.
What is the slot array for?
Why are you referencing the sprites by their ID number - Rule number one of coding is NEVER hard code any numbers. That is especially true for sprite ID's. You already have the references to them in board[x,y].spr

What I would do is add another variable to the type tCell called falling. It would be an integer behaving as a boolean (true of false \ 0 or 1).
After deleting (hiding) matches, check each cell to see if there is a visible sprite in the cell beneath it. If not then set the falling flag to true (1) .
Then loop through each cell updating the positions of any that are falling until they have all dropped into place.
Obviously you'll also need to create new sprites for the ones that are falling into the gaps at the top.

In short, to answer this: "Is there a easier way to do this code for sprite falling?"
Yes, there are many easier ways but probably very few ways you could make it more difficult than you are doing.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 9th Jul 2020 19:09
Ok, im back

I have decided to delete the sprites as it is more easy

I implicated the code and it works well with no errors

i'm not having new sprites as in this match game you have to clear the board.

So I have finished everything but the falling code

I need to find a way to check if a sprite exist then if not set the top sprites to fall

Thanks for your help.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 9th Jul 2020 21:07
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 10th Jul 2020 02:42
Yes, this is how I did it, lol, I have to put this code just about in every line now, but at least I dont have to keep switching images and the program gets confused.

Im not to sure how to check if if a sprite exists from bellow so the top sprites will fall is what I mean.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Jul 2020 10:02
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 10th Jul 2020 14:58
Yes, I understand that my friend.

I'm smarter then that lol

That checks the sprites that don't exists.

but then after this, I have to tell the sprites over the empty positions to fall. this is the hard part. Because I cant tell every sprite to fall.

Everything I write makes all the sprites above to fall, even the ones that don't have empty positions.

Im having fun trying, because I see some funny results.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 10th Jul 2020 16:25
If I can not hard code any id numbers how then do i assign sprite animations?

I tried this with no luck

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 11th Jul 2020 03:02
ok, I found a error in your code

you can not have more then one level

#constant MARGIN_LEFT 40
#constant MARGIN_TOP 240
#constant BOARD_SIZE 7
#constant CELL_SIZE 75
#constant QTY_STYLES 9
#constant HORIZONTAL 0
#constant VERTICAL 1

You can use the constants anywhere in your program to specify items of data that are not going to change throughout your programs execution

So i can not change the board size or shape or anything

I fixed everything to work, and it works good, so I tried to make a second level to find out the values cant be changed.

What do I do?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Jul 2020 03:18 Edited at: 11th Jul 2020 03:19
Quote: "What do I do? "

don't set them as #constants. constants can never change (and there's an advantage to that which i don't think you need for this project).

if you're going to use the variables inside functions, you may want to set them as global variables, instead.

otherwise, i think you've really gone down a rabbit hole with this while not showing YOUR code which leaves others guessing at what you're trying to accomplish and while you offer "I found a error in your code" when there was no error at all.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 11th Jul 2020 03:27
Well the error of not being able to change values is what I meant, no offense to his good working code, with out him i would not be where i'm at in appgamekit.

Thanks for the advice, I will change it now and see how it goes.

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 11th Jul 2020 03:37
Unexpected token "board size" any dimension must be a integer literal or #constant

Then this is the line it is talking about

global board as tCell[BOARD_SIZE, BOARD_SIZE]

and this is what i changed

global MARGIN_LEFT as integer:MARGIN_LEFT= 40
global MARGIN_TOP as integer:MARGIN_TOP= 240
global BOARD_SIZE as integer:BOARD_SIZE= 7
global CELL_SIZE as integer:CELL_SIZE= 70
#constant QTY_STYLES 9
#constant HORIZONTAL 0
#constant VERTICAL 1

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 11th Jul 2020 09:30
You got that message because "There's an error in your code"
Good luck with it.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 11th Jul 2020 16:41 Edited at: 11th Jul 2020 16:43
I think it's hard to give you help because we don't see what you are really doing. Only tiny isolated snippets of code.
If possible, when asking for help make a small video showing what you have and what the problem is along with the tiniest amount of code possible that gives the full picture.
You might even need to create a new project to do that. Yes, there is work involved but that has to be expected because there is also work involved whenever someone takes their time to help.

Anyway... I knocked this out and maybe it will help. Again, it is hard to know exactly what you are doing or even want to do.
This is just my best guess.

I included some general program structure in this just because I thought might be helpful at some point to you and others who are relatively new developers.



As others have mentioned there are many ways to do things. This is only one of them...
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 11th Jul 2020 17:36 Edited at: 11th Jul 2020 17:37
GarBenjamin

Thank you, I am cheeking it out and seeing how it works

I think people forget im new to appgamekit and am learning and this is so I can learn better.

If you want to help then help

if not then that is ok also.

I apprenticeship all the help indeed.

I can post the full code as it is just the same code he provided with my sprites and a couple things I added.

I like your code


My code in full


GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 11th Jul 2020 18:08 Edited at: 11th Jul 2020 18:09
Okay, hopefully it will be of some help.

It's not perfect by any means. Actually, I think there might be a possibility of a sprite falling below the board so a check should be added for that.

In a way it's a simple problem because breaking things down ultimately everything becomes a simple problem. And, on the other hand, to do things right and handle all cases, all edge cases and so forth... even things that seem very simple can become fairly involved. That's just the nature of things.

I completely get you are learning and if my wording came across in a wrong way that was not intended. Mainly, I was just trying to say the more information people have available the better the help is they can provide. That's all.

Good luck with it. Look forward to seeing your progress.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 11th Jul 2020 20:09 Edited at: 13th Jul 2020 06:49
I used the code you provide and added my images to each sprite and it works. Now I have to incorporate the same matching function to work with the code. I'm starting to fully get it because of your code.

Thanks


Ok update, I added Scraggle match code to yours and then edited your player remove sprite and it works lol.

2 pieces of code mixed works.

I'm using your code because it is formated more for a game with levels and a menu.

Well with trial and error I'm close to a working match 3 game.

Even invisible the program keeps matching them also. Even if I add if sprites are Visible check.

I'm close to a perfect running code.

I will post the code when I get it right.
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 13th Jul 2020 07:02
If you used the boardspritetype then you can check if the state of the sprites = SSTATE_ATREST and that will only check for visible non falling sprites.
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 13th Jul 2020 08:17
Hi

I did that and it didn't work, I'm not sure why. But I had another idea. I'm wanting to clear the board from each match. So I added a background sprite and am coloring the background to each match.

So reusing the sprites is a good idea.

Im still getting matches for them so I can still use it for my advantage.

And the sprites still fall also. But I'm working on it little bit at a time.

Thanks for the help.

Login to post a reply

Server time is: 2024-04-19 04:59:19
Your offset time is: 2024-04-19 04:59:19