Pardon the mess, Play My Code is in beta!

READY TO PLAY?
CLICK TO LOG IN!

sign up - lost password

Xlags Game »

You do not own this project, so changes will not be saved

//Untitled Tower Defense Game Copyright 2013 Markus Heichelbech. All Rights Reserved.
//-Load Images
//$user = new User()

 //Get the name of a user
//$userName = $user.getName()
//mySaveData = ""
//$user.saveGame(mySaveData)
//mySaveData = $user.loadGame()
$titleMusic = new Sound('darkangelintro.mp3')
$gameMusic = new Sound('darkangelloop.mp3')
$turret = new Array()
$turret = new Image("towers.png")
$controlButtons = new Image("cbuttons.png")
$bg = new Array()
4.times() do |i|
$bg[i] = new Image("bg0"+i+".png")//dbg.png")
end
$shot0 = new Image("shot00.png")
$boom0 = new Image("boom0.png")
$base = new Image("base00.png")
$glow = new Image("glow00.png")
$bug=new Image("bugs.png")
$bugBoss=new Image("bosses.png")
$fBoss=new Image("finalBoss00.png")
$gunButtons = new Image("guns.png")
$titleLogo = new Image("titlex.png")
$menuButtons = new Image("buttons.png")
$freezeGlow = new Image("freezeglow.png")
$poisonGlow = new Image("poisonglow.png")
$menuBg = new Image("menu.png")
$arrows = new Image("arrows.png")
$levelThumbs = new Array()
4.times() do |i|
    $levelThumbs[i]=new Image("level0"+i+".png")
end
//-End Load Images
//Initialize generic global variables
$mouseX = 0
$mouseY = 0
$cellX = 0
$cellY = 0
$currentButton = null
$mouseMode=99;
$currentTower = null
$totalTowers=11
$frameCount=0
$rowSize=19


//Initialize game variables
$audio = 1
$currentLevel = 0
$totalWaves = 80
$waveList = new Array()
$waveType=new Array()
$nCreeps = 10
tCreeps = ($bug.getHeight()/32).floor()
    i=0
    c=0
    x=0
    t=0
$totalWaves.times() do |i|
    t=x+c
    if(t>=tCreeps)
        t=0
    end
    $waveList[i]=t
    $waveType[i]=c
    c = c + 1
    if(c == 5)
        c=0
        x = x + 1
    end
end
    $nCells=0
    $explode = 0
    $cellCount = 0
    $cash = 300;
    $towers = new Array()
    $creeps = new Array()
    $booms = new Array()   
    $waves = new Array()  
    $shots = new Array()     
    $gameSpeed=1
    $tempSpeed=1
    $waveTime = 1000  
    $canPlace = 0
    $gameTime = 0
    $waveTimer=0
    $wave = 0  
    $interest = 3
    $lives=999999999
    $bonus = 0
    $score = 0    
    $waveCash = 100000000000000000000000000000    
    $tech = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 1]  //upgrade path
    $realTime=0
    $waveInt=new Array($totalWaves)
    $waveInt = [].fill($totalWaves, "1")
    $lastTime=0
    $bossWave = 0    
    $timeBonus = 100000000
    $entry = 0
//create game mode & arrays
$Tower_Buy_Buttons = new Array() //tower buy
$tower_Control_Buttons = new Array() //tower sell
$title_Buttons = new Array() //title maps
$game_Control_Buttons = new Array() //game control
$cells = new Array(228, 3)
$leveltext = ["Easy", "Medium", "Medium", "Hard"]
$tmodes = ["Closest", "Newest", "Oldest", "Strongest", "Weakest"]
$stats = [[.5, 1, 1],[.6, .94, 0],[.4, 1.6, 0],[.5, 1, 1],[.7, .9, 1],[2.5, 1, 0]]
$znames=["C", "N", "0", "S", "W"]
$ctext=["Speed up", "Pause/Menu", "Sound On/Off"]
$damages = [4, .3, .8, 1, 20, 8, 200, 2400, .1, 40, .1]
$costs = [75, 150, 300, 500, 800, 1000, 6000, 5000, 8000, 2000, 20000, 2000]
$ranges = [80, 70, 70, 90, 70, 70, 120, 200, 80, 200, 600, 200]
$rates = [10,6,8,6,28,4,4,24,30,10,20,10,10]
//$rates = [4,4,4,3,0,2,40,12,15,10,10,10,10]
$names = ["Auto Turret", "FlameThrower", "Stasis", "Laser", "Bomber", 
    "Radiation", "AutoCannon", "Missile Launcher", "Support Tower", "Interest", "Plasma Core", "Extra Lives"]
$descriptions = ["Basic Machine \nGun, medium \nrange & \ndamage", 
    "Flame\nThrowing turret,\nDoes Splash Damage.",
    "Stasis Pulse\nGenerator. Slows \nEnemies Down.",
    "Pulse laser \nbeam - long range, \ncontinuous damage", 
    "Bomber\nThrows Out Bombs.\nDoes Splash Damage.", 
    "Radiation Emitter\nPoisons Enemies with\nRadiation.",
    "Massive \nGatling Gun Fires\nHeavy Slugs.", 
    "Missile\nBattery Launches\nExplosive Missiles",
    "Boosts\nTurrets In Range",
    "Increase Interest\nRate by 3%",
    "Ultimate\nAnnihilation\nbeam!",
    "Get 3\nMore Lives", "Upgrade Tower", "Sell Tower", "Fast Forward", "Pause", "Sound On/Off"]
$locks = ["", "", "", "", "", "", "Research AutoCannon", "Research Missiles", "Research Booster", "Interest - \nNeed Bonus", "Plasma Beam-\nWarheads, Booster,\n& Voltage required.", "Extra Lives -\nNeed Bonus"]
$message = "Machine Spirits\nTD Game By\nDSTGames."
$startCell=3
$secondCell=3
$endCell=0
$worms = new Array()


a=530
b=100
j=0
k=0
12.times() do |i|
    ll=0
    if(i>5)
        ll=1
        if(i==9 || i==ll)
            ll=2
        end
    end        
    $tower_Buy_Buttons.add(new Button(a+j*36, b+k*36, i, ll))     //main buttons   (x, y, function, type)
    j=j+1
    if(j==3)
        j=0
        k=k+1
    end
end
3.times() do |i|
    $game_Control_Buttons.add(new Button(533+(i*32), 380, i, 6)) //pause, ffwd, sound buttons
end
$pmenu=new Poster()
$titleMode=new TitleMode()
$mainMode = new Mode()
$gameOverMode = new GameOverMode()
$currentMode = $titleMode
$titleMusic.setRepeating(true)
$gameMusic.setRepeating(true)
$titleMusic.play()

def resetGame(cm)
    if($audio == 1)
    $titleMusic.stop()
    $gameMusic.play()
end 
    $explode = 0
    $cellCount = 0
    $cash = 999999
    $towers.clear()
    $creeps.clear()
    $booms.clear()
    $waves.clear()    
    $shots.clear()
    $gameSpeed=1
    $tempSpeed=1
    $waveTime = 1000  
    $canPlace = 0
    $gameTime = 0
    $waveTimer=0
    $wave = 0
    $frameCount = 0    
    $interest = 3
    $lives=99
    $bonus = 0
    $score = 0    
    $waveCash = 999999999   
    $tech = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 1]  //upgrade path
    readMap(cm)
    $realTime=0
    $waveInt=new Array($totalWaves)
    $waveInt = [].fill($totalWaves, "1")
    $lastTime=getTime()
    $currentMode=$mainMode
    $bossWave = 0
    $nCreeps=10
    $timeBonus = 999999999
   // $currentmode.doThing(99)   //give bonus for testing    
end

def readMap(cx)
  //  $level = $levelThumbs[cx]+
  $currentLevel = cx
  $level =$levelThumbs[cx]

j=0
i=0
k=0
228.times() do |c|
    $cells[i][0]=0 //reset them at start
    if($level.getPixelGreen(j, k)>0 && $level.getPixelRed(j, k)==0) //for green
        $startCell=i
        $cells[i][0]=1
    else if($level.getPixelGreen(j, k)>0 && $level.getPixelRed(j, k)>0) //for yeller
        $secondCell = i
        $cells[i][0]=1
    end
    
    if($level.getPixelRed(j, k)>0 && $level.getPixelGreen(j, k)==0)
        $endCell=i
        $cells[i][0]=1
    end
    if($level.getPixelBlue(j, k) >0)
    $cells[i][0]=1
    end
    $cells[i][1]=j*32+16
    $cells[i][2]=k*32+16
    j = j+1
    if(j==19)
        j=0
        k = k+1
    end
    i=i+1
end//end loop
    countnCells()
    $entry = ($cells[$secondCell][2]-$cells[$startCell][2]).atan2($cells[$secondCell][1]-$cells[$startCell][1])
end//end read map
def countnCells()
        $cells.each() do |i|
        if($cells[i][0]==1)
            $cellCount = $cellCount + 1
            $nCells = $nCells + 1
        end
    end
end
def giveCash(b)
    $cash = ($cash + b).round()
    checkButtons()
end
def checkButtons()
    $tower_Buy_Buttons.each() do |thisone|
        thisone.processLock()
    end
end
def doBoost()
    $towers.each() do |thisone|
        thisone.reset()
        thisone.countCells()
    end
    $towers.each() do |thisone|
        if(thisone.getZ()==7)
            thisone.boost()
        end
    end
end

def calculateScore()
    total = 0
    $towers.each() do |thisone|
        total = total + thisone.getValue()
    end
        total = total + $cash
        total = total + (total*$lives*.1)
        if($lives >= 20)
            total = total * 1.2
        end
        total = total + (total * $timeBonus *.01)
        return total
    end
//resetGame(0)    
onEachFrame() do/////////////////////////////////////////////////////////////////MAIN LOOP//////////

    $currentButton = null
    $frameCount = $frameCount + 1
    $gameTime = getTime()
    drawImage($bg[$currentLevel], 310, 200, true)
    c=getControls()
    $mouseX=c.getMouseX()
    $mouseY=c.getMouseY()  
    $currentMode.run()
    c.isLeftPressed() do
        $currentMode.leftClick()
        $message = ""
    end   

   // fillText(fs(1, 2), 200, 200, true)
        
  //  fillText($waveInt[0]+":"+$waveInt[1]+":"+$waveInt[2], 100, 100)
     //   fillText($waves.size(), 40, 40)
end //end main Loop///////////////////////////////////////////////////////////////////////////////////

def testWave(b)
            $waveInt[b]=1
            xint = (($cash * $interest) / 100 ).floor()
            giveCash(xint)
            if($currentTower == null)
                    $message = "+ $"+xint+"\nInterest earned!"
                    end
            if(b==2)
            $explode = 1
            $creeps.clear()
            
            
            end
    end//testwave
    
def fs(b, s)
    ab=b.toString()
    x=ab.indexOf(".")
    if(x==-1)
        x=ab.length()
    end    
    y=ab.length()-(x+1)

    c=""
    x.times() do |i|
        c = c + ab.getChar(i)
    end
    
    if(y>0)
     y = (y).min(s)
        if(s>0 && x>0)
            c = c + "."
        end
        y.times() do |i|
            c = c + ab.getChar(i+x+1)
        end
    end
    return c
end

def setLives(b)
    $lives=$lives + b
    if($lives == 0)
         $score = calculateScore()
         $currentMode = $gameOverMode
    end
end
    
        
class Poster
    def new
        $tower_Control_Buttons.add(new Button(540, 340, 12, 3)) //upgrade button
        $tower_Control_Buttons.add(new Button(580, 340, 13, 3)) //sell button
        5.times() do |i|
        $tower_Control_Buttons.add(new Button(530+(i*18), 310, i, 4))//targeting buttons
        end
    end
    def post(thisone)  //show the tower stats and info in the menu
        stats=thisone.getStats()
        lines=stats.split(":")
        setColor( :white)
        x=lines[0].toInt()
        y=lines[1].toInt()
        name=lines[2]
        level=lines[3]
        range=lines[4].toNumber()
        erange=lines[5].toNumber()
        damage=lines[6].toNumber()
        edamage=lines[7].toNumber()
        rate=lines[8]
        cost=lines[9]
        value=lines[10]
        fillText(name, 520, 230)
        fillText("Level: "+level, 520, 240)
        fillText("Range: "+fs(range, 0)+"("+fs(erange,0)+")", 520, 250)
        fillText("Dam: "+fs(damage, 2)+"("+fs(edamage,2)+")", 520, 260)
        if($cash >= cost)
            setColor(20, 255, 20);
        else
            setColor( :red);
        end
        fillText("Cost: "+cost, 520, 270)
        setColor( :white)
        fillText("Value: "+value, 520, 280)
        setColor(20, 255, 20);
        fillText("Target:"+$tmodes[$currentTower.getMode()], 520, 290)
        setColor( :white)
        drawRect(x, y, 32, 32, true)
        drawEllipse(x, y, range*2, range*2, true)
        if(erange-range>0)
        setColor( :blue)
        drawEllipse(x, y, erange*2, erange*2, true)
    end
    end
end    

def giveBonus()
    $bonus = $bonus + 1
    6.times() do |i|
        $tower_Buy_Buttons[i+6].unLock()
    end
end

def useBonus(id)
    used = false
    if(id==9)
        $interest = $interest + 3
        used=true
    else if(id==11)
        $lives = $lives + 3
        used=true
    else if(id > 5)
        if($tech[id]==1)
        $tech[id]=0
        used=true
        else if($tech[id]==2)
            if($tech[6]==0 && $tech[7]==0 && $tech[8]==0)
                $tech[10]=0;
                used=true;//end id 9
            end//tech no open
        end//tech not 1
    end//id >5
    
    if(used==true)
        $bonus = $bonus - 1
    end
    if($bonus == 0)
        6.times() do |i|
            if($tech[i+6]==1)
                $tower_Buy_Buttons[i+6].lock()
            end//if techs
                
            end//loop
            end//if bonus
  
     end//end dobonus
def backToTitle()
    $currentMode = $titleMode
    if($audio == 1)
    $gameMusic.stop()
    $titleMusic.play()
    end
end

class GameOverMode < Mode
    def new()
        @dTime = 0
    end
    
    def run()
        @dTime = @dTime + 1
        render()
    end
    
    def leftClick()
        if(@dTime > 50)
        backToTitle()
    end
    end
    
    def render()
        setFont("Arial", 24)
        setColor(0, 0, 0, .5)
        fillRect(310, 220, 400, 300, true)
        setColor( 255, 200, 0, 1)
        if($lives>0)
        fillText("You finished the game with a score of:", 310, 150, true)
    end
        if($lives<=0)
            fillText("You were annihilated and scored:", 310, 150, true)
        end
        setColor( :white)
        fillText(fs($score, 0), 310, 175, true)
        setFont("Arial", 14)
        fillText("Game programmed by DST.\nGraphics by DST.\nSound by DST.\n\nSpecial Thanks to Andy White.", 310, 300, true)
    end
end
class TitleMode < Mode
    def new()
        4.times() do |i|
       // $title_Buttons.add(new Button(120+(i*130), 300, i, 5))
       $title_Buttons.add(new Button(700+(i*100), 200 + (i*50), i, 7))
    end
    end
    
    def run()
        setColor( :white)
        setFont("Arial", 18)
        drawImage($titleLogo, 310, 200, true)
        fillText("Click on a start button to choose a level!", 310, 160, true)
        setFont("Arial", 12)
        fillText("Copyright 2013 DSTGames.com.", 420, 385, false)
        $title_Buttons.each() do |thisone|
            thisone.run()
            thisone.render()
        end
    end
    def leftClick()
        if($currentButton!=null)
            $currentButton.doClick()
        end
    end
end

class Mode
    def new()
    end
    
    def doThing(thing)
        if(thing==99)
            giveBonus()
    end
    if(thing<12)
        if($tech[thing]==0)
        else  //if tech not available
             if($bonus >0 && thing >5 && thing <12)
               useBonus(thing)
             end //end bonus
    end //end tech
    end//end 13
        if(thing==12)
            if($currentTower!=null)
                    $currentTower.upGrade()
            end//not null
        end//thing 12
        if(thing==13)
                        if($currentTower!=null)
                            $currentTower.sell()
                            
                        end
                    end//thing == 13
            
    end//end dothing
    
    def leftClick()
        if($currentButton == null) //if no button selected
        found=0
        if($mouseX<500)      //if mouse in playfield
            $towers.each() do |thisone| //else get current tower
                if(($mouseX-thisone.getX()).abs()<16 && ($mouseY-thisone.getY()).abs()<16)
                    $currenttower=thisone    //set it to current tower if found
                    $mouseMode=87
                    found=1
                end //tower found
            end //end tower search loop
            if(found==0)// if in play but no tower found...
                if($mouseY>380 && $mouseX<240)    //advance wave if wave message clicked on
                   if($waveTimer < $waveTime)
                       $timeBonus = $timeBonus + ($waveTime - $waveTimer)
                   end
                   $waveTimer=$waveTime-1
              else //not on advance wave
                if($canPlace == 0 && $mouseMode<12 && $cash >= $costs[$mouseMode]) //add a tower if we're in that mode
                   $towers.add(new Tower($cellX, $cellY, $mouseMode, $cell))
                   doBoost()
                    $cells[$cell][0]=99     //mark cell as now unusable
                    giveCash(-$costs[$mouseMode])    //spend the money    
                else
                    $currentTower=null
                    $mouseMode=87
              end// canplace
              end//end not on advance wave elsennnnnnnn
              end//end not found
    end//end in playfield
    
else if($currentButton!=null)
            $currentButton.doClick()
            doThing($currentButton.getZ())
end

    end//doclick
    
//=======================================================DEF RUN========================/////   
    def run()
            228.times() do |i|
        if($cells[i][0]==1)
            setColor(150, 100, 0)
              //  setColor(10, 80, 102)
            drawRect($cells[i][1], $cells[i][2], 32, 32, true)
             //   setColor(10, 40, 82, .5)
             setColor(150, 0, 0, .4)
            fillRect($cells[i][1], $cells[i][2], 32, 32, true)            
        end
    end   
        setColor( :white )
    drawRotatedImage($arrows, $entry, $cells[$startCell][1], $cells[$startCell][2], true);

  //  fillRect(512, 0, 120, 420, false)
    drawImage($menuBg, 565, 200, true);
  //  setColor(50, 0, 0);
   // fillRect(520, 230, 92, 128, false)
    setColor( :white)    
    $game_Control_Buttons.each() do |thisone|
        thisone.run()
    end    
    
    $realTime = getTime()
    aa = $realTime - $lastTime
    aa = (aa/16.6).floor()+1  //total frames since last frame
    $lastTime=$realTime
    
    aa.times() do |no|
    $gameSpeed.times() do |i|


     if($waveTimer < $waveTime)
         $waveTimer = $waveTimer + 1
     end
     if($waveTimer==$waveTime && $wave < $totalWaves)
        $waves.add(new Wave($nCreeps, 1000, $waveList[$wave]))
        $wave = $wave + 1
        $waveTimer=0
      end

    if($mouseY<380 && $mouseX < 512)  //normal playfield mouse
    $cellX = (($mouseX-32)/32).ceil()
    $cellY = (($mouseY-32)/32).ceil()
    $cell = $cellX+($cellY*19)
    $cell=$cell.limit(0, 280)    
    $canPlace=1
    if($mouseMode<$totalTowers)
        setColor( :white)
        drawImage($gunButtons, $mouseMode*32, 0, 32, 32, $cells[$cell][1], $cells[$cell][2], true)
    end
    setColor( :red)
    if($mouseMode<$totalTowers && $cash >= $costs[$mouseMode] && $cells[$cell][0]==0)
        $canPlace = 0
        setColor( :green)
     end     //end canplace   
    $cellX = $cellX*32+16
    $cellY = $cellY*32+16
    drawRect($cellX, $cellY, 32, 32, true)
    if($mouseMode<12)
    drawEllipse($cellx, $celly, $ranges[$mouseMode]*2, $ranges[$mouseMode]*2, true)
    end//end mousemode
    end//end mouse in playfield
    
    setColor( :white)
    runObjects()
  end //end gamespeed
  end// end time function

    setColor( :white)
    $creeps.each() do |thisone|
        thisone.render()
    end      
        $towers.each() do |thisone|
        thisone.render()
       end   
        $towers.each() do |thisone|
        thisone.fire()
       end          
        $booms.each() do |thisone|
        thisone.render()
        
      end       
        $tower_Buy_Buttons.each() do |thisone|
        thisone.render()
      end
        $game_Control_Buttons.each() do |thisone|
        thisone.render()
      end      
    if($currentTower!=null)
        $tower_Control_buttons.each() do |thisone|   //show tower control buttons
            thisone.render()
        end
    end
    
    $shots.each() do |thisone|
        thisone.render()
    end
    
    if($currentButton!=null)
        $currentButton.hiLite()
    end
    setColor(237, 210, 102)

    setFont('Arial', 14)
    fillText($cash, 580, 2 )
    fillText($lives, 580, 20)
    fillText($bonus, 580, 36)

    fillText($interest+"%", 580, 55)   
        setColor( :white )
    fillText("Wave: "+$wave, 44, 376)
    b=$waveTimer/1000
    bc=90
    ii=$wave-1
    ll=$waveList.length()
    jj=ll-ii  //remaining waves...
    kk=ll.max(jj)
    xx=0
    ll.times() do |i|  //draw the wave preview at the bottom
        if(i>=ii)
        setColor(255, 255, 255, 1-(xx/10))
        drawImage($bug, 0, $waveList[i]*32, 32, 32, 224 + (xx*16)-(b*16), 384, 16, 16, true)
        xx=xx+1
        end
    end
    setColor( :white)
    drawRect(224, 384, 16, 16, true)
   // fillText("Score: "+$score, 520, 36)
    setColor(40, 0, 0)
    fillRect(120, 380, bc, 10, false)
    setColor( :red)
    fillRect(120, 382, bc-(b*bc), 10, false)
    setColor( :white)
    setFont( 'Arial', 10)    
    fillText("time till next", 120, 380)
    if($currentTower != null)
      $pmenu.post($currentTower)
    end
    fillText($message, 522, 228)
    setFont( 'Arial', 12)
    if($bonus >0 )
        setColor($rcolor[0], $rcolor[1], $rcolor[2], 1)
 else
     setColor( :white)
 end

    rotateColor()
    
    if($explode > 0)
        setColor( :white)
        drawEllipse(310, 200, $explode * 3, $explode*3, true)
        m=$explode/250
        m=1-m
        setColor(255, 255, 255, m)
        fillRect(310, 200, 620, 410, true)
        $explode = $explode + 1
        if($frameCount % 2 == 0)
            $booms.add(new boom(rand(600), rand(400), 10))
        end
        if($explode==250)

                $score = calculateScore()
                $currentMode = $gameOverMode
            end
        end

    end //end main game run!====================================================================//

end

class Wave
    def new(numberx, timer, typ)
        @number = numberx
        @time = 50
        @type = typ
        @myTime = 0
        @myWave = $wave
        $waveInt[$wave]=numberx
    end
    def run()
        @myTime = @myTime + 1
        if(@myTime == @time)
            $creeps.add(new Creep(@type, @myWave))
            @myTime = 0
            @number = @number - 1
            if(@number == 0)
                m=@myWave+1
               if(m==5 || m==15 || m==25 || m==35 || m==45)
                $creeps.add(new Boss($bossWave, @myWave))                
                $bossWave = $bossWave + 1
                $nCreeps = $nCreeps + 2
            else if(m==50)
                thiscreep=new Boss(0, 50)
                thiscreep.makeSuperBoss()
                 $creeps.add(thiscreep)
             end
            $waves.delete(this)
            end
        end
  //      fillRect(200, 200, 20, 20, true)
    end//end run
end

$dir = [-19, -1, 1, 19]
$dirs = [[0, -1],[-1, 0],[1,0],[0,1]]

def locToCell(xx, yy)
    aa = (xx/32).floor()
    bb = (yy/32).floor()
    cc = aa+(bb*19)
    return cc
end

class Shot
    def new(xx, yy, zz, dir, dd, mm)
        @x=xx
        @y=yy
        @z=zz
        @damage=dd
        @speed=1
        @rot=0
        @target=null
        @frame=0
        @xRot=dir
        @dTime=12
        @xTime = 1
        @mode=mm
        @range = 0
        if(zz==0)
            @rot=@rot+$gameTime
           // @dTime = (dd*20).floor() + 10
           @dTime = 12
        end
        if(zz==2)
            @speed=2
            @dtime=49
        end
        @dMax = @dTime
    end
    def setRange(x)
        @range = x
    end
    def setD(d)
        @dTime=d
    end
    def render()
        if(@z==0)
            renderFire()
        end
        if(@z==1)
            renderMissile()
        end
        if(@z==2)
            renderBomb()
        end
    end
    def renderMissile()
        setColor( :white)
        drawRotatedImage($shot0, @rot, 0, 32*@frame, 48, 32, @x, @y, true)
    end
    
    def renderFire()
        @xTime=(@dTime/@dMax)
        setColor(255, 255, 255, @xTime*2)
        @xTime = 1-@xTime
        @xTime = @xTime * @xTime
        bb=(@xTime * .3 * 128)+20
        drawRotatedImage($boom0, @rot, 0, 0, 32, 32,  @x, @y, bb, bb, true)
    end    
    def renderBomb()
        drawImage($glow, 0, 0, 32, 32, @x, @y, true);
    end
        
    
    def die()
        $shots.delete(this)
      //  $booms.add(new boom(@x, @y, 0))
    end
    
    def run()
        if(@z==0)
            runFire()
        end
        if(@z==1)
            runMissile()
        end
        if(@z==2)
            runBomb()
        end
    end
    
    def runBomb()
        @dtime=@dtime-1
        @speed = @speed *.95
        @x = @x+(@xRot).cos()*@speed
        @y = @y+(@xRot).sin()*@speed
        if(@dtime==0)
            $shots.delete(this)
            damageAllInRange(48)
                    $booms.add(new boom(@x, @y, 0))
        end
    end
        
    def runFire()
        if(@speed==1)
            @speed=4
        end
        @x = @x+(@xRot).cos()*@speed
        @y = @y+(@xRot).sin()*@speed
        @rot = @rot + .1
        @dTime = @dTime - 1
        if(@dTime==0)
            $shots.delete(this)
        end
        @rot = @rot.wrap(0, 6.2)
        if(@dTime%3==0)
            damageAllInRange(32)
    end
    end//end runfire
        
    def damageAllInRange(b)
                $creeps.each() do |thisone|
            xdist=dist(@x, @y, thisone.getX(), thisone.getY())
            if(xdist= 400)
            die()
        end
        @x = @x+(@rot).cos()*@speed
        @y = @y+(@rot).sin()*@speed
        if(@target!=null && @target.getHealth()>0)
            @speed=@speed*1.01
             @rot=(@target.getY()-@y).atan2(@target.getX()-@x)
             xx=dist(@target.getX(), @target.getY(), @x, @y);
             if(xx<32)
                 @target.getShot(@damage)
                 die()
             end
         else
             target()
             speed=1
         end
     end
     
     def target()
        @target=null
            xdist = 0
            tdist = @range
            $creeps.each() do |thisone|
                xdist=dist(@x, @y, thisone.getX(), thisone.getY())
                if(xdist0)
            drawEllipse(@x, @y, @width, @width, true)
        end
        setColor( :red)
        fillRect(@x-10, @y-16, 20, 3, false)
        xx = @health/@healthmax
        xx=xx.limit(0, 1)
        setColor( :green)
        fillRect(@x-10, @y-16, xx*20, 3, false)

end

    @renderCreep[1]=def()
        rrot=@ydir.atan2(@xdir)
        setColor( :white)
        drawRotatedImage($bugBoss, rrot, 0, @type*96, 96, 96, @x, @y, true)
        setColor(0, 100, 255, 1)
        if(@shield>0)
            drawEllipse(@x, @y, @width, @width, true)
        end
        setColor( :red)
        fillRect(@x-30, @y-16, 60, 3, false)
        xx = @health/@healthmax
        xx=xx.limit(0, 1)
        setColor( :green)
        fillRect(@x-30, @y-16, xx*60, 3, false)
       // setFont("Arial", 32)
     //   fillText(@type, 100, 100)

          end 
    @renderCreep[2]=def()
        rrot=@ydir.atan2(@xdir)
        setColor( :white)
        drawRotatedImage($fBoss, rrot, @x, @y, true)
        setColor(0, 100, 255, 1)
        setColor( :red)
        fillRect(@x-30, @y-16, 60, 3, false)
        xx = @health/@healthmax
        xx=xx.limit(0, 1)
        setColor( :green)
        fillRect(@x-30, @y-46, xx*60, 3, false)
        end           
  end
    
           

    def setPoison(b)
        if(@poison==0)
        @poison=b
    end
    end
    
    def makeBoss()
        @speed = @speed *.4
        @boss=1
        @xs=48
        @ys=48
      //  @health = @health * 5
    end
    def makeSuperBoss()
        @speed = @speed *.3
        @health = 30000
        @healthMax=@health
        @boss=2
    end
    
    def tellCell()
        return @myCell
    end
    
    def setStats(s, h, sx, v)
        @health=h
        @healthMax=h
        @speed=s
        @shield = sx
        @value = v
    end
    def setWidth(b)
        @width=b
    end
    def getWave()
        return @myWave
    end

    def getCell()
        return @myCell
    end
    
    def getShot(dam)
        if(@shield>0)
            xdam=@shield.min(dam)  //get shield left or damage, whicheve is smaller
            @shield = @shield - xdam   //subtract that from shield
            dam = dam - xdam           //and also from damage
        end
        @health = @health - dam        //then apply damage normally
    end
    def setTempSpeed(xx)
        @tempSpeed=xx
    end
    
    def getHealth()
        return @health
    end
    def run()
        if(@tempSpeed<@speed)
            @tempSpeed = @tempSpeed * 1.05
        end
        if(@tempSpeed >@speed)
            @tempSpeed=@speed
        end
        @x=@x+@xdir*@tempSpeed
        @y=@y+@ydir*@tempSpeed
        @myCell=locToCell(@x, @y) //get my current cell
        
        if(@myCell!=@lastCell)  //if we are in a new cell
          if(@myCell==$endCell)
                setLives(-1)
                @myCell=$startCell
                @lastCell=$startCell
                @x=$cells[$startCell][1]
                @y=$cells[$startCell][2]   
                @tx=$cells[$startCell+19][1]
                @ty=$cells[$startCell+19][2]                
                @xdir=0
                @ydir=1     
            else  //if we're not at the end yet
            if((@y-@ty).abs() <2 && (@x-@tx).abs()<2)  //wait till we're near the center of that cell
                @y=@ty
                @x=@tx
             4.times() do |i|
                j=@myCell + $dir[i]   //look in 4 surrounding (cardinal) cells.
                j=j.limit(0, 227)     //keep it inside celll array!
                if(j!=@lastCell)      //don't visited cells we were just in
                    if($cells[j][0]==1)  //if the cell is a valid path cell
                        @xdir=$dirs[i][0]  //set our dir in that direction
                        @ydir=$dirs[i][1]
                        @tx=$cells[j][1]   //grab coordinates for the center of our new target cell
                        @ty=$cells[j][2]
                    end //valid cell 
                 end //j not lastcell
              end//loop
                @lastCell=@myCell
                    end//abs
               end //else
       end//celll>mycell
    @health = @health - @poison*.1  
//    @poison = @poison * .996
    if(@poison<.001)
        @poison=0
    end
    if(@health<=0)
       die()
    end
    end//end run
    
    def die()
        giveCash(@value)
        $creeps.delete(this)
        $waveInt[@myWave] = $waveInt[@myWave] - 1
        if($waveInt[@myWave]<=0)
            testWave(@boss)
        end        
        $booms.add(new boom(@x, @y, 0))
        $booms.add(new tBoom(@x, @y, 0, "$"+@value))
        if(@boss==1)
            $currentmode.doThing(99) 
        end
        
            
    end
    def getX()
        return @x
    end
    def getY()
        return @y
    end
    
    def render()
        @renderCreep[@boss].call()
    end
end//end class creep    

def dist(xx, yy, xxx, yyy)
    f1=(xx-xxx).abs().square()
    f2=(yy-yyy).abs().square()
    f3=(f1+f2).sqrt()
return f3
end  



class Button 
    def new(xx, yy, zz, typ)
        @x=xx
        @y=yy
        @z=zz
        @on=0
        @tempY=yy
        @locke = 1
        @type = typ
        @myText=""
        @xs=16
        @ys=16
        if(@type == 7)
            @xs=50
            @ys=18
        end
        @myLock = new Array()
        @myRender = new Array() //set rendering modes for tower buy buttons type 0, 1, 2.        
        @myLock[0] = def() //normal tower buy button
           if($cash > $costs[getZ()])
            return 0
        else
            return 1
        end
        end
        @myLock[1] = def() //special tower buy button
            
            if($tech[getZ()]==1)
               if($bonus>0)
                   return 0
              else 
                   return 1
               end
            else if($tech[getZ()]==2)
                if($bonus>0 && $tech[6]==0 && $tech[7]==0 && $tech[8]==0)
                    return 0
                else
                    return 1
                end
                end//techz
            if($tech[getZ()]==0)
                setType(0)
            end                
        end//mylock[1]
        
        @myLock[2] = def() //bonus only buy button
            if($tech[getZ()]==1 && $bonus > 0)
                return 0
            else
                return 1
            end
        end
        
        @myLock[3]= def()  //upgrade/sell button
            return 0
        end
        
        @myLock[4]=def()  //tower target nbuttons
                if($currentTower.getMode() == getZ() )
                    setOn(1)
                else
                    setOn(0)
                end
                return 0
        end//def
        @myLock[5]=def()
            return 0
        end
        @myLock[6]=def()
            return 0
        end
        @myLock[7]=def()
            return 0
        end
        3.times() do |i|
        @myRender[i]= def()
            if(getLock()==0)
                 setColor( :white)
            else
                setColor( :grey)
            end //getLock test
        drawImage($gunButtons, 32*getZ(), 0, 32, 32, getX(), getTempY(), true)
        end //def
      end //loop
        
            @myRender[3] = def
                setColor( :white)
                drawImage($gunButtons, getZ()*32, 0, 32, 32, getX(), getTempY(), true)
               
            end
            @myRender[4] = def
                setColor(0, getOn()*200, 0, 1)
                fillRect(getX(), getY(), 16, 16, true)
                setColor( :white)
                fillText($znames[getZ()], getX(), getY(), true)

           
            end
    
            @myRender[5]=def()
                                drawImage($levelThumbs[getZ()], 0, 0, 16, 12, getX(), getTempY(), 95, 60, true)
                             fillText($levelText[getZ()], getX(), getY()+50, true)
            end
            @myRender[6]=def()
                setColor( :white)
                drawImage($controlButtons, getZ()*32, getOn()*32, 32, 32, getX(), getTempY(), true)
            end
            @myRender[7]=def()
                if(getX()>120)
                    aa=getX()-120
                    bb=aa/50
                    setX(getX()-(2*bb))
                end//getZ()*40
                drawImage($menuButtons, getOn()*96, 0, 96, 48, getX(), getY(), true)
            end
    end //end def new p.s. anon functions are awesome
        
    def switch()  //switch button state for buttons that indicate state by render
        @on = (@on-1).abs()
    end
    def setType(b)
        @type = b
    end
    def getType()
        return @type
    end
    def displayMessage() 
        $message=$descriptions[getZ()]+"\nCost: "+$costs[getZ()]
        if(getType()<5)
        if($tech[getZ()]>0)
            $message=$locks[getZ()]
        end
         end
        if(getType()==6)
            $message=$descriptions[getZ()+14]
        end

    end
    def getOn()
        return @on
    end
    def setOn(b)
        @on=b
    end
    def getLock()
        return @locke
    end
    def setX(xx)
        @x = xx
    end
    def getX()
        return @x
    end
    def getY()
        return @y
    end
    def getZ()
        return @z
    end
    def getTempY()
        return @tempY
    end
    def render()
        @myRender[getType()].call()
    end
    
    def processLock()
        @locke=@myLock[getType()].call()
    end
    
    def unLock()
        @locke=0
    end
    
    def lock()
        @locke=1
    end
    def hiLite()
    end
    def doClick()
     //   @myClick[type].call()
         if(getType()<2) //for tower buttons
             if(getLock()==0)
                 $mouseMode=getZ()  //set mouse to make tower...
             end
         end
         if(getType()==4)           //tower targeting buttons.
             $currentTower.setMode(getZ())
             end
             if(getType()==5)
        //         resetGame(getZ())
                 end
        if(getType()==6)
           // switch()
            doControl()
        end
        if(getType()==7)
            resetGame(getZ())
        end
             
    end//doclick
    
    def press()
        if(getType()!=6)
            setOn(1)
        end
        if($currentTower==null)
        displayMessage()
    end
        if(getLock()==0)
        $currentButton = this
        @tempY = @y+2
    end
    end   
    def run()
        runButton()
    end
    def runButton()
        if(getType()!=6)
            setOn(0)
        end
        @tempY=@y
        processLock()
        if(testMouse()==true)
            press()
        end
    end
    
    def testMouse()
        if( (@x-$mouseX).abs()<@xs && (@y-$mouseY).abs()<@ys)
            return true
        else
            return false
        end
    end
    
    def doControl()
        switch()
        if(getOn()==0)
            if(getZ()==0) //turning them off!~
                $tempSpeed=1
                if($gameSpeed==2)
                    $gameSpeed=1
                end
            end
            if(getZ()==1) //pause
                $gameSpeed=$tempSpeed
            end
            if(getZ()==2)
                $audio = 1
                $gameMusic.play()
            end
    else if(getOn()==1)
            if(getZ()==0)
                if($gameSpeed==0) //if paused
                    $tempSpeed=2 //this will be unpause speec
                else
                $gameSpeed=2
            end
            end
            if(getZ()==1)
                $tempSpeed=$gameSpeed                
                $gameSpeed=0
            end
            if(getZ()==2)
                $audio = 0
                $gameMusic.pause()
            end
            
        end//geton/else
        
    end //docontrol    
end  //class button


class Tower < gameObject
    def new(xx, yy, zz, ff)
        super(xx, yy, zz, ff)
        setDamage($damages[zz])
    end
    
    def run()
        count()
        bb=getZ()
        if(bb==0)
           runTower()
        end
        if(bb==1)
            runFlame()
        end
        if(bb==2)
            runStasis()
        end
        if(bb==3)
            runLaser()
        end
        if(bb==4)
            runBomber()
        end
        if(bb==5)
            runPoison()
        end
        if(bb==6)
            runAutoCannon()
        end
        if(bb==7)
            runLauncher()
        end
        if(bb==8)
            runBooster()
        end
        if(bb==9)
            runPlasma()
        end

        
        if(checkTarget()==false)
        target()
    end
    end
    def render()
        renderTower()

    end
    
end

    

class gameObject
    def new(xx, yy, zz, ff)
        @x=xx
        @y=yy
        @z=zz
        @rot = 0
        @frame = 0
        @target=null
        @damage = 1
        @range=$ranges[zz]
        @timer=0
        @level = 1
        @rate=0
        @value=$costs[zz]*.5
        @cost=@value
        @myCell = ff
        @mode=0
        @tempRange = @range
        @tempDamage = @damage   
        @myBoost=.08
        @rate = $rates[zz]
        @frameCount = 0
                if(@z==10)
            @z=9
        end
        @cellList = new Array(228)
        @towerFire = new Array(10)
        @towerFire[0]=def()  //Regular
            if(@target!=null)
                 if(@frame==1 || @frame==3)     
                  ax=@target.getX()//+rand(-10, 10)
                  bx=@target.getY()//+rand(-10, 10)        
                  cx=rand(4, 16)
                  setColor( :yellow)
                  drawLine(@x, @y, ax, bx)
                  setColor( :white)
                  fillEllipse(ax, bx, cx, cx, true)
                  setColor( :white)
                end
            end
        end
        @towerFire[1]=def() //flamethrower
        end
        @towerFire[2]=def()    //stasis
            setColor( :blue)
            cc=@timer/90
            setColor(255, 255, 255, 1-cc);            
            cc=cc*2
            drawImage($freezeGlow, @x, @y, cc*@range, cc*@range, true)
        end
        @towerFire[3]=def()  //Laser
             if(@frame>0 && @target!=null)         
                 setColor( :red)
                drawLine(@x, @y, @target.getX(), @target.getY())
                setColor( :white)
                drawImage($glow, 0, 0, 32, 32, @target.getX(), @target.getY(), true)
             end    
        end        
        @towerFire[4]=def() //Bomber
            if(@target !=null)
                if(@frame==1 || @frame==3)       
                cc = 4;
                if(@frame==3) 
                    cc=-4
                    end
                setColor( :yellow)
                drawLine(@x, @y+cc, @target.getX(), @target.getY())
                setColor( :white)
                end
            end
        end
        @towerFire[5]=def()    //Poison
         //   setBlend('add')
            cc=@timer/90
            setColor(255, 255, 255, 1-cc);            
            cc=cc*2
            drawImage($poisonGlow, @x, @y, cc*@range, cc*@range, true)
           // setBlend('alpha')
        end

    @towerFire[6]=def()  //Autocannon
        if(@target!=null)
             if(@frame==1 || @frame==3)         
         setColor( :yellow)
         drawLine(@x+(@rot).cos()*(@frame*4), @y+@rot.sin()*(@frame*4), @target.getX(), @target.getY())
         setColor( :white)
     end
    end
    end//fire
    @towerFire[7]=def()  //Missile Launcher (none)    
    end            
    @towerFire[8]=def()  //Autocannon        
    end
    @towerFire[9]=def()  //plasma
                  if(@target!=null && @frameCount%100>20)
         @frame=2      
         setColor( :blue)
        @rot=(@target.getY()-@y).atan2(@target.getX()-@x)
        xa=@rot.cos()
        xb=@rot.sin()
         drawLine(@x+xa*20, @y+xb*20, @x+(xa*600), @y+(xb*600), 10)
         setColor( :white)
            $creeps.each() do |thisone|
            arot=(thisone.getY()-@y).atan2(thisone.getX()-@x)
            if((arot-@rot).abs()<.1)
                thisone.getShot(@tempDamage*$gameSpeed)
         drawImage($glow, 32, 0, 32, 32, thisone.getX(), thisone.getY(), 64, 64,true) 
            end//rotmatch
        end//loop
           
     else
         @frame=0
     end //end target null
    end

        doBoost()
     end
    
    def countCells()
        228.times() do |i|
            @cellList[i]=0
            if($cells[i][0]==1)
            xdist = dist(@x, @y, $cells[i][1], $cells[i][2])
            if(xdist<200)
               @cellList[i]=1
           end
       end
       end
   end
    
    def fire()
        @towerFire[@z].call()
    end
    def count()
        @frameCount = @frameCount + 1
    end
    def reset()
        @tempRange=@range
        @tempDamage=@damage
    end
    def setMode(m)
        @mode=m
    end
    def getMode()
        return @mode
    end
    def queryCell(C)
        cc=C.tellCell()
        if(@cellList[cc]==0)
            return true
            
        else
         //   return false
        end
    end
                
        
    def upGrade()
        if(@level < 10 && $cash>=@cost)
        giveCash(-@cost)
        @level = @level + 1
        if(getZ()!= 1 && getZ()!=8)
        @range = @range * 1.1
        end
        @damage = @damage *1.5
      //  @rate = @rate * .95
        @value = (@value + (@cost * .5)).floor()
        @cost = (@cost * 1.8).floor()
        @myBoost = @myBoost * 2
        doBoost()
    end
    end
    

    def sell()
        $towers.delete(this)
        $cells[@myCell][0]=0
        $currentTower=null
        giveCash(@value)
        $booms.add(new tBoom(@x, @y, @z, "$"+@value))
        doBoost()
    end
    def getCost()
        return @cost
    end
    def getValue()
        return @value
    end
    

    def getStats()
        return @x+":"+@y+":"+$names[@z]+":"+@level+":"+@range+":"+@tempRange+":"+@damage+":"+@tempDamage+":"+@rate+":"+@cost+":"+@value
    end

    def checkTarget()
        if(@target!=null && @target.getHealth()>0)
            xdist = dist(@x, @y, @target.getX(), @target.getY())
            if(xdist<=@tempRange)
               @rot=(@target.getY()-@y).atan2(@target.getX()-@x)                    
               return true       
            else
               return false
            end
        else
            return false
        end
    end//end checktarget
    
    def setDamage(bb)
        @damage=bb
    end
    
    def getId()
        return @z
    end
    
    
    def target()
        @target=null
        xdist = 0
        if(@mode==0)
        tdist = @tempRange
    else if(@mode==1)
        tdist=500
    else if(@mode==2)
        tdist=0
    else if(@mode==3)
        tdist=0
    else if(@mode==4)
        tdist=10000000
    end
        $creeps.each() do |thisone|
            if(@cellList[thisone.tellCell()]==1)

            xdist=dist(@x, @y, thisone.getX(), thisone.getY())
            if(xdist<@tempRange)
            if(@mode==0)

            else if(@mode==1 || @mode==2)
                xdist=thisone.getCell()
            else if(@mode==3 || @mode==4)
                xdist=thisone.getHealth()
            end
            if(@mode==0 || @mode==1 || @mode==4)
            if(xdisttdist)
                tdist=xdist
                @target=thisone
            end//xdist
        end//mode
        end//end xdist < range for all targeting methods
    end//cell check
       end//loop
        if(@target!=null)
           @rot=(@target.getY()-@y).atan2(@target.getX()-@x)
       end
    end//end target
    
    def renderTower()
        setColor( :white)
        drawImage($base, @x, @y, true)
        drawRotatedImage($turret, @rot, @z*64, @frame*32, 64, 32, @x, @y, 64, 32, true)
    end
    
    def runTower()
        if(@frameCount % @rate == 0)
            if(@target!=null)  
                 @frame = @frame + 1
                 if(@frame == 4)
                     @frame = 0
                end
             if(@frame%2==0)
                @target.getShot(@tempDamage);
                end
            else
                 @frame=0
             end //end target null
        end //framecount check
    end//end run tower

    def runDual()
     //   @rot=($mouseY-@y).atan2($mouseX-@x)
     if(@frameCount % @rate == 0)
     if(@target!=null)
         
         @frame = @frame + 1
         if(@frame == 4)
             @frame = 0
         end
     if(@frame%2==0)
         @target.getShot(@tempDamage);
     end
     else
         @frame=0
     end //end target null
    end //framecount check
    end//end run dual

    
    def runLaser()
     if(@frameCount % @rate  == 0)
         
         @frame = @frame + 1
         if(@frame == 4)
             @frame = 0
         end
     end
          if(@target!=null)
         @target.getShot(@tempDamage);
     else
         @frame=0
     end //end target null
    end//end run Laser   

    def runFlame()
        if(@frameCount % @rate  == 0)
            @frame = 0
            if(@target!=null) 
                 setColor( :white)
            $shots.add(new shot(@x+(@rot).cos()*20, @y+@rot.sin()*20, 0, @rot, @tempDamage, @mode))
     else
         @frame=0
     end //end target null
 end
    end
    
    def runBomber()

        if(@frameCount % @rate == 0 )
           b=rand(0, 6.2)
                $shots.add(new Shot(@x+b.cos()*20, @y+b.sin()*20, 2, b, @tempDamage, @mode))
             //   $shots.add(new shot(@x+(@rot).cos()*20, @y+@rot.sin()*20, 0, @rot, @tempDamage, @mode))

        end
    end
    
    
  def runLauncher()
     //   @rot=($mouseY-@y).atan2($mouseX-@x)
     if(@frameCount % @rate  == 0)
     if(@target!=null)
          @rot=(@target.getY()-@y).atan2(@target.getX()-@x)
         @frame = @frame + 1
         if(@frame == 4)
             @frame = 0
         end
     if(@frame==2)         
         setColor( :yellow)
         xshot=(new shot(@x+(@rot).cos()*20, @y+@rot.sin()*0, 1, @rot, @tempDamage, @mode))
         xshot.setRange(@range)
         $shots.add(xshot)
         xshot=(new shot(@x-(@rot).cos()*20, @y-@rot.sin()*0, 1, @rot, @tempDamage, @mode))
         xshot.setRange(@range)
         $shots.add(xshot)         
         setColor( :white)
     end
     else
         @frame=0
     end //end target null
    end //framecount check
    end//end run Launcher

    def runStasis()
        @timer = @timer + 1
        if(@timer == 90)
            @timer = 0
            @frame=0
        end
        if(@timer == 40)
            @frame = 1
            $Creeps.each() do |thisone|
                dd = dist(@x, @y, thisone.getX(), thisone.getY())
                if(dd<@range)
                    thisone.setTempSpeed(.1)
                end //end range
            end//end loop
            end//end frame 10 
    end
    
    def runPoison()
        @timer = @timer + 1
        if(@timer == 90)
            @timer = 0
            @frame=0
        end
        if(@timer == 40)
            @frame = 1
            $Creeps.each() do |thisone|
                dd = dist(@x, @y, thisone.getX(), thisone.getY())
                if(dd<@range)
                    thisone.setPoison(.1)
                end //end range
            end//end loop
            end//end frame 10 
    end    

    def runAutoCannon()
     //   @rot=($mouseY-@y).atan2($mouseX-@x)
     if(@frameCount % @rate == 0)
     if(@target!=null)
         
         @frame = @frame + 1
         if(@frame == 4)
             @frame = 0
         end
     if(@frame%2==0)
         @target.getShot(@tempDamage);
     end
     else
         @frame=0
     end //end target null
 
    end //framecount check
    end//end run tower
    
    def runBooster()
        if(@frameCount % @rate ==0)
         @frame = @frame + 1            
         if(@frame == 4)
             @frame = 0
             end
        end
    end
    def getBoost(b)
        @tempRange=@range*(1+b)
        @tempDamage=@damage*(1+(b*2))
        countCells()
    end
    def boost()
        $towers.each() do |thisone|
            xdist=dist(getX(), getY(), thisone.getX(), thisone.getY())
            if(xdist<=@range && thisone.getZ()!=7)
                thisone.getBoost(@myBoost)
            end
        end
    end
     
    def runVolt()
        if(@frameCount % @rate ==0)
            found = 5
            $creeps.each() do |thisone|
                if(found >= 0 )
            xdist=dist(@x, @y, thisone.getX(), thisone.getY())
            if(xdist<@range)
                found = found - 1
                drawLine(@x, @y, thisone.getX(), thisone.getY(), 3)
                thisone.setTempSpeed(.5)
                thisone.getShot(@tempDamage)
                end
            end//found
            end
        end
    end
    
    def runPlasma()

    end
        
    
    def getX()
        return @x
    end
    def getY()
        return @y
    end
    def getZ()
        return @z
    end
    def run()
        @frameCount = @frameCount + 1
    end
    def render()
    end
    def testMouse()
        if( (@x-$mouseX).abs()<16 && (@y-$mouseY).abs()<16)
            return true
        else
            return false
        end
    end
        def hiLite()
            setColor( :yellow)
        drawRect(@x, @y, 32, 32, true)
            setColor( :white)
    end
end

def runWorms()
end
class worm
    def new()
        @x=0
        @y=0
        @rot = 90
        @posArray = new Array()
        @speed=4
    end
    def run()
        @x = @x + @rot.cos()*@speed
        @y = @y + @rot.sin()*@speed
        bb=(100).random().floor()
        if(bb<20)
            @rot = 4.random().floor() * 90
        end
    end
    def render()
        @posArray.each() do |row|
            row.each() do |coord|
            end
        end
    end
        
    end
class tBoom < boom
    def new(xx, yy, zz, tt)
        super(xx, yy, zz)
        setText(tt)
    end
    def render()
        renderText()
    end

end
    
        
    
class boom
    def new(xx, yy, zz)
        @x=xx
        @y=yy
        @z=zz
        @dTime=0
        @rot = (xx/yy).wrap(0, 6.2)
        @a=0
        @b=0
        @xs = 32
        @myText = null
        if(zz==10)
            @xs=rand(48, 128)
        end
    end
    def setText(mm)
        @myText=mm
    end
    def run()
    @dTime=@dTime+1
    @a = @a + 1
    if(@a == 4)
        @a=0
        @b=@b+1
    end
    if(@dTime==16)
        $booms.delete(this)
    end
end
    def render()
        renderImage()
    end
    def renderImage()
       drawRotatedImage($boom0, @rot, @a*32, @b*32, 32, 32, @x, @y, @xs, @xs, true)
   end
   def renderText()
       fillText(@myText, @x, @y-@dTime, true)
   end
   end
            
        

    def runObjects()
    $waves.each() do |thisone|
        thisone.run()
    end
    $creeps.each() do |thisone|
        thisone.run()
    end    
    $towers.each() do |thisone|
        thisone.run()
    end
    $tower_Buy_Buttons.each() do |thisone|
        thisone.run()
    end
    if($currentTower!=null)
    $tower_Control_Buttons.each() do |thisone|
        thisone.run()
    end
    end
    $booms.each() do |thisone|
        thisone.run()
    end  
    $shots.each() do |thisone|
        thisone.run()
    end        
    end
    
$rcolor = [255, 0, 0]
$rslot = 1
$rcount = 0
$cdir = 1
def rotateColor()
if($cdir > 0)    
    3.times() do |i|
        $rcolor[$rslot]=$rcolor[$rslot] + $cdir
    end
    $rcount = $rcount + $dir
    if($rcount >=255)
        $rslot = $rslot - 1
        $rslot = $rslot.wrap(0, 2)
        $cdir = $cdir * -1
    end
else
        3.times() do |i|
        $rcolor[$rslot]=$rcolor[$rslot] + $cdir
    end
    $rcount = $rcount + $cdir
    if($rcount <=0)
        $rslot = $rslot + 2
        $rslot = $rslot.wrap(0, 2)
        $cdir = $cdir * -1
    end
end
end


    

ERRORS

YOUR BROWSER DOES NOT SUPPORT HTML5!

Please use one of these instead

Our games cannot run in your browser