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 / RayCast and Timers

Author
Message
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 26th Aug 2015 07:39 Edited at: 26th Aug 2015 07:44
I just recently started a Platform Game Project and got my first level built. I went back to add in all the variables of what makes a game. I.E Player Health, Health Boost, Coins, Enemies...etc...

I ran into a problem when the player is attacked by the enemy my health decreases rapidly when it should only decrease by 1 every hit. The Health is effected by when either of his 2 sides touch the enemy. Determined by Raycast.



This works just fine ^ the only thing is I don't want to delete the sprite. I want there to be a recover time so the player can have a 2nd chance of killing it on his own.

If I don't delete the sprite the health decreases by a number greater than 1 throwing off the health cycle and killing the player.

My 2nd attempt.




This is the first time iv even looked at timers and there are a few issues.

1. Sometimes it skips to 5-6-7 and continues to finish (Dosnt always start at 0 )

2. It does not turn off the Raycast. What I am trying to accomplish is the Characters Raycast Ignore the Enemy during the Recover Time.

Thanks in Advance, any advice is greatly appreciated.

http://crazyprogrammerproductions.webs.com/
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Aug 2015 08:30
Timer() is the time since you started the app.


I haven't looked at your code in detail but you probably need to start by setting RecoverTime like this:

RecoverTime = Timer() + 10

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 26th Aug 2015 16:42 Edited at: 26th Aug 2015 16:44
Thanks BatVink for your advice

I figured it out.





It just hit me I was running the raycast without it asking permission. I got it all sorted out

http://crazyprogrammerproductions.webs.com/
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Aug 2015 18:29
Good to hear

I still think you may hit a problem later in your program using ResetTimer(), when it gets more complicated. You may need the timer for other activities. Normally you would only use ResetTimer() in between games (and only if you really need it).
It would be better to...

RecoverTime = Timer() + 10

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 29th Aug 2015 02:38
Thanks Batvink I recently updated the previous Timer function...

Now I am trying to add a Game Completion time at the end of the level.

Iv been playing around and I got this



Its working but..i started to think if Timer() = 169 it should be 2 minutes 48.96 seconds and in this case AppGameKit always rounds to make a whole number. So when the finishing number of seconds is greater than 30 the minutes round up throwing off the timer. How do you go about getting accurate time ?

Thanks for advice in advance

http://crazyprogrammerproductions.webs.com/
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Aug 2015 10:04
Timer() is a float, accurate to milliseconds.

You should use TimeM# and TimeS#, then you will get the full float value. Or declare your variables as floats:

global TimeM as float
global TimeS as float

Accuracy can wander after a significant amount of time, so consider resetting the timer each time the user starts a new game from your menu.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 30th Aug 2015 03:15
Sounds like you have something interesting going on here CP, another one for the Showcase section soon?

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 30th Aug 2015 04:50
Thanks Batvink...always quick and to the point

@Paul I'm working on a side scrolling platformer(nothing original) but it will have my spin off.
I only have 1 level loaded atm but have almost got the engine done enough for a demo...just few more days I'll have you a demo. I've been shelling out for some nice graphics and sounds...so I hope I can live up to the visuals.

http://crazyprogrammerproductions.webs.com/
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 30th Aug 2015 05:30
Sounds great, looking forward to having a peak

The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 31st Aug 2015 22:55
Quote: "Thanks Batvink...always quick and to the point"


You're welcome. Experience has taught me that the more you write, the harder it is to understand. Some of my posts may seem abrupt, but simplicity is the aim.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 1st Sep 2015 03:57 Edited at: 1st Sep 2015 04:40
Quote: "You\'re welcome. Experience has taught me that the more you write, the harder it is to understand. Some of my posts may seem abrupt, but simplicity is the aim. "



Back to Timer questions....

Been tinkering with a stop watch to monitor game time and this is what iv got so far...

For what I\'m trying to do its working perfect...It seems its not 100% accurate but who care about a few seconds over a 1-3 min game level.

I have a few questions about this.

1. Is having this constantly running in the game loop a good idea?

2. This is what I figured out from lack of examples...is there a better way?

Thanks for your advice in advance

Edit: Just found out if TimeS < 10 it just prints (1-9) not (01,02,03,04,05 ) etc....I shoulda known better, just something I over looked

So the fix for that problem is....



http://crazyprogrammerproductions.webs.com/
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Sep 2015 14:09
1. Your code will run in nanoseconds, it shouldn't slow down your game. The only thing I do to (possibly) improve this is save timer() in a global variable. If I'm using the timer() many times, I assume it is faster to read it from a variable than call a function every time I need it.

2. It works, and it is efficient. I'm sure the maths wizards may have a better way, but I would be happy to use what you have here.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 2nd Sep 2015 01:10
Thanks Batvink always very thankful for your advice.

Well I think that sums up any questions I have on Timers (I hope)

http://crazyprogrammerproductions.webs.com/
Stupinator
9
Years of Service
User Offline
Joined: 14th Sep 2015
Location: Vancouver, WA, USA
Posted: 15th Sep 2015 00:09
What I've done in most implications is used a two timer system. For example:



since the first timer is outside of the do loop, it's only updated when the game is first started, this will cause the script to (*dostuff()*) every 10 seconds.

-Stupinator

Login to post a reply

Server time is: 2024-11-21 14:55:48
Your offset time is: 2024-11-21 14:55:48