LoginLogin

How to make à library

Root / Programming Questions / [.]

HeredosCreated:
I'm a beginner on smile basic and I'm trying to make à platformer https://smilebasicsource.com/page?pid=1346 I need help beacause write collisions take à lot of memory and are sooooooooooooooooo long to write Thanks for tout help

I'm a beginner on smile basic and I'm trying to make à platformer https://smilebasicsource.com/page?pid=1346 I need help beacause write collisions take à lot of memory and are sooooooooooooooooo long to write Thanks for tout help
Ok I saw the program. I'll try to think of a way. I don't know at the moment.

K I found a way to do maps using DATA and easy graphic screen collision. I'll finish a demo and send you the key tomorrow.

Key: N3FEZXD3 Try to look at how I used GSPOIT to detect ground pixels around the player (the circle) It will help.

No, I juste want know how to use common def. I've make an unworking test here QKXN4J96

No, I juste want know how to use common def. I've make an unworking test here QKXN4J96
lol I didn't understand the question You have in a different slot your COMMON DEF or you could just put DEF in your normal slot. If you want to make a library for this game that other people can use, you should do COMMON DEF in the other slot. You use both of these in the same way, but on COMMON DEF you put common before DEF on the same line and have it in a different slot. Here is a simple tutorial to use these:
COMMON DEF DOSOMETHING
 SPSET 0,0
 SPANIM 0,"XY",-10,0,0,-10,0,8,-10,8,8,-10,8,0,0
END'When you call DOSOMETHING in your code, a sprite will appear and move around.
COMMON DEF ILIKEPIE V1'Now we can add arguments
 SPSET 0,0
 IF V1==0 THEN SPANIM 0,"XY",-10,0,0,-10,0,8,-10,8,8,-10,8,0,0 ELSE SPANIM 0,"R",-10,360,0
END'If you run ILIKEPIE 0 then the sprite will move around. If you put the same thing with any other number, it'll rotate. You could tack on more arguments, you just need to put a comma between them.
EDIT: I sad now it deleted half of my stuff when I pasted it in (it said "The form requires a session ID and one wasn't received" and I C/P'd and reloaded.)

I tried coming up with something simplified enough. You can use this function as many times as you want in your code before X=X+VX and Y=Y+VY. Remember to replace the variable names with your own!
'X and Y are your player coordinates, VX and VY are the player's velocities, R is the player's radius, and X1 to Y2 are your rectangle coordinates 
DEF RECT_COLLISION X,Y, VX,VY, R, X1,Y1,X2,Y2
 'If you're inside the rectangle 
 IF X+VX+R>=X1 && X+VX-R<X2 && Y+VY+R>=Y1 && Y+VY-R<Y2 THEN
  'If coming from the left  
  IF X+R<X1 THEN X=X1-R-1:VX=0
  'If coming from the right
  IF X-R>X2 THEN X=X2+R:VX=0
  'If coming from the top
  IF Y+R<Y1 THEN Y=Y1-R-1:INAIR=0:VY=0
  'If coming from the bottom
  IF Y-R>Y2 THEN Y=Y2+R:VY=0
 ENDIF
END
(EDIT) I looked at your failed attempt: the problem is that with your code, you don't actually check from which direction the player is coming. If the X velocity is positive, it doesn't necessarily mean that you're coming from the left; it just means you're moving to the right. My take on this is to check if the player's previous position was to the left of the rectangle. There are probably other ways to handle this.

My exercism.io ported code makes use of several source files. You can check out that if you want to see common def in use. I had planned to do a platformer tutorial series at one point but no one was interested. http://smilebasicsource.com/page?pid=886 Key: 5RDXV3CJ

My exercism.io ported code makes use of several source files. You can check out that if you want to see common def in use. I had planned to do a platformer tutorial series at one point but no one was interested. http://smilebasicsource.com/page?pid=886 Key: 5RDXV3CJ
platformer tutorials? YES please do it

I tried coming up with something simplified enough. You can use this function as many times as you want in your code before X=X+VX and Y=Y+VY. Remember to replace the variable names with your own!
'X and Y are your player coordinates, VX and VY are the player's velocities, R is the player's radius, and X1 to Y2 are your rectangle coordinates 
DEF RECT_COLLISION X,Y, VX,VY, R, X1,Y1,X2,Y2
 'If you're inside the rectangle 
 IF X+VX+R>=X1 && X+VX-R<X2 && Y+VY+R>=Y1 && Y+VY-R<Y2 THEN
  'If coming from the left  
  IF X+R<X1 THEN X=X1-R-1:VX=0
  'If coming from the right
  IF X-R>X2 THEN X=X2+R:VX=0
  'If coming from the top
  IF Y+R<Y1 THEN Y=Y1-R-1:INAIR=0:VY=0
  'If coming from the bottom
  IF Y-R>Y2 THEN Y=Y2+R:VY=0
 ENDIF
END
(EDIT) I looked at your failed attempt: the problem is that with your code, you don't actually check from which direction the player is coming. If the X velocity is positive, it doesn't necessarily mean that you're coming from the left; it just means you're moving to the right. My take on this is to check if the player's previous position was to the left of the rectangle. There are probably other ways to handle this.
ok but if xv= 0 then the player don't move

Sorry, the code I gave you doesn't really work... To apologize for being so lazy, instead of just writing you code on here, this time I took the time to test it in your game and make you a new version. I modified your program so it only relies on one function for collisions, like you wanted. Some other small modifications:
  • I made the skip to the title screen only happen after the initialization (when you skip the cutscene in your current version, it doesn't clear the screen or load the font!) I can't force you to, but I would really really recommend using ACLS instead of manually resetting things. It makes sure everything is reset to default.
  • I renamed your RADIUS variable "R" and replaced all of the "10"s in your code with R
Here's the key: QKF5ZXRD (Note to people reading in the future: I will unpublish this eventually, so don't bother)

Thanks you sooooooo much Sam, m'y code Can be optimized now thanks you. I will change some things but you are already in the credits