Results 1 to 9 of 9

Thread: rpg game question

  1. #1

    Thread Starter
    Lively Member manbearpig001's Avatar
    Join Date
    Oct 2009
    Posts
    73

    rpg game question

    Hey guys. heres the deal. for the past few days ive been struggling with a simple game idea. I wanted to have two players running around shooting each other (verryyyy low graphics, like circles and squares).

    Ive gotten this far; I have the ability to move around both characters, and change directions etc. ive also been able to set up my shooting. Only problem i run into is getting the bullet to move! I cant use a preset timer, because if i used that, i could only shoot one bullet at a time, so i would need to create new ones dynamically. Problem is, google did not yield this answer.

    so my question is; how does one add dynamic timers to a form on runtime, and alter the tick sub so that it moves the picturebox (bullet) and once it can be moved, i was wondering if anyone had ideas on a collision course. (i was thinking about using player locations in relation to the bullet, and if they were equal than the health would go down or whatever, but unfortunately, this means it would have to be directly in the middle of the player, which would be odd..

    K thanks guys!

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: rpg game question

    To create a timer at runtime with a 500ms (1/2 second interval) :

    Private NewTimer = New Timer(500)

    You'd then need to use AddHandler to hook up your code to the Timer's tick event:

    AddHandler NewTimer.tick, AddressOf MyHandler

    As for collisions - if your players are just squares you can check to see if the location of the bullet falls within the bounds of a rectangle.

    In pseudo code :

    Code:
    If bullet.X >= player.left and bullet.X <= player.left + player.width then
        If bullet.Y >= player.top and bullet.Y <= player.top + player.height then
             'got a hit
        End If
    End If

  3. #3
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: rpg game question

    I don't see why you can't use a preset timer. Have an array or collection hold the bullets, and then use a loop to move each bullet.

    Here's some example code using some psuedo-functions that would give an idea.

    Code:
    Public Sub Timer_Tick()
       For Each B as Bullet in Bullets.Values
            B.CalculateNextPosition(B.Position, B.Angle, B.Speed) 'Calculate the bullet's next position based on its current position, angle of trajectory, and speed.
            'Update Graphics for bullet here.
       Next
    End Sub
    From my burrow, 2 feet under.

  4. #4

    Thread Starter
    Lively Member manbearpig001's Avatar
    Join Date
    Oct 2009
    Posts
    73

    Re: rpg game question

    so how would i create a timer in the array of timers?

    and if i am understanding your code correctly, i just enable the timer once and it moves all the bullets? because that would look horrible with them moving at the same pace etc.

    or is it you enable each 'b' as bullet (as a timer)

    Thanks for the replies guys!

    *EDIT*
    btw i also need to shoot the bullets at different angels. so when the user is facing right, a value of a string is "right" and so on with left down and up. so how could i use this to make the bullet move in the direction of the string's property?

  5. #5
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: rpg game question

    You wouldn't create an array of timers. You would only use one timer, within whose tick event you would calculate the next position of every object on the map, from bullets to players.

  6. #6

    Thread Starter
    Lively Member manbearpig001's Avatar
    Join Date
    Oct 2009
    Posts
    73

    Re: rpg game question

    ooh ok.. so i understand the concept, but how would i execute it? keeping in mind i need to use angels etc.

    because right now, ive got one timer, and whenever i shoot, it continues until i shoot again. (obviously)

    heres my timer code.

    Code:
    If amobox.BackColor = Color.Red Then
                life2.Value = life2.Value - 1
                Me.Controls.Remove(amobox)
                If life2.Value < 5 Then life2.BackColor = Color.Orange
                If life2.Value < 3 Then life2.BackColor = Color.Red
                Timeright1.Stop()
            End If
            amobox.Left = amobox.Left + 2
            If amobox.Location.X >= Player2.Left And amobox.Location.X <= Player2.Left + Player2.Width Then
                If amobox.Location.Y >= Player2.Top And amobox.Location.Y <= Player2.Top + Player2.Height Then
                    amobox.BackColor = Color.Red
                End If
            End If
    life1 and life2 are progressbars for health.

    amobox is a picturebox (the bullet)
    its defined outside the timer_tick

  7. #7
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: rpg game question

    You won't be wanting to use picture boxes and controls. You'll want to use the graphics class to paint the form. GDI+ most likely, if you want faster rendering.

  8. #8

    Thread Starter
    Lively Member manbearpig001's Avatar
    Join Date
    Oct 2009
    Posts
    73

    Re: rpg game question

    care to explain what gdi+ is, or how i can use the graphics class :] maybe a link, or a code snippet for my project? :]

    Thanks btw.

    *EDIT* i took the liberty to look up gdi and graphic classes for vb.net, and i was able to figure out how to draw circles and stuff, but im still confused on how to move them with a timer, because timers need System.EventArgs, and cannot use System.Windows.Forms.PaintEventArgs. This makes it impossible to draw based on a timer. so how do i use a timer to maybe alter the location of a graphic image?
    Last edited by manbearpig001; Jan 1st, 2010 at 09:44 PM.

  9. #9
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: rpg game question

    You would use variables to keep track of current position. You should create a bullet class with variables to store current location, etc. and methods to calculate the next position. In the tick event, you would retrieve the new position of the bullet and draw a circle at those coords.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width