locked
I need help with my collision, options window an the speed of my zombies! RRS feed

  • Question

  • ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'initialize the window first'
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    homepage()
    Sub homepage
      GraphicsWindow.Hide()
      GraphicsWindow.CanResize  = "false"
      GraphicsWindow.Width = 1000
      GraphicsWindow.Height = 600
      GraphicsWindow.Title = "Zombie Adventure"
      GraphicsWindow.BrushColor = "Red"
      GraphicsWindow.Left = (Desktop.Width - 1000) / 2
      GraphicsWindow.Top  = (Desktop.Height - 668) / 2
     
      'Image of menu'
      background = ImageList.LoadImage("http://s23.postimg.org/qhdyatkzv/My_Image_jpg.jpg")
      backgroundDisplay = Shapes.AddImage(background)
      Shapes.Move(backgroundDisplay,0,-30)
     
      'Aniamtion for title screen'
      titleshape = Shapes.AddImage("http://s21.postimg.org/7diz4z3yv/Untitled_5.gif")
      Shapes.Move(titleshape, 130,-350)
      Shapes.Animate(titleshape, 240,40, 2500)
     
      'Buttons'
      Play = Controls.AddButton("Start your Adventure", 400, 540)
      Controls.SetSize(Play, 200, 55)
     
      Exit = Controls.AddButton("Exit", 840, 560)
      Controls.SetSize(Exit, 150, 37)
     
      Instructions = Controls.AddButton("Instructions", 10, 560)
      Controls.SetSize(Instructions, 150, 37)
     
      GraphicsWindow.Show()
    EndSub


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'init the keys'
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    returnKey = "Return"
    escapeKey = "Escape"
    Shoot = "RightMouseDown"

    gw = 840
    gh = 820

    radius = 20
    numzombies = 3


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Buttons Controls'
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Controls.ButtonClicked=MyButtonClicked

    Sub MyButtonClicked
      Button=Controls.LastClickedButton
      If Button = menu Then
        homepage()
      ElseIf Button = Play Then
        Mouse.HideCursor()
        Playscreen()
      ElseIf Button = Instructions then
        Instruct()
      ElseIf Button = Exit then
        Program.End()
      EndIf
    EndSub


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Game Windows
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub Playscreen
      GraphicsWindow.Clear()
      GraphicsWindow.Show()
      GraphicsWindow.BackgroundColor = "Black"
      GraphicsWindow.Width = gw
      GraphicsWindow.Height = gh
      GraphicsWindow.Show()
     
      GraphicsWindow.KeyDown = KeyPressed
      GameSetup()
    EndSub

    Sub KeyPressed
      If GraphicsWindow.LastKey = "Escape" Then
        OptionsWindow()
      EndIf
    EndSub

    Sub GameSetup
      GraphicsWindow.Left = (Desktop.Width - 1240)
      GraphicsWindow.Top  = (Desktop.Height - 895)
      GraphicsWindow.CanResize  = "false"
      GraphicsWindow.PenColor="Lightblue"
      GraphicsWindow.DrawLine(10,660,830,660)
      Gun = Shapes.AddImage("http://s22.postimg.org/n4mh54o4h/Character_finished.gif")
      GraphicsWindow.MouseMove = GunMove
      GraphicsWindow.MouseDown = Gunfire
      zombiesmove()
      gameloop()
    EndSub

    'zombie code'
    Sub zombiesmove
      For i = 1 To numzombies
        GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
        Zombie[i] = Shapes.AddEllipse(2*radius, 2*radius)
        zombiePosX[i] = Math.GetRandomNumber(gw)
        zombiePosY[i] = Math.GetRandomNumber(gh)
        zombieVelX[i] = Math.GetRandomNumber(5) - 3
        zombieVelY[i] = Math.GetRandomNumber(5)
      EndFor
    EndSub

    Sub gameloop
      While ("True")
        For i = 1 To numzombies
          zombiePosX[i] = zombiePosX[i]+zombieVelX[i]
          zombiePosY[i] = zombiePosY[i]+zombieVelY[i]
          
          If (zombiePosY[i] > gw +radius) Then
            zombiePosY = -radius
          EndIf
          
          If (zombiePosX[i] < radius Or zombiePosX[i] > gw-radius) Then
            zombieVelX[i] = -zombieVelX[i]
          EndIf
          
          Shapes.Move(Zombie[i],zombiePosX[i]-radius,zombiePosY[i]-radius)
        EndFor
      EndWhile
    EndSub


    Sub GunMove
      xPos = Mouse.MouseX - 450
      yPos = Mouse.MouseY
      Shapes.Move(Gun, xPos, 580)
    EndSub


    Sub Gunfire
      Bullet = Shapes.AddEllipse(8, 8)
      Shapes.Move(Bullet, xPos +15, 640)
      Shapes.Animate(Bullet, xPos, -100, 2000)
    EndSub



    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'instructions Window'
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub Instruct
      GraphicsWindow.Clear()
      GraphicsWindow.Show()
      GraphicsWindow.Width = 610
      GraphicsWindow.Height = 370
      GraphicsWindow.DrawText(200, 100, "Please read the instructions below")
      GraphicsWindow.DrawText(150,150, "Too move the character, move the mouse left or right")
      GraphicsWindow.DrawText(170,200, "To shoot press the right or left mouse button")
      GraphicsWindow.DrawText(130,250, "The aim of the game is to kill the zombies before they kill you")
     
      menu = Controls.AddButton("Return to Menu", 485, 310)
      Controls.SetSize(Menu, 120, 55)
    EndSub


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Options Window'
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub OptionsWindow
      Mouse.ShowCursor()
      GraphicsWindow.Clear()
      GraphicsWindow.Show()
      GraphicsWindow.Width = 300
      GraphicsWindow.Height = 400
      GraphicsWindow.Left = (Desktop.Width - 600) / 2
      GraphicsWindow.Top  = (Desktop.Height - 750) / 2
     
      Optionssize()
     
      Play = Controls.AddButton("Return to Game", 50, 70)
      Controls.SetSize(Play, 200, 60)
     
      menu = Controls.AddButton("Return to Menu", 50, 185)
      Controls.SetSize(Menu, 200, 60)
     
      Exit = Controls.AddButton("Exit", 50, 300)
      Controls.SetSize(Exit, 200, 60)
    EndSub

    Sub Optionssize
      GraphicsWindow.Clear()
      GraphicsWindow.FontSize = 20
      GraphicsWindow.DrawText(115, 30, "Options")
    EndSub
    Saturday, November 9, 2013 7:48 PM

Answers

  • Quite a lot of code and not quite sure how to help, and since there are no other replies I suspect others are unsure too.

    What it is supposed to do and what doesn't work as you want.

    Please try to narrow the problem down a bit.  Also checkout other posts on collisions, for example here is a recent one about Shapes.Animate and collision detection or many others.

    The key to getting good support is with a short bit of code demonstrating a problem you are working on that runs without additional code or images etc with a clear description of the problem that can be seen easily by running the program.

    Questions can also cover program design ideas like how to structure the code or using subroutines etc.

    Try to make the question fairly specific or ask several questions on different issues if there are several (e.g. smooth movement, collision detection, events, program structure etc.)

    Sunday, November 10, 2013 5:21 PM