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.

AppGameKit Classic Chat / Total lost need some help

Author
Message
ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 4th Oct 2012 20:36
So let me explain my game first then I'll get to the question. I made files with the names of my subs, so that i willmake my main.agc easier to read. I also "#Include" every file I made so that's not apart of my problem. So my main.agc loads then GoSub mainMene it works I load everything there, but how should I go about loading my other screens, when the correct button is clicked? I don't want to delete sprites then load new ones, because that would get old fast. Or is that the only way?
ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 4th Oct 2012 20:37
I'm also doing this in tier 1
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Oct 2012 21:09
If you break up things into files, you should probably use function and function calls instead of gosubs.

I'm not sure if gosubs work across files.

Are you sure that you have a return statement at the end of the subroutine code?

Cheers,
Ancient Lady
AGK Community Tester
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Oct 2012 21:26
I use go subs across files with no problem.


this.mess = abs(sin(times#))
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Oct 2012 22:02
Okay, I did say 'not sure' because I've not done it.

Personally, I don't like gosub and the sort-of similar goto. This goes back to my early Fortran days. It's easy for someone to get in trouble with gosubs, especially if you 'nest' your calls.

Cheers,
Ancient Lady
AGK Community Tester
ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 4th Oct 2012 22:41
Yes I use return statements in all my gosubs
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Oct 2012 22:58
We'd have to see your code in order to help you figure out what isn't working.

Cheers,
Ancient Lady
AGK Community Tester
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 5th Oct 2012 00:07
Quote: "We'd have to see your code in order to help you figure out what isn't working."

This might be more of a conceptual problem instead of a coding one. From what I gather, he's asking how to get from say the main menu to the actual game play.

Quote: "but how should I go about loading my other screens, when the correct button is clicked?"

The way I go about this is that I break up my game into 'frames'. The main menu being a frame, the first level being a frame, the options menu being a frame etc. An then I have 3 functions per frame, essentially, a Load, a Play and a Clean Up. The load functions loads in all of the media needed, sets sprite positions and essentially prepares everything for that frame. The play frame is what's repeatedly called inside a loop and handles events such as pushing buttons etc. Finally, when leaving the frame the clean up is called and deletes all media used by that frame so the next frame is free to take over without any worries.

Quote: "I don't want to delete sprites then load new ones, because that would get old fast. Or is that the only way?"

You can just hide your sprites (setSpriteVisible()) however, keep in mind that you're unnecessarily taking up RAM. This might not be your case but imagine if you have over 100 levels and you don't delete anything from going level to level. Just be careful when not deleting the unnecessary media for each 'frame'. It may also mean that AppGameKit has a larger job when it has to clean up all of the media when the app closes.

Happy programming

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Oct 2012 00:13
What I've done in the past, is use my main program loop for the "menu" screen, then call gosubs for each menu option, like "Play Game", "Options", "Credits", etc.

I like gosubs for the fact that you don't have to worry about global vs local.

And I like functions partly because you do get control of local vs global. Also because you get to pass values and receive a return.

Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 5th Oct 2012 03:18 Edited at: 5th Oct 2012 03:25
The way I do it is by having a variable I call GameState that holds the part of the program that is currently executing in the main loop. By changing this value I can switch to any part of the program and execute that part.



For switching screens I'll usually just delete all the sprites and then if needed I'll just recreate them.

Alternatively you can just SetSpriteVisible() and hide them.

One more option would be to reposition the sprites offscreen so that they are effectively hidden and then just move them back when you need them.

Last you could just do all your screens offscreen and then use SetViewOffset() to move between screens.

Auger
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Oct 2012 16:37
Instead of multiple if statements, try the select structure:


The way you have your code (and this might be deliberate), all of the steps are executed in the first sync cycle. This means that the main menu might get displayed, but you immediately set the state flag to the next state and, because the following if statement is true, it executes Initialiseround(), then sets the flag again and the PlayGame() function gets called. As a result, since there is only one apparent call to Sync(), only the game play is visible (unless you do Sync() calls and wait for stuff in the other functions).

For the above code, make sure that GameState is global so that it is visible in the main loop when you set the value inside of some function.

Cheers,
Ancient Lady
AGK Community Tester
Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 5th Oct 2012 20:32
Yes, ill usually just branch off and the return to the main loop. I just have that sync in the main loop because I like to put debug information down near the end of the main loop.
The reason I like if is because I can do things like. If gamestate = 300 and playerlives > 0

I can do the same select with another if test inside the case branch. I just prefer to do it that way

Auger
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Oct 2012 20:42
Auger, your code is NOT showing a branching (gosub or goto calls), it is showing that you are using functions.

I'll assume that the functions you call do a loop w/sync until the proper condition is met. Otherwise, the code you posted runs through IntializeGame(), MainMenu() and IntializeRound() in sequence without any displays at all and then goes into PlayGame() (which presumably does some displays) and stays there.

A state engine would work better with a select/case setup and the called functions or executed processes would change the state variable to move it along.

But, if it is working the way you want, no sweat, all is good.

Cheers,
Ancient Lady
AGK Community Tester
Auger
13
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 5th Oct 2012 22:24
Sorry typing this from my phone during my work breaks , so I'm probably not explaining myself clearly enough. Yes all my functions are self contained and include a sync() within them. Plus I agree that select is more efficient.

Auger
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 5th Oct 2012 23:07
Gosub.....you say.....Gosub?

I will not tolerate such terrible language in these posts!

It has made me feel a little poorly. I may have to regress a little to 1980.

Sorry all....could not resist! It was either this or watch strictly....arrrgh

Constantly seeking!
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 5th Oct 2012 23:10
Rich....sounds like your falling toward OOP....after all it answers ALL of those questions

Constantly seeking!
ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 7th Oct 2012 02:43
I got an another question. I'm making a 2d side scroller and I was wanted to know how would you make the background scroll?
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 7th Oct 2012 03:27
ChoppingLemons, I think there's really two basic ways to get a backdrop scroll.

1. Move backdrop sprites. If you have multiple layers of backdrop sprites, the back layer can move slowly, the next closest a little faster, etc. This gives parallax scrolling and looks very neat.

2. Move the view.

ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 7th Oct 2012 20:39
I didn't think about the parallax scrolling, but I got some ideas now. I'm making a very cartoonish game, and I couldn't draw bricks so I took a picture of the side of my house. Then I crop it so it would like like a platform of bricks. So I may take pictures of real items and add them to the cartoon background. So while the character is walking in front of a cartoon mountain a real tree could pass him.
Thanks RICH for the idea.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 7th Oct 2012 21:54
Sounds cool, ChoppingLemons. If you are working with a paint program that does "posterization" that is a good way to make photos look "cartoony"

ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 8th Oct 2012 01:35
Well my wife does photography on the side, so I'm sure she has some nice programs I could use, and maybe she'll do the work for me. But I have another question. What the best way to have a sound toggle switch in the game? So the player can turn off the sound if he wants. I was thinking just delete all of the music, but I'm thinking it will crash the program.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 8th Oct 2012 12:11
Well, you could just set the master sound volume to zero.

Or you could make a function that plays a sound only if a global flag is true.

ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 12th Oct 2012 03:28
It never cross my mind to set the music to zero. I've already set the volume down so I wouldn't drown out the sound effects, but never thought why don't I use one line of code instead of making it very complicated. Thanks Rich some time I amaze myself with with how dumb I can be.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 14th Oct 2012 02:02 Edited at: 14th Oct 2012 02:05
Quote: "... I think there's really two basic ways to get a backdrop scroll.
1. Move backdrop sprites.
2. Move the view.
"

... and ...
3. Move the texture across a single static background sprite.

This would be useful for a game such as Mario World if you wanted to use the view offsets for the main level and still have a parallax background.

Really only useful for repeating backgrounds

http://forum.thegamecreators.com/?m=forum_view&t=194972&b=41
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th Oct 2012 02:53
Quote: "Really only useful for repeating backgrounds"


Somewhat, but it IS possible to set the UV of the sprite to only show a fraction of the image, and scroll the rest. Eventually it will repeat, but you could get 3 or 4 screens worth of backdrop for sure.

ChoppingLemons
12
Years of Service
User Offline
Joined: 25th Sep 2012
Location:
Posted: 18th Oct 2012 04:11
Could I see someone's code snippet for a moving background? I looked at the space game that could in the examples but I have no clue whats going on there. And if you do provide a snippet please let it be commented on or at least give me some type of detail of why you did what you did. I don't care how you move the background, I just want some idea of how to do that.

I made like haft a game in java and I moved the background with the player. But I don't have the slightest clue of how to do it in agk.

Login to post a reply

Server time is: 2024-11-27 17:08:56
Your offset time is: 2024-11-27 17:08:56