Making a Flash game like Plants Vs Zombies – step 3

Here we go with 3rd step of Plants Vs Zombies game. Now we will place the bought plant on the game field and let the zombies enter.

Adding a zombie is quite easy because we manage it in the same way we managed the sun. Just like suns appear out of the top of the stage and then fall down, Zombies appear out of the right edge of the stage and move left. They don’t interact with plants yet.

As for placing the plant, we have to make sure when the player presses the mouse while dragging the plant that the tile he wants to place the plant is free and it’s inside game area. Then the plant is placed, the selector and the listener are removed, and the routine starts again with the player collecting suns and selecting which plant (only one available at the moment) to place on the game field.

I commented line by line the whole code, to help you understanting what’s happening.

This is the result:

Collect suns and buy and place plants while zombies arrive.

Download the source code. Next time, we’ll fight the zombies.

  • Wilson Silva

    I love your code. It’s so simple and efficient. I’m waiting for the next part :D

  • Pingback: Tweets that mention Making a Flash game like Plants Vs Zombies – step 3 - Emanuele Feronato -- Topsy.com()

  • rishabh

    i agree silva

    even if emanuele didnt comment his code

    you can understand it easily :3

    i didnt like what you did with the zombie

    it would be nice to have a movingZombie.speed
    variable which differs mattering on the type of zombie :3

    i know he will do it in the later tuts
    but i guess making the variable now is better then changing the coding later

  • itisasecret

    Zombies are currently on top of suns, so it’s hard to catch them.

    • rishabh

      That is easily fixable

      just add the zombieContainer to the display list before you add the sunContainer

  • Emad

    Good work, I’ll wait for the next part.
    thanks.

  • Giovanni

    I don’t really like it to be honest, it is kinda dirty code.
    Why do you put everything inside your main class instead of building a zombie, plant, sun class? etc and subclasses for the types of zombies and plants.

  • Sam

    Hi, im very new to flash and have a few questions. Could I edit the zombies to look however I want? And Also make a number of plants to select from?
    Thanks for any help

  • Mark B

    Thank you for doing these tutorials. They are very informative and fun to follow along with.

  • Cataclysm Studios

    Any particular reason you’re not using separate classes? (Much of OOP in general for that matter)

  • rishabh

    To explain with multiple classes , will be very time consuming , (see how long todds box2d tutorial chapter 2 took)

    but the finish product is much easier to modify

  • Hi,
    This is priyesh sheth the flash developer.
    I like your tutorials.
    I need one tutorials for game
    Do you know about angry bird iPhone/ipad game ?i need some idea for that type of game.. i want to do it with flash cs5 + as3
    so Please help me.. please

  • Andrew

    Perfect. Looking forward to no.4 :D

  • great tutorial… looking forward for the next part!

  • Ali

    Great Tutorial!!
    Thank You Very Much!

  • Farzad

    Ready for killing zombies !

  • Micky

    Great Tutorial!
    When is part 4 coming? i cant wait!!

  • kkgn

    Cool dude.. will be looking forward for the 4th part, Thanks!

  • Sascha

    Hey we need the next parts of tutorial :).
    The first three of it was amazing thx for that.

  • Limnick

    When I use the placePLant function it isn’t placing the sun in the grid where I want it to go … Any suggestions??

  • Pingback: ???????????Flash??3 | ?????()

  • carmine

    hi ,
    i missed lesson 1 and 2
    where can I find them ?
    grazie

  • May this will be play in tablet or ipad