2

Hey guys so my problem is that I have 2 scenes a battle scene that represents the main gameplay scene and the result scene which represents the player monsters skills, so far what I have is whatever monster was chosen at the character scene will determine the image and strings representing that monsters skills etc. the problem is both the battle scene and the result scene need to switch on a constant basis until either player wins. The thing is when I try to go back to the battle scene from the result scene and go back again the labels will be overlapping for example say the first skill has a 1 on it the first time I went to the result scene but the second time instead of replacing the 1 with a 2 or 3 it will place the 2 or 3 on top of the 1.

I also noticed that when I added damage calculation (which I have removed temporarily) if the skill would do 7HP damage it would work on the first occasion but the second or 3rd occasion the damage would double each time.

Heres my code;

using System;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;
using Sce.PlayStation.HighLevel.UI;

namespace MonsterKombat_v3
{
public class dragonClass : characterClass
{
    public dragonClass ()
    {
        base.maxHealth = new Label();
        base.healthBar = new ProgressBar();
        base.monster = new ImageBox();
        base.name = new Label();
        base.sLabel = new Label[6];
        base.mTitle = new Label();
        base.skills = new string[6];
        base.Skills = new int[6];

        base.name.HorizontalAlignment = HorizontalAlignment.Center;
        base.name.VerticalAlignment = VerticalAlignment.Middle;
        base.name.SetPosition(10, 400);
        base.name.SetSize(160, 50);
        base.name.Text = "Name: Dragon";

        base.currentHealth = 85;

        base.maxHealth.HorizontalAlignment = HorizontalAlignment.Center;
        base.maxHealth.VerticalAlignment = VerticalAlignment.Middle;
        base.maxHealth.SetSize(100, 50);
        base.maxHealth.SetPosition(170, 480);
        base.maxHealth.Text = (base.currentHealth + "/85");

        base.healthBar.Progress = 0.85f;
        base.healthBar.SetSize(250, 50);
        base.healthBar.SetPosition(100, 469);

        base.monster.Image = new ImageAsset("/Application/Images/Monsters/MonsterIcon1.png");
        base.monster.Width = 375;
        base.monster.Height = 400;
        base.monster.PivotType = PivotType.MiddleCenter;
        base.monster.SetPosition(175, 200);

        base.mTitle.HorizontalAlignment = HorizontalAlignment.Center;
        base.mTitle.VerticalAlignment = VerticalAlignment.Middle;
        base.mTitle.Font.Style = FontStyle.Bold;
        base.mTitle.Font.Style = FontStyle.Italic;
        base.mTitle.SetPosition(220, 15);
        base.mTitle.Text = "Dragon";

        for(int i = 0; i < 6; i++)
        { 
            //makes a new label based on the value of 'i'
            base.sLabel[i] = new Label();
            base.sLabel[i].SetSize(600, 100);
            base.sLabel[i].HorizontalAlignment = HorizontalAlignment.Center;
            base.sLabel[i].VerticalAlignment = VerticalAlignment.Middle;
            assetClass.panel2.AddChildLast(base.sLabel[i]);
        }

        for(int i = 0; i < 6; i++)
        {
            //converts the int value of each skill to a string  
            base.skills[i] = base.Skills[i].ToString();
        }

        sLabel[0].Text = "1) Claw: 7HP {1}" + "".PadRight(50) + base.skills[0];
        sLabel[0].SetPosition(270, 40);
        sLabel[1].Text = "2) Tail Smash: 9HP {1}" + "".PadRight(42) + base.skills[1];
        sLabel[1].SetPosition(270, 110);
        sLabel[2].Text = "3) Bite: 17HP {2}" + "".PadRight(49) + base.skills[2];
        sLabel[2].SetPosition(270, 170);
        sLabel[3].Text = "4) Roar: 5HP(all, enemy misses turn) {2}" + "".PadRight(18) + base.skills[3];
        sLabel[3].SetPosition(270, 230);
        sLabel[4].Text = "5) Fire Breath: 20HP + 5 for every odd number {3}" + "".PadRight(5) + base.skills[4];
        sLabel[4].SetPosition(270, 300);
        sLabel[5].Text = "6) Nova Flame: 30HP(all) + 10".PadRight(60) + "\n for every even number {5}" + "".PadRight(37) + base.skills[5];
        sLabel[5].SetPosition(270, 370);

        assetClass.panel2.AddChildLast(base.mTitle);
        assetClass.panel.AddChildLast(base.name);
        assetClass.panel.AddChildLast(base.maxHealth);
        assetClass.panel.AddChildLast(base.healthBar);
        assetClass.panel.AddChildLast(base.monster);
    }

    public static void Skills(int number1, int number2, int number3)
    {
        Label[] sLabel = new Label[6];
        Label mTitle = new Label();
        string[] skills = new string[6];
        int[] Skills = new int[6];

        switch(number1)
        {
            case 1:
                Skills[0]++;
                break;
            case 2:
                Skills[1]++;
                break;
            case 3:
                Skills[2]++;
                break;
            case 4:
                Skills[3]++;
                break;
            case 5:
                Skills[4]++;
                break;
            case 6:
                Skills[5]++;
                break;
        }

        switch(number2)
        {
            case 1:
                Skills[0]++;
                break;
            case 2:
                Skills[1]++;
                break;
            case 3:
                Skills[2]++;
                break;
            case 4:
                Skills[3]++;
                break;
            case 5:
                Skills[4]++;
                break;
            case 6:
                Skills[5]++;
                break;
        }

        switch(number3)
        {
            case 1:
                Skills[0]++;
                break;
            case 2:
                Skills[1]++;
                break;
            case 3:
                Skills[2]++;
                break;
            case 4:
                Skills[3]++;
                break;
            case 5:
                Skills[4]++;
                break;
            case 6:
                Skills[5]++;
                break;
        }

        mTitle.HorizontalAlignment = HorizontalAlignment.Center;
        mTitle.VerticalAlignment = VerticalAlignment.Middle;
        mTitle.Font.Style = FontStyle.Bold;
        mTitle.Font.Style = FontStyle.Italic;
        mTitle.SetPosition(220, 15);
        mTitle.Text = "Dragon";

        for(int i = 0; i < 6; i++)
        {
            //converts the int value of each skill to a string  
            skills[i] = Skills[i].ToString();
        }

        for(int i = 0; i < 6; i++)
        { 
            //makes a new label based on the value of 'i'
            sLabel[i] = new Label();
            sLabel[i].SetSize(600, 100);
            sLabel[i].HorizontalAlignment = HorizontalAlignment.Center;
            sLabel[i].VerticalAlignment = VerticalAlignment.Middle;
            assetClass.panel2.AddChildLast(sLabel[i]);
        }

        sLabel[0].Text = "1) Claw: 7HP {1}" + "".PadRight(50) + skills[0];
        sLabel[0].SetPosition(270, 40);
        sLabel[1].Text = "2) Tail Smash: 9HP {1}" + "".PadRight(42) + skills[1];
        sLabel[1].SetPosition(270, 110);
        sLabel[2].Text = "3) Bite: 17HP {2}" + "".PadRight(49) + skills[2];
        sLabel[2].SetPosition(270, 170);
        sLabel[3].Text = "4) Roar: 5HP(all, enemy misses turn) {2}" + "".PadRight(18) + skills[3];
        sLabel[3].SetPosition(270, 230);
        sLabel[4].Text = "5) Fire Breath: 20HP + 5 for every odd number {3}" + "".PadRight(5) + skills[4];
        sLabel[4].SetPosition(270, 300);
        sLabel[5].Text = "6) Nova Flame: 30HP(all) + 10".PadRight(60) + "\n for every even number {5}" + "".PadRight(37) + skills[5];
        sLabel[5].SetPosition(270, 370);

        assetClass.panel2.AddChildLast(mTitle);
    }
}
}

battle scene class;

using System;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;
using Sce.PlayStation.HighLevel.GameEngine2D;
using Sce.PlayStation.HighLevel.GameEngine2D.Base;
using Sce.PlayStation.HighLevel.UI;

namespace MonsterKombat_v3
{
public class battleScene : Sce.PlayStation.HighLevel.GameEngine2D.Scene
{
    public static int[] bsNumber = new int[3];

    public battleScene()
    {           
        //defines a variable to store random numbers for each die
        //3 ints used to calculate a random number between 1-6 for each die
        var bsDice = new Random();
        bsNumber[0] = (bsDice.Next() % 6) + 1;
        bsNumber[1] = (bsDice.Next() % 6) + 1;
        bsNumber[2] = (bsDice.Next() % 6) + 1;

        for(int i = 0; i < 2; i++)
        { 
            //makes a new label based on the value of 'i'
            assetClass.bsLabel[i] = new Sce.PlayStation.HighLevel.UI.Label();
            assetClass.bsLabel[i].HorizontalAlignment = HorizontalAlignment.Center;
            assetClass.bsLabel[i].VerticalAlignment = VerticalAlignment.Middle;
            assetClass.bsLabel[i].SetSize(80, 50);
            assetClass.bsLabel[i].Text = "Health:";
            assetClass.bsLabel[i].PivotType = PivotType.MiddleCenter;
            assetClass.panel.AddChildLast(assetClass.bsLabel[i]);
        }

        assetClass.bsLabel[0].SetPosition(50, 470);
        assetClass.bsLabel[1].SetPosition(610, 470);

        //defines the properties for the player monster
        /*assetClass.playerMonster.Width = 375;
        assetClass.playerMonster.Height = 400;
        assetClass.playerMonster.PivotType = PivotType.MiddleCenter;
        assetClass.playerMonster.SetPosition(175, 200);*/

        //defines the properties for the enemy monster
        /*assetClass.enemyMonster.Width = 375;
        assetClass.enemyMonster.Height = 400;
        assetClass.enemyMonster.PivotType = PivotType.MiddleCenter;
        assetClass.enemyMonster.SetPosition(775, 200);*/

        //defines the properties for the player health bar
        //assetClass.playerBar.SetSize(250, 50);
        //assetClass.playerBar.SetPosition(100, 469);

        //defines the properties for the enemy health bar
        /*assetClass.enemyBar.SetSize(250, 50);
        assetClass.enemyBar.SetPosition(670, 469);*/

        for(int i = 0; i < 3; i++)
        { 
            //makes a new die based on the value of 'i'
            assetClass.dice[i] = new ImageBox();
            assetClass.dice[i].Width = 250;
            assetClass.dice[i].Height = 120;
            assetClass.dice[i].PivotType = PivotType.MiddleCenter;
            assetClass.panel.AddChildLast(assetClass.dice[i]);
        }

        //assigns the position for each die
        assetClass.dice[0].SetPosition(475, 65);
        assetClass.dice[1].SetPosition(475, 200);
        assetClass.dice[2].SetPosition(475, 332);

        //defines the properties for the roll button
        assetClass.button.Width = 300;
        assetClass.button.Height = 100;
        assetClass.button.PivotType = PivotType.MiddleCenter;
        assetClass.button.SetPosition(475, 469);
        assetClass.button.IconImage = new ImageAsset("/Application/Images/Buttons/RollButton.png");
        assetClass.button.Style = ButtonStyle.Custom;
        assetClass.button.TouchEventReceived += (sender, e) => {
            //changes the scene to the result scene
            sceneClass.sceneSelect("result");
            //hides the panel
            //assetClass.panel.Visible = false;
            assetClass.panel.RemoveChild(assetClass.title);
            //calls the set die function from the diceclass
            diceClass.setDie(bsNumber[0], bsNumber[1], bsNumber[2]);
            /*switch(characterScene.selectedMonster)
            {
                case 1:
                    dragonClass.Skills(bsNumber[0], bsNumber[1], bsNumber[2]);
                    break;

            }*/
            //skillClass.applyPoints(bsNumber[0], bsNumber[1], bsNumber[2]);
            //playerClass.playerSkill(characterScene.player);
        };

        //DamageCalculationClass.Damage();
        //EnemyClass.EnemyHealth();

        //assigns the assets to the panel
        assetClass.panel.AddChildLast(assetClass.button);

        //assigns the panel to the UI scene
        sceneClass.battleScene.RootWidget.AddChildLast(assetClass.panel);
        Director.Instance.GL.Context.SetClearColor(0, 0, 0, 0);
    }
}
}

result scene class;

using System;
using System.Threading;
using System.Diagnostics;
using System.Collections.Generic;

using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.Core.Graphics;
using Sce.PlayStation.Core.Input;
using Sce.PlayStation.HighLevel.GameEngine2D;
using Sce.PlayStation.HighLevel.GameEngine2D.Base;
using Sce.PlayStation.HighLevel.UI;

namespace MonsterKombat_v3
{
public class resultScene : Sce.PlayStation.HighLevel.GameEngine2D.Scene
{
    public resultScene()
    {
        //defines 3 variables that define random numbers for each die
        //3 ints used to calculate a random number between 1-6 for each die
        var rsDice = new Random();
        int[] rsNumber = new int[3];
        rsNumber[0] = (rsDice.Next() % 6) + 1;
        rsNumber[1] = (rsDice.Next() % 6) + 1;
        rsNumber[2] = (rsDice.Next() % 6) + 1;

        assetClass.panel2.Width = Director.Instance.GL.Context.GetViewport().Width;
        assetClass.panel2.Height = Director.Instance.GL.Context.GetViewport().Height;           

        for(int i = 0; i < 6; i++)
        { 
            //makes a new button based on the value of 'i'
            assetClass.sButton[i] = new Button();
            assetClass.sButton[i].Width = 300;
            assetClass.sButton[i].Height = 100;
            assetClass.sButton[i].PivotType = PivotType.MiddleCenter;
            assetClass.sButton[i].IconImage = new ImageAsset("/Application/Images/Buttons/SkillButton.png");
            assetClass.sButton[i].Style = ButtonStyle.Custom;
            assetClass.sButton[i].TouchEventReceived += (sender, e) => 
                sceneClass.sceneSelect("battle");
            assetClass.panel2.AddChildLast(assetClass.sButton[i]);
        }

        //assigns the position of each button
        assetClass.sButton[0].SetPosition(920, 90);
        assetClass.sButton[1].SetPosition(920, 155);
        assetClass.sButton[2].SetPosition(920, 220);
        assetClass.sButton[3].SetPosition(920, 285);
        assetClass.sButton[4].SetPosition(920, 350);
        assetClass.sButton[5].SetPosition(920, 415);

        for(int i = 0; i < 3; i++)
        { 
            //makes a new die based on the value of 'i'
            assetClass.dice[i] = new ImageBox();
            assetClass.dice[i].Width = 250;
            assetClass.dice[i].Height = 120;
            assetClass.dice[i].PivotType = PivotType.MiddleCenter;
            assetClass.panel2.AddChildLast(assetClass.dice[i]);
        }

        assetClass.dice[0].SetPosition(125, 65);
        assetClass.dice[1].SetPosition(125, 200);
        assetClass.dice[2].SetPosition(125, 332);

        //SkillClass.ApplySkill();

        //assigns the panel to the UI scene
        sceneClass.resultScene.RootWidget.AddChildLast(assetClass.panel2);
        //clears the screen to a specific colour
        Director.Instance.GL.Context.SetClearColor(255, 0, 0, 0);
    }
}
}

sorry its all a mess but i'm new here. Btw I'm making my game in PSM studio hence the reason for some some syntax differences.

Andrei
  • 42,814
  • 35
  • 154
  • 218
jimmy_123
  • 21
  • 1
  • 1
    What does the debugger tell you? Have you tried setting breakpoints and looking at the values you are setting? – Gusdor Mar 07 '14 at 12:08
  • The debugger doesn't really tell me anything but to be honest I haven't actually tried using breakpoints. From what I can see it seems like that whenever it moves between the battle scene and the result scene it makes a new instance of that scene but makes each object twice like it'll make a new label on top of the old label and damage wise it would do the calculations multiple times – jimmy_123 Mar 07 '14 at 12:28

0 Answers0