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 / Tower Defense Template/Tutorial [TD]

Author
Message
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 18th Nov 2021 01:20 Edited at: 24th Oct 2022 05:50
the following is offered as a starting place for anyone who hasn't written a traditional Tower Defense game using a grid-based Tile system.

it uses a Waypoint system (sometimes referred to as "breadcrumbs") to guide Enemies down the Road.

for new users, please read up on User-Defined Types, V2 Arrays, and User Functions where the code relies upon them:


while i've used similar functionality before, i've never "put them all together" for something like this. so, please direct to any errors you might find; it's running fine on my end, but i expect it can be "broken"

and, i'm sure there are more-efficient methods but i'm trying to keep it simple for new users (and my own sanity in trying to get this out ASAP for the Comp).

11/21/21: Code updated with Tower Upgrades and more! - see below
01/09/22: HealthBars added - updated source and playable demo @ itch.io
10/23/22: Save/Load (Desktop & HTML) added @ itch.io. Core functions: HERE

Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Nov 2021 01:45
Nice starting point there VN, hopefully pulls a few more entries in, although I don't really want to see clone upon clone it will certainly be interesting to see how many different directions this template can take. awesome stuff

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Game_Code_here
4
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 18th Nov 2021 01:58
300 lines?

Impressive

I'm at around three thousand lines in three different include files lol.

But I'm sure new people will take it and use it full force.

I will even look at it to learn new things.

I always learn something new from you.

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 18th Nov 2021 02:49 Edited at: 18th Nov 2021 02:50
found that i wasn't (also) using the Map[] properly to determine if a space was buildable. code fixed and updated above.

meanwhile, apparently wave ~25 is max where i'm out of real estate:

Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Nov 2021 05:26 Edited at: 18th Nov 2021 05:27
Ah, that is called a "negative feedback loop"... its one of game making biggest pitfalls, putting the player in a situation where he can not win, I want my game to detect this and snap a webcam pic the moment he rage quits .... lmao!!

I know... I'm a git!"

That's when you start upgrading towers, to kill more enemy's, they come faster, upgrade, rinse and repeat, or open up another section of the map, and again, rinse and repeat, looks like you got plenty of credits, make the upgrades expensive
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 22nd Nov 2021 02:39 Edited at: 22nd Nov 2021 02:46
Tower Upgrades and more!



review the original code and spot the changes (mostly //noted) in the new code:


i'm calling Wave 50 MAX (made it to 48 before i found i was accidentally limiting Towers to Level 9 ).

is anyone (beside me) using this for the comp?

i'd like to know!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Nov 2021 04:40
Quote: "meanwhile, apparently wave ~25 is max where i'm out of real estate:"

Make a bigger map and zoom out!
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 22nd Nov 2021 05:06
RC01
2
Years of Service
User Offline
Joined: 4th Dec 2021
Location:
Posted: 4th Dec 2021 19:48
Hmm I must be doing something wrong, it just crashes?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Dec 2021 20:37 Edited at: 4th Dec 2021 20:41
You are accessing a invalid array item (-1)

Show the block of code, its impossible to debug from a error dialog, line 91 in Vn's code is a EndIf ... that would not generate that error, we need to see your array code

Edit: or first example???

this??


if so, change to this
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 5th Dec 2021 02:42 Edited at: 5th Dec 2021 02:50
i'll take a look at it but the array length 30 in the error is referring to the y-size of the map array: GLOBAL Map as Integer [20,30]

so, you must have somehow been able to click above y = 0 to return -1?

again, its reference -1 so: if ThisX <> -1 and ThisY <> -1 is still going to let you click < 0. if anything, wrap it in if ThisX > -1 and ThisY > -1 which still leaves it susceptible to x > 20 and y > 30 (which i didn't worry about since i hadn't implemented view offset yet.

meanwhile, i'm assuming the error number is off because i tend to enter 2+ lines of code in line 1. for example:

i'm not sure if the compiler counts that as 7 lines of code or not <shrugs> but i don't remember ever being "that far off".

@RC01, this is my first attempt at a tutorial. are the comments throughout "enough" to follow what i've been trying to show? any feedback from a newcomer along those lines is appreciated incase i try to do another sometime.

finally, i have health bars implemented. i may add something else this weekend and post an update. when i do, i'll make each line "its own line" for clarity purposes/scenarios like this. no need to perpetuate all of my bad habits
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 5th Dec 2021 11:00
Quote: " is still going to let you click"


You are correct, the best practice is to check the range (if ThisX >= 0 and ThisX <= 20) etc, but as you say with no view offset it should always be within range.

Quote: "i'm not sure if the compiler counts that as 7 lines of code"


Yes, when ':' is used the compiler sees 1 line, I just did a quick test and it appears to report the correct line number
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 5th Dec 2021 16:32 Edited at: 5th Dec 2021 16:33
just noted the crash is with the first example (where the text was black). i tried re-creating the scenario (building tower in the top-right corner) and didn't receive the error in the updated code and it's probably to do with my not adding proper safety nets to ensure clicking within the map (only).

@ RC01, was that the case? had you somehow clicked off the map?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 10th Jan 2022 01:29 Edited at: 10th Jan 2022 04:30
small update to this with HealthBars added:

playable demo and updated source code added @ itch.io

btw, i'm calling 68 MAX level

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 24th Oct 2022 05:39 Edited at: 18th Nov 2022 00:39
updated to include "single string" Save/Load functionality for both Desktop & HTML via some simple string Building and Parsing that some might find useful: https://virtual-nomad.itch.io/td-template.

The Core (although a number of other changes were made):


Make sure to modify the Player for same-site Cookie support.

Login to post a reply

Server time is: 2024-11-23 09:38:18
Your offset time is: 2024-11-23 09:38:18