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

Username:   Password: 
 RegisterRegister   
 RPG game eperience calculating problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Sun Feb 12, 2006 6:01 pm   Post subject: RPG game eperience calculating problem

This is my code for my RPG game, as you can see, when you kill the black dot, you keep getting exp, i want it to just add exp once then it is over

to help me, you need to know the controls:
arrow keys to move
when you get close to the black dot, game pauses (it enters attack mode)and you must click to attack, the stats in the top corner change to show your HP and enemy HP.

please help me solve the EXP problem.
code:
setscreen ("offscreenonly")

var x, y, button : int
var playerx : int := 50
var playery : int := 50
var playerDEF, playerATK, playerMGC, playerHP, playerLVL, playerdamage, prandATK, erandATK, playerEXP : int
var enemyDEF, enemyATK, enemyMGC, enemyHP, enemyLVL, enemyx, enemyy, enemydamage, enemyEXP : array 1 .. 5 of int
var chars : array char of boolean

playerDEF := 5
playerATK := 5
playerMGC := 1
playerLVL := 1
playerHP := 100
playerEXP := 1
enemyx (1) := 200
enemyy (1) := 200
enemyDEF (1) := 3
enemyATK (1) := 5
enemyMGC (1) := 1
enemyLVL (1) := 1
enemyHP (1) := 75

loop
    randint (enemyEXP (1), 5, 15)
    Mouse.Where (x, y, button)
    View.Update
    delay (20)
    cls
    drawfilloval (playerx, playery, 10, 10, 12)
    drawfilloval (enemyx (1), enemyy (1), 10, 10, 7)
    Input.KeyDown (chars)
    locate (1, 1)
    if chars (KEY_UP_ARROW) then
        playery += 2
    end if
    if chars (KEY_RIGHT_ARROW) then
        playerx += 2

    end if
    if chars (KEY_LEFT_ARROW) then
        playerx -= 2

    end if
    if chars (KEY_DOWN_ARROW) then
        playery -= 2
    end if
    put "enemy HP: ", enemyHP (1) ..
    locate (2, 1)
    put "Your HP: ", playerHP ..
    locate (3, 1)
    put "Your EXP: ", playerEXP ..

    if playerx >= enemyx (1) - 20 and playery >= enemyy (1) - 20 and playerx <= enemyx (1) + 20 and playery <= enemyy (1) + 20 then
        loop
            Mouse.Where (x, y, button)
            if button = 1 then
                View.Update
                cls
                put "enemy HP: ", enemyHP (1) ..
                locate (2, 1)
                put "Your HP: ", playerHP ..
                locate (3, 1)
                put "Your EXP: ", playerEXP ..
                drawfilloval (playerx, playery, 10, 10, 12)
                drawfilloval (enemyx (1), enemyy (1), 10, 10, 7)
                randint (erandATK, 1, 6)
                randint (prandATK, 1, 6)
                enemydamage (1) := erandATK + enemyATK (1) - playerDEF
                playerdamage := prandATK + playerATK - enemyDEF (1)
                enemyHP (1) := enemyHP (1) - playerdamage
                playerHP := playerHP - enemydamage (1)
                delay (1000)
                exit when enemyHP (1) <= 0
            end if
        end loop
    end if
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HERE IS MY PROBLEM
    if enemyHP (1) <= 0 then
        enemyx (1) := 10000
        playerEXP := playerEXP + enemyEXP (1) %%%%%%%%% IT KEEPS ADDING EXP
    end if

    if playerx <= enemyx (1) and playery <= enemyy (1) then
        enemyx (1) -= 1
        enemyy (1) -= 1
    end if
    if playerx <= enemyx (1) and playery >= enemyy (1) then
        enemyx (1) -= 1
        enemyy (1) += 1
    end if
    if playerx >= enemyx (1) and playery <= enemyy (1) then
        enemyx (1) += 1
        enemyy (1) -= 1
    end if
    if playerx >= enemyx (1) and playery >= enemyy (1) then
        enemyx (1) += 1
        enemyy (1) += 1
    end if

    if playerx >= maxx - 10 then
        playerx := maxx - 11
    elsif playerx <= 10 then
        playerx := 11
    elsif playery >= maxy - 10 then
        playery := maxy - 11
    elsif playery <= 10 then
        playery := 11
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sun Feb 12, 2006 6:35 pm   Post subject: (No subject)

An RPG eh? Good luck. Although I strongly suggest you learn far more from the Turing Walkthrough before continuing, especially considering you just leart basic arrays. Otherwise, I fear you won't get very far in your RPG.

Anyways, the problem is that once the enemy is dead, the condition is met at every iteration of the loop and you gain xp. What you have to do is put the gaining of xp somewhere that will only be executed at the moment that you kill the enemy. How does right after you exit the fight loop sound?
shoobyman




PostPosted: Sun Feb 12, 2006 6:45 pm   Post subject: (No subject)

that sounds great, and i thank you for your concern, but i read the tutorial on RPGs and it doesn't look too hard.
anyways, it won't be too much of an advanced RPG, just walking around and killing as well as buying new items then killing some more.
leveling up, gaing exp, buying armour and weapons, you know, the RPG stuff.
pavol




PostPosted: Mon Feb 13, 2006 11:58 am   Post subject: (No subject)

your program keeps adding the experience points because the enemyHP is still <= 0. after you kill the enemy (hp reaches 0) then add 1 or whatever amount of experience points and make the enemyHp something like 100 again or more if you wish to have advanced levels or something
hope it helps Very Happy
codemage




PostPosted: Mon Feb 13, 2006 1:26 pm   Post subject: (No subject)

When you kill the enemy, reset it to full health & another location.
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: