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 / [BASIC] how to use type?

Author
Message
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 22nd Jun 2017 10:04
Hi! I'm unsure how to check if one of my ball types has left the screen area. Do I have to loop through all my ball types, or is there a more clever way?

hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 22nd Jun 2017 20:54 Edited at: 22nd Jun 2017 21:47
I believe you'd need to loop through them. If you're just wanting to check until you've found any single ball that has left the screen, you could write a function that returns the index using exitfunction when the first out-of-screen ball is found, or -1 for none found.

pseudo code:



edit: D'oh, just realized this is probably a poor idea since you'd likely end up looping needlessly through your ball list twice. Ideally you'd have a function/routine that updates your ball list and sets a flag if one of them has gone out of the screen.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 23rd Jun 2017 00:06
Quote: "Ideally you'd have a function/routine that updates your ball list and sets a flag if one of them has gone out of the screen."


Yes this way you can reuse your bullets, there is an example of this method in the examples "Games\SpaceShooter"
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 23rd Jun 2017 17:15 Edited at: 23rd Jun 2017 17:31
Thanks for the help! I just tried this:
If the balls leave on the right or left of the screen, their horizontal velocity is reversed.
If the balls leave on the top or bottom of the screen, their vertical velocity is reversed.
Seem to work ... !



Or even more compressed:
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 24th Jun 2017 00:55 Edited at: 24th Jun 2017 00:56
You could use the SetPhysicsWallLeft/Right/Top/Bottom() as well
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 24th Jun 2017 13:04
Thanks! But actually, I had to disable SetPhysicsWallSomething(). The reason: I use SetScissor(0,0,0,0), and SetPhysicsWallSomething() are using the old, non-scissorized values.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 24th Jun 2017 14:28 Edited at: 24th Jun 2017 14:33
Pseudocode:

You can add friction and restitution so it acts like you want

Using AGKv2 Tier1

Login to post a reply

Server time is: 2024-04-20 01:55:02
Your offset time is: 2024-04-20 01:55:02