jumping tutorial?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
Guys, I'm really beat. I'll try and attempt walls tomorrow morning thank you for the continued support though!
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
hi com_1,
inside love.draw you should be doing stuff that "draws" only.
The keybard() call should be inside love.update.
While love.update has a parameter called dt . It will help you control your speed without having to invoke sleep(). This will ensure that the game will run at the same pace in all computers, regardless of their processor speed. If you have doubts about how to use dt, please open a new thread.
map_options seems too complicated. Maybe this will help you. It also seems a bit inefficient to do it on every frame. See if you can put it inside love.load and call it only once.
map_pos. See if you can start using love.graphics.translate instead of relying on map_x and map_y. The tile scrolling tutorial was written before love.graphics.translate existed.
map_image: it should really not take more than 10 lines. Use loops so you don't have to repeat your code so much.
inside love.draw you should be doing stuff that "draws" only.
The keybard() call should be inside love.update.
While love.update has a parameter called dt . It will help you control your speed without having to invoke sleep(). This will ensure that the game will run at the same pace in all computers, regardless of their processor speed. If you have doubts about how to use dt, please open a new thread.
map_options seems too complicated. Maybe this will help you. It also seems a bit inefficient to do it on every frame. See if you can put it inside love.load and call it only once.
map_pos. See if you can start using love.graphics.translate instead of relying on map_x and map_y. The tile scrolling tutorial was written before love.graphics.translate existed.
map_image: it should really not take more than 10 lines. Use loops so you don't have to repeat your code so much.
When I write def I mean function.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: jumping tutorial?
Or use the love.keypressed(), which might be more appropriate here (it's hard to read your code).kikito wrote:The keybard() call should be inside love.update.
Help us help you: attach a .love.
Re: jumping tutorial?
Thank for comments kikito, but this all I know.
Did anyone ever have any problems with the speed ?
Try my next code.
Did anyone ever have any problems with the speed ?
Try my next code.
Code: Select all
--______________________________________________________________________________________________
function love.load()
-- screen
scrx=640; scry=480; zx=(scrx/2); zy=(scry/2); zi=200;
love.graphics.setMode(scrx,scry,false,true,0); love.graphics.setCaption("Love2D project"); love.graphics.setBackgroundColor(10,30,50);
-- font
love.graphics.setFont(12);
-- global
col=0; alpha=255; k_up=0; k_right=0; k_down=0; k_left=0; k_enter=0;
-- global dim
kl=10; dost={};
for d=0,kl-1 do-- for >
dost[d]=0;
end-- for <
end
--______________________________________________________________________________________________
function love.draw()
-- function
keyboard();
map_options();
object_options();
map_pos();
object_pos();
map_image();
object_image();
end
--______________________________________________________________________________________________
function keyboard()
-- sleep
love.timer.sleep(10);
-- keyboard
k_up=0; k_right=0; k_down=0; k_left=0; k_enter=0;
-- up, right, down, left
if love.keyboard.isDown("up") then k_up=1;end;
if love.keyboard.isDown("right") then k_right=1;end;
if love.keyboard.isDown("down") then k_down=1;end;
if love.keyboard.isDown("left") then k_left=1;end;
-- enter
if love.keyboard.isDown("return") then k_enter=1;end;
-- exit
if love.keyboard.isDown("escape") then os.exit();end;
---- text
--col=(250/1); love.graphics.setColor((col*1),(col*1),(col*1),alpha);
--love.graphics.print("k_enter: "..k_enter,10,200,0,1,1);
-- image
col=(250/2); love.graphics.setColor((col*1),(col*1),(col*1),alpha);
love.graphics.line(zx-zi,zy,zx+zi,zy); love.graphics.line(zx,zy-zi,zx,zy+zi);
end
--______________________________________________________________________________________________
function map_options()
if dost[1]==0 then dost[1]=1;-- dost >
-- map
map="-,1,=,=,=,=,=,2,-,-,"..
"1,4,-,-,-,-,-,3,2,-,"..
"|,-,-,-,<,>,-,-,|,-,"..
"3,2,p,-,-,-,-,1,4,-,"..
"-,3,=,=,=,=,=,4,-,-,";
-- len
ma_len=string.len(map); ma_len=(ma_len/2);
-- dim
ma_kl1=ma_len; ma_kl2=5; ma_x={}; ma_y={}; ma_rx={}; ma_ry={}; ma_x2={}; ma_y2={}; ma_x3={}; ma_y3={}; ma_tip={};
-- options
ma_rr=30; ma_xx=0; ma_yy=0; ma_aa=(ma_len/5)-1; ma_bb=ma_aa; map_x=0; map_y=0; map_x2=0; map_y2=0; ma_xx1=10000; ma_yy1=10000; ma_xx2=-10000; ma_yy2=-10000; ma_pl=0;
for d1=0,ma_kl1-1 do-- for >
-- options
ma_x[d1]={}; ma_y[d1]={}; ma_rx[d1]={}; ma_ry[d1]={}; ma_x2[d1]={}; ma_y2[d1]={}; ma_x3[d1]={}; ma_y3[d1]={}; ma_tip[d1]={};
for d2=0,ma_kl2-1 do-- for >
-- options
ma_x[d1][d2]=0; ma_y[d1][d2]=0; ma_x2[d1][d2]=0; ma_y2[d1][d2]=0; ma_x3[d1][d2]=0; ma_y3[d1][d2]=0; ma_rx[d1][d2]=0; ma_ry[d1][d2]=0; ma_tip[d1][d2]="";
if d2==0 then-- d2 >
-- tip
ma_tip[d1][d2]=string.sub(map,1+(d1*2),1+(d1*2));
-- tip - object
if ma_tip[d1][d2]=="p" then ma_pl=ma_pl+1;end;
-- pos.
ma_x[d1][d2]=100+ma_xx; ma_y[d1][d2]=100+ma_yy;
ma_xx=ma_xx+ma_rr; if d1==ma_bb then ma_bb=ma_bb+ma_aa+1; ma_xx=0; ma_yy=ma_yy+ma_rr; end;
-- pos. on screen
if ma_tip[d1][d2]=="=" or ma_tip[d1][d2]=="|" or ma_tip[d1][d2]=="+" then-- tip >
if ma_xx1>=ma_x[d1][d2] then ma_xx1=ma_x[d1][d2];
elseif ma_yy1>=ma_y[d1][d2] then ma_yy1=ma_y[d1][d2];
elseif ma_xx2<=ma_x[d1][d2] then ma_xx2=ma_x[d1][d2];
elseif ma_yy2<=ma_y[d1][d2] then ma_yy2=ma_y[d1][d2];
end;
end;-- tip <
else-- d2 >
-- pos.
ma_x[d1][d2]=ma_x[d1][0]; ma_y[d1][d2]=ma_y[d1][0];
-- tip
ma_tip[d1][d2]=ma_tip[d1][0];
end;-- d2 <
-- radius
if ma_tip[d1][d2]=="=" then-- tip >
if d2==0 then ma_rx[d1][d2]=(ma_rr/2); ma_ry[d1][d2]=5;else ma_rx[d1][d2]=2; ma_ry[d1][d2]=2;end;
elseif ma_tip[d1][d2]=="|" then-- tip >
if d2==0 then ma_rx[d1][d2]=5; ma_ry[d1][d2]=(ma_rr/2);else ma_rx[d1][d2]=2; ma_ry[d1][d2]=2;end;
elseif ma_tip[d1][d2]=="1" or ma_tip[d1][d2]=="2" or ma_tip[d1][d2]=="3" or ma_tip[d1][d2]=="4" then-- tip >
-- radius
ma_rx[d1][d2]=5; ma_ry[d1][d2]=5;
-- pos.
if d2==1 then if ma_tip[d1][d2]=="3" or ma_tip[d1][d2]=="4" then ma_x[d1][d2]=ma_x[d1][0]; ma_y[d1][d2]=ma_y[d1][0]-(ma_ry[d1][0]*2);end;
elseif d2==2 then if ma_tip[d1][d2]=="1" or ma_tip[d1][d2]=="3" then ma_x[d1][d2]=ma_x[d1][0]+(ma_rx[d1][0]*2); ma_y[d1][d2]=ma_y[d1][0];end;
elseif d2==3 then if ma_tip[d1][d2]=="1" or ma_tip[d1][d2]=="2" then ma_x[d1][d2]=ma_x[d1][0]; ma_y[d1][d2]=ma_y[d1][0]+(ma_ry[d1][0]*2);end;
elseif d2==4 then if ma_tip[d1][d2]=="2" or ma_tip[d1][d2]=="4" then ma_x[d1][d2]=ma_x[d1][0]-(ma_rx[d1][0]*2); ma_y[d1][d2]=ma_y[d1][0];end;
end;
elseif ma_tip[d1][d2]=="<" or ma_tip[d1][d2]==">" then-- tip >
if d2==0 then ma_rx[d1][d2]=(ma_rr/2); ma_ry[d1][d2]=5; else ma_rx[d1][d2]=2; ma_ry[d1][d2]=2;end;
end;-- tip <
end-- for <
end-- for <
-- options
ma_rastx=zx-ma_xx1; ma_rasty=zy-ma_yy1; ma_radx=((ma_xx2-ma_xx1)/2); ma_rady=((ma_yy2-ma_yy1)/2); ma_xx1=10000; ma_yy1=10000; ma_xx2=-10000; ma_yy2=-10000;
for d1=0,ma_kl1-1 do-- for >
for d2=0,ma_kl2-1 do-- for >
-- pos.
ma_x[d1][d2]=ma_x[d1][d2]+ma_rastx-ma_radx; ma_y[d1][d2]=ma_y[d1][d2]+ma_rasty-ma_rady;
-- pos. 2
ma_x2[d1][d2]=ma_x[d1][d2]; ma_y2[d1][d2]=ma_y[d1][d2];
end-- for <
end-- for <
end-- dost >
end
--______________________________________________________________________________________________
function map_pos()
for d1=0,ma_kl1-1 do-- for >
for d2=0,ma_kl2-1 do-- for >
-- pos.
ma_x[d1][d2]=ma_x2[d1][d2]+ma_x3[d1][d2]+(map_x+map_x2);
ma_y[d1][d2]=ma_y2[d1][d2]+ma_y3[d1][d2]+(map_y+map_y2);
end-- for <
end-- for <
end
--______________________________________________________________________________________________
function map_image()
-- color
col=(250/1); love.graphics.setColor((col*1),(col*1),(col*1),alpha);
for d1=0,ma_kl1-1 do-- for >
for d2=0,ma_kl2-1 do-- for >
---- image
--love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
--love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
--love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
--love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
-- image
if d2==0 then-- d2 >
if ma_tip[d1][d2]=="=" then-- tip >
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
elseif ma_tip[d1][d2]=="|" then-- tip >
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
elseif ma_tip[d1][d2]=="1" then-- tip >
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+(ma_rx[d1][d2]*3),ma_y[d1][d2]-ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+(ma_rx[d1][d2]*3),ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+(ma_ry[d1][d2]*3));
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+(ma_ry[d1][d2]*3));
elseif ma_tip[d1][d2]=="2" then-- tip >
love.graphics.line(ma_x[d1][d2]-(ma_rx[d1][d2]*3),ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-(ma_rx[d1][d2]*3),ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+(ma_ry[d1][d2]*3));
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+(ma_ry[d1][d2]*3));
elseif ma_tip[d1][d2]=="3" then-- tip >
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+(ma_rx[d1][d2]*3),ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+(ma_rx[d1][d2]*3),ma_y[d1][d2]-ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-(ma_ry[d1][d2]*3),ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-(ma_ry[d1][d2]*3),ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
elseif ma_tip[d1][d2]=="4" then-- tip >
love.graphics.line(ma_x[d1][d2]-(ma_rx[d1][d2]*3),ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-(ma_rx[d1][d2]*3),ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-(ma_ry[d1][d2]*3),ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-(ma_ry[d1][d2]*3),ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
elseif ma_tip[d1][d2]=="<" then-- tip >
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
elseif ma_tip[d1][d2]==">" then-- tip >
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]-ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
love.graphics.line(ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]-ma_ry[d1][d2],ma_x[d1][d2]+ma_rx[d1][d2],ma_y[d1][d2]+ma_ry[d1][d2]);
end;-- tip <
end;-- d2 <
end-- for <
end-- for <
---- text
--col=(250/1); love.graphics.setColor((col*1),(col*1),(col*1),alpha);
--love.graphics.print("map: "..map,10,20,0,1,1);
--love.graphics.print("ma_len: "..ma_len,10,40,0,1,1);
end
--______________________________________________________________________________________________
function object_options()
if dost[2]==0 then dost[2]=1;-- dost >
-- dim
ob_kl1=ma_pl; ob_kl2=9; ob_x={}; ob_y={}; ob_rx={}; ob_ry={}; ob_tip={}; ob_kas={}; ob_x2={}; ob_y2={}; ob_x3={}; ob_y3={}; ob_dost={}; ob_my={}; ob_my2={}; ob_xx={}; ob_yy={}; ob_xx1={}; ob_yy1={}; ob_xx2={}; ob_yy2={}; ob_xx3={}; ob_yy3={}; ob_xx4={}; ob_yy4={}; ob_n={}; ob_s={}; ob_i1={}; ob_i2={};
-- options
ob_sky1=3; ob_sky2=0.1; ob_nakl=0; ob_rr=5;
for d1=0,ob_kl1-1 do-- for >
-- options
ob_x[d1]={}; ob_y[d1]={}; ob_rx[d1]={}; ob_ry[d1]={}; ob_tip[d1]={}; ob_kas[d1]={}; ob_x2[d1]={}; ob_y2[d1]={}; ob_x3[d1]={}; ob_y3[d1]={}; ob_dost[d1]={}; ob_my[d1]={}; ob_my2[d1]={}; ob_xx[d1]=0; ob_yy[d1]=0; ob_xx1[d1]=0; ob_yy1[d1]=0; ob_xx2[d1]=0; ob_yy2[d1]=0; ob_xx3[d1]=0; ob_yy3[d1]=0; ob_xx4[d1]=0; ob_yy4[d1]=0; ob_n[d1]=0; ob_s[d1]={}; ob_i1[d1]={}; ob_i2[d1]={};
for d2=0,ob_kl2-1 do-- for >
-- options
ob_x[d1][d2]=0; ob_y[d1][d2]=0; ob_rx[d1][d2]=0; ob_ry[d1][d2]=0; ob_tip[d1][d2]=0; ob_kas[d1][d2]=0; ob_x2[d1][d2]=0; ob_y2[d1][d2]=0; ob_x3[d1][d2]=0; ob_y3[d1][d2]=0; ob_dost[d1][d2]=0; ob_my[d1][d2]=0; ob_my2[d1][d2]=0; ob_s[d1][d2]=1; ob_i1[d1][d2]=0; ob_i2[d1][d2]=0;
end-- for <
end-- for <
-- options
ob_nn=0;
for d=0,ma_kl1-1 do-- for >
if ma_tip[d][0]=="p" then
-- pos.
ob_x[ob_nn][0]=ma_x[d][0]; ob_y[ob_nn][0]=ma_y[d][0]--+14;
-- tip
if ma_tip[d][0]=="p" then ob_tip[ob_nn][0]="player";
elseif ma_tip[d][0]=="o" then ob_tip[ob_nn][0]="object";
end;
ob_nn=ob_nn+1;
end;
end-- for <
for d1=0,ob_kl1-1 do-- for >
for d2=0,ob_kl2-1 do-- for >
-- tip
if d2>=1 then ob_tip[d1][d2]=ob_tip[d1][0];end;
-- pos. and radius
if d2==0 then ob_rx[d1][d2]=10; ob_ry[d1][d2]=10;
elseif d2==1 then ob_rx[d1][d2]=9-0; ob_ry[d1][d2]=5; ob_x[d1][d2]=ob_x[0][0]; ob_y[d1][d2]=ob_y[0][0]-(ob_ry[0][0]*1)+ob_ry[d1][d2];
elseif d2==2 then ob_rx[d1][d2]=5; ob_ry[d1][d2]=9-0; ob_x[d1][d2]=ob_x[0][0]+(ob_rx[0][0]*1)-ob_rx[d1][d2]; ob_y[d1][d2]=ob_y[0][0];
elseif d2==3 then ob_rx[d1][d2]=9-0; ob_ry[d1][d2]=0; ob_x[d1][d2]=ob_x[0][0]; ob_y[d1][d2]=ob_y[0][0]+(ob_ry[0][0]*1)-ob_ry[d1][d2];
elseif d2==4 then ob_rx[d1][d2]=5; ob_ry[d1][d2]=9-0; ob_x[d1][d2]=ob_x[0][0]-(ob_rx[0][0]*1)+ob_rx[d1][d2]; ob_y[d1][d2]=ob_y[0][0];
elseif d2==5 then ob_rx[d1][d2]=5; ob_ry[d1][d2]=5; ob_x[d1][d2]=ob_x[0][0]+(ob_rx[0][0]*1)-ob_rx[d1][d2]; ob_y[d1][d2]=ob_y[0][0]-(ob_ry[0][0]*1)+ob_ry[d1][d2];
elseif d2==6 then ob_rx[d1][d2]=5; ob_ry[d1][d2]=5; ob_x[d1][d2]=ob_x[0][0]+(ob_rx[0][0]*1)-ob_rx[d1][d2]; ob_y[d1][d2]=ob_y[0][0]+(ob_ry[0][0]*1)-ob_ry[d1][d2];
elseif d2==7 then ob_rx[d1][d2]=5; ob_ry[d1][d2]=5; ob_x[d1][d2]=ob_x[0][0]-(ob_rx[0][0]*1)+ob_rx[d1][d2]; ob_y[d1][d2]=ob_y[0][0]+(ob_ry[0][0]*1)-ob_ry[d1][d2];
elseif d2==8 then ob_rx[d1][d2]=5; ob_ry[d1][d2]=5; ob_x[d1][d2]=ob_x[0][0]-(ob_rx[0][0]*1)+ob_rx[d1][d2]; ob_y[d1][d2]=ob_y[0][0]-(ob_ry[0][0]*1)+ob_ry[d1][d2];
end;
-- pos. 2
ob_x2[d1][d2]=ob_x[d1][d2]; ob_y2[d1][d2]=ob_y[d1][d2];
end-- for <
end-- for <
end-- dost <
col=(250/1); love.graphics.setColor((col*1),(col*1),(col*1),alpha);
for d1=0,ob_kl1-1 do-- for >
-- keyboard
if k_right==1 then ob_xx[d1]=ob_x[d1][0]+(ob_rx[d1][0]/1); ob_yy[d1]=ob_y[d1][0];end;
if k_left==1 then ob_xx[d1]=ob_x[d1][0]-(ob_rx[d1][0]/1); ob_yy[d1]=ob_y[d1][0];end;
if k_up==1 then ob_xx[d1]=ob_x[d1][0]; ob_yy[d1]=ob_y[d1][0]-(ob_ry[d1][0]/1);end;
if k_down==1 then ob_xx[d1]=ob_x[d1][0]; ob_yy[d1]=ob_y[d1][0]+(ob_ry[d1][0]/1);end;
if k_up==1 and k_right==1 then ob_xx[d1]=ob_x[d1][0]+(ob_rx[d1][0]/1); ob_yy[d1]=ob_y[d1][0]-(ob_rx[d1][0]/1);end;
if k_right==1 and k_down==1 then ob_xx[d1]=ob_x[d1][0]+(ob_rx[d1][0]/1); ob_yy[d1]=ob_y[d1][0]+(ob_rx[d1][0]/1);end;
if k_down==1 and k_left==1 then ob_xx[d1]=ob_x[d1][0]-(ob_rx[d1][0]/1); ob_yy[d1]=ob_y[d1][0]+(ob_rx[d1][0]/1);end;
if k_left==1 and k_up==1 then ob_xx[d1]=ob_x[d1][0]-(ob_rx[d1][0]/1); ob_yy[d1]=ob_y[d1][0]-(ob_rx[d1][0]/1);end;
end-- for <
-- map and object
for d1=0,ob_kl1-1 do-- for >
for d2=0,ob_kl2-1 do-- for >
-- options
ob_kas[d1][d2]=0;
end-- for <
end-- for <
-- map and object
for d3=0,ma_kl1-1 do-- for >
for d4=0,ma_kl2-1 do-- for >
if ma_tip[d3][d4]=="=" or ma_tip[d3][d4]=="|" or ma_tip[d3][d4]=="1" or ma_tip[d3][d4]=="2" or ma_tip[d3][d4]=="3" or ma_tip[d3][d4]=="4" or ma_tip[d3][d4]=="<" or ma_tip[d3][d4]==">" then-- tip >
for d1=0,ob_kl1-1 do-- for >
for d2=0,ob_kl2-1 do-- for >
if ob_x[d1][d2]+ob_rx[d1][d2]+ob_s[d1][d2]>=ma_x[d3][d4]-ma_rx[d3][d4] and ob_y[d1][d2]+ob_ry[d1][d2]+ob_s[d1][d2]+ob_my2[d1][d2]>=ma_y[d3][d4]-ma_ry[d3][d4] and ob_x[d1][d2]-ob_rx[d1][d2]-ob_s[d1][d2]<=ma_x[d3][d4]+ma_rx[d3][d4] and ob_y[d1][d2]-ob_ry[d1][d2]-ob_s[d1][d2]<=ma_y[d3][d4]+ma_ry[d3][d4] then-- kas >
-- kas
ob_kas[d1][d2]=1;
end;-- kas <
end-- for <
end-- for <
end;-- tip <
end-- for <
end-- for <
for d1=0,ob_kl1-1 do-- for >
for d2=0,ob_kl2-1 do-- for >
if ob_tip[d1][d2]=="player" then-- player >
-- keyboard
if ob_kas[d1][1]==1 then k_up=0;end;
if ob_kas[d1][2]==1 then k_right=0;end;
if ob_kas[d1][3]==1 then k_down=0;end;
if ob_kas[d1][4]==1 then k_left=0;end;
-- right
if ob_kas[d1][2]==0 then
if k_right==1 and k_up==0 and k_down==0 then
ob_x3[d1][d2]=ob_x3[d1][d2]+ob_s[d1][d2];
if d2==0 then
map_x=map_x-ob_s[d1][d2];
ob_nakl=2;
end;
end;
end;
-- left
if ob_kas[d1][4]==0 then
if k_left==1 and k_up==0 and k_down==0 then
ob_x3[d1][d2]=ob_x3[d1][d2]-ob_s[d1][d2];
if d2==0 then
map_x=map_x+ob_s[d1][d2];
ob_nakl=4;
end;
end;
end;
---- up
--if ob_kas[d1][1]==0 then
--if k_up==1 and k_right==0 and k_left==0 then
--ob_y3[d1][d2]=ob_y3[d1][d2]-ob_s[d1][d2];
--if d2==0 then map_y=map_y+ob_s[d1][d2];end;
--end;
--end;
--
---- down
--if ob_kas[d1][3]==0 then
--if k_down==1 and k_right==0 and k_left==0 then
--ob_y3[d1][d2]=ob_y3[d1][d2]+ob_s[d1][d2];
--if d2==0 then map_y=map_y-ob_s[d1][d2];end;
--end;
--end;
-- up and right
if ob_kas[d1][5]==0 then
if k_up==1 and k_right==1 then
ob_x3[d1][d2]=ob_x3[d1][d2]+ob_s[d1][d2];
--ob_y3[d1][d2]=ob_y3[d1][d2]-ob_s[d1][d2];
if d2==0 then
map_x=map_x-ob_s[d1][d2];
--map_y=map_y+ob_s[d1][d2];
ob_nakl=2;
end;
end;
end;
-- up and left
if ob_kas[d1][8]==0 then
if k_up==1 and k_left==1 then
ob_x3[d1][d2]=ob_x3[d1][d2]-ob_s[d1][d2];
--ob_y3[d1][d2]=ob_y3[d1][d2]-ob_s[d1][d2];
if d2==0 then
map_x=map_x+ob_s[d1][d2];
--map_y=map_y+ob_s[d1][d2];
ob_nakl=4;
end;
end;
end;
-- down and right
if ob_kas[d1][6]==0 then
if k_down==1 and k_right==1 then
ob_x3[d1][d2]=ob_x3[d1][d2]+ob_s[d1][d2];
--ob_y3[d1][d2]=ob_y3[d1][d2]+ob_s[d1][d2];
if d2==0 then
map_x=map_x-ob_s[d1][d2];
--map_y=map_y-ob_s[d1][d2];
ob_nakl=2;
end;
end;
end;
-- down and left
if ob_kas[d1][7]==0 then
if k_down==1 and k_left==1 then
ob_x3[d1][d2]=ob_x3[d1][d2]-ob_s[d1][d2];
--ob_y3[d1][d2]=ob_y3[d1][d2]+ob_s[d1][d2];
if d2==0 then
map_x=map_x+ob_s[d1][d2];
--map_y=map_y-ob_s[d1][d2];
ob_nakl=4;
end;
end;
end;
-- jump
if ob_dost[d1][d2]==0 then-- dost >
if k_enter==1 then ob_dost[d1][d2]=1; ob_my[d1][d2]=ob_sky1;end;
end;-- dost <
if ob_kas[d1][1]==1 then ob_my[d1][d2]=0;end;
if ob_kas[d1][3]==0 then
ob_y3[d1][d2]=ob_y3[d1][d2]-ob_my[d1][d2]+ob_my2[d1][d2]; ob_my2[d1][d2]=ob_my2[d1][d2]+ob_sky2;
else
ob_my[d1][d2]=0; ob_my2[d1][d2]=0; ob_dost[d1][d2]=0;
end;
-- angle
if k_right==0 and k_left==0 or ob_kas[d1][2]==1 or ob_kas[d1][4]==1 then ob_nakl=0;end;
end-- player <
-- image
if d2==0 then-- d2 >
-- pos.
ob_xx1[d1]=ob_x[d1][d2]+((ob_rx[d1][d2]+5)*math.sin((math.pi/4)+ob_n[d1]));
ob_yy1[d1]=ob_y[d1][d2]-((ob_ry[d1][d2]+5)*math.cos((math.pi/4)+ob_n[d1]));
ob_xx2[d1]=ob_x[d1][d2]+((ob_rx[d1][d2]+5)*math.sin(math.pi-(math.pi/4)+ob_n[d1]));
ob_yy2[d1]=ob_y[d1][d2]-((ob_ry[d1][d2]+5)*math.cos(math.pi-(math.pi/4)+ob_n[d1]));
ob_xx3[d1]=ob_x[d1][d2]+((ob_rx[d1][d2]+5)*math.sin(math.pi+(math.pi/4)+ob_n[d1]));
ob_yy3[d1]=ob_y[d1][d2]-((ob_ry[d1][d2]+5)*math.cos(math.pi+(math.pi/4)+ob_n[d1]));
ob_xx4[d1]=ob_x[d1][d2]+((ob_rx[d1][d2]+5)*math.sin((math.pi*2)-(math.pi/4)+ob_n[d1]));
ob_yy4[d1]=ob_y[d1][d2]-((ob_ry[d1][d2]+5)*math.cos((math.pi*2)-(math.pi/4)+ob_n[d1]));
-- angle
if ob_nakl==0 then ob_n[d1]=0;
elseif ob_nakl==2 then ob_n[d1]=ob_n[d1]+0.1;
elseif ob_nakl==4 then ob_n[d1]=ob_n[d1]-0.1;
end;
end;-- d2 <
-- text
--love.graphics.print(ob_kas[d1][d2],ob_x[d1][d2],ob_y[d1][d2],0,1,1);
--love.graphics.print(d2.." ".."ob_kas: "..ob_kas[d1][d2],10,20+(d2*20),0,1,1);
end-- for <
end-- for <
end
--______________________________________________________________________________________________
function object_pos()
for d1=0,ob_kl1-1 do-- for >
for d2=0,ob_kl2-1 do-- for >
-- pos.
ob_x[d1][d2]=ob_x2[d1][d2]+ob_x3[d1][d2]+(map_x+map_x2);
ob_y[d1][d2]=ob_y2[d1][d2]+ob_y3[d1][d2]+(map_y+map_y2);
end-- for <
end-- for <
end
--______________________________________________________________________________________________
function object_image()
col=(250/2); love.graphics.setColor((col*2),(col*1),(col*1),alpha);
for d1=0,ob_kl1-1 do-- for >
---- image - help
--love.graphics.line(ob_xx[d1]-ob_rr,ob_yy[d1]-ob_rr,ob_xx[d1]-ob_rr,ob_yy[d1]+ob_rr);
--love.graphics.line(ob_xx[d1]+ob_rr,ob_yy[d1]-ob_rr,ob_xx[d1]+ob_rr,ob_yy[d1]+ob_rr);
--love.graphics.line(ob_xx[d1]-ob_rr,ob_yy[d1]-ob_rr,ob_xx[d1]+ob_rr,ob_yy[d1]-ob_rr);
--love.graphics.line(ob_xx[d1]-ob_rr,ob_yy[d1]+ob_rr,ob_xx[d1]+ob_rr,ob_yy[d1]+ob_rr);
--if ob_my2[d1][0]==0 then
-- image
love.graphics.line(ob_xx1[d1],ob_yy1[d1],ob_xx2[d1],ob_yy2[d1]);
love.graphics.line(ob_xx2[d1],ob_yy2[d1],ob_xx3[d1],ob_yy3[d1]);
love.graphics.line(ob_xx3[d1],ob_yy3[d1],ob_xx4[d1],ob_yy4[d1]);
love.graphics.line(ob_xx4[d1],ob_yy4[d1],ob_xx1[d1],ob_yy1[d1]);
--end;
for d2=0,ob_kl2-1 do-- for >
--if d2==0 then-- d2 >
----if d2==0 or d2>=5 then-- d2 >
---- image
--love.graphics.line(ob_x[d1][d2]-ob_rx[d1][d2],ob_y[d1][d2]-ob_ry[d1][d2],ob_x[d1][d2]-ob_rx[d1][d2],ob_y[d1][d2]+ob_ry[d1][d2]);
--love.graphics.line(ob_x[d1][d2]+ob_rx[d1][d2],ob_y[d1][d2]-ob_ry[d1][d2],ob_x[d1][d2]+ob_rx[d1][d2],ob_y[d1][d2]+ob_ry[d1][d2]);
--love.graphics.line(ob_x[d1][d2]-ob_rx[d1][d2],ob_y[d1][d2]-ob_ry[d1][d2],ob_x[d1][d2]+ob_rx[d1][d2],ob_y[d1][d2]-ob_ry[d1][d2]);
--love.graphics.line(ob_x[d1][d2]-ob_rx[d1][d2],ob_y[d1][d2]+ob_ry[d1][d2],ob_x[d1][d2]+ob_rx[d1][d2],ob_y[d1][d2]+ob_ry[d1][d2]);
--end;-- d2 <
end-- for <
end-- for <
-- text
col=(250/1); love.graphics.setColor((col*1),(col*1),(col*1),alpha);
love.graphics.print("Press button: ".."Up, Right, Down, Left",10,scry-25,0,1,1);
love.graphics.print(" ".."Enter - jump",10,scry-10,0,1,1);
end
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
Ok, I am back and fully rested! Now, what do I have to do next again?
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
I'm stumped, I know what I have to do: to find the players X and Y coordinates and check if a wall block is touching my player, then if it is set player_canMove_l to false. And vice versa, but I do not know how to do this at all. I don't know how to find the blocks, or find the coordinates of those blocks please help.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
Start with map2world. See this post from you. Then re-read Hint 2 in Walls.
This should pretty much tell you how you should write map2world. Make sure that you understand how to use it, and that drawMap works with it.
Once that is working, world2map should be straightforward: it's just the "opposite".
With those two functions, you will have the equivalence between player coordinates and map coordinates.
EDIT: By the way, I noticed a small bug on Hint 2. I have corrected it (I mispelled mx and my in one place)
This should pretty much tell you how you should write map2world. Make sure that you understand how to use it, and that drawMap works with it.
Once that is working, world2map should be straightforward: it's just the "opposite".
With those two functions, you will have the equivalence between player coordinates and map coordinates.
EDIT: By the way, I noticed a small bug on Hint 2. I have corrected it (I mispelled mx and my in one place)
When I write def I mean function.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
Can I do the camera first? I would like to see the whole map and stuff. If not I am fine with making walls
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
I'd prefer if you stick with smaller maps for now, so they hold on one screen. If your map is just slightly bigger than the screen, you might consider increasing the screen resolution.toaster468 wrote:Can I do the camera first? I would like to see the whole map and stuff. If not I am fine with making walls
We can add a basic scrolling function at the end, if you desire.
When I write def I mean function.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 5 guests