Please need help with my first game.

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
rikardhassel
Posts: 9
Joined: Sat Oct 08, 2005 2:19 am

Please need help with my first game.

Post by rikardhassel »

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: Select all


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
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Please need help with my first game.

Post by Shine »

What about "r0 = math.random(480)" instead of "r0 = r2"? It's only Lua, not Prolog, where you can define a rule based system :-)
JEK
Posts: 12
Joined: Sat Sep 03, 2005 12:04 am
Location: Norway

Post by JEK »

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: Select all

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
rikardhassel
Posts: 9
Joined: Sat Oct 08, 2005 2:19 am

Problem

Post by rikardhassel »

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: Select all

    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 &#40;&#40;r1 > x0 and r0 < x0+45&#41; or &#40;r0+10 > x0 and r0+10 < x0+45&#41;&#41; and &#40;&#40;r1 > y0 and r1 < y0+5&#41; or &#40;r1+5 > y0 and r1+5 < y0+5&#41; or &#40;r1+10 > y0 and r1+10 < y0+5&#41;&#41; then
	score = score + 1


	end

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

	-- End of Highscore and Score function --
	 
	 screen&#58;blit&#40;0, 0, tech, 0, 0, tech&#58;width&#40;&#41;, tech&#58;height&#40;&#41;, false&#41;
         
         -- Gaming Space --
 
	 screen&#58;drawLine&#40;480, 0, 480, 272, white&#41;
         screen&#58;drawLine&#40;480, 272, 0, 480, white&#41;
	 screen&#58;drawLine&#40;0, 0, 480, 0, white&#41;
	 screen&#58;drawLine&#40;0, 0, 0, 272, white&#41;

	 -- End of gaming space --

	 screen&#58;print&#40;10, 10, "Raining points, randomized..", white&#41;

	 screen&#58;print&#40;150, 130, "RikaRdo's gaming project", white&#41;

         screen&#58;print&#40;150, 140, "Highscore," , white&#41;
	 screen&#58;print&#40;150, 150, "Score," , white&#41;

        -- Highscore and Score function, printed --

	 screen&#58;print&#40;230, 140, highscore, white&#41;
         screen&#58;print&#40;200, 150, score, white&#41;	 

	 -- 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&#58;fillRect&#40;x0, y0, c, c1, white&#41;
	 
	 -- End of objects --

-- If the cursor goes outside the "gaming space" then let it be in there &#58;&#41; --

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

-- Almost the end end --
	
	x = math.sin&#40;5 * 2 / 360 * r1&#41; * r0 + r1
        
        screen&#58;fillRect&#40;r0, r1, 10, 10, white&#41; 

        screen&#58;print&#40;10, 20, "r0", white&#41;
        screen&#58;print&#40;10, 30, "r1", white&#41;

	screen&#58;print&#40;30, 20, r0, white&#41;
        screen&#58;print&#40;30, 30, r1, white&#41;

	r1 = r1 + 2                                  

	if r1 > 256 then
		r1 = 0
	
	elseif r1 >= 256 then
	r0 = math.random&#40;480&#41;

end           

	 screen.flip&#40;&#41;
	 screen&#58;waitVblankStart&#40;&#41;


if pad&#58;start&#40;&#41; then

		break

	end

end

Post Reply