 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
suckerr70
Joined: 18 Mar 2006 Posts: 2
|
Posted: Sun Mar 19, 2006 4:26 pm Post subject: Changing variables help! |
|
|
Ok, so Im trying to make a simple game (yes this code very based off a tutorial but It's my first program/game i'm working on) and I'm trying to get the "R" trigger button to change weapons and weapon names but when I hit "R", it just flickers "Charged" and goes right back to "RockBuster". Thank you for your help! After I'm going to add sprites and stuff. Please Help me.
This is what I think my problem is:
| Code: | if pad:r() and oldpad:r() ~= pad:r() and currentWeapon == 1 then
currentWeapon = 2 else
currentWeapon = 1
end |
Heres the whole thing:
| Code: |
green = Color.new(0,255,0)
red = Color.new(255,0,0)
blue = Color.new(0,0,150)
white = Color.new(200,200,200)
currentEnemy = 1
currentWeapon = 1
currentPlayer = 1
pad = Controls.read()
oldpad = Controls.read()
Enemy = {}
Enemy[1] = { type = "Fireman" , health = 100 }
Enemy[2] = { type = "Iceman", health = 100 }
Enemy[3] = { type = "Gutsman", health = 100 }
Enemy[4] = { type = "Elecman", health = 100 }
Enemy[5] = { type = "Cutman", health = 100 }
Player = {}
Player[1] = { name = "Rockman" , health = 100 }
Player[2] = { name = "Blues" , health = 100 }
Weapon = {}
Weapon[1] = { weapon = 5 , name = "Rockbuster" }
Weapon[2] = { weapon = 20 , name = "Charged Shot"}
while true do
screen:clear()
screen:print(5,10, Player[currentPlayer].name .. "s Health: " .. Player[currentPlayer].health,green)
screen:print(5,20, Player[currentPlayer].name .. "s Weapon: " .. Weapon[currentWeapon].name,green)
screen:print(250,20,"Enemy Name: " .. Enemy[currentEnemy].type,red)
screen:print(250,10,"Enemy Health: " .. Enemy[currentEnemy].health,red)
screen:print(90, 40,"Press [X] to Attack!!!",white)
if currentEnemy == 5 and Enemy [currentEnemy].health == 0 then
screen:print(100,100,"All RobotMasters have been Killed!",blue)
end
if Enemy[currentEnemy].health == 0 and currentEnemy <= 4 then
currentEnemy = currentEnemy + 1
end
if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[currentEnemy].health > 0 then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - Weapon[currentWeapon].weapon
end
if pad:r() and oldpad:r() ~= pad:r() and currentWeapon == 1 then
currentWeapon = 2 else
currentWeapon = 1
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
pad = Controls.read()
if pad:start() then
break
end
end
|
Thanks again!
P.S.
Also, If its not to hard, can anyone tell me instead of just making the enemies health go down right when you press "X", that a picture(bullet) moves from your current location straight to the last direction you were facing and then if it hits another picture (enemie) that the "health" variable goes down.? and yes... I do love Rockman (Megaman)... THANKS~! |
|
| Back to top |
|
 |
CT_Bolt
Joined: 04 Mar 2006 Posts: 14 Location: Computer Chair
|
Posted: Sun Mar 19, 2006 4:46 pm Post subject: Code is fixed. |
|
|
Your code is fixed:
I'm not sure what exactly was wrong with it but, The lines with -- *** next to them are the comments I added(next to code I changed).
| Code: | green = Color.new(0,255,0)
red = Color.new(255,0,0)
blue = Color.new(0,0,150)
white = Color.new(200,200,200)
currentEnemy = 1
currentWeapon = 1
currentPlayer = 1
--pad = Controls.read() -- *** This goes near the top of the main loop
--oldpad = Controls.read() -- *** You don't need this here
Enemy = {}
Enemy[1] = { type = "Fireman" , health = 100 }
Enemy[2] = { type = "Iceman", health = 100 }
Enemy[3] = { type = "Gutsman", health = 100 }
Enemy[4] = { type = "Elecman", health = 100 }
Enemy[5] = { type = "Cutman", health = 100 }
Player = {}
Player[1] = { name = "Rockman" , health = 100 }
Player[2] = { name = "Blues" , health = 100 }
Weapon = {}
Weapon[1] = { weapon = 5 , name = "Rockbuster" }
Weapon[2] = { weapon = 20 , name = "Charged Shot"}
while true do
pad = Controls.read() -- *** This is where it should read controls
screen:clear()
screen:print(5,10, Player[currentPlayer].name .. "s Health: " .. Player[currentPlayer].health,green)
screen:print(5,20, Player[currentPlayer].name .. "s Weapon: " .. Weapon[currentWeapon].name,green)
screen:print(250,20,"Enemy Name: " .. Enemy[currentEnemy].type,red)
screen:print(250,10,"Enemy Health: " .. Enemy[currentEnemy].health,red)
screen:print(90, 40,"Press [X] to Attack!!!",white)
if currentEnemy == 5 and Enemy [currentEnemy].health == 0 then
screen:print(100,100,"All RobotMasters have been Killed!",blue)
end
if Enemy[currentEnemy].health == 0 and currentEnemy <= 4 then
currentEnemy = currentEnemy + 1
end
if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[currentEnemy].health > 0 then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - Weapon[currentWeapon].weapon
end
-- *** This is a better way of changing weapons:
if pad:r() and oldpad:r() ~= pad:r() then
currentWeapon = currentWeapon + 1
if currentWeapon > table.getn(Weapon) then currentWeapon = 1 end
end
screen.waitVblankStart()
screen.flip()
oldpad = pad
--pad = Controls.read() -- *** This is near the top.
if pad:start() then break end -- *** This looks better.
end |
You were right about what was wrong but, there were more things I corrected.
By the way I'm here to help, if you have any other problems. |
|
| Back to top |
|
 |
suckerr70
Joined: 18 Mar 2006 Posts: 2
|
Posted: Sun Mar 19, 2006 5:02 pm Post subject: |
|
|
Thank-you very much! I get all the things you shifted around and/or took out but I don't really get what exacly was going on with the actual weapon shifting thing. I get how yours works but what exacly made my change right back to the original weapon? Since I am a brand new at this I would like to understand how my way didn't work so I don't make that mistake again. Like what exacly did the computer "think/do" when it was reading my script.
Thanks!
*EDIT*
One last thing I don't understand. Why should "oldpad = pad" be near the bottem? And is there a difference between "oldpad = pad" and "oldpad = Controls.read()"? |
|
| Back to top |
|
 |
CT_Bolt
Joined: 04 Mar 2006 Posts: 14 Location: Computer Chair
|
Posted: Mon Mar 20, 2006 5:29 am Post subject: What it means. |
|
|
This needs to be near the bottom because that is right before you make pad read the controls agian(when it starts looping again).
So that you can compare the controls then to the controls now.
If you make oldpad = Controls.read() then it gets the current controls pressed not what was pressed before.
| Code: | if pad:r() and oldpad:r() ~= pad:r() and currentWeapon == 1 then
currentWeapon = 2 else
currentWeapon = 1
end |
What the above means:
if R is pressed currently and if R that was pressed before(the loop ended) doesn't equal the current R value and the currentWeapon(weapon number) is equal to 1(not anything else) then
set currentWeapon = 2
else if R is not pressed currently and if R that was pressed before(the loop ended) does equal and currentWeapon isn't equal to 1(any number but 1) then
set currentWeapon = 1
end
Remember: pad:r() is a true or false value, and the 'else' statement is the exact opposite of the if statements before it.
If you need more help, post what you need. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|