Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Prithak

Pages: [1] 2 3 4
1
QB64 Discussion / Re: Blocking stuff D:
« on: April 07, 2020, 11:41:23 am »
Well, that was odd but glad you got that sorted out lol

2
QB64 Discussion / Re: Blocking stuff D:
« on: April 05, 2020, 04:27:29 am »
Hi Prithak

your last post code is very incomplete!

So I add something to become it clearer than now....

but the glitch is logic and not about typing....

This your issue let me remember another in a graphic game engine in which the output of grafic doesn't recognize the position of objects of the scene  in respect with the main character... in that engine issue the engine has not option to distinguish the position of the character towards the object that are able to be pass back.

In your collision engine you haven't thought what it happens to the OldY and OldX variable at the second cycle of loop...
here my code can show you what it happens
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2. _SCREENMOVE 1, 1 ' better show alla the window
  3.  
  4. TYPE vec1
  5.     x AS INTEGER
  6.     y AS INTEGER
  7.     speed AS INTEGER
  8.  
  9. TYPE vec2
  10.     x1 AS INTEGER
  11.     y1 AS INTEGER
  12.     x2 AS INTEGER
  13.     y2 AS INTEGER
  14.     r AS INTEGER
  15.     g AS INTEGER
  16.     b AS INTEGER
  17.     btype AS STRING
  18.  
  19. DIM SHARED player AS vec1
  20. DIM SHARED obstacle(9) AS vec2
  21. DIM SHARED oldx, oldy AS INTEGER
  22.  
  23. player.speed = 5
  24.  
  25. player.x = 100 ' character need a point of start X and Y
  26. player.y = 200
  27.  
  28.  
  29.  
  30. map = "map1.txt"
  31.  
  32. openMap
  33. j = 1
  34.     CLS , _RGB32(0, 255, 61) ' it is better to give a color to background
  35.     makeplayer
  36.     playerMovement
  37.  
  38.     FOR j = 1 TO i 'the loop checks for obstacles
  39.  
  40.         LOCATE 9: PRINT j
  41.         ' here graphic output
  42.         LINE (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2), _RGB32(obstacle(j).r, obstacle(j).g, obstacle(j).b), BF
  43.         ' here it tests for collision between character and obstacles
  44.         block obstacle(j).x1, obstacle(j).y1, obstacle(j).x2, obstacle(j).y2
  45.  
  46.     NEXT j
  47.  
  48.     _DISPLAY
  49.     _LIMIT 20
  50. LOOP UNTIL _KEYHIT = 32 ' you can exit from game with spacebar
  51.  
  52. SUB openMap
  53.     OPEN map FOR INPUT AS #1
  54.     WHILE NOT EOF(1)
  55.         i = i + 1
  56.         INPUT #1, obstacle(i).btype, obstacle(i).x1, obstacle(i).y1, obstacle(i).x2, obstacle(i).y2, obstacle(i).r, obstacle(i).g, obstacle(i).b
  57.     WEND
  58.     CLOSE #1
  59.     PRINT i
  60.  
  61. SUB makeplayer
  62.     CIRCLE (player.x, player.y), 10, _RGB32(100, 200, 255)
  63.     PAINT (player.x, player.y), _RGB32(100, 200, 255), _RGB32(100, 200, 255)
  64.  
  65. SUB playerMovement
  66.     IF _KEYDOWN(18432) THEN player.y = player.y - player.speed
  67.     IF _KEYDOWN(20480) THEN player.y = player.y + player.speed
  68.     IF _KEYDOWN(19200) THEN player.x = player.x - player.speed
  69.     IF _KEYDOWN(19712) THEN player.x = player.x + player.speed
  70.  
  71. SUB block (x1, y1, x2, y2)
  72.  
  73.     IF (player.x + 10 >= x1 AND player.x - 10 <= x2) AND (player.y + 10 >= y1 AND player.y - 10 <= y2) THEN
  74.         ' if player X is in the X range of obstacle AND player Y is in the Y range of obstacle
  75.         ' I restore the old X and Y to player
  76.         player.x = oldx
  77.         player.y = oldy
  78.  
  79.         LOCATE 10
  80.         PRINT "X="; player.x; " Y="; player.y; " x1 "; x1; " x2 "; x2; " y1 "; y1; " y2 "; y2
  81.         PRINT "Oldx = "; oldx; " OldY= "; oldy
  82.  
  83.     ELSE
  84.         ' if player is out of obstacle
  85.         ' I store actual X and Y of player into OLD X and Y
  86.         oldx = player.x
  87.         oldy = player.y
  88.     END IF
  89.  
  90.  

as you can see when you go through the second obstacle using a FOR loop that tests before first obstacle and then the following second obstacle so it changes the value of OldX and OldY and then when it tests the second obstacle it restore the OldX and OldY calculated towards the first obstacle.

So you can imagine how to solve this issue... a STATIC flag into the collision engine? Or and array of OldY and OldY dor each obstacle to use...or whatelse?

THANK YOU! YOU ARE A LIFE SAVER. Like seriously, why didn't I think about that. Now, I am using an array for Oldx and Oldy. So, the blocking mechanism is working PERFECTLY. I had to make some changes tho. Here is the code:
Code: [Select]
screen _newimage(1280,720,32)

type vec1
    x as integer
    y as integer
    speed as integer
end type

type vec2
    x1 as integer
    y1 as integer
    x2 as integer
    y2 as integer
    r as integer
    g as integer
    b as integer
    btype as string
    oldx as integer
    oldy as integer
    wl as string
end type


dim shared player as vec1
dim shared map as string
dim shared obstacle(9) as vec2
player.speed = 5

dim shared i as integer

map = "map1.txt"

player.x = _width / 2
player.y = _height / 2

openMap
j=1
do
    cls

    makeplayer
    playerMovement

    for j = 1 to i
        if obstacle(j).btype = "obs" then
            line (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2),_rgb32(obstacle(j).r,obstacle(j).g,obstacle(j).b),BF
            if player.x + 10 >= obstacle(j).x1 and player.x - 10 <= obstacle(j).x2 and player.y + 10 >= obstacle(j).y1 and player.y - 10 <= obstacle(j).y2 then
                player.x = obstacle(j).oldx
                player.y = obstacle(j).oldy
            else
                obstacle(j).oldx = player.x
                obstacle(j).oldy = player.y
            end if
        elseif obstacle(j).btype = "warp" then
            line (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2),_rgb32(obstacle(j).r,obstacle(j).g,obstacle(j).b),BF
            if collision%(obstacle(j).x1, obstacle(j).y1, obstacle(j).x2, obstacle(j).y2) then
                map = obstacle(i).wl
                openMap
            end if
        end if
    next j

    _display
    _limit 120
loop

sub openMap
    i=0
    open map for input as #1
    while not eof(1)
        i = i + 1
        input #1, obstacle(i).btype, obstacle(i).x1, obstacle(i).y1, obstacle(i).x2, obstacle(i). y2, obstacle(i).r, obstacle(i).g, obstacle(i).b
        if obstacle(i).btype = "warp" then input #1, obstacle(i).wl
    wend
    close #1
end sub

sub makeplayer
    circle (player.x, player.y), 10, _rgb32(100,200,255)
    paint (player.x, player.y), _rgb32(100,200,255), _rgb32(100,200,255)
end sub

sub playerMovement
    if _keydown(18432) then player.y = player.y - player.speed
    if _keydown(20480) then player.y = player.y + player.speed
    if _keydown(19200) then player.x = player.x - player.speed
    if _keydown(19712) then player.x = player.x + player.speed
end sub

function collision%(x1,y1,x2,y2)
    if player.x >= x1 and player.x <= x2 and player.y >= y1 and player.y <= y2 then
        collision% = 1
    end if
end function

Map1.txt
Code: [Select]
obs,600,50,1280,100,100,200,255
obs,0,0,700,50,100,200,255
warp,500,500,550,550,255,200,100,map2.txt

Map2.txt
Code: [Select]
obs, 600,50,1280,100,242,242,242
obs, 500,0,700,50,242,242,242
warp, 100,100,150,150,255,200,100,map1.txt

-Prithak

3
QB64 Discussion / Re: Blocking stuff D:
« on: April 04, 2020, 08:44:29 am »
I FINALLY did things with Array. But, the same problem has arrived to my doorstep D:
Code: [Select]
screen _newimage(1280,720,32)

type vec1
    x as integer
    y as integer
    speed as integer
end type

type vec2
    x1 as integer
    y1 as integer
    x2 as integer
    y2 as integer
    r as integer
    g as integer
    b as integer
    btype as string
end type

dim shared player as vec1
dim shared speed as integer
dim shared map as string
dim shared obstacle(9) as vec2
dim shared oldx, oldy as integer

player.speed = 5

dim shared i as integer

map = "map1.txt"

openMap
j=1
do
    cls

    makeplayer
    playerMovement

    for j = 1 to i
        line (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2),_rgb32(obstacle(j).r,obstacle(j).g,obstacle(j).b),BF
        block obstacle(j).x1, obstacle(j).y1, obstacle(j).x2, obstacle(j).y2
    next j

    _display
    _limit 60
loop

sub openMap
    open map for input as #1
    while not eof(1)
        i = i + 1
        input #1, obstacle(i).btype, obstacle(i).x1, obstacle(i).y1, obstacle(i).x2, obstacle(i). y2, obstacle(i).r, obstacle(i).g, obstacle(i).b
    wend
    close #1
end sub

sub makeplayer
    circle (player.x, player.y), 10, _rgb32(100,200,255)
    paint (player.x, player.y), _rgb32(100,200,255), _rgb32(100,200,255)
end sub

sub playerMovement
    if _keydown(18432) then player.y = player.y - player.speed
    if _keydown(20480) then player.y = player.y + player.speed
    if _keydown(19200) then player.x = player.x - player.speed
    if _keydown(19712) then player.x = player.x + player.speed
end sub

sub block(x1,y1,x2,y2)

    if player.x + 10 >= x1 and player.x - 10 <= x2 and player.y + 10 >= y1 and player.y - 10 <= y2 then
        player.x = oldx
        player.y = oldy
    else
        oldx = player.x
        oldy = player.y
    end if

end sub


4
QB64 Discussion / Re: Blocking stuff D:
« on: April 04, 2020, 07:46:51 am »
I tried to Re-Do some stuff and Look what I've Found:
Code: [Select]
screen _newimage(1280,720,32)

type vec1
    x as integer
    y as integer
end type

type vec2
    x1 as integer
    y1 as integer
    x2 as integer
    y2 as integer
    r as integer
    g as integer
    b as integer
    btype as string
end type

dim shared player as vec1
dim shared speed as integer
dim shared map as string
dim shared obstacle(9) as vec2

dim shared i as integer

map = "map1.txt"

openMap

do
    cls
    j = j + 1



    if j > i then j = 0
    _display
loop

sub openMap
    open map for input as #1
    while not eof(1)
        input #1, obstacle(i).btype, obstacle(i).x1, obstacle(i).x2, obstacle(i).y1, obstacle(i). y2, obstacle(i).r, obstacle(i).g, obstacle(i).b
        i = i + 1
    wend
    close #1
end sub
"Input pas end of file!"
WHYYYY??

-Prithak

5
QB64 Discussion / Re: Blocking stuff D:
« on: April 04, 2020, 07:37:23 am »
Are you sure? I easily get 25-35 fps with my current programs and they are far more CPU/Memory heavy than what you've posted. I cant see that you'd notice any difference in speed if you used arrays aposed to individual variables to store each value.

Good luck,

Unseen
Ok. Would you mind sending me an example. Cuz, when I tried to do it. It just didn't work.

Sincerely,
Prithak

6
QB64 Discussion / Re: Blocking stuff D:
« on: April 04, 2020, 06:15:59 am »
Just to get the code to compile I had to make this change to explicitly specify that the map1 file is in the same directory as the exe:

Code: QB64: [Select]
  1. map = ".\map1.txt"
Uhh... No you don't need to do that...

7
QB64 Discussion / Re: Blocking stuff D:
« on: April 04, 2020, 06:09:25 am »
Hi,

Its cause your only storing one set of data for the obstacles. You need to use an array to store more than one.

Id suggest you define a TYPE for the obstacles and then use an array of that type to handle them

i.e

type Obstacle
X1 AS integer
X2 as integer
Y1 as integer
Y2 as integer
Color as _unsigned long
End type

Dim Obstacle(9) as obstacle '// Creates an array of ten Obstacle type variables.

Have fun and happy coding!

Unseen
Ya. I figured. But, Using Arrays would SIGNIFICANTLY slow down the computer. So, I figured this plan out. If this works, I won't have to worry about performance. Soo... If there is a way out, PLEASE TEACH MEH!!!

-Prithak

8
QB64 Discussion / Blocking stuff D:
« on: April 04, 2020, 04:30:12 am »
Hey, Long time no see. Anyways,

I was developing a game where I run on a problem IMMEDIATELY xD. And I can't quite figure out what that problem is. Would you look at the code and find it out?
Code: [Select]
screen _newimage(1280,720,32)

_fullscreen

'Declaring Variables
type vec
    x as integer
    y as integer
    speed as integer
end type

dim shared player as vec
dim shared map as string

dim shared oldx, oldy as integer

player.speed = 3
map = "map1.txt"

player.x = _width / 2
player.y = _height / 2

'Main Loop
do
    cls

    makeplayer
    playerMovement
    'Test
    'makeObstacle 100,100,200,200,255,200,100

    makeMap

    'For Experiments: The co-ordinates
    _printstring (0,0), str$(player.x) + str$(player.y)

    _display
loop until _keyhit = 27
system
'Subs and Functions

sub makeplayer
    circle (player.x, player.y), 10, _rgb32(100,200,255)
    paint (player.x, player.y), _rgb32(100,200,255), _rgb32(100,200,255)
end sub

sub playerMovement
    if _keydown(18432) then player.y = player.y - player.speed
    if _keydown(20480) then player.y = player.y + player.speed
    if _keydown(19200) then player.x = player.x - player.speed
    if _keydown(19712) then player.x = player.x + player.speed
end sub

sub makeObstacle(x1,y1,x2,y2,r,g,b)

    line (x1,y1)-(x2,y2),_rgb32(r,g,b), BF

    if player.x + 10 >= x1 and player.x - 10 <= x2 and player.y + 10 >= y1 and player.y - 10 <= y2 then
        player.x = oldx
        player.y = oldy
    else
        oldx = player.x
        oldy = player.y
    end if

end sub

sub makeMap
    open map for input as #1
    while not eof(1)
        input #1, cm$,x1,y1,x2,y2,r,g,b
        if cm$ = "obs" then
            makeObstacle x1,y1,x2,y2,r,g,b
        end if
    wend
    close #1
end sub

Here's the file called "map1.txt"
Code: [Select]
obs, 0,0,700,50,242,242,242
obs, 800,50,1280,100,242,242,242

Here, the 1st obstacle is blocking the character perfectly, but the second one isn't. Why???

-Prithak

9
QB64 Discussion / Re: Not working!
« on: July 22, 2019, 11:17:31 pm »
Thank you everyone for helping me out! Thanks to you now I can really continue making this game xD! Well... I guess I'm gonna go coding whilst solving a Rubik's cube lol!

-Prithak

10
QB64 Discussion / Not working!
« on: July 22, 2019, 03:50:59 am »
Alright! Back to programming with my exams now gone! Here I coded this stuff:

Code: [Select]
screen _newimage(800,600,32)

dim shared x as integer
dim shared y as integer
dim shared oldx as integer
dim shared oldy as integer

x = 100
y = 200

color , _rgb32(50,200,0)

cls

do
cls

open "blocks.txt" for input as #1

while not eof(1)

input #1, x1,y1,x2,y2,r,g,b

makeobs x1,y1,x2,y2,r,g,b
wend

close #1

    IF _KEYDOWN(CVI(CHR$(0) + "P")) THEN y = y - 5   '_KEYDOWN(20480)
    IF _KEYDOWN(CVI(CHR$(0) + "H")) THEN y = y + 5   '_KEYDOWN(18432)
    IF _KEYDOWN(CVI(CHR$(0) + "K")) THEN x = x + 5   '_KEYDOWN(19200)
    IF _KEYDOWN(CVI(CHR$(0) + "M")) THEN x = x - 5   '_KEYDOWN(19712)

'The sprites will be 20x20 pixels, I believe...
line (_width/2,_height/2)-step(20,20),_rgb32(255,200,100),BF

_printstring(0,0),str$(x) + " " + str$(y)

_limit 100
_Display
loop
 
FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
    IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
        collision% = 0
    ELSE
        collision% = 1
    END IF
END FUNCTION

sub makeobs (x1,y1,w,h,r,g,b)

line(x + x1, y + y1)-step(w,h),_rgb32(r,g,b),BF
Line(x + x1, y + y1)-step(w,h),_Rgb32(255,255,255),B
'200, 200 - 220, 220

if collision%(_width/2,_height/2,20,20,x + x1, y + y1,w,h) then
y = oldy
x = oldx
else
oldy = y
oldx = x
end if


end sub

And here's "blocks.txt"
Code: [Select]
200,100,100,100,100,200,255
200,300,100,100,100,200,255
100,200,100,100,100,200,255
300,200,100,100,100,200,255

Ok. For some reason, the character's only being blocked by the first obstacle? WHY??

-Prithak

11
QB64 Discussion / Why is it not blocking?
« on: April 14, 2019, 03:20:29 am »
Man, I've tried everything! It is not working!
Code: QB64: [Select]
  1. 'First Prototype of my game project!
  2. 'Never knew I would get this far!
  3. 'A Special thanks to Petr, Pete, bplus, _vince, TempodiBasic, SMcNeil Let me know if I forgot your name here xD
  4. '-Prithak
  5.  
  6. _TITLE "Japang!"
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. COLOR _RGB32(0, 0, 0), _RGB32(211, 211, 211)
  9. DIM SHARED y_change AS SINGLE
  10.  
  11. main:
  12.     _PRINTSTRING (600, 100), "Japang!"
  13.     _PRINTSTRING (600, 300), "Play"
  14.     _PRINTSTRING (600, 350), "Help"
  15.  
  16.     _PRINTSTRING (600, 400), "Exit"
  17.     LINE (570, 340)-(600 + LEN("help") * 16, 375), _RGB32(255, 255, 255), B
  18.     LINE (570, 290)-(600 + LEN("play") * 16, 325), _RGB32(255, 255, 255), B
  19.     LINE (570, 390)-(600 + LEN("exit") * 16, 425), _RGB32(255, 255, 255), B
  20.     IF mouseclick(570, 290, 600 + LEN("play") * 16, 325) THEN
  21.         game
  22.     END IF
  23.     IF mouseclick(570, 340, 600 + LEN("help") * 16, 375) THEN
  24.         GOTO help
  25.     END IF
  26.     IF mouseclick(570, 290, 600 + LEN("exit") * 16, 425) THEN
  27.         SYSTEM
  28.     END IF
  29.     _DISPLAY
  30.  
  31. help:
  32. PRINT "Use the arrow keys to move around!"
  33. PRINT "Use the upper arrow key to jump!"
  34. PRINT "Get to the green block for victory!"
  35. PRINT "Touching any red blocks will kill you!"
  36. GOTO main
  37.  
  38. SUB game
  39. IF level = 2 THEN GOTO lvl2
  40. IF level = 3 THEN GOTO lvl3
  41. IF level = 4 THEN GOTO lvl4
  42. IF level = 5 THEN GOTO lvl5
  43. camx = 0
  44. camy = 0
  45. 'Just for testing!
  46. x = 200
  47. y = 200
  48. gravity = 9.8
  49.     CLS
  50.     makechar
  51.     IF _KEYDOWN(19200) THEN
  52.         x = x - 10
  53.  
  54.     END IF
  55.     IF _KEYDOWN(19712) THEN
  56.         x = x + 10
  57.  
  58.     END IF
  59.     IF _KEYDOWN(18432) THEN
  60.         jump_i = 1
  61.     END IF
  62.  
  63.     IF jump_i = 1 AND y > 100 THEN
  64.         y = y - 20
  65.         cycle = cycle + 1
  66.         IF cycle > 20 THEN cycle = 0: jump_i = -1
  67.     END IF
  68.  
  69.     y = y + gravity
  70.     'Blocks
  71.     makeobs 100, 400
  72.  
  73.     LINE (500, 400)-STEP(200, 50), _RGB32(127, 255, 127), BF
  74.     IF collision%(x, y, 20, 20, 500, 400, 200, 50) THEN
  75.         CLS
  76.         _PRINTSTRING (300, 300), "LEVEL 1 COMPLETE!"
  77.         _DISPLAY
  78.         _DELAY 2
  79.         GOTO lvl2
  80.         END
  81.     END IF
  82.     IF y > 600 THEN game
  83.  
  84.     _DISPLAY
  85.     _LIMIT 60
  86.  
  87. lvl2:
  88. level = 2
  89. x = 200
  90. y = 400
  91.     CLS
  92.     makechar
  93.     IF _KEYDOWN(19200) THEN
  94.         x = x - 10
  95.  
  96.     END IF
  97.     IF _KEYDOWN(19712) THEN
  98.         x = x + 10
  99.  
  100.     END IF
  101.     IF _KEYDOWN(18432) THEN
  102.         jump_i = 1
  103.     END IF
  104.  
  105.     IF jump_i = 1 AND y > 100 THEN
  106.         y = y - 20
  107.         cycle = cycle + 1
  108.         IF cycle > 20 THEN cycle = 0: jump_i = -1
  109.     END IF
  110.  
  111.     y = y + gravity
  112.  
  113.     IF y > 600 THEN GOTO lvl2
  114.     angle = angle + 5
  115.  
  116.     rotate _WIDTH / 2, _HEIGHT / 2, angle
  117.  
  118.  
  119.     makeobs 100, 500
  120.  
  121.     makeobs 500, 500
  122.  
  123.     IF coins < 1 THEN
  124.         CIRCLE (600, 480), 5, _RGB32(255, 255, 17)
  125.         PAINT (600, 480), _RGB32(255, 255, 17), _RGB32(255, 255, 17)
  126.         IF collision%(x, y, 20, 20, 600, 480, 5, 5) THEN
  127.             coins = coins + 1
  128.         END IF
  129.     END IF
  130.  
  131.     LINE (100, 300)-STEP(200, 50), _RGB32(127, 255, 127), BF
  132.     IF collision%(x, y, 20, 20, 100, 300, 200, 50) THEN
  133.         CLS
  134.         _PRINTSTRING (300, 300), "LEVEL 2 COMPLETE!"
  135.         _PRINTSTRING (300, 325), "Coins collected: " + STR$(coins)
  136.         _DISPLAY
  137.         _DELAY 2
  138.         GOTO lvl3
  139.         END
  140.     END IF
  141.  
  142.     _DISPLAY
  143.     _LIMIT 60
  144.  
  145. lvl3:
  146. level = 3
  147. x = 100
  148. y = 300
  149.     CLS
  150.     makechar
  151.  
  152.     IF _KEYDOWN(19200) THEN
  153.         x = x - 10
  154.  
  155.     END IF
  156.     IF _KEYDOWN(19712) THEN
  157.         x = x + 10
  158.  
  159.     END IF
  160.     IF _KEYDOWN(18432) THEN
  161.         jump_i = 1
  162.     END IF
  163.  
  164.     IF jump_i = 1 AND y > 100 THEN
  165.         y = y - 20
  166.         cycle = cycle + 1
  167.         IF cycle > 20 THEN cycle = 0: jump_i = -1
  168.     END IF
  169.  
  170.     y = y + gravity
  171.  
  172.     IF coins < 2 THEN
  173.         CIRCLE (650, 470), 5, _RGB32(255, 255, 17)
  174.         PAINT (650, 470), _RGB32(255, 255, 17), _RGB32(255, 255, 17)
  175.         IF collision%(x, y, 20, 20, 650, 470, 5, 5) THEN
  176.             coins = coins + 1
  177.         END IF
  178.     END IF
  179.  
  180.  
  181.     makesobs 50, 500, 100, 50
  182.  
  183.     angle = angle + 5
  184.  
  185.     rotate _WIDTH / 2, 400, angle
  186.     rotate _WIDTH / 2, 200, angle
  187.  
  188.     makesobs 600, 500, 100, 50
  189.  
  190.     LINE (100, 200)-STEP(200, 50), _RGB32(127, 255, 127), BF
  191.     IF collision%(x, y, 20, 20, 100, 50, 200, 50) THEN
  192.         CLS
  193.         _PRINTSTRING (300, 300), "LEVEL 3 COMPLETE!"
  194.         _PRINTSTRING (300, 325), "Total coins: " + STR$(coins)
  195.         _DISPLAY
  196.         _DELAY 2
  197.         GOTO lvl4
  198.         END
  199.     END IF
  200.  
  201.     IF y > 600 THEN GOTO lvl3
  202.  
  203.     _DISPLAY
  204.     _LIMIT 60
  205. lvl4:
  206. level = 4
  207. x = 100
  208. y = 300
  209. camx = 0
  210. camy = 0
  211.     CLS
  212.     makechar
  213.  
  214.     IF _KEYDOWN(19200) THEN
  215.         x = x - 10
  216.         camx = camx + 5
  217.     END IF
  218.     IF _KEYDOWN(19712) THEN
  219.         x = x + 10
  220.         camx = camx - 5
  221.     END IF
  222.     IF _KEYDOWN(18432) THEN
  223.         jump_i = 1
  224.     END IF
  225.  
  226.  
  227.     IF jump_i = 1 AND y > 100 THEN
  228.         y = y - 20
  229.         camy = camy - 5
  230.         cycle = cycle + 1
  231.         IF cycle > 20 THEN cycle = 0: jump_i = -1
  232.     END IF
  233.  
  234.     y = y + gravity
  235.     camy = camy + 2
  236.     _PRINTSTRING (0, 0), "Get used to the camera folks!"
  237.     IF camy > 50 THEN camy = 50
  238.  
  239.  
  240.     makeobs camx + 50, camy + 500
  241.     makeredobs camx + 300, camy + 500
  242.     makeobs camx + 550, camy + 500
  243.     makeredobs camx + 800, camy + 500
  244.  
  245.     LINE (camx + 1050, camy + 500)-STEP(200, 50), _RGB32(127, 255, 127), BF
  246.     IF collision%(x, y, 20, 20, camx + 1050, camy + 500, 200, 50) THEN
  247.         CLS
  248.         _PRINTSTRING (300, 300), "LEVEL 4 COMPLETE!"
  249.         _DISPLAY
  250.         _DELAY 2
  251.         GOTO lvl5
  252.         END
  253.     END IF
  254.  
  255.     IF y > 600 THEN GOTO lvl4
  256.  
  257.     _LIMIT 60
  258.     _DISPLAY
  259.  
  260. lvl5:
  261. level = 5
  262. x = 200
  263. y = 100
  264. camx = 0
  265. camy = 0
  266.     CLS
  267.     makechar
  268.  
  269.     IF _KEYDOWN(19200) THEN
  270.         x = x - 10
  271.         camx = camx + 5
  272.     END IF
  273.     IF _KEYDOWN(19712) THEN
  274.         x = x + 10
  275.         camx = camx - 5
  276.     END IF
  277.     IF _KEYDOWN(18432) THEN
  278.         jump_i = 1
  279.     END IF
  280.  
  281.  
  282.     IF jump_i = 1 AND y > 100 THEN
  283.         y = y - 20
  284.         camy = camy - 5
  285.         cycle = cycle + 1
  286.         IF cycle > 20 THEN cycle = 0: jump_i = -1
  287.     END IF
  288.  
  289.     y = y + gravity
  290.     camy = camy + 2
  291.  
  292.     IF camy > 50 THEN camy = 50
  293.  
  294.     makeobs camx + 50, camy + 500
  295.     angle = angle + 5
  296.     rotate camx + 350, camy + 450, angle
  297.  
  298.     makeobs camx + 500, camy + 400
  299.     makeobs camx + 800, camy + 400
  300.  
  301.     IF y > 600 THEN GOTO lvl5
  302.  
  303.     _DISPLAY
  304.     _LIMIT 60
  305.  
  306.  
  307.  
  308. SUB makechar
  309. 'CIRCLE (x, y), 20, _RGB32(100, 150, 255)
  310. 'PAINT (x, y), _RGB32(100, 150, 255), _RGB32(100, 150, 255)
  311. LINE (x, y)-STEP(20, 20), _RGB32(100, 150, 255), BF
  312.  
  313. FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
  314. IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
  315.     collision% = 0
  316.     collision% = 1
  317.  
  318. SUB makeobs (bx, by)
  319. LINE (bx, by)-STEP(200, 50), _RGB32(255, 150, 100), BF
  320. IF collision%(x, y, 20, 20, bx, by, 200, 50) THEN
  321.     y = oldy
  322.     gravity = 0
  323.     y_change = 0
  324.     oldy = y
  325.     gravity = 9.8
  326.  
  327. SUB makesobs (bx, by, w, h)
  328. LINE (bx, by)-STEP(w, h), _RGB32(255, 150, 100), BF
  329. IF collision%(x, y, 20, 20, bx, by, w, h) THEN
  330.     y = oldy
  331.     gravity = 0
  332.     y_change = 0
  333.     oldy = y
  334.     gravity = 9.8
  335.  
  336. SUB makeredobs (bx, by)
  337. LINE (bx, by)-STEP(200, 50), _RGB32(255, 0, 0), BF
  338. IF collision(x, y, 20, 20, bx, by, 200, 50) THEN
  339.     CLS
  340.     _PRINTSTRING (300, 300), "GAME OVER!"
  341.     _DISPLAY
  342.     _DELAY 2
  343.     game
  344. SUB rotate (px, py, deg)
  345. px2 = px + COS(_D2R(deg)) * 100
  346. py2 = py + SIN(_D2R(deg)) * 100
  347.  
  348. CIRCLE (px2, py2), 10, _RGB32(255, 0, 0)
  349. PAINT (px2, py2), _RGB32(255, 0, 0), _RGB32(255, 0, 0)
  350.  
  351. LINE (px, py)-(px2, py2), _RGB32(0, 0, 0)
  352.  
  353. IF collision(x, y, 20, 20, px2, py2, 10, 10) THEN
  354.     CLS
  355.     _PRINTSTRING (300, 300), "GAME OVER!"
  356.     _DISPLAY
  357.     _DELAY 2
  358.     game
  359.  
  360. FUNCTION mouseclick (x1, y1, x2, y2)
  361. mx = _MOUSEX
  362. my = _MOUSEY
  363. mb = _MOUSEBUTTON(1)
  364.  
  365. IF mx >= x1 AND mx <= x2 AND my >= y1 AND my <= y2 AND mb THEN
  366.     mouseclick = 1
In the 5th level, why is the second obstacle not blocking the character?

12
Programs / Re: Japang!
« on: April 13, 2019, 09:19:32 pm »
Fine! Well suited. Very fast!

Please add <Help> button with instructions for keys active and a little story or the goal.

Negative Feedback:
Aargh! There is a big big big mistake at line code 25...
Code: QB64: [Select]
  1. IF mouseclick(570, 290, 600 + LEN("play") * 16, 425) THEN
you use LEN("play")! Aargh! you must use LEN("quit")!!!!
:-)
:-P what do you think of this joke?

Lol! The length of "play" and the length of "quit" is the same is it not? Yeah, The help button will be added along with setting on the next update! I won't be able to code today but tomorrow? That might be a nice time!

13
Programs / Japang!
« on: April 13, 2019, 08:23:40 am »
Sorry for the weird name! I'll change it soon enough!

This is a game I made in 2 days:
Code: QB64: [Select]
  1. 'First Prototype of my game project!
  2. 'Never knew I would get this far!
  3. 'A Special thanks to Petr, Pete, bplus, _vince, TempodiBasic, SMcNeil Let me know if I forgot your name here xD
  4. '-Prithak
  5.  
  6. _TITLE "Japang!"
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. COLOR _RGB32(0, 0, 0), _RGB32(211, 211, 211)
  9. DIM SHARED y_change AS SINGLE
  10.     _PRINTSTRING (600, 100), "Japang!"
  11.     _PRINTSTRING (600, 300), "Play"
  12.     _PRINTSTRING (600, 400), "Exit"
  13.     LINE (570, 290)-(600 + LEN("play") * 16, 325), _RGB32(255, 255, 255), B
  14.     LINE (570, 390)-(600 + LEN("exit") * 16, 425), _RGB32(255, 255, 255), B
  15.     IF mouseclick(570, 290, 600 + LEN("play") * 16, 325) THEN
  16.         game
  17.     END IF
  18.     IF mouseclick(570, 290, 600 + LEN("play") * 16, 425) THEN
  19.         SYSTEM
  20.     END IF
  21.  
  22.  
  23. SUB game
  24.     x = 200
  25.     y = 200
  26.     gravity = 9.8
  27.     CLS
  28.     DO
  29.         CLS
  30.         makechar
  31.         IF _KEYDOWN(19200) THEN
  32.             x = x - 10
  33.  
  34.         END IF
  35.         IF _KEYDOWN(19712) THEN
  36.             x = x + 10
  37.  
  38.         END IF
  39.         IF _KEYDOWN(18432) THEN
  40.             jump_i = 1
  41.         END IF
  42.  
  43.         IF jump_i = 1 AND y > 100 THEN
  44.             y = y - 20
  45.             cycle = cycle + 1
  46.             IF cycle > 20 THEN cycle = 0: jump_i = -1
  47.         END IF
  48.  
  49.         y = y + gravity
  50.         'Blocks
  51.         makeobs 100, 400
  52.  
  53.         LINE (500, 400)-STEP(200, 50), _RGB32(127, 255, 127), BF
  54.         IF collision%(x, y, 20, 20, 500, 400, 200, 50) THEN
  55.             CLS
  56.             _PRINTSTRING (300, 300), "LEVEL 1 COMPLETE!"
  57.             _DISPLAY
  58.             _DELAY 2
  59.             GOTO lvl2
  60.             END
  61.         END IF
  62.         IF y > 600 THEN game
  63.  
  64.         _DISPLAY
  65.         _LIMIT 60
  66.     LOOP
  67.  
  68.     lvl2:
  69.     x = 200
  70.     y = 400
  71.     DO
  72.         CLS
  73.         makechar
  74.         IF _KEYDOWN(19200) THEN
  75.             x = x - 10
  76.  
  77.         END IF
  78.         IF _KEYDOWN(19712) THEN
  79.             x = x + 10
  80.  
  81.         END IF
  82.         IF _KEYDOWN(18432) THEN
  83.             jump_i = 1
  84.         END IF
  85.  
  86.         IF jump_i = 1 AND y > 100 THEN
  87.             y = y - 20
  88.             cycle = cycle + 1
  89.             IF cycle > 20 THEN cycle = 0: jump_i = -1
  90.         END IF
  91.  
  92.         y = y + gravity
  93.  
  94.         IF y > 600 THEN GOTO lvl2
  95.         angle = angle + 5
  96.  
  97.         rotate _WIDTH / 2, _HEIGHT / 2, angle
  98.  
  99.  
  100.         makeobs 100, 500
  101.  
  102.         makeobs 500, 500
  103.  
  104.         IF coins < 1 THEN
  105.             CIRCLE (600, 480), 5, _RGB32(255, 255, 17)
  106.             PAINT (600, 480), _RGB32(255, 255, 17), _RGB32(255, 255, 17)
  107.             IF collision%(x, y, 20, 20, 600, 480, 5, 5) THEN
  108.                 coins = coins + 1
  109.             END IF
  110.         END IF
  111.  
  112.         LINE (100, 300)-STEP(200, 50), _RGB32(127, 255, 127), BF
  113.         IF collision%(x, y, 20, 20, 100, 300, 200, 50) THEN
  114.             CLS
  115.             _PRINTSTRING (300, 300), "LEVEL 2 COMPLETE!"
  116.             _PRINTSTRING (300, 325), "Coins collected: " + STR$(coins)
  117.             _DISPLAY
  118.             _DELAY 2
  119.             GOTO lvl3
  120.             END
  121.         END IF
  122.  
  123.         _DISPLAY
  124.         _LIMIT 60
  125.     LOOP
  126.  
  127.     lvl3:
  128.     x = 100
  129.     y = 300
  130.     DO
  131.         CLS
  132.         makechar
  133.  
  134.         IF _KEYDOWN(19200) THEN
  135.             x = x - 10
  136.  
  137.         END IF
  138.         IF _KEYDOWN(19712) THEN
  139.             x = x + 10
  140.  
  141.         END IF
  142.         IF _KEYDOWN(18432) THEN
  143.             jump_i = 1
  144.         END IF
  145.  
  146.         IF jump_i = 1 AND y > 100 THEN
  147.             y = y - 20
  148.             cycle = cycle + 1
  149.             IF cycle > 20 THEN cycle = 0: jump_i = -1
  150.         END IF
  151.  
  152.         y = y + gravity
  153.  
  154.         IF coins < 2 THEN
  155.             CIRCLE (650, 470), 5, _RGB32(255, 255, 17)
  156.             PAINT (650, 470), _RGB32(255, 255, 17), _RGB32(255, 255, 17)
  157.             IF collision%(x, y, 20, 20, 650, 470, 5, 5) THEN
  158.                 coins = coins + 1
  159.             END IF
  160.         END IF
  161.  
  162.  
  163.         makesobs 50, 500, 100, 50
  164.  
  165.         angle = angle + 5
  166.  
  167.         rotate _WIDTH / 2, 400, angle
  168.         rotate _WIDTH / 2, 200, angle
  169.  
  170.         makesobs 600, 500, 100, 50
  171.  
  172.         LINE (100, 200)-STEP(200, 50), _RGB32(127, 255, 127), BF
  173.         IF collision%(x, y, 20, 20, 100, 50, 200, 50) THEN
  174.             CLS
  175.             _PRINTSTRING (300, 300), "LEVEL 3 COMPLETE!"
  176.             _PRINTSTRING (300, 325), "Total coins: " + STR$(coins)
  177.             _DISPLAY
  178.             _DELAY 2
  179.             END
  180.         END IF
  181.  
  182.         IF y > 600 THEN GOTO lvl3
  183.  
  184.         _DISPLAY
  185.         _LIMIT 60
  186.     LOOP
  187.  
  188. SUB makechar
  189.     'CIRCLE (x, y), 20, _RGB32(100, 150, 255)
  190.     'PAINT (x, y), _RGB32(100, 150, 255), _RGB32(100, 150, 255)
  191.     LINE (x, y)-STEP(20, 20), _RGB32(100, 150, 255), BF
  192.  
  193. FUNCTION collision% (b1x, b1y, b1w, b1h, b2x, b2y, b2w, b2h)
  194.     IF (b1y + b1h < b2y) OR (b1y > b2y + b2h) OR (b1x > b2x + b2w) OR (b1x + b1w < b2x) THEN
  195.         collision% = 0
  196.     ELSE
  197.         collision% = 1
  198.     END IF
  199.  
  200. SUB makeobs (bx, by)
  201.     LINE (bx, by)-STEP(200, 50), _RGB32(255, 150, 100), BF
  202.     IF collision%(x, y, 20, 20, bx, by, 200, 50) THEN
  203.         y = oldy
  204.         gravity = 0
  205.         y_change = 0
  206.     ELSE
  207.         oldy = y
  208.         gravity = 9.8
  209.     END IF
  210.  
  211. SUB makesobs (bx, by, w, h)
  212.     LINE (bx, by)-STEP(w, h), _RGB32(255, 150, 100), BF
  213.     IF collision%(x, y, 20, 20, bx, by, w, h) THEN
  214.         y = oldy
  215.         gravity = 0
  216.         y_change = 0
  217.     ELSE
  218.         oldy = y
  219.         gravity = 9.8
  220.     END IF
  221.  
  222. SUB rotate (px, py, deg)
  223.     px2 = px + COS(_D2R(deg)) * 100
  224.     py2 = py + SIN(_D2R(deg)) * 100
  225.  
  226.     CIRCLE (px2, py2), 10, _RGB32(100, 150, 255)
  227.     PAINT (px2, py2), _RGB32(100, 150, 255), _RGB32(100, 150, 255)
  228.  
  229.     LINE (px, py)-(px2, py2), _RGB32(0, 0, 0)
  230.  
  231.     IF collision(x, y, 20, 20, px2, py2, 10, 10) THEN
  232.         CLS
  233.         _PRINTSTRING (300, 300), "GAME OVER!"
  234.         _DISPLAY
  235.         _DELAY 2
  236.         game
  237.     END IF
  238.  
  239. FUNCTION mouseclick (x1, y1, x2, y2)
  240.     mx = _MOUSEX
  241.     my = _MOUSEY
  242.     mb = _MOUSEBUTTON(1)
  243.  
  244.     IF mx >= x1 AND mx <= x2 AND my >= y1 AND my <= y2 AND mb THEN
  245.         mouseclick = 1
  246.     END IF
  247.  

I will be making more of this! AT LEAST 10 LEVELS! Until then, play this!

-Prithak

14
QB64 Discussion / Re: Why is this happening?
« on: April 13, 2019, 06:11:58 am »
It’s because the _KEYDOWN check is in an ELSEIF statement.  Make all those become independent IF checks instead.

Thanks man, wouldh've never figured out that on my own!

15
QB64 Discussion / Re: Why is this happening?
« on: April 13, 2019, 12:42:13 am »
Alright, another question!

When I press the upper arrow key and the left arrow key at the same time, only the upper arrow key works but not the left arrow key. What is causing it and How do I solve it? HELP!

-Prithak

Pages: [1] 2 3 4