jumping tutorial?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

I'm running into a bit of a snag it says the for loop needs "do" at the end, but in the example it doesn't have one

here is my code:

Code: Select all


-- Office Man Stan --



function love.load()

	love.graphics.setMode(320, 320)
	love.graphics.setCaption( "Office Man Stan" )

	stan_right = love.graphics.newImage( "P.PNG" )
	ground = love.graphics.newImage( "X.png" )
	background = love.graphics.newImage( "z.png" )
	stan_left = love.graphics.newImage( "P_left.png" )
	-- game variables
	
	player_X = 50
	player_Y = 260
	player_direction = "r"
	-- background color
	love.graphics.setBackgroundColor(104, 136, 248)

	-- map stuff
	
	-- map variables 
	map_w = 20
	map_h = 20
	map_x = 0
	map_y = 0
	map_offset_x = 32
	map_offset_y = 32
	map_display_w = 14
	map_display_h = 10
	tile_w = 48
	tile_h = 48
	
	map={ 
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
}
	
	love.graphics.setFont(12)
	
	--tiles
	tile = {}
	for i=0,1
		tile[i] = love.graphics.newImage( "tile_image"..i..".png" ) do
end
end

function draw_map()

	for y=1, map_display_h do
		for x=1, map_display_w do
			love.graphics.draw(
				tile[map[y+map_y] [x+map_x]],
				(x*tile_w)+map_offset_x,
				(y*tile_h)+map_offset_y )
		end
	end
end

function love.update(dt)
	
if love.keyboard.isDown( "left" ) then
	player_X = player_X - 1
	player_direction = "l"
	map_y = map_y-1
	map_x = math.max(map_x-1, 0)
	end
	
if love.keyboard.isDown( "right" ) then
	player_X = player_X + 1
	player_direction = "r"
	map_x = math.min(map_x+1, map_w-map_display_w)
	end

	
if love.keyboard.isDown( "down" ) then
	player_Y = player_Y + 1
	player_direction = "d"
	if map_y > map_h-map_display_h then map_y = map_h-map_display_h; end
	end
	
if love.keyboard.isDown( "up" ) then
	player_Y = player_Y - 1 
	player_direction = "u"
	if map_y < 0 then map_y = 0; end
	end
end

function love.draw()

if player_direction == "r" then
	love.graphics.draw( stan_right, player_X, player_Y )
	end

if player_direction == "l" then
	love.graphics.draw( stan_left, player_X, player_Y )
	end

if player_direction == "u" then
	love.graphics.draw( stan_right, player_X, player_Y )
	end
	
if player_direction == "d" then
	love.graphics.draw( stan_right, player_X, player_Y )
	end
	
	love.graphics.draw( ground, 0, 260 )
	
	draw_map()
	
end

I left the default values.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: jumping tutorial?

Post by zac352 »

...?
Which one of these generic syntax examples that look like they were pulled from the manual are you looking for? :P

Code: Select all

while statement do
block
end

Code: Select all

for var=start, max[, inc] do
block
end

Code: Select all

do
block
end

Code: Select all

for var in iter do
block
end
Hello, I am not dead.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

well the map part i got from the wiki. This seems to be the biggest of my problems i havent gotten any progress yet :|
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: jumping tutorial?

Post by zac352 »

toaster468 wrote:well the map part i got from the wiki. This seems to be the biggest of my problems i havent gotten any progress yet :|
What have you left to do?
Hello, I am not dead.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: jumping tutorial?

Post by TechnoCat »

toaster468 wrote:

Code: Select all

	--tiles
	tile = {}
	for i=0,1
		tile[i] = love.graphics.newImage( "tile_image"..i..".png" ) do
end
The errors are in this part. You have a bad for syntax, missing both a "do" and an "end."
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

OK,I'll see what happens when I change it.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

Awesome!, it works now. Thanks guys :)
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

I just really need to fix the views and stuff
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

OK now every time I go farther than what is on the screen at start i get a user data error :(
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: jumping tutorial?

Post by kikito »

Can you post your current .love file and explain what you mean by "go farther than what is on the screen"?
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 5 guests