forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Please need help with my first game.

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
rikardhassel



Joined: 08 Oct 2005
Posts: 9

PostPosted: Sat Oct 08, 2005 11:25 pm    Post subject: Please need help with my first game. Reply with quote

Here is a part where objects is gonna fall. I' ve made them, make them fall and I' ve random the beginning of the fall once, need it always.

Code:


System.usbDiskModeActivate()

white = Color.new(255, 255, 255)

time = 0
ground = 262

x0 = 0
x1 = 0
y0 = 0
y1 = 0

r0 = math.random(480)
r1 = 0
r2 = math.random(480)

while true do

   screen:clear()
 
   x = math.sin(5 * 2 / 360 * r1) * r1 + r0
       
        screen:fillRect(r0, r1, 10, 10, white)

        screen:print(10, 10, "r0", white)
        screen:print(10, 20, "r1", white)

   screen:print(30, 10, r0, white)
        screen:print(30, 20, r1, white)

   r1 = r1 + 1

   if r1 > 262 then
      r1 = 0
   
   elseif r1 >= 262 then
   r0 = r2                                   -- HERE IS MY PROBLEM --       

   end
 
   screen.waitVblankStart()
   screen.flip()
 
   pad = Controls.read()
   if pad:start() then
      break
   end
end
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sat Oct 08, 2005 11:33 pm    Post subject: Re: Please need help with my first game. Reply with quote

What about "r0 = math.random(480)" instead of "r0 = r2"? It's only Lua, not Prolog, where you can define a rule based system :-)
Back to top
View user's profile Send private message
JEK



Joined: 03 Sep 2005
Posts: 12
Location: Norway

PostPosted: Sat Oct 08, 2005 11:35 pm    Post subject: Reply with quote

You want the object to be at a random point every time it starts at the top of the screen again?
Added a line for you.

Code:

white = Color.new(255, 255, 255)

time = 0
ground = 262

x0 = 0
x1 = 0
y0 = 0
y1 = 0

r0 = math.random(480)
r1 = 0
r2 = math.random(480)

while true do

   screen:clear()
 
   x = math.sin(5 * 2 / 360 * r1) * r1 + r0
       
        screen:fillRect(r0, r1, 10, 10, white)

        screen:print(10, 10, "r0", white)
        screen:print(10, 20, "r1", white)

   screen:print(30, 10, r0, white)
        screen:print(30, 20, r1, white)

   r1 = r1 + 1

   if r1 > 262 then
      r1 = 0
      r2 = math.random(480)        -- ADDED THIS (JEK)
   elseif r1 >= 262 then
   r0 = r2                                   -- HERE IS MY PROBLEM --       

   end
 
   screen.waitVblankStart()
   screen.flip()
 
   pad = Controls.read()
   if pad:start() then
      break
   end
end

_________________
--
JEK
Back to top
View user's profile Send private message Send e-mail
rikardhassel



Joined: 08 Oct 2005
Posts: 9

PostPosted: Sun Oct 09, 2005 12:55 am    Post subject: Problem Reply with quote

This is ALMOST working, BUT SOMETHING does that if you take a point on the right side of the cursor you get 2 points :S, and on the left side 1 point. If you just stand still after catched point, you just have one after one free when they hit the ground. PLEASE ANYONE help me.. would be VERY gracefully.

Code:
    System.usbDiskModeActivate()

white = Color.new(255, 255, 255)
black = Color.new(0, 0, 0)

red = Color.new(255, 0, 0)
blue = Color.new(0, 0, 255)
green = Color.new(0, 255, 0)
yellow = Color.new(0, 255, 255)


tech = Image.createEmpty(480, 272)
tech:clear(black )

highscore = 5
score = 0

line = screen:drawLine(480, 0, 480, 272, white)

x0 = 0
y0 = 262
x1 = 0
y1 = 0

r0 = math.random(480)
r1 = 0

c = 45
c1 = 5
   


-- But how to get them to fall, and if get it 2 sec between each ? --

-- CREATE points, HOW ? --

-- END --

while true do

pad = Controls.read()
 
   dx = pad:analogX()
   if math.abs(dx) > 32 then
           x0 = x0 + dx / 20

    end


   if ((r1 > x0 and r0 < x0+45) or (r0+10 > x0 and r0+10 < x0+45)) and ((r1 > y0 and r1 < y0+5) or (r1+5 > y0 and r1+5 < y0+5) or (r1+10 > y0 and r1+10 < y0+5)) then
   score = score + 1


   end

        -- Highscore and Score function --
   
   if score > highscore then
   highscore = highscore + 1
   
   end

   -- End of Highscore and Score function --
   
    screen:blit(0, 0, tech, 0, 0, tech:width(), tech:height(), false)
         
         -- Gaming Space --
 
    screen:drawLine(480, 0, 480, 272, white)
         screen:drawLine(480, 272, 0, 480, white)
    screen:drawLine(0, 0, 480, 0, white)
    screen:drawLine(0, 0, 0, 272, white)

    -- End of gaming space --

    screen:print(10, 10, "Raining points, randomized..", white)

    screen:print(150, 130, "RikaRdo's gaming project", white)

         screen:print(150, 140, "Highscore," , white)
    screen:print(150, 150, "Score," , white)

        -- Highscore and Score function, printed --

    screen:print(230, 140, highscore, white)
         screen:print(200, 150, score, white)   

    -- End of Highscore and Score function, printed --

    -- GET the points falling ? --
   
    -- AND if they collaps with the cursor then get a point else IF
    -- hitting the bottom, GAME OVER ! --

        -- Makes a object random fallin --
            
    screen:fillRect(x0, y0, c, c1, white)
   
    -- End of objects --

-- If the cursor goes outside the "gaming space" then let it be in there :) --

   if x0 > 480 then
      x0 = -46
   end
   
   if x0 < -46 then
      x0 = 480
   end

-- Almost the end end --
   
   x = math.sin(5 * 2 / 360 * r1) * r0 + r1
       
        screen:fillRect(r0, r1, 10, 10, white)

        screen:print(10, 20, "r0", white)
        screen:print(10, 30, "r1", white)

   screen:print(30, 20, r0, white)
        screen:print(30, 30, r1, white)

   r1 = r1 + 2                                 

   if r1 > 256 then
      r1 = 0
   
   elseif r1 >= 256 then
   r0 = math.random(480)

end           

    screen.flip()
    screen:waitVblankStart()


if pad:start() then

      break

   end

end

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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