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)
Offline
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)
Offline
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
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!!!!!!!!!!!!!!
Offline
Every object is stationary. By the way, it only took me like an hour to make.
Offline
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?
Offline
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!
Offline
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
, 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.
Offline
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.
Offline
Cool! I never knew that XP
Offline
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
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!
Offline
Thanks, I am going to use this in my class.
Offline
No problem, but you should code it yourself........
Offline
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
OHZA NOZA!!! TEH SOFTWARE IT NO WORKY!!! (It doesn't run in my version of basic
)
Offline
Waaa!!! It No Worky On Mah Version Of Basic
Offline
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++
Offline
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
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"
Offline