This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-06-28 19:24:52

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

RPG Battle Engine in Visual Basic

Here is the code for a battle engine:

Public Class RPG
    Dim playerHP As Integer
    Dim playerMP As Integer
    Dim enemyHP As Integer
    Dim enemyMP As Integer
    Dim turn As Integer
    Dim enemyatt As Integer
    Dim playeratt As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        enemyHP = enemyHP - 1
        Button1.Visible = False
        Button2.Visible = False
        Button3.Visible = False
        TextBox1.Text = TextBox4.Text + "-Weak Attack"
        TextBox2.Text = playerHP
        TextBox3.Text = playerMP
        TextBox5.Text = enemyHP
        TextBox6.Text = enemyMP
    End Sub

    Private Sub RPG_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        playerHP = 100
        playerMP = 25
        enemyHP = 100
        enemyMP = 25
        TextBox2.Text = playerHP
        TextBox3.Text = playerMP
        TextBox5.Text = enemyHP
        TextBox6.Text = enemyMP
        turn = 1
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Label6.Text = TextBox4.Text
        Button4.Visible = False
        TextBox4.Visible = False
        Label6.Visible = True
        TextBox1.Text = "It is your turn."
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If turn = 1 Then
            turn = 2
            Button1.Visible = False
            Button2.Visible = False
            Button3.Visible = False
            Randomize()
            enemyatt = Int((3 * Rnd()) + 1)
            If enemyatt = 1 Then
                TextBox1.Text = "Goblin-Weak Attack"
                playerHP = playerHP - 1
            End If
            If enemyatt = 2 Then
                If enemyMP >= 5 Then
                    TextBox1.Text = "Goblin-Fireball"
                    Randomize()
                    playerHP = playerHP - Int((20 * Rnd() + 5))
                    enemyMP = enemyMP - 5
                Else : TextBox1.Text = "Goblin-Missed"
                End If
            End If
            If enemyatt = 3 Then
                If enemyMP >= 10 Then
                    TextBox1.Text = "Goblin-Random ATT"
                    Randomize()
                    playerHP = playerHP - Int((25 * Rnd()))
                    enemyMP = enemyMP - 10
                Else : TextBox1.Text = "Goblin-Missed"
                End If
            End If

        Else
            If turn = 2 Then
                turn = 1
                Button1.Visible = True
                Button2.Visible = True
                Button3.Visible = True
                TextBox1.Text = "It is your turn."
                enemyMP = enemyMP + 1
                playerMP = playerMP + 1
            End If
            If playerHP <= 0 Then
                Button1.Visible = False
                Button2.Visible = False
                Button3.Visible = False
                PictureBox1.Visible = False
                PictureBox2.Visible = False
                Button5.Visible = False
                Label6.Visible = False
                Label3.Visible = False
                Label4.Visible = False
                Label5.Visible = False
                Label2.Visible = False
                TextBox2.Visible = False
                TextBox3.Visible = False
                TextBox5.Visible = False
                TextBox6.Visible = False
                TextBox1.Text = "The goblin has won....."
            End If
            If enemyHP <= 0 Then
                Button1.Visible = False
                Button2.Visible = False
                Button3.Visible = False
                PictureBox1.Visible = False
                PictureBox2.Visible = False
                Button5.Visible = False
                Label6.Visible = False
                Label3.Visible = False
                Label4.Visible = False
                Label5.Visible = False
                Label2.Visible = False
                TextBox2.Visible = False
                TextBox3.Visible = False
                TextBox5.Visible = False
                TextBox6.Visible = False
                TextBox1.Text = "You won!"
            End If
        End If
        TextBox2.Text = playerHP
        TextBox3.Text = playerMP
        TextBox5.Text = enemyHP
        TextBox6.Text = enemyMP
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If playerMP >= 5 Then
            Randomize()
            enemyHP = enemyHP - Int((20 * Rnd() + 5))
            playerMP = playerMP - 5
            Button1.Visible = False
            Button2.Visible = False
            Button3.Visible = False
            TextBox1.Text = TextBox4.Text + "-Fireball"
            TextBox2.Text = playerHP
            TextBox3.Text = playerMP
            TextBox5.Text = enemyHP
            TextBox6.Text = enemyMP
        Else : TextBox1.Text = TextBox4.Text + "-Missed"
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If playerMP >= 10 Then
            Randomize()
            enemyHP = enemyHP - Int((25 * Rnd()))
            playerMP = playerMP - 10
            Button1.Visible = False
            Button2.Visible = False
            Button3.Visible = False
            TextBox1.Text = TextBox4.Text + "-Random ATT"
            TextBox2.Text = playerHP
            TextBox3.Text = playerMP
            TextBox5.Text = enemyHP
            TextBox6.Text = enemyMP
        Else : TextBox1.Text = TextBox4.Text + "-Missed"
        End If
    End Sub
End Class



Any ideas on how to improve? I know nothing at all about motion of objects, otherwise this battle would be animated (^_^)

Last edited by Cyclone103 (2008-06-28 19:25:34)


All your base are belong to us

Offline

 

#2 2008-06-28 19:27:25

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

The label 6 idea was that you entered your name into textbox 4, pressed a button, and then it displayed your name as a label over your head and in the "event" textbox (textbox1)


All your base are belong to us

Offline

 

#3 2008-06-28 19:34:26

Hobbs1100
Scratcher
Registered: 2008-02-16
Posts: 500+

Re: RPG Battle Engine in Visual Basic

Wow...... A lot of script.....

Offline

 

#4 2008-06-28 19:38:45

dingdong
Scratcher
Registered: 2007-08-09
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

excuse me! that's nothing! even my scratch games have more than that! of course that's only the engine, everything else such as effects and stuff will take more scripts


http://img851.imageshack.us/img851/2829/superanbanner.png
click the image for my music

Offline

 

#5 2008-06-28 19:42:52

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

dingdong wrote:

excuse me! that's nothing! even my scratch games have more than that! of course that's only the engine, everything else such as effects and stuff will take more scripts

Well, I know it is not much. It is a simple turn based battle ENGINE, not a full game. As you said, this has no flashy effects since I am a VB noob  tongue  My Scratch projects are far more complex. I just started visual basic like a week ago. I am trying to figure out how to get things to move. Then, I would have animated attacks!!!!!!!!!!!!!!


All your base are belong to us

Offline

 

#6 2008-06-28 19:43:54

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

Every object is stationary. By the way, it only took me like an hour to make.


All your base are belong to us

Offline

 

#7 2008-06-29 02:23:12

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

I thought it is possible in vb to create a bitmap object? That way you could rapidly change the source and it would result in an animation. ...


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#8 2008-06-29 11:15:50

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

JSO wrote:

I thought it is possible in vb to create a bitmap object? That way you could rapidly change the source and it would result in an animation. ...

Well, as I said, I am a VB noob and don't know much. Could you please explain?


All your base are belong to us

Offline

 

#9 2008-06-29 11:44:39

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

Hey Cyclone...I tried loading the Express VB but something messed up.  I'll have to try it again a little later today.  It's cool that you are learning VB - it's a pretty handy language!  After looking over your Engine script (which I must admit, I don't fully understand) I do have a couple of recommendations:

1.  It's a good idea to rename your interface objects to more meaningful names, rather than leaving the default names.  So, rather than "Button1", maybe it would be called "Attack Btn" or something.  Good naming conventions make the code much more readable.  So always try to make your variable and object names as meaningful as possible...you will find it much easier to remember what you were doing when you go back to make a change six months from now!

2. It's also a good idea to add comments to your scripts explaining what you are doing.  The more you can make your script tell a story, the easier it is to understand it and the easier it is to maintain it.

3. I believe it is possible to define your own objects in VB so rather than having variables like EnemyHP and EnemyMP you would have Enemy.HP and Enemy.MP where you are referencing the HP and MP attributes of the Enemy object.  I apologize if I have the syntax or terminology messed up...I'm working from a very faulty memory here!  My point is that you might want to explore the object-oriented features of the language.

That's it for now!  Have fun programming!


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#10 2008-06-29 11:51:03

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

Paddle2See wrote:

Hey Cyclone...I tried loading the Express VB but something messed up.  I'll have to try it again a little later today.  It's cool that you are learning VB - it's a pretty handy language!  After looking over your Engine script (which I must admit, I don't fully understand) I do have a couple of recommendations:

1.  It's a good idea to rename your interface objects to more meaningful names, rather than leaving the default names.  So, rather than "Button1", maybe it would be called "Attack Btn" or something.  Good naming conventions make the code much more readable.  So always try to make your variable and object names as meaningful as possible...you will find it much easier to remember what you were doing when you go back to make a change six months from now!

2. It's also a good idea to add comments to your scripts explaining what you are doing.  The more you can make your script tell a story, the easier it is to understand it and the easier it is to maintain it.

3. I believe it is possible to define your own objects in VB so rather than having variables like EnemyHP and EnemyMP you would have Enemy.HP and Enemy.MP where you are referencing the HP and MP attributes of the Enemy object.  I apologize if I have the syntax or terminology messed up...I'm working from a very faulty memory here!  My point is that you might want to explore the object-oriented features of the language.

That's it for now!  Have fun programming!

Comments are added in by using REM right? I should do that....as for renaming, I was too lazy and I just made this in like an hour anyway. The problem with not having a variable is I have no idea how to declare a new property. I realize that I could store all of those variables in an array, or make health more precise by using single or double precision floating numbers. I just don't know how I would do that! Sorry to hear your download didn't work  sad  , and your syntax was just fine. In this version, you type a letter and a menu comes up with all the options for any letter, and if you mouse over one it provides a simple explanation. I just started a week ago though, so I don't know if you can just use a property or if you need to declare it.


All your base are belong to us

Offline

 

#11 2008-06-29 13:39:31

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

Cyclone103 wrote:

Comments are added in by using REM right?

Well, REM still works, but most people just use the single quote ' since it is faster to type and can be used to comment at the end of code lines.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#12 2008-06-29 14:02:03

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

Cool! I never knew that XP


All your base are belong to us

Offline

 

#13 2008-06-29 21:56:14

S65
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: RPG Battle Engine in Visual Basic

It's great that you're progressing beyond Scratch and learning more advanced programming languages. I'm currently doing that myself, and learning a language called Blitz3D. I'm also making a full-fledged 3D Mario fangame in it (video, if you see what I have so far). If I posted the current source to that, it would be over 2000 lines of code! Luckily, I've learnt how to comment and organize everything =P

If Scratch ever gets some sort of off-topic forum, I might post an update topic for it. I might even do it in Show and Tell if I ever feel like it.

Last edited by S65 (2008-06-29 21:57:23)

Offline

 

#14 2008-06-29 22:10:29

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

S65 wrote:

It's great that you're progressing beyond Scratch and learning more advanced programming languages. I'm currently doing that myself, and learning a language called Blitz3D. I'm also making a full-fledged 3D Mario fangame in it (video, if you see what I have so far). If I posted the current source to that, it would be over 2000 lines of code! Luckily, I've learnt how to comment and organize everything =P

If Scratch ever gets some sort of off-topic forum, I might post an update topic for it. I might even do it in Show and Tell if I ever feel like it.

Cool lol!


All your base are belong to us

Offline

 

#15 2008-09-28 13:25:19

oliiscool
Scratcher
Registered: 2008-07-08
Posts: 31

Re: RPG Battle Engine in Visual Basic

wot abot i post some scripts

<when[ ostler]clicked><say[ i own the finest stables in the whole of camelot ]for( 5 )secs>

Offline

 

#16 2008-09-28 13:27:14

oliiscool
Scratcher
Registered: 2008-07-08
Posts: 31

Re: RPG Battle Engine in Visual Basic

<when[ space ]key pressed><switch to costume[ sword raised<wait( 0.4 )secsc><switch to costume[ sword down<wait( 0.4[ )secsc><switch to costume[ normal

Offline

 

#17 2008-09-28 14:53:01

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

oliiscool, Cyclone103 is building an engine in Visual Basic, not Scratch...


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#18 2008-09-28 21:14:37

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

Thanks, I am going to use this in my class.  smile

Offline

 

#19 2008-10-06 20:42:21

Cyclone103
Scratcher
Registered: 2008-03-20
Posts: 500+

Re: RPG Battle Engine in Visual Basic

No problem, but you should code it yourself........


All your base are belong to us

Offline

 

#20 2008-10-07 18:18:07

Bobby500
Scratcher
Registered: 2008-04-19
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

I did, actually. I made a little starwars game. Can you help me with animations because I am not good with those. I can't do them, its something about the pictures not being found...

Offline

 

#21 2010-04-18 22:16:24

trekkie2000
Scratcher
Registered: 2009-02-15
Posts: 100+

Re: RPG Battle Engine in Visual Basic

OHZA NOZA!!! TEH SOFTWARE IT NO WORKY!!! (It doesn't run in my version of basic  sad   )


"If life gives you lemons, sell lemonade for $.25...
...Sell antidote to poison in lemonade for $250" -Me

Offline

 

#22 2010-04-28 21:24:08

trekkie2000
Scratcher
Registered: 2009-02-15
Posts: 100+

Re: RPG Battle Engine in Visual Basic

Waaa!!! It No Worky On Mah Version Of Basic


"If life gives you lemons, sell lemonade for $.25...
...Sell antidote to poison in lemonade for $250" -Me

Offline

 

#23 2010-04-29 11:28:57

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: RPG Battle Engine in Visual Basic

trekkie2000 wrote:

Waaa!!! It No Worky On Mah Version Of Basic

What version are you using? Its likely this was done with VB 2008... or maybe VB 2005...

A way of improving it. Don't use VB, try C++


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#24 2010-07-30 08:06:16

DoogleGames
Scratcher
Registered: 2008-10-04
Posts: 1

Re: RPG Battle Engine in Visual Basic

This Is Really Bad Code

This is why:

Your controls (.ocx) are named in there original names (Command Button 1)
RENAME THEM SO YOU KNOW WHAT THEY ARE!!!

Command1 to cmdOk (If its an ok button)

Command Button = cmd
Form = frm
Module = mod
ect.

Also try and use more variables to store information to minimize code!

Offline

 

#25 2010-08-18 17:44:41

trekkie2000
Scratcher
Registered: 2009-02-15
Posts: 100+

Re: RPG Battle Engine in Visual Basic

markyparky56 wrote:

trekkie2000 wrote:

Waaa!!! It No Worky On Mah Version Of Basic

What version are you using? Its likely this was done with VB 2008... or maybe VB 2005...

A way of improving it. Don't use VB, try C++

Oh wow... I just use a dumbed down version of basic. Fittingly titled "Just Basic"


"If life gives you lemons, sell lemonade for $.25...
...Sell antidote to poison in lemonade for $250" -Me

Offline

 

Board footer