Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with fighting system
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Talion




PostPosted: Sun Jan 15, 2006 9:36 am   Post subject: Help with fighting system

Alright i'm trying to make a game here with a fighting system. Now I can make the maps and characters and their stats and such but my battle system wont work. Atm I've scrapped it entirely and now am trying to rebuild it. It's not working though and i've been at it for ages so I've come to ask for some help.

The problems I have are that
A)you can only attack once with a button before it simply stops working
and
B) I can't make it so that if you kill the enemy it says they die but if you dont kill them it says it's their turn. (I haven't added in the enemies turn yet though...since i've noticed it says they die no matter what)

code:
var mousex, mousey, mouseb : int
var winID : int
var button1, button2, button3, button4, button5, button6, button7 : int
var input : int := 0
type charstats :
    record
        Name : string
        Level : int
        MaxHP : int
        CurHP : int
        Class : string
        Race : string
        ATK : int
        DEF : int
        Spells : string
        EXP : int
        MaxMP : int
        CurMP : int
        Weapon : string
        WPower : int
    end record
var stat : array 1 .. 1 of charstats

type Enemstats :
    record
        Name : string
        Level : int
        MaxHP : int
        CurHP : int
        ATK : int
        DEF : int
        Weapon : string
    end record
var Estat : array 1 .. 15 of Enemstats

Estat (1).Name := 'Robo Scout'
Estat (1).Level := 1
Estat (1).MaxHP := 10
Estat (1).CurHP := Estat (1).MaxHP
Estat (1).ATK := 1
Estat (1).DEF := 1
Estat (1).Weapon := 'probe'

Estat (2).Name := 'Gremlin'
Estat (2).Level := 2
Estat (2).MaxHP := 15
Estat (2).CurHP := Estat (2).MaxHP
Estat (2).ATK := 6
Estat (2).DEF := 8
Estat (2).Weapon := 'cackle'

proc Pstats
    for i : 1 .. 1
        put "Enter your Name"
        get stat (i).Name : *
        cls
        put "Enter your Race"
        put "Human" : 10, "Elf" : 10, "Dwarf" : 10
        put "Ogre" : 10, "Sprite" : 10, "shifter" : 10
        get stat (i).Race : *
        cls
        loop
            put "Enter your class"
            put "Warrior" : 14, "Archer" : 14, "Mage" : 14, "Thief"
            get stat (i).Class
            cls
            if stat (i).Class = 'warrior' or stat (i).Class = 'Warrior' then
                stat (i).WPower := 5
                stat (i).MaxHP := 35
                stat (i).CurHP := stat (i).MaxHP
                stat (i).Weapon := 'sword'
                stat (i).ATK := 10
                stat (i).DEF := 5
                stat (i).MaxMP := 0
                stat (i).CurMP := 0
                stat (i).Spells := 'N/a'
                stat (i).EXP := 0
                stat (i).Level := 1
                exit
            elsif stat (i).Class = 'archer' or stat (i).Class = 'Archer' then
                stat (i).WPower := 4
                stat (i).MaxHP := 25
                stat (i).CurHP := stat (i).MaxHP
                stat (i).Weapon := 'Bow'
                stat (i).ATK := 8
                stat (i).DEF := 7
                stat (i).MaxMP := 0
                stat (i).CurMP := 0
                stat (i).Spells := 'N/a'
                stat (i).EXP := 0
                stat (i).Level := 1
                exit
            elsif stat (i).Class = 'mage' or stat (i).Class = 'Mage' then
                stat (i).WPower := 2
                stat (i).MaxHP := 15
                stat (i).CurHP := stat (i).MaxHP
                stat (i).Weapon := 'staff'
                stat (i).ATK := 2
                stat (i).DEF := 4
                stat (i).MaxMP := 9
                stat (i).CurMP := 9
                stat (i).Spells := 'N/a'
                stat (i).EXP := 0
                stat (i).Level := 1
                exit
            elsif stat (i).Class = 'thief' or stat (i).Class = 'Thief' then
                stat (i).WPower := 3
                stat (i).MaxHP := 20
                stat (i).CurHP := stat (i).MaxHP
                stat (i).Weapon := 'daggers'
                stat (i).ATK := 8
                stat (i).DEF := 7
                stat (i).MaxMP := 0
                stat (i).CurMP := 0
                stat (i).Spells := 'N/a'
                stat (i).EXP := 0
                stat (i).Level := 1
                exit
            else
                put "No, no NO! I cannot teach you in that class..."
            end if
        end loop
        put "Name:", stat (i).Name
        put "Level:", stat (i).Level
        put "HP:", stat (i).CurHP, "/", stat (i).MaxHP
        put "Race:", stat (i).Race
        put "Class:", stat (i).Class
        put "Weapon:", stat (i).Weapon
        put "ATK:", stat (i).ATK
        put "DEF:", stat (i).DEF
        put "Magic Points:", stat (i).CurMP, "/", stat (i).MaxMP
        put "Spells: ", stat (i).Spells
        put "Experience:", stat (i).EXP
    end for
    delay (2000)
end Pstats

proc battlecore
    var font : int
    font := Font.New ('Arial:30')
    winID := Window.Open ('position:200;200,graphics:800;500,nobuttonbar,center,center')
    Font.Draw ('Battle Mode', maxx div 3, maxy - 30, font, black)
    var i : int := Rand.Int (1, 2)
    locatexy (550, maxy - 70)
    put Estat (i).Name
    locatexy (50, 120)
    put stat (1).Name
    locatexy (50, 100)
    put "Level: ", stat (1).Level
    locatexy (50, 90)
    put "Hit Points: ", stat (1).CurHP, "/", stat (1).MaxHP
    locatexy (30, 20)
    put "Attack"
    locatexy (130, 20)
    put "Defend"
    locatexy (250, 20)
    put "Magic"
    locatexy (345, 20)
    put "Inventory"
    locatexy (460, 20)
    put "Companion"
    locatexy (570, 20)
    put "Run Away"
    loop
        drawbox (10, 10, 100, 40, black)
        drawbox (110, 10, 210, 40, black)
        drawbox (220, 10, 320, 40, black)
        drawbox (330, 10, 430, 40, black)
        drawbox (440, 10, 540, 40, black)
        drawbox (550, 10, 650, 40, black)
        mousewhere (mousex, mousey, mouseb)
        if mousex >= 10 and mousex < 100 and mousey >= 10 and mousey < 40 and mouseb = 1 then
            var j : int := Rand.Int (stat (1).ATK - 3, stat (1).ATK + 3)
            var atkpower : int
            var dmg : int := 0
            atkpower := j + stat (1).WPower
            dmg := atkpower - Estat (i).DEF
            if Estat (i).CurHP >= 1 and dmg >= 1 then
                locatexy (0, maxy - 50)
                put "You hit ", Estat (i).Name, " for ", dmg, "dmg!!"
                Estat (i).CurHP := Estat (i).CurHP - dmg
                if Estat (i).CurHP <= 0 then
                    locatexy (0, maxy - 80)
                    put "You have slain ", Estat (i).Name, "!!!"
                elsif Estat (i).CurHP > 0 then
                    locatexy (0, maxy - 80)
                    put Estat (i).Name, "'s turn!"
                end if
            elsif Estat (i).CurHP >= 1 and dmg < 1 then
                locatexy (0, maxy - 50)
                put Estat (i).Name, " evaded your attack!"
                Estat (i).CurHP := Estat (i).CurHP
            end if
        elsif mousex >= 110 and mousex < 210 and mousey >= 10 and mousey < 40 and mouseb = 1 then
            locatexy (0, maxy - 80)
            put "testing..."
        elsif mousex >= 220 and mousex < 320 and mousey >= 10 and mousey < 40 and mouseb = 1 then
            locatexy (0, maxy - 80)
            put "test 2..."
        elsif mousex >= 330 and mousex < 430 and mousey >= 10 and mousey < 40 and mouseb = 1 then
            locatexy (0, maxy - 80)
            put "test 3..."
        elsif mousex >= 440 and mousex < 540 and mousey >= 10 and mousey < 40 and mouseb = 1 then
            locatexy (0, maxy - 80)
            put "test 4..."
        elsif mousex >= 550 and mousex < 650 and mousey >= 10 and mousey < 40 and mouseb = 1 then
            locatexy (0, maxy - 80)
            put "test 5..."
        end if
    end loop
end battlecore
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Pstats
battlecore


So can anyone help me out here?

Martin says: Can you please use more descriptive titles in the future?
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sun Jan 15, 2006 10:07 am   Post subject: (No subject)

Your main problem is that the if structure is based on the direct output of mousewhere(). This is usually not a problem, but since this loop won't take all that long to recurse, a single click will be registered several times over - hence several actions will be taken at one time.

Look up Mouse.ButtonMoved() and Mouse.ButtonWait() and incorporate those into it. I tried it and in a good situation, I was able to click several times each producing a different amount of damage dealt. I also got the 'it's enemy's turn' message, so things should be working correctly.

However, if I started with the enemy evading my attack, they continually did so, no matter how many times I clicked.

You know how to make records, so why not improve on your mouse variables by making a 'mouse' type? While you're at it, 'button1..button7' sounds suspiciously like a series of variables that would be better off as an array.
For your assignments of classes, HP, etc - try incorporate a function instead of brute initialization. This will make your life easier and cut down on the number of meaningful lines of code you have.
So:
code:

% Instead of:
myType (1).name := "Name"
myType (1).smilie := ":D"
myType (2).name := "Name2"
myType (2).smilie := ":P"

% First create:
function init_mt (inName, inSmile : string) : mt
   var temp : mt
   temp.name := inName
   temp.smilie := inSmile
   result temp
end init_mt
% And now:
myType (3) := init_mt ("name3", "^_^")


I'm glad to see you didn't break down and try use Turing's native GUI. Sure your's could do with some streamlining (did I hear someone say something about equationally checking for mouse positions instead of using absolute values?), but at least it meets your on needs.
Talion




PostPosted: Sun Jan 15, 2006 10:47 am   Post subject: (No subject)

Thanks! I think i'll go try that out then.
Cervantes




PostPosted: Sun Jan 15, 2006 10:52 am   Post subject: (No subject)

This type of program will be very difficult to make without a robust knowledge of aggregate data structures. You may not have the time for what I'm about to suggest (assuming this is a final project due soon), but learning about Classes, Object Interaction, and Inheritence and Polymorphism will provide you with the structure these programs require.
Talion




PostPosted: Sun Jan 15, 2006 7:44 pm   Post subject: (No subject)

Thanks to you both again! Very Happy Still need to work on those tutorials you showed cervantes a good deal but so far their helping me out a bit. ^__^ gosh people are smart! I never even thought of that function thing. Gosh I have a lot to learn....

Well thanks all! ^__^ your help is really appreciated
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: