
-----------------------------------
hayawi
Sat Aug 13, 2011 2:48 am

Help Me!!!
-----------------------------------
OK, so im trying to make a game just for fun, and i need help with some of the code.
var gy1 : int := 200
var gx2 : int := 220
var gy2 : int := 220
var rx1 : int := 400
var ry1 : int := 400
var rx2 : int := 420
var ry2 : int := 440
var endscreen : int := 630 - gx2

%for making the attacks in the middle
var mult : int := 225

%for sensing the keys that are pressed
var chars : array char of boolean
Input.KeyDown (chars)

var shieldx1 : int := gx2 + 5
var shieldy1 : int := gy1
var shieldx2 : int := shieldx1 + 3
var shieldy2 : int := gy2
var gatkx : int := gx2
var gatky : int := gy2 + gy2 - mult

%my procedures

%go right
procedure right
    gx1 := gx1 + 1
    gx2 := gx2 + 1
    delay (10)
end right

%go left
procedure left
    gx1 := gx1 - 1
    gx2 := gx2 - 1
    delay (10)
end left

%go up
procedure up
    gy1 := gy1 + 1
    gy2 := gy2 + 1
    delay (10)
end up

%go down
procedure down
    gy1 := gy1 - 1
    gy2 := gy2 - 1
    delay (10)
end down

%unused code
%procedure rockshield
%    Draw.FillBox (shieldx1, shieldy1, shieldx2, shieldy2, brown)
%    delay (10)
%end rockshield

%the atk
procedure rockblast
    for i : 1 .. endscreen
        cls
        Draw.FillBox (gx1, gy1, gx2, gy2, green)
        Draw.FillOval (gatkx + i, gatky, 2, 2, brown)
        delay (10)
        Input.KeyDown (chars)
        locate (1, 1)
        if chars (KEY_RIGHT_ARROW) then
            right
        elsif chars (KEY_LEFT_ARROW) then
            left
        elsif chars (KEY_UP_ARROW) then
            up
        elsif chars (KEY_DOWN_ARROW) then
            down
        end if
    end for
end rockblast

%the movement
loop
    shieldx1 := gx2 + 5
    shieldy1 := gy1
    shieldx2 := shieldx1 + 3
    shieldy2 := gy2
    gatkx := gx2
    gatky := gy2 + gy2 - mult
    cls
    Draw.FillBox (gx1, gy1, gx2, gy2, green)
    Input.KeyDown (chars)

    if chars (KEY_RIGHT_ARROW) then
        right
    elsif chars (KEY_LEFT_ARROW) then
        left
    elsif chars (' ') then
        rockblast
    elsif chars (KEY_UP_ARROW) then
        up
    elsif chars (KEY_DOWN_ARROW) then
        down
    end if
delay (10)
end loop



So im trying to make the character move diagonally, because at the moment he only moves up, down, left, or right.



Also, im trying to make the character shoot multiple times, instead of just once, and having to wait until the shot is expired.



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


also, im using turing 4.1.1, please help asap

-----------------------------------
Zren
Sat Aug 13, 2011 12:04 pm

RE:Help Me!!!
-----------------------------------
For #1: Try drawing a diagonal line on a sketch of a graph. Observe how the point's x and y values differ.

For #2: Arrays. Particles. Search for those keywords.

-----------------------------------
hayawi
Sat Aug 13, 2011 8:30 pm

Re: Help Me!!!
-----------------------------------
Damn it, ive never been good with arrays, and i dont get what you mean by the diagonal line, im just saying that i want it to go up and right when you press up and right, also, how do i stop clipping of the images?

-----------------------------------
Zren
Sat Aug 13, 2011 9:20 pm

RE:Help Me!!!
-----------------------------------
You can be pressing all 4+ buttons at once. You require to be pressing at least 2 (up/down and right/left) to move diagonally. Your code only lets you press one at a time.

Remember that in if/elsif/else blocks, only one (the first one that is satisfied) part of the code executes.

-----------------------------------
hayawi
Sun Aug 14, 2011 1:49 am

Re: Help Me!!!
-----------------------------------
so if im not supposed to use ifs, what do i use?
or are you saying the ifs have to be written differently

-----------------------------------
DemonWasp
Sun Aug 14, 2011 11:38 am

RE:Help Me!!!
-----------------------------------
You're supposed to use ifs. You just need to write them such that you can, for example, be pressing both up and right at the same time.

It's up to you whether you want to allow people to press up and down at the same time, or left and right at the same time. However, you must allow (one of up or down) and (one of left or right) at the same time.

-----------------------------------
Raknarg
Sun Aug 14, 2011 7:52 pm

RE:Help Me!!!
-----------------------------------
Think about it this way: when you use an if, the if will end as soon as an if it goes over is true. ex:

var foo : int := 5

if foo = 5 then
     stuff
elsif foo = 5 then
     other stuff
end if

Both statements may hold, but only "stuff" will happen because it skips the rest of the if since the first if was true.

var foo : int := 5

if foo = 5 then
     stuff
end if
if foo = 5 then
     other stuff
end if

Now because they have their own ifs, "stuff" and "other stuff" both happen.

-----------------------------------
hayawi
Sun Aug 14, 2011 8:36 pm

Re: Help Me!!!
-----------------------------------
wow thanks, that really helps, i was on the verge of figuring it out when i made another player and used a different if, but this really explains the concept, thanks
