miscellaneous

Forum > Miscellaneous > Maths people/programmers
Reply To Thread (login)
Fishwick [132]
Moderator
2013-12-24 11:30:22 🔗
[11 years, 7 days ago]

I'm making a tower defense game and I need to prevent a user placing a tower on the path. The path is generated by supplying co-ordinates (like 0,5 then 10,20) etc. The co-ordinates are linked up and that is my path.

So far, I have managed to do this with this equation:

(x2-x1)/(y2-y1) == (x-x1)/(y-y1)

This WORKS! But, it only works for a one-pixel path between the two points. I need that path to be 30m wide (so 15px each side of the center)

The way I have been looking at is performing the formula 15 times with one added each time.

for(j=1; j<15;j++){
  if((x2-x1)/(y2-y1) == (x-x1)/(y-y1)){
    // you can't place tower here
  }
}

I'm going to need that above loop, but I need to modify the formula to take into account the variable "j".

Terribly explained because my head is a much, but any help would be appreciated.


 
New Alan [79]
2013-12-24 13:02:52 🔗
[11 years, 7 days ago]

Just do x1 plus j. Loop. THEN, loop y1 + j.

Id love to see this project..also, if you are using canvas, remember the y is switched from a typical graph.


 
New Alan [79]
2013-12-24 13:05:41 🔗
[11 years, 7 days ago]

Also, are your towers blocks or circles? This wont technically work.

Youll have to find the max area of this tower. Like (x-15),(y-15). You need start from the top left point and go to right then one pixel down until (x+15),(y+15) is the bottom right.

Im not sure on the exact loop right now.


 
Fishwick [132]
Moderator
2013-12-24 13:18:48 🔗
[11 years, 7 days ago]

I actually ended up getting it working shortly after posting this, though wasted a few hours beforehand.

Used this:

  if(((x2+j)-(x1+j))/(y2-y1) == (x-(x1+j))/(y-y1)){
    return true;
  }
  if(((x2-j)-(x1-j))/(y2-y1) == (x-(x1-j))/(y-y1)){
    return true;
  }

My mistake had been adding j to both x and y, whereas it seems to work if you only add it to one of them.

It's only just really started, so there a tons of bugs, but you can find it here: http://afishwick.com/pria/ . It's really not a "game" as of yet, so the waves come before you can place a tower. I'd recommend placing the tower (drag the coloured pokemon boxes) and then refreshing (they are stored locally, so won't disappear).


 
Esvrainzas [134]
2013-12-24 13:35:08 🔗
[11 years, 7 days ago]

Nice project, keep updating it here :)


 
New Alan [79]
2013-12-24 13:53:57 🔗
[11 years, 7 days ago]

Look pretty neat.

  • Needs a "start button"
  • Towers should be able to be put closer to each other
  • Box that you drag should light up or darken if you can place it there or not
  • Time between waves, like 10 seconds
  • When game is complete, save that. When you refresh page, it should check to see if the game was beaten. I can just refresh and get the max 675 score :)
  • Monsters/towers should be in a Monsters/Towers object. This will make it easier to loop through them later when there are more. ;)

Looks really good so far man. I'll be checking every few days! o/

  • Btw, why make your own $ function? Why not use jquery?

 
New Alan [79]
2013-12-24 13:55:15 🔗
[11 years, 7 days ago]

Also, when I run it and click another tab and come back, the monsters are all over the map :)


 
Fishwick [132]
Moderator
2013-12-24 13:59:18 🔗
[11 years, 7 days ago]

Thanks for those points, I'll be tackling those (and all the ones in my head) over the next few weeks.

Monsters/Towers have their own array already, "enemies" and "defenses".

Btw, why make your own $ function? Why not use jquery?

It's a university assignment strictly for javascript, so frameworks aren't allowed. Besides, jQuery isn't worth it for the filesize just for the selector, my $ function does basically the same thing, just slightly less advanced.

As for the changing tab thing, yeah I know. I know why that is, but it's not worth fixing for the assignment as I will make sure I don't change tab in the demo. Basically, I'm redrawing everything depending on where it was when the function last ran. Using RequestAnimationFrame (basically an optimization technique to get the best FPS possible), means that things aren't redrawn when you change tab. Whereas time continues to tick, so when it finally is redrawn, its messed up.


 
New Alan [79]
2013-12-24 14:03:03 🔗
[11 years, 7 days ago]

Didn't see the array :)

Sucky about the jquery thing :(

You could, if you want, do an "elapsed time since last run" check. Ed's battle code does that. If you change tabs during the battle, it'll hold. Then, it'll catch back up. You can see this with the bar to the left that says how many seconds are left.

Nonetheless, badass dude. Badass.


 
Scabara [27]
2013-12-24 16:30:27 🔗
[11 years, 7 days ago]

Pushed a little update to make it more game-like, will extend it after xmas.


 
New Alan [79]
2013-12-25 22:13:01 🔗
[11 years, 5 days ago]

Played new version. Much more game like. o/

  • When clicking new waves during a wave, it ends the current, maybe it could add on? :)
  • When pulling a tower over, it disappears..
  • The Levels are tough! hahaha
  • Maybe some more expensive towers.
  • On the wave X spot, on the top right, it could say Wave 2/10 or something? So you know when it ends.

I know this is just a school project, but it could get really cool really fast :D


 
New Alan [79]
2013-12-25 22:20:43 🔗
[11 years, 5 days ago]

Also, do you have lives to lose? Or no? :)


 
Fishwick [132]
Moderator
2013-12-25 22:39:02 🔗
[11 years, 5 days ago]

Just for you :P :

  • Eventually it will require no enemies be alive to go to next wave
  • Maybe you placed it on the path? should be in the error box underneath, not sure what you mean otherwise
  • Levels need balancing yet, atm 3 small (meowth), 2 of each medium (jesse/james) and 1 more big (giovanni) is added each wave. I will look at how I can balance, thoughts towards that are appreciated
  • Towers will be upgradable yet, making more means more work creating their faces in canvas later on
  • I hope for it to be unlimited once I nail down balancing, continually getting harder until you die or your comp can't process it anymore

And lives will be implemented soon.

Thanks for the interest, btw :)


 
New Alan [79]
2013-12-25 22:58:03 🔗
[11 years, 5 days ago]
  • I drag the box over to place and it doesn't give that box anymore.
  • To make levels hard, make the big guys come first, then spam the little guys. Maybe, as levels go up, like every 10, it adds a set amount of hp/speed
  • Tower Types??? :) Monsters being weak to certain things?? :)
  • I spammed your game clicking wave after wave until the game broke. Got to wave ~260.

I love the game Bloons. They just came out with Bloons TD battles where you actually send out bloons against other players while defending against auto-waves and their sent out bloons. Get's crazy! I've built a pretty badass strategy. :)


 
Fishwick [132]
Moderator
2013-12-25 23:04:44 🔗
[11 years, 5 days ago]

Bloons TD 5 made me decide to make it tbh. I got it in a humble bundle for android and absolutely bummed it for a few weeks.

It should create the tower, I still don't know what you mean, clarify if you don't mind

I'll probably make speed and hp increase over time to deal with upgrades.

I want to make towers weak to certain things and it seems relatively easy in theory. Ideally one tower (e.g. squirtle) would turn the enemy into it's type (water) meaning grass is then super effective (and fire isn't). That will come later though. Pikachu would mess up that combat triangle, maybe he won't get to play with weaknesses.


 
New Alan [79]
2013-12-25 23:14:14 🔗
[11 years, 5 days ago]

I mean certain towers being grass, and charmander hits harder. Not changing tower types..

I mean when I click a tower and pull it to the path, that "big" box I said to get rid of isn't there anymore, which is fine. But, the tower isn't even shown. I must guess where it is via my mouse. Does that explain it?

Bloons o/


 
Fishwick [132]
Moderator
2013-12-25 23:21:44 🔗
[11 years, 5 days ago]

Ahh yeah that explains it. I'll be implementing some sort of feature later on where you see the tower as you drag and it shows how far it will reach (range) and whether it can be placed there or not.

As for types, I reckon it would be better to allow the enemies type to be changed as it leaves a little more up to the user. You would have to think about which order to put your towers in, e.g. squirt > charmander > bulba and repeat to get the maximum effectiveness.

If I were to give enemies their own weakness that doesn't change, i would probably change from team rocket to typically "dark" or "evil" pokemon that attack. Like Zubat, no one likes zubat.


 
New Alan [79]
2013-12-25 23:23:27 🔗
[11 years, 5 days ago]

I'm excited!

Poor Zubat :(

  • Zubat
  • Rattata
  • Pidgey (Pigeot is so badass tho...)
  • Raticate
  • Geodude

 
dragonrose [64]
Head Moderator
2013-12-26 02:43:11 🔗
[11 years, 5 days ago]

I like zubat ...


 
Mithrandon [170]
2013-12-26 13:43:37 🔗
[11 years, 5 days ago]

feature or bug that you can stack the towers?


 
Fishwick [132]
Moderator
2013-12-26 14:02:26 🔗
[11 years, 5 days ago]

Bug, lots of fixes to do yet


 
Fishwick [132]
Moderator
2013-12-28 22:55:39 🔗
[11 years, 2 days ago]

Just pushed quite a few decent changes including working (and optimised for) mobile. A bit more of a "pokemon" look and feedback when deciding where to place a tower (including prevention of stacking).

Still not sure what to do for enemies. Team Rocket members or actual pokemon? Keep them as squares? A letter (e.g. Z for zubat). Could do with some inspiration in this area :)

If you see any bugs, please pm or post here.

www.afishwick.com/pria


 
Mithrandon [170]
2013-12-29 07:42:59 🔗
[11 years, 2 days ago]

just a thought, enemies could be berries


 
New Alan [79]
2013-12-29 13:05:34 🔗
[11 years, 2 days ago]

Game is really shaping up man.

I figured something out, a tower can shoot at every monster? Is that right? I noticed many shots coming from a monster in different directions. If this isnt the case, and that is "fixed" it will make the game extremely harder since so many monsters come at once. If you made a time set between monsters in each wave, thatd be better. Like, on each wave , 1000); for one second later. Etc, that way you can send 10 at once or one big one every second or two.


 
Fishwick [132]
Moderator
2013-12-29 13:08:38 🔗
[11 years, 2 days ago]

I'm working on what monsters come at what time at the minute, not entirely sure how it will end up, but I'm thinking about a set time per round, and increasing amounts of enemies come each wave. At the minute wave 100 or whatever takes forever.

As for one tower attacking many, thats half and half. Pikachu is intended to be Area of Effect, attacking everyone with lightning, but with less damage than the other, single target towers. However, there is a bug that I haven't found yet, charmander (and probably the other single target towers) can occasionally attack two at once, not entirely sure why.


 
New Alan [79]
2013-12-29 13:12:55 🔗
[11 years, 2 days ago]

On your "wave" code. That long list. You could put a time at the end, like 500-2000);

Then when the wave comes, it setTimeouts that number. :)

Didnt know pikachu was area of effect. Nice!


 
Esvrainzas [134]
2014-01-09 21:52:27 🔗
[10 years, 356 days ago]

I've tested the game today and it was awesome. It worths to try it now. Congrats Fishwick :)

http://afishwick.com/pria/


 
Fishwick [133]
Moderator
2014-01-14 07:35:20 🔗
[10 years, 351 days ago]

Cheers for all the feedback, particularly Tryhard, Alan, Esv, Rith and a few others. Just demonstrated it and got 91% \o/. A first is 70% so I'm pretty happy with that haha.


 
New Alan [79]
2014-01-14 07:50:03 🔗
[10 years, 351 days ago]

Hell of a job Fishy. Hell of a job.


 
Esvrainzas [134]
2014-01-14 15:59:08 🔗
[10 years, 351 days ago]

Congratulations Fishwick. Why did you lose 6%???


 
Esvrainzas [134]
2014-01-14 15:59:29 🔗
[10 years, 351 days ago]

9%*


 
Fishwick [133]
Moderator
2014-01-14 16:54:13 🔗
[10 years, 351 days ago]

Getting 100% is pretty much impossible at uni haha, 91 is extremely good, was the highest in the class by far (second was 78%)


 
Leader2 [69]
2014-01-14 17:04:59 🔗
[10 years, 351 days ago]

Lets throw a party then :D


 
Esvrainzas [134]
2014-01-14 17:13:38 🔗
[10 years, 351 days ago]

You can all dump energy on Escapism members to celebrate Fishwick's grade! Hurray \o/


 
Leader2 [69]
2014-01-14 17:15:24 🔗
[10 years, 351 days ago]

id rather invite the whole community round to my house and watch a boring movie :P


 
Esvrainzas [134]
2014-01-14 17:34:40 🔗
[10 years, 351 days ago]

If you pay me the flying tickets I wouldn't mind to watch a boring movie.


 
King Zal [80]
2014-01-14 20:27:38 🔗
[10 years, 351 days ago]

Congrats Fishy you smarty pants you :P


 
dragonrose [65]
Head Moderator
2014-01-15 16:39:02 🔗
[10 years, 350 days ago]

Nice going Fishy :)

What do you consider a boring movie Leader?


 
Forum > Miscellaneous > Maths people/programmers
Reply To Thread (login)