QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Patrick_coots on June 02, 2020, 03:30:41 pm

Title: Help with my program
Post by: Patrick_coots on June 02, 2020, 03:30:41 pm
 https://qb64.org/basbin/A3CA/bas (code)

when 5-10 seconds pass i'm trying to make more fire appear moving in different directions,
Title: Re: Help with my program
Post by: TerryRitchie on June 02, 2020, 03:35:44 pm
need fire.png
Title: Re: Help with my program
Post by: Patrick_coots on June 02, 2020, 04:47:45 pm
https://imgur.com/a/peSVZeE sorry, keep forgetting
Title: Re: Help with my program
Post by: _vince on June 02, 2020, 06:41:27 pm
This doesn't answer your question but I notice this:
Code: QB64: [Select]
  1.     FOR i = 1 TO numfire
  2.  
  3.         test1(i) = _LOADIMAGE("./fire.png")
  4.         _PUTIMAGE (test1.x, test1.y), test1(i)
  5.     NEXT
  6.  

Wouldn't this load multiple copies of the same image? Seems inefficient, I think this would have the same result:
Code: QB64: [Select]
  1. dim zzz as long
  2. zzz = _loadimage("fire.png")
  3.     FOR i = 1 TO numfire
  4.         test1(i) = zzz
  5.         _PUTIMAGE (test1.x, test1.y), test1(i)
  6.     NEXT
  7.  

Also, I believe all loadimage handles should be LONGs.  I may answer your actual question later
Title: Re: Help with my program
Post by: Patrick_coots on June 02, 2020, 07:15:12 pm
its jsut a placeholder, and if you check test1 type, you can see test1.fire is a long
Title: Re: Help with my program
Post by: TerryRitchie on June 02, 2020, 08:28:08 pm
https://imgur.com/a/peSVZeE sorry, keep forgetting

No problem. I'll take a look at it in a bit. Working on another program right now.

Oh, by the way, welcome to the forum! :-)
Title: Re: Help with my program
Post by: _vince on June 02, 2020, 08:59:51 pm
You're almost there! Just need to fill in the FOR loops, here goes:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. TYPE test
  3.     x AS INTEGER
  4.     y AS INTEGER
  5.  
  6. TYPE test2
  7.     x AS INTEGER
  8.     y AS INTEGER
  9.     xdest AS INTEGER
  10.     ydest AS INTEGER
  11.     number AS INTEGER
  12.     fire AS LONG
  13.  
  14. DIM SHARED spider AS test
  15. reDIM SHARED test1(100) AS test2
  16. n = 1
  17. test1(n).x = 50
  18. test1(n).y = 100
  19.  
  20. test1(n).xdest = 1
  21. test1(n).ydest = 0
  22. test1(n).fire = _LOADIMAGE("./fire.png")
  23.  
  24. dim timer1 as single
  25. timer1 = timer
  26.         if timer - timer1 > 3 then
  27.                 'add fire
  28.                 if n<100 then
  29.                 n = n + 1
  30.  
  31.                 test1(n).x = rnd*640
  32.                 test1(n).y = rnd*480
  33.  
  34.                 test1(n).xdest = 1
  35.                 test1(n).ydest = 1
  36.                 test1(n).fire = _LOADIMAGE("./fire.png")
  37.  
  38.                 timer1 = timer
  39.                 end if
  40.         end if
  41.  
  42.     bounce
  43.     border
  44.     check
  45.     IF _KEYDOWN(105) THEN adfire
  46.     PCOPY 1, _DISPLAY
  47.     CLS
  48.     IF _KEYDOWN(18432) THEN spider.y = spider.y - 5
  49.     IF _KEYDOWN(20480) THEN spider.y = spider.y + 5
  50.  
  51.     IF _KEYDOWN(19200) THEN spider.x = spider.x - 5
  52.     IF _KEYDOWN(19712) THEN spider.x = spider.x + 5
  53.     CIRCLE (spider.x, spider.y), 5, _RGB(177, 83, 127)
  54.  
  55.         for i=1 to n
  56.                 _PUTIMAGE (test1(i).x, test1(i).y), test1(i).fire
  57.  
  58.                 IF test1(i).xdest = 1 THEN test1(i).x = test1(i).x + 5
  59.                 IF test1(i).xdest = 0 THEN test1(i).x = test1(i).x - 5
  60.  
  61.                 IF test1(i).ydest = 1 THEN test1(i).y = test1(i).y - 5
  62.                 IF test1(i).ydest = 0 THEN test1(i).y = test1(i).y + 5
  63.         next
  64.  
  65.  
  66.     WAIT &H3DA, &H3DA
  67.     WAIT &H3DA, &H3DA, 8
  68.     _DISPLAY
  69.     PCOPY _DISPLAY, 1
  70. 'lazy teacher!
  71. 'these fill in the code templates are not teaching
  72. 'make us write our own code!
  73. SUB fired
  74.     FOR i = 1 TO n
  75.  
  76.         test1(i).fire = _LOADIMAGE("./fire.png")
  77.         _PUTIMAGE (test1(i).x, test1(i).y), test1(i).fire
  78.     NEXT
  79. SUB bounce 'makes the fire bounce
  80.         for i=1 to n
  81.                 IF test1(i).x >= 628 THEN
  82.                         test1(i).xdest = 0
  83.                 END IF
  84.                 IF test1(i).x <= 1 THEN
  85.                         test1(i).xdest = 1
  86.                 END IF
  87.                 IF test1(i).y >= 468 THEN
  88.                         test1(i).ydest = 1
  89.                 END IF
  90.                 IF test1(i).y <= 1 THEN
  91.                         test1(i).ydest = 0
  92.                 END IF
  93.         next
  94. SUB border 'prevents palyer from going OOB
  95.     IF spider.x > 630 THEN spider.x = spider.x - 5
  96.     IF spider.x < 0 THEN spider.x = spider.x + 5
  97.     IF spider.y > 470 THEN spider.y = spider.y - 5
  98.     IF spider.y < 0 THEN spider.y = spider.y + 5
  99. SUB check
  100.         for i=1 to n
  101.                 IF (spider.x - test1(i).x) ^ 2 + (spider.y - test1(i).y) ^ 2 <= 2 ^ 3 THEN END
  102.         next
  103. SUB hit
  104.     _PRINTSTRING (300, 240), "GAME OVER: PRESS ENTER TO RESTART"
  105.     SLEEP
  106.     STOP
  107. SUB adfire
  108.     fired
  109.  
  110.  
Title: Re: Help with my program
Post by: Patrick_coots on June 02, 2020, 09:12:25 pm
hey man, thanks! this kind of stuff isnt my forte, i appreciate it
Title: Re: Help with my program
Post by: TerryRitchie on June 02, 2020, 09:45:51 pm
Looks like _vince took care of you. :-)