can some one figure this out ??? or is there a bug

Monkey Forums/Monkey Beginners/can some one figure this out ??? or is there a bug

dubbsta(Posted 2016) [#1]
i followed invader jims tutorial, im on video 4 in simple game at the part where he rendered the block player and the first block floor. the problem im having is the block floor is not rendering and i followed his code exact and spent hours comparing it...cant figure it out, dont want to continue till i do :/

this is main

Import Falling


Const STATE_MENU:Int = 0
Const STATE_GAME:Int = 1
Const STATE_DEATH:Int = 2 



Class FallingGame Extends App

Field gameState:Int = STATE_MENU


Field gravity:Float = 0.2

Field Player1:Player = New Player(KEY_LEFT,KEY_RIGHT, 320, 50) 

Field Cam:Camera = New Camera()

Field mapWidth:Int
Field mapOffset:Float
  
Field blocks:List<Block> = New List<Block>()

		Method OnCreate()
		
			SetUpdateRate(60)
			
			GenerateFloor(3)
			
			mapWidth = SCREEN_WIDTH / TILE_WIDTH
			mapOffset = (SCREEN_WIDTH Mod TILE_WIDTH)/2
			
	    End 
	    
	    
	    
	    Method OnUpdate()
	   
	      Select gameState
	      
	      	Case STATE_MENU
	        	If KeyHit(KEY_ENTER)
	        	   gameState = STATE_GAME
	        	End 
	        	
	        Case STATE_GAME
	        	If KeyHit(KEY_R)
	        		Player1.Reset()
	        		Cam.Reset()
	        	End 
	        	
	            Player1.Update(gravity)	
	        	Cam.Update(1.0)	
	        
	        Case STATE_DEATH
	        
	        End 
	    End 
	    
	    
	    
	    Method OnRender()
	    
	    	Cls(0,0,0)
	    
	
	
	    	Select gameState
	    	
	    		Case STATE_MENU
	    		
	    			DrawText("Falling Game!", 320, 100, 0.5)
	     			DrawText("Press Enter to Play", 320, 400, 0.5)
	     		
	     		Case STATE_GAME
	     		
	     			PushMatrix()
	     			
	     			
	     			Translate(Cam.position.x, Cam.position.y)
	     			
	     			For Local block:Block = Eachin blocks
	     				block.Draw()
	     			End 
	     			
	     			Player1.Draw()
	     			
	     			PopMatrix()
	     			
	 			
	     		Case STATE_DEATH
	     		
	     	End 
	    
	    End 
	    
	    Method GenerateFloor(row:Int)
			For Local x:=0 Until mapWidth
			blocks.AddLast(New Block(mapOffset + TILE_WIDTH/2 + x*TILE_WIDTH, row*TILE_HEIGHT + TILE_HEIGHT/2))
			End 
		End 
		   
End 








Function Main()


 	New FallingGame()
 	
End 




this is falling tab

Import mojo

Const TILE_WIDTH:Int = 48
Const TILE_HEIGHT:Int = 48

Const SCREEN_WIDTH:Int = 640
Const SCREEN_HEIGHT:Int = 480



'''''''''''''''''''''''''''''''''''''
Class Vec2D
	Field x:Float
	Field y:Float
	
	
	Method New(x:Float=0, y:Float=0)
		Set(x,y)
	End 
	
	
	Method Set(x:Float, y:Float)
		Self.x= x
		Self.y= y
	End 
	
End 


Class Vec2Di
	Field x:Int 
	Field y:Int 
	
	
	Method New(x:Int =0, y:Int =0)
		Set(x,y)
	End 
	
	
	Method Set(x:Int , y:Int )
		Self.x= x
		Self.y= y
	End 
	
End 



''''''''''''''''''''''''''''''
Class Player
	
	Field originalPos:Vec2D
	Field position:Vec2D
	Field velocity:Vec2D
	
	
	Field speed:Float= 4.0
	
	Field leftkey:Int 
	Field rightkey:Int 
	
	
	Method New(leftkey:Int, rightkey:Int, x:Float, y:Float)
	
		originalPos = New Vec2D(x,y)
		position = New Vec2D(x,y)
		velocity = New Vec2D()
		
		Self.leftkey = leftkey
		Self.rightkey = rightkey
		
	
	End 
	
	
	Method Reset()
		position.Set(originalPos.x,originalPos.y) 
		velocity.Set(0,0)
	End 	
	
	
	
	Method Update(gravity:Float)
	
		velocity.x = 0 
		velocity.y += gravity
	
	
		If KeyDown(leftkey)
			velocity.x = -speed
	    End 
	    
	    If KeyDown(rightkey)
	    	velocity.x = speed 
	    End 
	    
	    position.x += velocity.x
	    position.y += velocity.y
	
	End 
	
	
	Method Draw()
		SetColor(0,255,0)
		
		DrawRect(position.x-16, position.y-16,32,32)
	End 
	
End 



''''''''''''''''''''''''
Class Camera

  Field originalPos:Vec2D
  Field position:Vec2D
  
  
  Method New(x:Float=0, y:Float=0)
  
  		position = New Vec2D(x,y)
  		originalPos = New Vec2D(x,y)
  End 
  
  
  Method Reset()
  	position.Set(originalPos.x, originalPos.y)
  	
  End 
  
  
  Method Update(fallSpeed:Float)
  
 		position.y -= fallSpeed 
 End 
  
End   


  
'''''''''''''''''''''' 
Class Block 
	Field position:Vec2D
	
	Method New(x:Float, y:Float)
	
		position = New Vec2D(x,y)
	End 
	
	
	Method Draw()
		SetColor(123,123,123)
		DrawRect(position.x-(TILE_WIDTH/2), position.y-(TILE_HEIGHT/2),TILE_WIDTH,TILE_HEIGHT)
  
  
  		SetColor(60,60,60)
  		DrawRect(position.x-((TILE_WIDTH-8)/2), position.y-((TILE_HEIGHT-8)/2),TILE_WIDTH-8,TILE_HEIGHT-8)

   
   End  
End 
  
  
'''''''''''''''''''''''' 
  
  
  



Paul - Taiphoz(Posted 2016) [#2]
You are calling Generate floor before you have set the floor width so those values are zero resulting in a zero loop meaning no floor.


dubbsta(Posted 2016) [#3]
TY!!!