QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: MasterGy on March 04, 2021, 02:32:51 pm

Title: MasterGy is looking for ideas to implement ("i suffer")
Post by: MasterGy on March 04, 2021, 02:32:51 pm
Hello ! I'm bored.
This program is like grabbing a pencil and scratching the paper. Idiocy, no sense. There is a lack of ideas

Code: QB64: [Select]
  1. monx = 600 'window size
  2. mony = 400
  3.  
  4. mon = _NEWIMAGE(monx, mony, 32): SCREEN mon
  5.  
  6.  
  7. actx = monx / 2 'start draw to middle
  8. acty = mony / 2
  9. add_zoom = .01 'the amount to be added to the position
  10. radius = 20 'how many degrees can you go?
  11. ang_min = -1 'how many degrees can there be a difference between the current and the new direction?
  12. ang_max = -ang_min
  13. cyc_min = 30 'how long do you do a new direction? (min)
  14. cyc_max = 100 ' (max)
  15.  
  16.  
  17. DO: _LIMIT 3000
  18.     DO
  19.         PSET (actx, acty)
  20.         IF cyc_counter <= 0 THEN
  21.             add_ang = (ang_min + (ang_max - ang_min) * RND(1)) * (forced_ang_max_up + 1)
  22.             cyc_counter = cyc_min + (cyc_max - cyc_min) * RND(1)
  23.         END IF
  24.  
  25.         try_act_ang = act_ang + add_ang
  26.         xang_norad = try_act_ang * (_PI / 180)
  27.         try_x = actx + SIN(xang_norad) * radius * add_zoom
  28.         try_y = acty + COS(xang_norad) * radius * add_zoom
  29.  
  30.         IF try_x < 0 OR try_x > monx - 1 OR try_y < 0 OR try_y > mony - 1 THEN cyc_counter = -1: forced_ang_max_up = forced_ang_max_up + 1
  31.  
  32.         IF cyc_counter > 0 THEN
  33.             forced_ang_max_up = 0
  34.             actx = try_x
  35.             acty = try_y
  36.             act_ang = try_act_ang
  37.         END IF
  38.  
  39.         cyc_counter = cyc_counter - 1
  40.  
  41.     LOOP WHILE forced_ang_max_up
Title: Re: i suffer
Post by: MasterGy on March 04, 2021, 02:39:42 pm
I deal with night watch. there are road constructions in Hungary. highways, overpasses, such. my privacy sucks, so i bought a van, it has a bed, table, heating, I have a lot of time. The bland game, and everything was born here. I have a lack of ideas lately. I'm suffering. I would do something so much !!!! I drank wine and made this nonsense in embarrassment. What should I do? Give me an idea! :)
Title: Re: i suffer
Post by: FellippeHeitor on March 04, 2021, 03:01:30 pm
the code is pretty cool tho.
Title: Re: i suffer
Post by: bplus on March 04, 2021, 03:11:31 pm
Yeah reminds me of Curlie Borealis or Guts :)
Title: Re: i suffer
Post by: bplus on March 04, 2021, 03:17:03 pm
Quote
I have a lack of ideas lately. I'm suffering. I would do something so much !!!! I drank wine and made this nonsense in embarrassment. What should I do? Give me an idea! :)

https://www.qb64.org/forum/index.php?topic=3713.0
Quote
TYPE elements are always* initialised to 0. This includes when REDIMming an array of them.

* There's an elusive bug that sometimes causes elements to not be initialised to 0, but this is only for TYPEs that have an AS STRING element.

Find the elusive bug and make as simple example as possible that can be replicated by us to show what bad things  happens  when one assumes all is zero or "" in freshly minted UDT. Maybe we could Kill the bug for good if we have an example that can be replicated.


Title: Re: i suffer
Post by: SpriggsySpriggs on March 04, 2021, 03:19:10 pm
@bplus I think as long as we get in the habit of initializing variables and then setting them to zero then we should be ok. Or, using that ZeroMemory function and getting it cleared out for sure without needing a loop.
Title: Re: i suffer
Post by: bplus on March 04, 2021, 03:23:57 pm
@bplus I think as long as we get in the habit of initializing variables and then setting them to zero then we should be ok. Or, using that ZeroMemory function and getting it cleared out for sure without needing a loop.

I would like to feel safe to assume all is 0 or "" without extraordinary efforts from a new variable or UDT.
Title: Re: i suffer
Post by: SpriggsySpriggs on March 04, 2021, 03:25:13 pm
@bplus
It really isn't safe to assume zero or "" for any variable. Think about C/C++, for instance. In code examples they almost always declare a variable and then immediately set it to zero or an empty string.
Title: Re: i suffer
Post by: bplus on March 04, 2021, 03:40:19 pm
@SpriggsySpriggs

Think of the founders of BASIC and their mission to get a PL for non professional programmers or computer scientists.

Besides I am merely suggesting an idea for a challenging problem, you don't have to like it ;-))

MasterGy is extremely clever fellow, hate to see good mind wasted by wine.
Title: Re: i suffer
Post by: Dimster on March 04, 2021, 03:48:30 pm
@MasterGy - not sure if you can access TED TALKS or maybe it's just TED, but they apparently have some discussions on Where Ideas originate. Glass of Wine, feet up on the table in the van, laptop blaring out a good Ted Talk.
Title: Re: i suffer
Post by: SpriggsySpriggs on March 04, 2021, 03:49:38 pm
@SpriggsySpriggs
Besides I am merely suggesting an idea for a challenging problem, you don't have to like it ;-))

@bplus I'm not saying I don't like it. I was suggesting ways of getting around it for now and suggesting using more modern code practices. There's nothing wrong with wanting it to already be zero. If we can guarantee it to always be zero then that's neat and saves some trouble. I don't expect we'll get to a point of guaranteeing that anytime soon, though. The main thing now would be to make them zero or assign them a value immediately.
Title: Re: i suffer
Post by: bplus on March 04, 2021, 03:55:58 pm
Quote
I don't expect we'll get to a point of guaranteeing that anytime soon, though. The main thing now would be to make them zero or assign them a value immediately.

Yes we know the fix, why do we have to fix?

Quote
I don't expect we'll get to a point of guaranteeing that anytime soon

That because people blow off this problem, can't fix anything anytime soon if you merely wish it wasn't there and use the fix that works sure enough. Let someone else figure it out, someone who has time to kill, someone say, who is bored out of their gourd and drinks wine and doodles "shamefully"  ;-))

Title: Re: i suffer
Post by: SpriggsySpriggs on March 04, 2021, 03:57:04 pm
@bplus

Sounds like we've found your next project!
Title: Re: i suffer
Post by: bplus on March 04, 2021, 03:59:44 pm
@bplus

Sounds like we've found your next project!

Yeah busted! I am on it at the moment but I wish MasterGy would take it off my hands ;)
Title: Re: i suffer
Post by: bplus on March 04, 2021, 04:14:25 pm
You know this is a Nessie problem, Sasquatch, Bigfoot, Yeti of Qb64

People have had sightings but nobody can catch it or even bring back a creditable picture that isn't grainy as hell.
Title: Re: i suffer
Post by: Petr on March 04, 2021, 04:19:23 pm
Hi MasterGY. I'll give you one of my ideas that I wanted to make, but I just don't have time for anything right now. As you know, the situation in the Czech Republic is the worst in the world with coronavirus, and unfortunately people in the very vicinity have already become ill. So I'm still working on other things - absolutely not with programming.

To the idea. There is a thread somewhere that describes where the individual QB64 programmers are from. I wanted to make a round planet earth (you can do better than me) and place on this globe the approximate position of individual users, always with the flag of the state from which they are. If you are interested in this, then I am passing on this idea to you.
Title: Re: i suffer
Post by: bplus on March 04, 2021, 07:50:52 pm
You know this is a Nessie problem, Sasquatch, Bigfoot, Yeti of Qb64

People have had sightings but nobody can catch it or even bring back a creditable picture that isn't grainy as hell.

Nessie caught on film:
https://www.qb64.org/forum/index.php?topic=3713.msg130703#msg130703
Title: Re: i suffer
Post by: Pete on March 04, 2021, 08:43:20 pm
Big Foot is nothing more than a pet, belonging to a space alien. The alien transports the Big Foot in down, possibly someone sights it, then the foot prints abruptly end, when it gets 'ported back up, to go home. Good boy, did you make a poo, poo? Good! Time to go home!

Another one of life's little mysteries solved by SCREEN ZERO HERO. You're welcome.

Pete
Title: Re: i suffer
Post by: Bert22306 on March 04, 2021, 09:19:59 pm
Big Foot is nothing more than a pet, belonging to a space alien. The alien transports the Big Foot in down, possibly someone sights it, then the foot prints abruptly end, when it gets 'ported back up, to go home. Good boy, did you make a poo, poo? Good! Time to go home!

Another one of life's little mysteries solved by SCREEN ZERO HERO. You're welcome.

Pete

Daggone it. Now I too "suffer." Thanks a lot, Pete.

On the other hand, I just finished three programs, tricky SOBs each one, and all three are Screen 12! Put that in your pipe.
Title: Re: i suffer
Post by: Pete on March 04, 2021, 10:44:03 pm
SCREEN 12??? Okay Bert, now you're pushing my SCREEN 0 buttons!

Pete
Title: Re: i suffer
Post by: MasterGy on March 05, 2021, 03:10:09 pm
Hello ! Thank you for your answers !

I answer in line:

Fellippe, thank you! :)

Bplus, I don't know Curlie Borealis and Gutsra. I don't fully understand the "TYPE" problem. I’ll tell you honestly, I don’t like to get lost in the details. I never considered design important. How should I say ? I don’t care about the look of the machines, a car, or the program. The look of the car, the essential things of programming for me. Function as simply described as possible. I don’t even use TYPE if I don’t have to. Why? Just as I don’t go with a modern car either, though I could buy it because I don’t care about design. I have a 35-year-old Honda Civic, the better car I don’t need, though my friends also tell me why I don’t buy another one. My answer is: the old car is simpler, more functional. Simpler, fewer errors, easier to repair. I'm the same with programming. Through the car example, I tried to illustrate what I was interested in programming. SIMPLICITY! A source code is not a poem to admire, but to work in the simplest way (Occam's razor) :)

Dimster! Don’t think I’m an alcoholic, but if I drink, my brain really spins up, then I can exclude the outside world, at the same time I see the task, then I’m the most effective. After 1 bottle of wine… 2 even better… and I’m not kidding, I mean that. If I don’t drink, it goes much slower and I don’t see through complicated things, I can’t focus… a lot of people don’t believe it, because usually people can’t think about alcohol. For me, it's the other way around. I can drink it as much as I vomit sooner, but I never lose my mind, in fact!

Petr! We are neighbours ? :) I am interested in your globe idea, it would be good to know in what file the website stores the data of registered users. The program would automatically download and display the names on the globe! I like the idea !
Title: Re: i suffer
Post by: bplus on March 05, 2021, 03:24:55 pm
Quote
Bplus, I don't know Curlie Borealis and Gutsra. I don't fully understand the "TYPE" problem. I’ll tell you honestly, I don’t like to get lost in the details. I never considered design important. How should I say ? I don’t care about the look of the machines, a car, or the program. The look of the car, the essential things of programming for me. Function as simply described as possible. I don’t even use TYPE if I don’t have to. Why? Just as I don’t go with a modern car either, though I could buy it because I don’t care about design. I have a 35-year-old Honda Civic, the better car I don’t need, though my friends also tell me why I don’t buy another one. My answer is: the old car is simpler, more functional. Simpler, fewer errors, easier to repair. I'm the same with programming. Through the car example, I tried to illustrate what I was interested in programming. SIMPLICITY! A source code is not a poem to admire, but to work in the simplest way (Occam's razor) :)

Yeah this is my heart too. Type makes an object or structure of numerous variables easy to describe under one name.

Shameless doodling, Curlie Borealus:
Code: QB64: [Select]
  1. _Title "Curlie Borealis" 'Quick trans B+ 2019-08-29
  2. 'Curlie borealis.bas for SmallBASIC 0.12.2 [B+=MGA] 2016-04-23
  3. ' ;-) cool mods thanks to alpha
  4.  
  5. Const xmax = 1200, ymax = 700
  6. Dim Shared qb(15)
  7. qb(0) = &HFF000000
  8. qb(1) = &HFF000088
  9. qb(2) = &HFF008800
  10. qb(3) = &HFF008888
  11. qb(4) = &HFF88000
  12. qb(5) = &HFF880088
  13. qb(6) = &HFF888800
  14. qb(7) = &HFFCCCCCC
  15. qb(8) = &HFF888888
  16. qb(9) = &HFF0000FF
  17. qb(10) = &HFF00FF00
  18. qb(11) = &HFF00FFFF
  19. qb(12) = &HFFFF0000
  20. qb(13) = &HFFFF00FF
  21. qb(14) = &HFFFFFF00
  22. qb(15) = &HFFFFFFFF
  23.  
  24. Screen _NewImage(1200, 700, 32)
  25. _ScreenMove 100, 20
  26. ff = 2.03: maxi = 25000
  27. Color &HFFFFFFFF, 0: Cls
  28. x = xmax / 2: y = ymax / 2
  29.     loopcnt = loopcnt + 1
  30.     Line (0, 0)-(xmax, ymax), _RGBA(0, 0, 0, 3), BF 'Fells trick
  31.     ff = ff + 100.431
  32.     If Rnd < .1 Then c = 0 Else c = Int(Rnd * 16) 'need more black oh ALPHA my friend!!!
  33.     For i = 0 To maxi
  34.         f = f + ff
  35.         x = min(xmax, -1 * x + Cos(f * i))
  36.         y = min(ymax, -1 * y + Sin(f * i))
  37.         PSet (x, y), qb(c)
  38.     Next
  39.     cc = cc + 1
  40.     If loopcnt Mod 1000 = 0 Then
  41.         Locate 1, 1: Print Space$(10)
  42.         Locate 1, 1: Print loopcnt: _Delay 1
  43.     End If
  44.     If loopcnt Mod 1800 = 0 Then x = xmax / 2: y = ymax / 2: ff = 0: f = 0 'jiggle this sucker
  45.     If Rnd < .001 Then Paint (Rnd * xmax, Rnd * ymax), _RGBA(Rnd * 255, Rnd * 255, Rnd * 255, Rnd * 255)
  46.     _Display
  47.     _Limit 200 'oh man my fan is hot
  48.  
  49. Function min (a, b)
  50.     If a < b Then min = a Else min = b
  51.  

More shameless doodling, Guts:
Code: QB64: [Select]
  1. _Title "Guts" 'passed down through ages, I first encountered it through Richard Russel author BBC 4 Windows
  2. ' 2019-04-05 B+ translation to QB64 from: Guts.bas SmallBASIC 0.12.0 2015-11-17 MGA/B+
  3. 'modified  > GUTS  Original ARM BBC BASIC version by Jan Vibe, 800x600 ?
  4.  
  5. Const xmax = 800
  6. Const ymax = 600
  7. Screen _NewImage(xmax, ymax, 32)
  8.  
  9. Dim bX(15), bY(15), bZ(15), COLR(15) As _Unsigned Long
  10. bX(1) = -100: A = 0
  11. For N = 1 To 15
  12.     COLR(16 - N) = _RGB32(7 * N + 150, 14 * N + 45, 14 * N + 45)
  13.  
  14. X1 = Rnd * xmax: Y1 = Rnd * ymax: DX1 = (Rnd * 16 + 1) * (Rnd - .5): DY1 = (Rnd * 16 + 1) * (Rnd - .5)
  15. X2 = Rnd * xmax: Y2 = Rnd * ymax: DX2 = (Rnd * 16 + 1) * (Rnd - .5): DY2 = (Rnd * 16 + 1) * (Rnd - .5)
  16. While _KeyDown(27) = 0
  17.     H = X1 + DX1: If H < 0 Or H > xmax Then DX1 = (Rnd * 16 + 1) * -Sgn(DX1)
  18.     H = Y1 + DY1: If H < 0 Or H > ymax Then DY1 = (Rnd * 16 + 1) * -Sgn(DY1)
  19.     X1 = X1 + DX1: Y1 = Y1 + DY1
  20.     If X2 < X1 And DX2 < 24 Then DX2 = DX2 + 1
  21.     If X2 > X1 And DX2 > -24 Then DX2 = DX2 - 1
  22.     If Y2 < Y1 And DY2 < 24 Then DY2 = DY2 + 1
  23.     If Y2 > Y1 And DY2 > -24 Then DY2 = DY2 - 1
  24.     X2 = X2 + DX2: Y2 = Y2 + DY2: A = (A + 10) Mod 360: Z = (Sin(_D2R(A) + 1)) + 2
  25.     For N = 2 To 15
  26.         bX(N - 1) = bX(N): bY(N - 1) = bY(N): bZ(N - 1) = bZ(N)
  27.     Next
  28.     bX(15) = X2: bY(15) = Y2: bZ(15) = Z
  29.     For N = 1 To 15: fcirc bX(N), bY(N), N * bZ(N) + 5, COLR(N): Next
  30.     _Display
  31.     _Limit 60
  32.  
  33. 'from Steve Gold standard
  34. Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
  35.     Dim Radius As Integer, RadiusError As Integer
  36.     Dim X As Integer, Y As Integer
  37.  
  38.     Radius = Abs(R)
  39.     RadiusError = -Radius
  40.     X = Radius
  41.     Y = 0
  42.  
  43.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  44.  
  45.     ' Draw the middle span here so we don't draw it twice in the main loop,
  46.     ' which would be a problem with blending turned on.
  47.     Line (CX - X, CY)-(CX + X, CY), C, BF
  48.  
  49.     While X > Y
  50.         RadiusError = RadiusError + Y * 2 + 1
  51.         If RadiusError >= 0 Then
  52.             If X <> Y + 1 Then
  53.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  54.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  55.             End If
  56.             X = X - 1
  57.             RadiusError = RadiusError - X * 2
  58.         End If
  59.         Y = Y + 1
  60.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  61.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  62.     Wend
  63.  
  64.  


Title: Re: i suffer
Post by: MasterGy on March 05, 2021, 03:36:01 pm
there is no shortage of ideas here please! creative ! :)

may i ask what those two people did?
Title: Re: i suffer
Post by: Petr on March 05, 2021, 03:51:30 pm
Quote
Petr! We are neighbours ? :) I am interested in your globe idea, it would be good to know in what file the website stores the data of registered users. The program would automatically download and display the names on the globe! I like the idea !

Yes, we are neighbors. I have been to Hungary twice on holiday at Lake Balaton. Hungary is very nice country. I can't find a thread that contains a list of members and their locations. It's somewhere in the forum. It would probably be best to add the option to enter the state name and user name. This then uses a 3D vector to determine the position where the flag name will appear. I imagine it as a 3D vector from the center of the sphere, the angles between all three axes determine the position. I think it's so solvable.

Areas that cover QB64 users (from the head) are: India, Russia, USA - I don't remember the countries, but there are a lot of them, Australia, Italy, Germany, Brazil, Hungary, the Czech Republic, Slovakia. It is highly probable that I forgot about a some state. Of course, new users are comming every day, so the possibility of editing the database (a custom type) would be appropriate.
Title: Re: i suffer
Post by: MasterGy on March 05, 2021, 04:03:41 pm

maybe it could be the first time the globe is very accurate, place a signal where it needs to be based on gps coordinates. Then we would need a database that is country -> flag location gps-based.
Then you should have qb64.org to store the data. I tried to download it from a program eg: "https://www.qb64.org/forum/index.php?action=profile;u=454". 454 is the point ... this is my place. I started playing..0 ... 1 ... 2..3..4 ... I think it shows a lot who the founding members are. Greetings odin, Fellippe, Ashish, keybone ..... I may be wrong, but you don't know that I can simply get the topographic data in html with _OPENCLIENT?

I live beyond the Tisza, I have been to Lake Balaton twice in my life. For me, the Tisza is very good for bathing in summer.
Title: Re: i suffer
Post by: Petr on March 05, 2021, 04:15:32 pm
You're right, I don't know anything about how to get topographic data. I've never solved it, now it's the first time :) I thought that users would be able to add themselves to the database (if they wanted to).
Title: Re: i suffer
Post by: MasterGy on March 05, 2021, 04:19:50 pm
the database is ready :) here is the forum server :) the problem is that the html is generated from a php command, which you see in the browser, for example. This could also be a solution, but it is painful to solve it. It would be much simpler to have a "direct link", specifically the file that contains what we need. the program takes out what it needs and everyone already has it.
Title: Re: i suffer
Post by: SMcNeill on March 05, 2021, 06:58:20 pm
Here’s an idea for you, which I’d love to see someone implement with _MAPTRIANGLE sometime:  Make a complete set of polyhedral dice in 3D and have them roll at a set X,Y coordinate.

https://i1.wp.com/metallicdicegames.com/wp-content/uploads/2018/05/003CopperPolyhedralHighRes.png?fit=1000%2C1000&ssl=1

Way I’d picture it would be something like:

 FUNCTION RollDice (sides, x, y)
sides would be the number of sides on the die: 4, 6, 8, 10, 12, 20
x,y would be the coordinates of where to place/roll the die on the screen.

You’d have to draw the dice in 3d, rotate/roll them, and convert your 3d coordinates to a 2d screen...

I’ve played around with doing it with opengl commands in the past, but would love to see the concept done with maptriangle sometime, and it sounds like something you’d be good at and might have a challenge working with.
Title: Re: i suffer
Post by: SpriggsySpriggs on March 05, 2021, 06:59:33 pm
Sounds like Steve wants to make DnD in QB64!
Title: Re: i suffer
Post by: SMcNeill on March 05, 2021, 07:04:47 pm
Sounds like Steve wants to make DnD in QB64!

Just wants to add dice graphics to his dice roller and a few other projects: https://www.qb64.org/forum/index.php?topic=977.msg101977#msg101977. ;D
Title: Re: i suffer
Post by: MasterGy on March 06, 2021, 01:56:37 pm
SMcNeill huh! very good idea! it also coincides with what I’ve been thinking for a long time, but I don’t even know how to get started. "rigid body physics". I'm thinking of an off-road game. If I could solve this, I could help in the dice as well.
I want something like that, but I feel like I’m very short of that. (the interesting thing is that this is a special solution, 95 DOS program, at that time this little primitive game had the most lifelike physics) If I could solve this, I would help in the dice game!

Title: Re: i suffer
Post by: MasterGy on March 06, 2021, 02:35:14 pm
I found the old programs. i remember my first pc after commodore64 was a 386DX 40mhz machine with hercules monochrome monitor. I loved it !!! DOS folder qbasic.exe !!! not even interested in anything but this! I couldn’t even make rudimentary games in color because that monitor only knew 2 colors. I don’t want to tire you of this, but if you’re not angry, I’ll show you a couple. I still used a lot of goto here, it wasn’t structured. I also did a Tetris game, just loading it into qb64 the characters don't show up because the value of ascii is different here. Here, for example, is a number system conversion program. You specify the number system you enter, you also enter the number, and it converts. I'm trying to revive the tetris to qb64. I translate Hungarian into English

Code: QB64: [Select]
  1. DECLARE SUB atalakito (decimalisszam)
  2. DECLARE SUB bekeres (decimalisszam)
  3.  
  4.  
  5. PRINT "SZŹMRENDSZER ŹTVŹLT˘ program                            (C)T˘th Gyula 1998-03-28"
  6. LOCATE 3, 4
  7. PRINT "  Ez a program b rmely sz mot  t tud sz molni k‚t 2-22 sz mrendszer k”z”tt."
  8. bekeres x
  9.  
  10. atalakito x
  11.  
  12. SUB atalakito (szam)
  13.     k$ = "0123456789ABCDEFGHIJKLMNOP"
  14.     FOR szr = 2 TO 22
  15.         PRINT USING "##"; szr;: PRINT "-number system (0-" + MID$(k$, szr, 1); ") :";
  16.         IF szr ^ 20 < szam THEN PRINT " It does not fit ": GOTO ss
  17.         xszam = szam: s$ = "": FOR h = 30 TO -6 STEP -1
  18.             IF h = -1 THEN s$ = s$ + "."
  19.             a = INT(xszam / (szr ^ h))
  20.             s$ = s$ + MID$(k$, a + 1, 1): xszam = xszam - a * szr ^ h
  21.         NEXT h
  22.         FOR h = 1 TO LEN(s$): IF MID$(s$, h, 1) <> "0" THEN EXIT FOR
  23.         NEXT h: PRINT MID$(s$, h)
  24.     ss: NEXT szr
  25.  
  26. SUB bekeres (x)
  27.     k$ = "0123456789ABCDEFGHIJKLMNOP"
  28.    11 INPUT "in what number system do you enter?(2-22) "; szr
  29.     IF szr <> INT(szr) OR szr > 22 OR szr < 2 THEN 11
  30.  
  31.     12 PRINT "enter the number ! (using characters: 0-" + MID$(k$, szr, 1) + ")"
  32.     INPUT szam$: ertek = 0
  33.     sz$ = "": FOR t = LEN(szam$) TO 1 STEP -1
  34.         x$ = MID$(szam$, t, 1)
  35.         IF x$ = "." THEN ht = LEN(szam$) - t ELSE sz$ = sz$ + x$
  36.     NEXT t
  37.     sz$ = UCASE$(sz$)
  38.     FOR t = LEN(sz$) TO 1 STEP -1
  39.         x$ = MID$(sz$, LEN(sz$) - t + 1, 1)
  40.         FOR y = 1 TO szr: IF MID$(k$, y, 1) = x$ THEN GOTO ok
  41.         NEXT y: PRINT "wrong character"; LEN(sz$) - t + 1; ". character ! (" + x$ + ")": GOTO 12
  42.         ok:
  43.         ertek = ertek + (y - 1) * szr ^ (LEN(sz$) - t)
  44.     NEXT t
  45.     x = ertek / szr ^ ht
  46.  
Title: Re: i suffer
Post by: MasterGy on March 06, 2021, 03:21:16 pm
here is the TETRIS game written 24 years ago :) looking at the source code is a disaster :)

Code: QB64: [Select]
  1. DECLARE SUB idominfo (id$(), kep$(), xkep$())
  2. DECLARE SUB kepprn (kep$())
  3. varakozas = 1
  4. idomokszama = 19
  5.  
  6. DIM kep$(29), xkep$(29), id$(idomokszama - 1, 4)
  7. idominfo id$(), kep$(), xkep$()
  8. GOTO cimlap
  9.  
  10. jatek:
  11.  
  12. idominfo id$(), kep$(), xkep$(): CLS: kepprn kep$()
  13. LOCATE 24, 32: PRINT "Points   :";
  14. LOCATE 4, 12: PRINT "Next      :"
  15. ujalak:
  16. FOR t = 1 TO VAL(RIGHT$(TIME$, 2)): r = RND(1): NEXT t
  17. aktid = kovetkezo
  18. kovetkezo = INT(idomokszama * RND(1)): elfor = 0: x = 9: y = 0
  19. FOR fug = 0 TO 2: LOCATE 3 + fug, 24: PRINT MID$(id$(kovetkezo, 0), 3 * fug + 1, 3): NEXT fug
  20.  
  21.  
  22.  
  23. FOR fug = 0 TO 2: FOR viz = 0 TO 2
  24.         kepp$ = MID$(kep$(y + fug), x + viz, 1)
  25.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  26.         IF idop$ = "±" AND (kepp$ <> " ") THEN GOTO jatekv
  27. NEXT viz, fug
  28.  
  29. s_s = .3
  30. sebesseg = s_s
  31. bt = TIMER
  32. ciklus:
  33.  
  34.  
  35.  
  36. leptek = leptek + 1: 'IF leptek <> varakozas THEN GOTO billentyuk
  37. IF ABS(TIMER - bt) < sebesseg THEN GOTO billentyuk
  38. leptek = 0
  39. bt = TIMER
  40. FOR viz = 0 TO 2: FOR fug = 0 TO 2
  41.         kepp$ = MID$(kep$(y + fug + 1), x + viz, 1)
  42.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  43.         IF idop$ = "±" AND (kepp$ = "°" OR kepp$ = "Ű") THEN GOTO fixalo
  44. NEXT fug, viz
  45. y = y + 1
  46.  
  47. FOR viz = 0 TO 2
  48.  
  49.     kepp$ = MID$(kep$(y - 1), x + viz, 1)
  50.     IF kepp$ <> "Ű" AND kepp$ <> "°" THEN kep$(y - 1) = LEFT$(kep$(y - 1), x + viz - 1) + " " + MID$(kep$(y - 1), x + viz + 1)
  51.  
  52.     FOR fug = 0 TO 2
  53.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  54.         kepp$ = MID$(kep$(fug + y), x + viz, 1): pr$ = kepp$
  55.         IF idop$ = " " AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = " "
  56.         IF idop$ = "±" AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = "˛"
  57.         kep$(y + fug) = LEFT$(kep$(y + fug), x + viz - 1) + pr$ + MID$(kep$(y + fug), x + viz + 1)
  58. NEXT fug, viz
  59. kepprn kep$()
  60. pontszam = pontszam + 1: LOCATE 24, 42: PRINT pontszam;
  61.  
  62. billentyuk:
  63.  
  64. a$ = INKEY$
  65. a$ = " " + a$
  66. ky = ASC(RIGHT$(a$, 1))
  67.  
  68. IF ky <> 75 THEN GOTO jobbra:
  69. REM 'nyil balra'                  ( az idom balra mozgatasa )
  70. FOR viz = 0 TO 2: FOR fug = 0 TO 2
  71.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  72.         kepp$ = MID$(kep$(fug + y), x + viz - (1), 1)
  73.         IF idop$ = "±" AND (kepp$ = "°" OR kepp$ = "Ű") THEN GOTO ciklus
  74. NEXT fug, viz: x = x - 1
  75. FOR fug = 0 TO 2
  76.  
  77.     kepp$ = MID$(kep$(fug + y), x + 3, 1)
  78.     IF kepp$ <> "Ű" AND kepp$ <> "°" THEN kep$(y + fug) = LEFT$(kep$(y + fug), x + 2) + " " + MID$(kep$(y + fug), x + 4)
  79.  
  80.     FOR viz = 0 TO 2
  81.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  82.         kepp$ = MID$(kep$(fug + y), x + viz, 1): pr$ = kepp$
  83.         IF idop$ = " " AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = " "
  84.         IF idop$ = "±" AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = "˛"
  85.         kep$(y + fug) = LEFT$(kep$(y + fug), x + viz - 1) + pr$ + MID$(kep$(y + fug), x + viz + 1)
  86. NEXT viz, fug
  87.  
  88. jobbra:
  89. IF ky <> 77 THEN GOTO fel
  90. REM 'nyil jobbra'          (az idom jobbra mozgatasa)
  91. FOR viz = 0 TO 2: FOR fug = 0 TO 2
  92.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  93.         kepp$ = MID$(kep$(fug + y), x + viz + (1), 1)
  94.         IF idop$ = "±" AND (kepp$ = "°" OR kepp$ = "Ű") THEN GOTO ciklus
  95. NEXT fug, viz: x = x + 1
  96. FOR fug = 0 TO 2
  97.  
  98.     kepp$ = MID$(kep$(fug + y), x - 1, 1)
  99.     IF kepp$ <> "Ű" AND kepp$ <> "°" THEN kep$(y + fug) = LEFT$(kep$(y + fug), x - 2) + " " + MID$(kep$(y + fug), x)
  100.  
  101.     FOR viz = 0 TO 2
  102.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  103.         kepp$ = MID$(kep$(fug + y), x + viz, 1): pr$ = kepp$
  104.         IF idop$ = " " AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = " "
  105.         IF idop$ = "±" AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = "˛"
  106.         kep$(y + fug) = LEFT$(kep$(y + fug), x + viz - 1) + pr$ + MID$(kep$(y + fug), x + viz + 1)
  107. NEXT viz, fug
  108.  
  109. fel:
  110. IF ky <> 72 THEN GOTO le
  111. REM 'nyil fel'                               (az idom forgatasa)
  112. xelfor = elfor: elfor = elfor + 1: IF id$(aktid, elfor) = "" THEN elfor = 0
  113. FOR viz = 0 TO 2: FOR fug = 0 TO 2
  114.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  115.         kepp$ = MID$(kep$(fug + y), x + viz, 1)
  116.         IF idop$ = "±" AND (kepp$ = "°" OR kepp$ = "Ű") THEN elfor = xelfor
  117. NEXT fug, viz
  118. FOR viz = 0 TO 2: FOR fug = 0 TO 2
  119.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  120.         kepp$ = MID$(kep$(fug + y), x + viz, 1): pr$ = kepp$
  121.         IF idop$ = " " AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = " "
  122.         IF idop$ = "±" AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = "˛"
  123.         kep$(y + fug) = LEFT$(kep$(y + fug), x + viz - 1) + pr$ + MID$(kep$(y + fug), x + viz + 1)
  124. NEXT fug, viz
  125.  
  126. le:
  127. IF ky <> 80 THEN GOTO vg
  128. sebesseg = s_s / 5: kepprn kep$(): GOTO ciklus
  129.  
  130. REM 'nyil le'    ( lerakni a megfelelo helyre , billentyuk kizarva)
  131. ckls:
  132. FOR viz = 0 TO 2: FOR fug = 0 TO 2
  133.         kepp$ = MID$(kep$(y + fug + 1), x + viz, 1)
  134.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  135.         IF idop$ = "±" AND (kepp$ = "°" OR kepp$ = "Ű") THEN GOTO fixalo
  136. NEXT fug, viz
  137. y = y + 1
  138. pontszam = pontszam + 2: LOCATE 24, 42: PRINT pontszam;
  139. FOR viz = 0 TO 2
  140.  
  141.     kepp$ = MID$(kep$(y - 1), x + viz, 1)
  142.     IF kepp$ <> "Ű" AND kepp$ <> "°" THEN kep$(y - 1) = LEFT$(kep$(y - 1), x + viz - 1) + " " + MID$(kep$(y - 1), x + viz + 1)
  143.  
  144.     FOR fug = 0 TO 2
  145.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  146.         kepp$ = MID$(kep$(fug + y), x + viz, 1): pr$ = kepp$
  147.         IF idop$ = " " AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = " "
  148.         IF idop$ = "±" AND kepp$ <> "Ű" AND kepp$ <> "°" THEN pr$ = "˛"
  149.         kep$(y + fug) = LEFT$(kep$(y + fug), x + viz - 1) + pr$ + MID$(kep$(y + fug), x + viz + 1)
  150. NEXT fug, viz
  151. kepprn kep$()
  152. GOTO ckls
  153. vg:
  154. sebesseg = s_s
  155. kepprn kep$(): GOTO ciklus
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. fixalo:
  163. FOR viz = 0 TO 2: FOR fug = 0 TO 2
  164.         idop$ = MID$(id$(aktid, elfor), fug * 3 + viz + 1, 1)
  165.         kepp$ = MID$(kep$(y + fug), x + viz, 1)
  166.         IF idop$ = "±" THEN kep$(y + fug) = LEFT$(kep$(y + fug), x + viz - 1) + "°" + MID$(kep$(y + fug), x + viz + 1)
  167.         IF idop$ = " " AND (kepp$ <> "Ű" AND kepp$ <> "°") THEN kep$(y + fug) = LEFT$(kep$(y + fug), x + viz - 1) + " " + MID$(kep$(y + fug), x + viz + 1)
  168. NEXT fug, viz
  169.  
  170. vizsgalo:
  171. FOR t = 0 TO 21
  172.     IF kep$(t) = " ۰°°°°°°°°°°°°°°°Ű " THEN GOTO telesor
  173. NEXT t: GOTO ujalak
  174.  
  175. telesor:
  176. pontszam = pontszam + 200: LOCATE 24, 42: PRINT pontszam;
  177. FOR ck = 1 TO 8
  178.     kep$(t) = " ۰°°°°°°°°°°°°°°°Ű ": kepprn kep$()
  179.     kep$(t) = " Ű                Ű ": kepprn kep$()
  180.     kep$(t) = " ŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰ ": kepprn kep$()
  181. NEXT ck
  182. FOR ck = t TO 1 STEP -1: kep$(ck) = kep$(ck - 1): NEXT ck
  183. kep$(0) = " Ű                Ű "
  184. GOTO vizsgalo
  185.  
  186. cimlap:
  187. FOR fug = 21 TO 0 STEP -1
  188.     kep$(fug) = xkep$(fug)
  189.     kepprn kep$()
  190. NEXT fug
  191.     a$ = INKEY$
  192.     IF a$ = "u" THEN GOTO jatek
  193.     IF a$ = "k" THEN CLS: END
  194.     IF a$ = "i" THEN GOTO bemutato
  195.  
  196. bemutato:
  197. FOR idomok = 1 TO idomokszama
  198.     FOR elford = 0 TO 3: IF id$(idomok - 1, elford) = "" THEN GOTO kv
  199.  
  200.         FOR fug = 0 TO 2: FOR viz = 0 TO 2
  201.                 LOCATE 4 + elford * 4 + fug, (80 - 4 * idomokszama) / 2 + viz + (idomok - 1) * 4
  202.                 idop$ = MID$(id$(idomok - 1, elford), fug * 3 + viz + 1, 1)
  203.                 kepp$ = "°": IF idop$ = "±" THEN kepp$ = "Ű"
  204.                 PRINT kepp$;
  205.         NEXT viz, fug
  206. kv: NEXT elford, idomok
  207. LOCATE 23, 27
  208. PRINT "      Press any key      "
  209.  
  210. jatekv:
  211. LOCATE 24, 42: PRINT pontszam;
  212. FOR fug = 20 TO 0 STEP -1
  213.     kep$(fug) = " ۰°°°°°°°°°°°°°°°Ű ": kepprn kep$()
  214. NEXT fug
  215.  
  216. SUB idominfo (id$(), kep$(), xkep$())
  217.     id$(0, 0) = "     ±±±±"
  218.     id$(0, 1) = "±±  ±  ± "
  219.     id$(0, 2) = "   ±±±±  "
  220.     id$(0, 3) = " ±  ±  ±±"
  221.  
  222.     id$(1, 0) = "   ±  ±±±"
  223.     id$(1, 1) = " ±  ± ±± "
  224.     id$(1, 2) = "   ±±±  ±"
  225.     id$(1, 3) = " ±± ±  ± "
  226.  
  227.     id$(2, 0) = "   ±± ±  "
  228.     id$(2, 1) = "   ±  ±± "
  229.     id$(2, 2) = "    ± ±± "
  230.     id$(2, 3) = "   ±±  ± "
  231.  
  232.     id$(3, 0) = "    ± ±±±"
  233.     id$(3, 1) = "  ± ±±  ±"
  234.     id$(3, 2) = "   ±±± ± "
  235.     id$(3, 3) = " ±  ±± ± "
  236.  
  237.     id$(4, 0) = "   ±±±   "
  238.     id$(4, 1) = " ±  ±  ± "
  239.  
  240.     id$(5, 0) = "  ±±±±±  "
  241.     id$(5, 1) = "±±  ±  ±±"
  242.  
  243.     id$(6, 0) = " ±  ± ±±±"
  244.     id$(6, 1) = "  ±±±±  ±"
  245.     id$(6, 2) = "±±± ±  ± "
  246.     id$(6, 3) = "±  ±±±±  "
  247.  
  248.     id$(7, 0) = "   ±±±± ±"
  249.     id$(7, 1) = "±± ±  ±± "
  250.     id$(7, 2) = "   ± ±±±±"
  251.     id$(7, 3) = " ±±  ± ±±"
  252.  
  253.     id$(8, 0) = " ±  ±±  ±"
  254.     id$(8, 1) = "    ±±±± "
  255.  
  256.     id$(9, 0) = "  ± ±± ± "
  257.     id$(9, 1) = "   ±±  ±±"
  258.  
  259.     id$(10, 0) = "±±± ± ±±±"
  260.     id$(10, 1) = "± ±±±±± ±"
  261.  
  262.     id$(11, 0) = "  ±  ±±±±"
  263.     id$(11, 1) = "±±±  ±  ±"
  264.     id$(11, 2) = "±±±±  ±  "
  265.     id$(11, 3) = "±  ±  ±±±"
  266.  
  267.     id$(12, 0) = " ± ±±± ± "
  268.  
  269.     id$(13, 0) = "   ±± ±±±"
  270.     id$(13, 1) = "  ± ±± ±±"
  271.     id$(13, 2) = "   ±±± ±±"
  272.     id$(13, 3) = "±± ±± ±  "
  273.  
  274.     id$(14, 0) = "    ±±±±±"
  275.     id$(14, 1) = "±± ±±  ± "
  276.     id$(14, 2) = "   ±±±±± "
  277.     id$(14, 3) = " ±  ±± ±±"
  278.  
  279.     id$(15, 0) = " ± ±±±± ±"
  280.     id$(15, 1) = " ±±±±  ±±"
  281.     id$(15, 2) = "± ±±±± ± "
  282.     id$(15, 3) = "±±  ±±±± "
  283.  
  284.     id$(16, 0) = "   ±± ±± "
  285.  
  286.     id$(17, 0) = "    ±    "
  287.  
  288.     id$(18, 0) = "   ±±    "
  289.     id$(18, 1) = "    ±  ± "
  290.  
  291.  
  292.     FOR t = 0 TO 20: kep$(t) = " Ű                Ű ": NEXT t
  293.     kep$(21) = " " + STRING$(18, "Ű") + " "
  294.  
  295.     xkep$(0) = " ŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰ "
  296.     xkep$(1) = " ۰°°°°°°°°°°°°°°°Ű "
  297.     xkep$(2) = " ۰°           °°°Ű "
  298.     xkep$(3) = " ۰             °°Ű "
  299.     xkep$(4) = " Ű  T E T R I S  °Ű "
  300.     xkep$(5) = " Ű               °Ű "
  301.     xkep$(6) = " Ű    G A M E    °Ű "
  302.     xkep$(7) = " ۰             °°Ű "
  303.     xkep$(8) = " ۰°           °°°Ű "
  304.     xkep$(9) = " ۰°°°°°°°°°°°°°°°Ű "
  305.     xkep$(10) = " ۰(C)T˘TH GYULA °Ű "
  306.     xkep$(11) = " ۰  1997-12-30  °Ű "
  307.     xkep$(12) = " ۰°°°°°°°°°°°°°°°Ű "
  308.     xkep$(13) = " ۰U - new game°°°Ű "
  309.     xkep$(14) = " ۰°°°°°°°°°°°°°°°Ű "
  310.     xkep$(15) = " ۰I - characters°Ű "
  311.     xkep$(16) = " ۰°°°°°°°view°°°°Ű "
  312.     xkep$(17) = " ۰°°°°°°°°°°°°°°°Ű "
  313.     xkep$(18) = " ۰K - exit°°°°°°°Ű "
  314.     xkep$(19) = " ۰°°from game°°°°Ű "
  315.     xkep$(20) = " ۰°°°°°°°°°°°°°°°Ű "
  316.     xkep$(21) = " ŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰŰ "
  317.  
  318.  
  319.  
  320. SUB kepprn (kep$())
  321.     FOR t = 0 TO 21: LOCATE 2 + t, 31: PRINT kep$(t);: NEXT t
  322.  
Title: Re: i suffer
Post by: MasterGy on March 07, 2021, 05:30:16 am
I have tried this too, although I have seen a similar one here

Code: QB64: [Select]
  1.  
  2. gdb = 100 'number of balls
  3. gsugar = 15 'radius of balls
  4. ero = 2 'energy
  5.  
  6. ' use a smaller radius for more balls
  7.  
  8. DIM ball(gdb - 1, 3) 'ball array index 0=posX  1=posY  2=forceX  3=forceY
  9. kepx = 800: kepy = 600: kep = _NEWIMAGE(kepx, kepy, 32): SCREEN kep
  10.  
  11. 'install random ball
  12. FOR t = 0 TO gdb - 1
  13.     masikpoz:
  14.     ball(t, 0) = (kepx - gsugar * 4) * RND(1) + gsugar * 2
  15.     ball(t, 1) = (kepy - gsugar * 4) * RND(1) + gsugar * 2
  16.     FOR t2 = 0 TO gdb - 1
  17.         tavx = ball(t, 0) - ball(t2, 0): tavy = ball(t, 1) - ball(t2, 1): tav = SQR(tavx * tavx + tavy * tavy)
  18.         IF (tav <= gsugar * 2) AND t <> t2 THEN GOTO masikpoz
  19.     NEXT t2
  20.  
  21.  
  22. 'to give energy to one of the balls
  23. szog = 360 * RND(1)
  24. ball(0, 2) = SIN(3.14159265 / 180 * szog) * ero
  25. ball(0, 3) = COS(3.14159265 / 180 * szog) * ero
  26.  
  27.  
  28.  
  29. DO: _LIMIT 500: CLS
  30.  
  31.     'wall impact test
  32.     FOR t = 0 TO gdb - 1
  33.         ujra:
  34.         kx = ball(t, 0) + ball(t, 2)
  35.         ky = ball(t, 1) + ball(t, 3)
  36.         IF kx < gsugar OR kx > kepx - gsugar THEN ball(t, 2) = -ball(t, 2)
  37.         IF ky < gsugar OR ky > kepy - gsugar THEN ball(t, 3) = -ball(t, 3)
  38.         ball(t, 0) = ball(t, 0) + ball(t, 2)
  39.         ball(t, 1) = ball(t, 1) + ball(t, 3)
  40.     NEXT t
  41.  
  42.     'ball crash test
  43.     FOR t = 0 TO gdb - 1
  44.         FOR t2 = t + 1 TO gdb - 1
  45.             tavx = ball(t, 0) - ball(t2, 0)
  46.             tavy = ball(t, 1) - ball(t2, 1)
  47.             tav = SQR(tavx * tavx + tavy * tavy)
  48.             IF (tav <= gsugar * 2) AND t2 <> t THEN
  49.  
  50.                 utk = utk + 1
  51.                 angle = ATN((ball(t2, 1) - ball(t, 1)) / (ball(t2, 0) - ball(t, 0)))
  52.                 ex1 = ball(t, 2) * COS(-angle) - ball(t, 3) * SIN(-angle)
  53.                 ey1 = ball(t, 2) * SIN(-angle) + ball(t, 3) * COS(-angle)
  54.                 ex2 = ball(t2, 2) * COS(-angle) - ball(t2, 3) * SIN(-angle)
  55.                 ey2 = ball(t2, 2) * SIN(-angle) + ball(t2, 3) * COS(-angle)
  56.                 ball(t, 2) = ex2 * COS(angle) - ey1 * SIN(angle)
  57.                 ball(t, 3) = ex2 * SIN(angle) + ey1 * COS(angle)
  58.                 ball(t2, 2) = ex1 * COS(angle) - ey2 * SIN(angle)
  59.                 ball(t2, 3) = ex1 * SIN(angle) + ey2 * COS(angle)
  60.  
  61.             END IF
  62.     NEXT t2, t
  63.     'draw
  64.     FOR t = 0 TO gdb - 1
  65.     CIRCLE (ball(t, 0), ball(t, 1)), gsugar: NEXT t
  66.     LOCATE 1, 1: PRINT "crash:"; utk
  67.     _DISPLAY
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
Title: Re: i suffer
Post by: xra7en on March 08, 2021, 08:24:10 pm
Hello ! I'm bored.

Hi bored :P
I have a good project I have not seen anyone tackle yet, (I will be shortly), Create a routine to display THEDRAW images :-)
If you dont know what those are you might be too young heheh
I love using THEDRAW and would love to implement the results in my QB projects.

there ya go -

seeeee, now ya not so bored
Title: Re: i suffer
Post by: bplus on March 08, 2021, 09:02:15 pm
Oh check out Boids on the Internet, that's a cool one too!
Title: Re: i suffer
Post by: xra7en on March 08, 2021, 09:22:38 pm
Oh check out Boids on the Internet, that's a cool one too!

GAWD!!! TYVM for not saying "G****" it"

what is boids? all i see is some AI life gen proggy
Title: Re: i suffer
Post by: bplus on March 09, 2021, 02:32:56 am
Here is my attempt at Boids from some time ago, watch where you point the mouse it scares them off!

Code: QB64: [Select]
  1. _Title "Boid Watching 3  by bplus 2018-09-07"
  2. 'QB64 version 2017 1106/82 (the day before they switched to version 1.2)
  3. 'from Boid Watching.bas for QB64 version 2017 1106/82 B+ 2018-04-28
  4. 'from Boid Watching.txt for JB 2.0 B+ 2018-04-28
  5. 'from networking.bas  SmallBASIC 0.12.9 [B+=MGA] 2017-04-14
  6. ' combined with
  7. 'Mouse school critter attract or repell.txt for JB 2.0 B+ 2018-04-26
  8. ' plus what I picked up generally from the videos
  9.  
  10. '2018-09-07 try a quick fix
  11.  
  12. Const xmax = 1200
  13. Const ymax = 700
  14. Screen _NewImage(xmax, ymax, 32)
  15. _ScreenMove 100, 40
  16.  
  17.  
  18. 'Boid behavior based on several modes
  19.  
  20. centerMode = 1 ' on / off
  21. cf = .01 'centering factor how strong a pull from 0 to 1  .01 is week .1 pretty strong!
  22.  
  23. headMode = 1 ' on / off
  24. sway = _Pi / 6 'just turn neighbor towards neighbor
  25. hf = .2 'heading factor how strong an influence  0 to 1
  26.  
  27. spaceMode = 1 ' on / off
  28. spacing = 15 'space amount approx
  29.  
  30. noise = 10 'general randomness added to movements individualism
  31.  
  32. Boids = 50
  33.  
  34. Dim Shared x(Boids), y(Boids), z(Boids), a(Boids), r(Boids), c(Boids) As _Unsigned Long, predator
  35.  
  36. For i = 1 To Boids
  37.     newCritter i
  38.  
  39. land& = _NewImage(xmax, ymax, 32)
  40. _Dest land&
  41. drawLandscape
  42.  
  43.     _PutImage , land&, 0
  44.     If InKey$ = "q" Then End
  45.     For i = 1 To Boids
  46.         m = _MouseInput: mb = _MouseButton(1): mx = _MouseX: my = _MouseY
  47.  
  48.         For j = i + 1 To Boids
  49.  
  50.             If distance(x(i), y(i), x(j), y(j)) < 100 Then
  51.  
  52.                 'sway the neighbors towards each other
  53.                 If headMode Then
  54.                     If a(i) > a(j) Then
  55.                         a(i) = a(i) - sway * hf
  56.                         a(j) = a(j) + sway * hf
  57.                     Else
  58.                         a(i) = a(i) + sway * hf
  59.                         a(j) = a(j) - sway * hf
  60.                     End If
  61.                 End If
  62.  
  63.                 'stickiness stay close to neighbors, close distance between
  64.                 If centerMode Then
  65.                     If x(i) > x(j) Then
  66.                         x(i) = x(i) - cf * (x(i) - x(j))
  67.                         x(j) = x(j) + cf * (x(i) - x(j))
  68.                     Else
  69.                         x(i) = x(i) + cf * (x(j) - x(i))
  70.                         x(j) = x(j) - cf * (x(j) - x(i))
  71.                     End If
  72.                     If y(i) > y(j) Then
  73.                         y(i) = y(i) - cf * (y(i) - y(j))
  74.                         y(j) = y(j) + cf * (y(i) - y(j))
  75.                     Else
  76.                         y(i) = y(i) + cf * (y(j) - y(i))
  77.                         y(j) = y(j) - cf * (y(j) - y(i))
  78.                     End If
  79.                 End If
  80.  
  81.                 'don't let them bunch up
  82.                 If spaceMode Then
  83.                     ' The following is STATIC's adjustment of ball positions if overlapping
  84.                     ' before calcultion of new positions from collision
  85.                     ' Displacement vector and its magnitude.  Thanks STxAxTIC !
  86.                     nx = x(j) - x(i)
  87.                     ny = y(j) - y(i)
  88.                     nm = Sqr(nx ^ 2 + ny ^ 2)
  89.                     If nm < spacing + 20 Then
  90.                         nx = nx / nm
  91.                         ny = ny / nm
  92.                         ' Regardless of momentum exchange, separate the balls along the lone connecting them.
  93.                         While nm < spacing + 30
  94.                             x(j) = x(j) + .1 * spacing * nx
  95.                             y(j) = y(j) + .1 * spacing * ny
  96.                             x(i) = x(i) - .1 * spacing * nx
  97.                             y(i) = y(i) - .1 * spacing * ny
  98.                             nx = x(j) - x(i)
  99.                             ny = y(j) - y(i)
  100.                             nm = Sqr(nx ^ 2 + ny ^ 2)
  101.                             nx = nx / nm
  102.                             ny = ny / nm
  103.                         Wend
  104.                     End If 'spacer
  105.                 End If 'space Mode
  106.             End If 'distance
  107.         Next
  108.         'IF y(i) < 30 OR y(i) > ymax - 30 THEN a(i) = a(i) + sway
  109.         'out of sight
  110.         If x(i) < -1 * r(i) Or x(i) > xmax + r(i) Or y(i) < -1 * r(i) Or y(i) > ymax + r(i) Then 'start new
  111.             newCritter i
  112.         End If
  113.         If distance(x(i), y(i), mx, my) < 75 Then
  114.             a(i) = _Atan2(my - y(i), mx - x(i)) + _Pi
  115.             predatorMode = 1
  116.         Else
  117.             predatorMode = 0
  118.         End If
  119.  
  120.         'update points
  121.         x(i) = x(i) + 10 * Cos(a(i)) + Rnd * noise - .5 * noise
  122.         y(i) = y(i) + 10 * Sin(a(i)) + Rnd * noise - .5 * noise
  123.  
  124.         drawBoid i
  125.  
  126.     Next
  127.     'mouse predator
  128.     'COLOR _RGB32(160, 0, 0)
  129.     'fcirc mx, my, 25
  130.  
  131.     _Display
  132.     _Limit 20
  133.  
  134. Sub newCritter (index)
  135.     side = rand(2, 3)
  136.     Select Case side
  137.         Case 0 'right
  138.             x(index) = rand(xmax, xmax + 100)
  139.             y(index) = rand(20, ymax - 20)
  140.             a(index) = _D2R(rand(100, 260))
  141.         Case 2 'left
  142.             x(index) = rand(-100, 0)
  143.             y(index) = rand(20, ymax - 20)
  144.             a(index) = _D2R(rand(-80, 80))
  145.  
  146.         Case 1 'from above
  147.             x(index) = rand(20, xmax - 20)
  148.             y(index) = rand(-100, 0)
  149.             a(index) = _D2R(rand(10, 170))
  150.  
  151.         Case 3 'from below
  152.             x(index) = rand(20, xmax - 20)
  153.             y(index) = rand(ymax, ymax + 100)
  154.             a(index) = _D2R(rand(190, 350))
  155.  
  156.     End Select
  157.     z(index) = Rnd * .6 + .4
  158.     r(index) = rand(10, 12)
  159.     r = rand(10 + Int(z(i) * 40), 40 + Int(z(i) * 40))
  160.     c(index) = _RGB32(r, r, r)
  161.  
  162. 'SUB critter (i)
  163. '    COLOR c&(i)
  164. '    'fcirc x(i), y(i), r(i)
  165. '    IF predator THEN
  166. '        x1 = x(i) + .75 * r(i) * COS(a(i) - _PI(1 / 9) + _PI)
  167. '        y1 = y(i) + .75 * r(i) * SIN(a(i) - _PI(1 / 9) + _PI)
  168. '        x2 = x(i) + .75 * r(i) * COS(a(i) + _PI(1 / 9) + _PI)
  169. '        y2 = y(i) + .75 * r(i) * SIN(a(i) + _PI(1 / 9) + _PI)
  170. '    ELSE
  171. '        x1 = x(i) + .75 * r(i) * COS(a(i) - _PI(1 / 9))
  172. '        y1 = y(i) + .75 * r(i) * SIN(a(i) - _PI(1 / 9))
  173. '        x2 = x(i) + .75 * r(i) * COS(a(i) + _PI(1 / 9))
  174. '        y2 = y(i) + .75 * r(i) * SIN(a(i) + _PI(1 / 9))
  175. '    END IF
  176. '    COLOR _RGB32(255, 255, 255)
  177. '    ' fcirc x1, y1, .25 * r(i)
  178. '    'fcirc x2, y2, .25 * r(i)
  179. '    IF predator THEN
  180. '        x3 = x1 + .125 * r(i) * COS(a(i) + _PI)
  181. '        y3 = y1 + .125 * r(i) * SIN(a(i) + _PI)
  182. '        x4 = x2 + .125 * r(i) * COS(a(i) + _PI)
  183. '        y4 = y2 + .125 * r(i) * SIN(a(i) + _PI)
  184. '    ELSE
  185. '        x3 = x1 + .125 * r(i) * COS(a(i))
  186. '        y3 = y1 + .125 * r(i) * SIN(a(i))
  187. '        x4 = x2 + .125 * r(i) * COS(a(i))
  188. '        y4 = y2 + .125 * r(i) * SIN(a(i))
  189. '    END IF
  190. '    COLOR _RGB32(0, 0, 0)
  191. '    ' fcirc x3, y3, .125 * r(i)
  192. '    'fcirc x4, y4, .125 * r(i)
  193. 'END SUB
  194.  
  195. Sub drawBoid (i)
  196.     r = Rnd * _Pi(1 / 4) 'flapping
  197.     w = _Pi(7 / 12)
  198.     If predator Then
  199.         x1 = x(i) + z(i) * r(i) * Cos(a(i) + _Pi)
  200.         y1 = y(i) + z(i) * r(i) * Sin(a(i) + _Pi)
  201.         x2 = x(i) + z(i) * r(i) * Cos(a(i) + _Pi + w + r)
  202.         y2 = y(i) + z(i) * r(i) * Sin(a(i) + _Pi + w + r)
  203.         x3 = x(i) + z(i) * r(i) * Cos(a(i) + _Pi - w - r)
  204.         y3 = y(i) + z(i) * r(i) * Sin(a(i) + _Pi - w - r)
  205.  
  206.     Else
  207.         x1 = x(i) + z(i) * r(i) * Cos(a(i))
  208.         y1 = y(i) + z(i) * r(i) * Sin(a(i))
  209.         x2 = x(i) + z(i) * r(i) * Cos(a(i) + w + r)
  210.         y2 = y(i) + z(i) * r(i) * Sin(a(i) + w + r)
  211.         x3 = x(i) + z(i) * r(i) * Cos(a(i) - w - r)
  212.         y3 = y(i) + z(i) * r(i) * Sin(a(i) - w - r)
  213.     End If
  214.     filltri x(i), y(i), x1, y1, x2, y2, c(i)
  215.     filltri x(i), y(i), x1, y1, x3, y3, c(i)
  216.  
  217. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  218. Sub filltri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
  219.     a& = _NewImage(1, 1, 32)
  220.     _Dest a&
  221.     PSet (0, 0), K
  222.     _Dest 0
  223.     _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
  224.     _FreeImage a& '<<< this is important!
  225.  
  226. ''Steve McNeil's  copied from his forum   note: Radius is too common a name
  227. 'SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  228. '    DIM subRadius AS LONG, RadiusError AS LONG
  229. '    DIM X AS LONG, Y AS LONG
  230.  
  231. '    subRadius = ABS(R)
  232. '    RadiusError = -subRadius
  233. '    X = subRadius
  234. '    Y = 0
  235.  
  236. '    IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  237.  
  238. '    ' Draw the middle span here so we don't draw it twice in the main loop,
  239. '    ' which would be a problem with blending turned on.
  240. '    LINE (CX - X, CY)-(CX + X, CY), , BF
  241.  
  242. '    WHILE X > Y
  243. '        RadiusError = RadiusError + Y * 2 + 1
  244. '        IF RadiusError >= 0 THEN
  245. '            IF X <> Y + 1 THEN
  246. '                LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  247. '                LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  248. '            END IF
  249. '            X = X - 1
  250. '            RadiusError = RadiusError - X * 2
  251. '        END IF
  252. '        Y = Y + 1
  253. '        LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  254. '        LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  255. '    WEND
  256. 'END SUB
  257.  
  258. Function rand% (lo%, hi%)
  259.     rand% = Int(Rnd * (hi% - lo% + 1)) + lo%
  260.  
  261. Function distance (x1, y1, x2, y2)
  262.     distance = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5
  263.  
  264. Function rdir ()
  265.     If Rnd < .5 Then rdir = -1 Else rdir = 1
  266.  
  267. Sub drawLandscape
  268.     'the sky
  269.     For i = 0 To ymax
  270.         midInk 0, 0, 128, 128, 128, 255, i / ymax
  271.         Line (0, i)-(xmax, i)
  272.     Next
  273.     'the land
  274.     startH = ymax - 200
  275.     rr = 70: gg = 70: bb = 90
  276.     For mountain = 1 To 6
  277.         Xright = 0
  278.         y = startH
  279.         While Xright < xmax
  280.             ' upDown = local up / down over range, change along Y
  281.             ' range = how far up / down, along X
  282.             upDown = (Rnd * .8 - .35) * (mountain * .5)
  283.             range = Xright + rand(15, 25) * 2.5 / mountain
  284.             lastx = Xright - 1
  285.             For X = Xright To range
  286.                 y = y + upDown
  287.                 Color _RGB(rr, gg, bb)
  288.                 Line (lastx, y)-(X, ymax), , BF 'just lines weren't filling right
  289.                 lastx = X
  290.             Next
  291.             Xright = range
  292.         Wend
  293.         rr = rand(rr - 15, rr): gg = rand(gg - 15, gg): bb = rand(bb - 25, bb)
  294.         If rr < 0 Then rr = 0
  295.         If gg < 0 Then gg = 0
  296.         If bb < 0 Then bb = 0
  297.         startH = startH + rand(5, 20)
  298.     Next
  299.  
  300. Sub midInk (r1, g1, b1, r2, g2, b2, fr)
  301.     Color _RGB(r1 + (r2 - r1) * fr, g1 + (g2 - g1) * fr, b1 + (b2 - b1) * fr)
  302.  
Title: Re: i suffer
Post by: STxAxTIC on March 09, 2021, 02:49:48 am
Jeez bplus I'm amazed at how damn convincing the scenery looks given few lines of code it took to make it. Nice nice.
Title: Re: i suffer
Post by: bplus on March 09, 2021, 02:18:00 pm
Oh yeah, I think that landscape thing was something I picked up from Aurel, years *6 ago, much tinkering with colors and variable tweaks since.
Title: Re: i suffer
Post by: bplus on March 09, 2021, 07:00:26 pm
oh yeah, this might light someone's fire!

Code: QB64: [Select]
  1. _Title "Drawlandscape Parallax test" 'started 2019-03-27
  2. 'test if can get end of landscape level to start for big looping background
  3. '2019-03-27 a more gentle adjustment back to Mountain starting height for
  4. 'more seamless connect of back end to front
  5. '2019-03-27 start this file with parallax drawing test
  6.  
  7.  
  8. Screen _NewImage(800, 600, 32)
  9. _ScreenMove 100, 20
  10. Type parallaxType
  11.     handle As Long
  12.     rate As Single 'number of pixels per frame added to le (leading edge)
  13.     le As Single
  14. nLevels = 6
  15. Dim Shared para(1 To nLevels) As parallaxType
  16.  
  17. Dim Shared scape&
  18. LoadLandscape
  19. scapeWidth = _Width(para(1).handle)
  20. scapeHeight = _Height(para(1).handle)
  21.  
  22. While t < 6000
  23.     Cls
  24.     For i = 1 To nLevels
  25.         If para(i).le + 800 > scapeWidth Then
  26.             te = scapeWidth - para(i).le
  27.             _PutImage (0, 0)-(te, scapeHeight), para(i).handle, 0, (scapeWidth - te, 0)-(scapeWidth, scapeHeight)
  28.             _PutImage (te, 0)-(800, scapeHeight), para(i).handle, 0, (0, 0)-(800 - te, scapeHeight)
  29.  
  30.         Else
  31.             _PutImage (0, 0)-(800, scapeHeight), para(i).handle, 0, (para(i).le, 0)-(para(i).le + 800, scapeHeight)
  32.         End If
  33.  
  34.         para(i).le = para(i).le - para(i).rate
  35.         If para(i).le < 0 Then para(i).le = scapeWidth
  36.     Next
  37.     t = t + 1
  38.     _Display
  39.     _Limit 120
  40.  
  41. Sub LoadLandscape
  42.     cur& = _Dest
  43.     xmax = 800 * 3.25: ymax = 600
  44.     hdl& = 1
  45.     para(hdl&).handle = _NewImage(xmax, ymax, 32)
  46.     _Dest para(hdl&).handle
  47.  
  48.     For i = 0 To ymax
  49.         midInk 0, 0, 128, 128, 128, 200, i / ymax
  50.         Line (0, i)-(xmax, i)
  51.     Next
  52.     'the land
  53.     startH = ymax - 200
  54.     rr = 70: gg = 70: bb = 90
  55.     For mountain = 1 To nLevels
  56.         If mountain > 1 Then
  57.             para(mountain).handle = _NewImage(xmax, ymax, 32)
  58.             _Dest para(mountain).handle
  59.         End If
  60.         Xright = 0
  61.         y = startH
  62.         Color _RGB(rr, gg, bb)
  63.         While Xright < xmax - 50
  64.             ' upDown = local up / down over range, change along Y
  65.             ' range = how far up / down, along X
  66.             upDown = (Rnd * .8 - .4) * (mountain * .5)
  67.             range = Xright + rand%(15, 25) * 2.5 / mountain
  68.             If range > xmax - 50 Then range = xmax - 50
  69.             lastx = Xright - 1
  70.             For x = Xright To range 'need less flat tops
  71.                 test = y + upDown
  72.                 test2 = y - upDown
  73.                 If Abs(test - startH) < .13 * startH Then y = test Else y = test2: upDown = -upDown
  74.                 Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  75.                 lastx = x
  76.             Next
  77.             Xright = range
  78.         Wend
  79.         x = lastx + 1
  80.         dy = (startH - y) / 50 'more gentle adjustment back to start of screen
  81.         While x <= xmax
  82.             y = y + dy
  83.             Line (lastx, y)-(x, ymax), , BF 'just lines weren't filling right
  84.             lastx = x
  85.             x = x + 1
  86.         Wend
  87.         rr = rand%(rr - 15, rr): gg = rand%(gg - 15, gg): bb = rand%(bb - 25, bb)
  88.         If rr < 0 Then rr = 0
  89.         If gg < 0 Then gg = 0
  90.         If bb < 0 Then bb = 0
  91.         startH = startH + mountain * rand%(2, 10)
  92.         para(mountain).le = xmax - 800
  93.         para(mountain).rate = mountain * .5
  94.     Next
  95.     _Dest cur&
  96.  
  97. Function rand% (lo%, hi%)
  98.     rand% = Int(Rnd * (hi% - lo% + 1)) + lo%
  99.  
  100. Sub midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
  101.     Color _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)
  102.  
  103.  
Title: Re: i suffer
Post by: Aurel on March 10, 2021, 03:09:40 am
Yo Mark..
Boid...is really great with that landscape and birds..
could be nice intro for some game i think ...

second..Paralax...looks to me like
Mars rover movin' camera....but on night
really cool..

ps..that landscape i rgink that pjot(BaCon) made it first...
Title: Re: i suffer
Post by: MasterGy on March 13, 2021, 09:55:41 am
Hey BPLUS ! Landspace is VERY VERY GOOD !! inspiring !!! completely upset my brain! some game should be brought out of this, don't you think ????? don't be mad if you have plans for it, then I won't use your idea for anything!
Title: Re: i suffer
Post by: bplus on March 13, 2021, 10:56:11 am
@MasterGy

I am so glad you can see the potential of this demo. I look forward to seeing what you will do with it!
Title: Re: i suffer
Post by: Pete on March 13, 2021, 01:52:23 pm
2-D or not 2-D? That is the question.

If the world were flat, cats would be pushing us over the edge.

Pete


Title: Re: i suffer
Post by: bplus on March 13, 2021, 02:03:11 pm
If the world weren't flat Flappy could fly around the pipes :-))
Title: Re: i suffer
Post by: Pete on March 14, 2021, 12:22:51 am
Put a moose in thar and sum cross hairs an ye got youself a real fun shootin game, varmint!

 - Sam
Title: Re: i suffer
Post by: bplus on March 14, 2021, 02:54:49 pm
Put a moose in thar and sum cross hairs an ye got youself a real fun shootin game, varmint!

 - Sam

Or maybe a horse that looks allot like somebodies else logo, and don't horse around by shooting at them, race them.
Title: Re: i suffer
Post by: Pete on March 14, 2021, 03:15:03 pm
Hey, I could program that in SCREEN 0. Of course it would be a horse's ascii.

Pete
Title: Re: i suffer
Post by: MasterGy on March 15, 2021, 07:03:04 am
infinite space illusion .control WASD and mouse

Code: QB64: [Select]
  1. DIM col(99) AS _INTEGER64, tris(19999, 10), points(19999, 10), cam(19), me(19)
  2. dim_s = 1000 'size of space
  3. max_vol = .4 'kocka darabszam a dim_s-hez kepest szazalekban
  4. d_min = 4 'csucs min
  5. d_max = 7 'csucs max
  6. r_min = 50 'legkisebb sugar
  7. r_max = 50 'legnagyobb_sugar
  8. rot_min = 1 / 100 'forgatas min sebesseg
  9. rot_max = 2 / 100 'forgatas max sebesseg
  10. sp_kalib = 3
  11. sp_min = .5 * sp_kalib
  12. sp_max = 2.5 * sp_kalib
  13.  
  14. crash = 1
  15. text_c = 50
  16. text_d = 150
  17. text_m = 7
  18. text_col = 70
  19.  
  20. msenx = .05 'mouse sensitive XY
  21. msenz = .08 'mouse sensitive Z
  22.  
  23. pre_calc = 2 'calculation for step multiplier impact test
  24. stepping = 10 'movement speed
  25. max_couch = 70 'correct angle of impact tolerance
  26. zoom_calib = .01
  27. zoom_xy = 20 * zoom_calib '_maptriangle multiplier XY
  28. zoom_distance = 60 * zoom_calib 'maptriangle multiplier Z (as large as fisheye optics)
  29.  
  30.  
  31.  
  32.  
  33. pip180 = _PI / 180
  34.  
  35. '-------------------------------------------------------------------------------------------------------------------------------------------------------
  36.  
  37. 'creating textures
  38. FOR t = 0 TO text_col - 1: col(t) = _RGB32(256 * RND(1), 256 * RND(1), 256 * RND(1)): NEXT t 'set object colors
  39. DIM text(text_c - 1)
  40. FOR t = 0 TO text_c - 1: temp = _NEWIMAGE(text_d, text_d, 32): _DEST temp: CLS
  41.     LINE (text_m, text_m)-(text_d - 1 - text_m, text_d - 1 - text_m), col(INT(text_col * RND(1))), BF
  42.     text(t) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  43.  
  44. 'creating 3d points
  45. DIM ob(9999, 19)
  46. DO WHILE volume_sum < dim_s ^ 3 / 100 * max_vol
  47.  
  48.     DO: re = 0: 'hova, es mekkora ?
  49.         ob(a_ob, 0) = INT(d_min + (d_max - d_min) * RND(1)) 'resolution 360/da degree horisontal DA
  50.         ob(a_ob, 1) = INT(d_min + (d_max - d_min) * RND(1)) 'resolution 360/db degree vertical     DB
  51.         ob(a_ob, 2) = points 'start ponits
  52.         ob(a_ob, 3) = r_min + (r_max - r_min) * RND(1) 'sugar
  53.         FOR t = 4 TO 6: ob(a_ob, t) = ob(a_ob, 3) + (dim_s - ob(a_ob, 3) * 2) * RND(1): NEXT t
  54.         IF a_ob THEN
  55.             FOR t = 0 TO a_ob - 1
  56.                 dis1 = ((ob(a_ob, 4) - ob(t, 4)) ^ 2 + (ob(a_ob, 5) - ob(t, 5)) ^ 2 + (ob(a_ob, 6) - ob(t, 6)) ^ 2)
  57.                 dis2 = (ob(a_ob, 3) + ob(t, 3)) ^ 2
  58.                 re = re OR (dis2 > dis1)
  59.             NEXT t
  60.         END IF
  61.     LOOP WHILE re
  62.     FOR t = 7 TO 9: ob(a_ob, t) = rot_min + (rot_max - rot_min) * RND(1): NEXT t 'random rotating arrow,speed
  63.     FOR t = 10 TO 12: ob(a_ob, t) = 360 * RND(1): NEXT t 'actual rotate
  64.     ob(a_ob, 14) = 360 * RND(1) 'radA arrow random
  65.     ob(a_ob, 15) = 360 * RND(1) 'radB arrow random
  66.     ob(a_ob, 16) = sp_min + (sp_max - sp_min) * RND(1) 'random speed
  67.  
  68.  
  69.     'creating squares
  70.     FOR da2 = 0 TO ob(a_ob, 0) - 2: FOR db2 = 0 TO ob(a_ob, 1) - 2
  71.             p0 = da2 * ob(a_ob, 1) + db2 + ob(a_ob, 2): p1 = p0 + 1: p2 = p0 + ob(a_ob, 1): p3 = p2 + 1: text_act = INT(text_c * RND(1))
  72.             tris(triangles, 0) = 1: tris(triangles, 1) = p0: tris(triangles, 2) = p1: tris(triangles, 3) = p2: tris(triangles, 4) = 0: tris(triangles, 5) = 0
  73.             tris(triangles, 6) = text_d - 1: tris(triangles, 7) = 0: tris(triangles, 8) = 0: tris(triangles, 9) = text_d - 1: tris(triangles, 10) = text_act
  74.             triangles = triangles + 1
  75.             tris(triangles, 0) = 1: tris(triangles, 1) = p3: tris(triangles, 2) = p1: tris(triangles, 3) = p2: tris(triangles, 4) = text_d - 1
  76.             tris(triangles, 5) = text_d - 1: tris(triangles, 6) = text_d - 1: tris(triangles, 7) = 0: tris(triangles, 8) = 0: tris(triangles, 9) = text_d - 1: tris(triangles, 10) = text_act
  77.             triangles = triangles + 1
  78.     NEXT db2, da2
  79.  
  80.     points = points + ob(a_ob, 0) * ob(a_ob, 1)
  81.     volume_sum = volume_sum + (4 * ob(a_ob, 3) ^ 3 * _PI / 3)
  82.     a_ob = a_ob + 1
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. DO: _LIMIT 100
  92.  
  93.     'control
  94.     kw = _KEYDOWN(119) OR _MOUSEBUTTON(1): ks = _KEYDOWN(115) OR _MOUSEBUTTON(2): ka = _KEYDOWN(97): kd = _KEYDOWN(100): et_ir = (ABS(ka OR kd OR kw) OR -ABS(ks))
  95.     ir = 0: IF inv_me10 = -1 THEN SWAP ka, kd
  96.     FOR elt1 = 0 TO max_couch STEP 2: FOR elt2 = 0 TO 360 STEP 12: IF ir = 0 THEN
  97.                 elt_xy = SIN(elt2 * pip180) * elt1: elt_z = COS(elt2 * pip180) * elt1
  98.                 szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd): szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180: szog_z = me(11) + pip180 * (90 + elt_z)
  99.                 irx = -SIN(szog_xy) * COS(szog_z): iry = -COS(szog_xy) * COS(szog_z): irz = SIN(szog_z): ir = et_ir: multi = stepping * ir * pre_calc * 2
  100.                 multi = stepping * ir / max_couch * (max_couch - elt1): me(0) = me(0) + irx * multi: me(1) = me(1) + iry * multi
  101.     me(2) = me(2) + irz * multi: END IF: NEXT elt2, elt1
  102.  
  103.     mousex = 0: mousey = 0: WHILE _MOUSEINPUT: mousex = mousex + _MOUSEMOVEMENTX: mousey = mousey + _MOUSEMOVEMENTY: WEND: me(11) = me(11) + mousey / 7 * msenz
  104.     me(11) = me(11) - 2 * _PI * ABS(me(11) > 2 * _PI): me(11) = me(11) + 2 * _PI * ABS(me(11) < 0): inv_me10 = 1: IF me(11) < _PI THEN inv_me10 = -1
  105.     me(10) = me(10) + mousex / 5 * msenx * inv_me10
  106.  
  107.  
  108.     FOR t = 0 TO 2
  109.         IF me(t) < 0 THEN me(t) = me(t) + dim_s
  110.         IF me(t) > dim_s - 1 THEN me(t) = me(t) - dim_s
  111.     NEXT t
  112.  
  113.  
  114.  
  115.  
  116.     'calculating objection points
  117.     FOR act_ob = 0 TO a_ob - 1
  118.         FOR da2 = 0 TO ob(act_ob, 0) - 1: dega = (360 / (ob(act_ob, 0) - 1) * da2) * pip180
  119.             FOR db2 = 0 TO ob(act_ob, 1) - 1: degb = (180 / (ob(act_ob, 1) - 1) * db2) * pip180
  120.                 ap = da2 * ob(act_ob, 1) + db2 + ob(act_ob, 2)
  121.                 x1 = SIN(degb) * COS(dega): y1 = SIN(degb) * SIN(dega): z1 = COS(degb)
  122.                 x2 = (x1 * COS(ob(act_ob, 12))) - (y1 * SIN(ob(act_ob, 12))): y2 = (x1 * SIN(ob(act_ob, 12))) + (y1 * COS(ob(act_ob, 12)))
  123.                 x3 = (x2 * COS(ob(act_ob, 11))) - (z1 * SIN(ob(act_ob, 11))): z2 = (x2 * SIN(ob(act_ob, 11))) + (z1 * COS(ob(act_ob, 11)))
  124.                 y3 = (y2 * COS(ob(act_ob, 10))) - (z2 * SIN(ob(act_ob, 10))): z3 = (y2 * SIN(ob(act_ob, 10))) + (z2 * COS(ob(act_ob, 10)))
  125.                 points(ap, 1) = x3 * ob(act_ob, 3) + ob(act_ob, 4)
  126.                 points(ap, 2) = y3 * ob(act_ob, 3) + ob(act_ob, 5)
  127.                 points(ap, 3) = z3 * ob(act_ob, 3) + ob(act_ob, 6)
  128.     NEXT db2, da2, act_ob
  129.  
  130.  
  131.  
  132.  
  133.  
  134.     'calculating view
  135.     me(5) = 0
  136.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2
  137.     cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
  138.     cam(2) = me(2) + me(5) / 4
  139.     cam(3) = me(10)
  140.     cam(4) = me(11)
  141.     cosrotz = COS(cam(3)): sinrotz = SIN(cam(3)): cosrotx = COS(cam(4)): sinrotx = SIN(cam(4))
  142.  
  143.     nei = 1
  144.     FOR cx = -nei TO nei: cx2 = cx * dim_s: FOR cy = -nei TO nei: cy2 = cy * dim_s: FOR cz = -nei TO nei: cz2 = cz * dim_s
  145.  
  146.                 FOR actual_point = 0 TO points - 1: IF points(actual_point, 1) THEN
  147.                         px = points(actual_point, 1) - cam(0) + cx2
  148.                         py = points(actual_point, 2) - cam(1) + cy2
  149.                         pz2 = points(actual_point, 3) - cam(2) + cz2
  150.                         px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = py2 * sinrotx + pz2 * cosrotx
  151.                 points(actual_point, 4) = -px3 * zoom_xy: points(actual_point, 5) = -py3 * zoom_xy: points(actual_point, 6) = -pz3 * zoom_distance: END IF: NEXT actual_point
  152.  
  153.                 'drawing triangles
  154.                 FOR actual_triangle = 0 TO triangles - 1
  155.                     wx1 = points(tris(actual_triangle, 1), 4): wy1 = points(tris(actual_triangle, 1), 5): wz1 = points(tris(actual_triangle, 1), 6)
  156.                     wx2 = points(tris(actual_triangle, 2), 4): wy2 = points(tris(actual_triangle, 2), 5): wz2 = points(tris(actual_triangle, 2), 6)
  157.                     wx3 = points(tris(actual_triangle, 3), 4): wy3 = points(tris(actual_triangle, 3), 5): wz3 = points(tris(actual_triangle, 3), 6)
  158.                     sx1 = tris(actual_triangle, 4): sy1 = tris(actual_triangle, 5)
  159.                     sx2 = tris(actual_triangle, 6): sy2 = tris(actual_triangle, 7)
  160.                     sx3 = tris(actual_triangle, 8): sy3 = tris(actual_triangle, 9)
  161.  
  162.  
  163.                     _MAPTRIANGLE (sx1, sy1)-(sx2, sy2)-(sx3, sy3), text(tris(actual_triangle, 10)) TO(wx1, wy1, wz1)-(wx2, wy2, wz2)-(wx3, wy3, wz3), , _SMOOTH
  164.  
  165.                 NEXT actual_triangle
  166.     NEXT cz, cy, cx
  167.     _DISPLAY: CLS
  168.  
  169.     'moving/rotating objects
  170.     FOR act_ob = 0 TO a_ob - 1
  171.         FOR t = 0 TO 2: ob(act_ob, 10 + t) = ob(act_ob, 10 + t) + ob(act_ob, 7 + t): NEXT t 'rotating
  172.  
  173.         DO
  174.             ar(0) = SIN(ob(act_ob, 15)) * COS(ob(act_ob, 14)): ar(1) = SIN(ob(act_ob, 15)) * SIN(ob(act_ob, 14)): ar(2) = COS(ob(act_ob, 15))
  175.             FOR t = 0 TO 2
  176.                 poss(t) = ob(act_ob, 4 + t) + ar(t) * ob(act_ob, 16)
  177.                 IF poss(t) < 0 THEN poss(t) = poss(t) + dim_s
  178.                 IF poss(t) > dim_s THEN poss(t) = poss(t) - dim_s
  179.             NEXT t
  180.             re = 0
  181.             IF crash THEN
  182.  
  183.                 FOR an = 0 TO a_ob - 1: IF an = act_ob THEN _CONTINUE
  184.                     dis2 = (ob(an, 3) + ob(act_ob, 3))
  185.                     IF ABS(poss(0) - ob(an, 4)) > dis2 THEN _CONTINUE
  186.                     IF ABS(poss(1) - ob(an, 5)) > dis2 THEN _CONTINUE
  187.                     IF ABS(poss(2) - ob(an, 6)) > dis2 THEN _CONTINUE
  188.                     dis1 = SQR((poss(0) - ob(an, 4)) ^ 2 + (poss(1) - ob(an, 5)) ^ 2 + (poss(2) - ob(an, 6)) ^ 2)
  189.                     re = (dis2 > dis1): IF re THEN EXIT FOR
  190.                 NEXT an
  191.  
  192.                 IF re THEN
  193.                     ob(act_ob, 14) = 360 * RND(1) 'radA arrow random
  194.                     ob(act_ob, 15) = 360 * RND(1) 'radB arrow random
  195.                     ob(act_ob, 16) = sp_min + (sp_max - sp_min) * RND(1) 'random speed
  196.                     FOR t = 7 TO 9: ob(act_ob, t) = rot_min + (rot_max - rot_min) * RND(1): NEXT t 'random rotating arrow,speed
  197.                 END IF
  198.             END IF
  199.         LOOP WHILE re
  200.  
  201.         FOR t = 0 TO 2: ob(act_ob, 4 + t) = poss(t): NEXT t
  202.  
  203.     NEXT act_ob
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
Title: Re: i suffer
Post by: bplus on March 15, 2021, 03:48:30 pm
@MasterGy  That! is an interesting start to something but something is a bit off, not sure what, are you sensing it?

Plus I am giving giving you a ticket for all the double, triple, quadruple, quin... parking you are doing here:
Code: QB64: [Select]
  1.     'control
  2.     kw = _KEYDOWN(119) OR _MOUSEBUTTON(1): ks = _KEYDOWN(115) OR _MOUSEBUTTON(2): ka = _KEYDOWN(97): kd = _KEYDOWN(100): et_ir = (ABS(ka OR kd OR kw) OR -ABS(ks))
  3.     ir = 0: IF inv_me10 = -1 THEN SWAP ka, kd
  4.     FOR elt1 = 0 TO max_couch STEP 2: FOR elt2 = 0 TO 360 STEP 12: IF ir = 0 THEN
  5.                 elt_xy = SIN(elt2 * pip180) * elt1: elt_z = COS(elt2 * pip180) * elt1
  6.                 szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd): szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180: szog_z = me(11) + pip180 * (90 + elt_z)
  7.                 irx = -SIN(szog_xy) * COS(szog_z): iry = -COS(szog_xy) * COS(szog_z): irz = SIN(szog_z): ir = et_ir: multi = stepping * ir * pre_calc * 2
  8.                 multi = stepping * ir / max_couch * (max_couch - elt1): me(0) = me(0) + irx * multi: me(1) = me(1) + iry * multi
  9.     me(2) = me(2) + irz * multi: END IF: NEXT elt2, elt1
  10.  

LOL!

szog? has me irx'd elt kw'd, pip180 at least! ;-))
Title: Re: i suffer
Post by: MasterGy on March 15, 2021, 03:58:31 pm
I'll tell you honestly that I've gathered so many programs that I've just flipped through the controls and the display system. (copy/paste form 3d maze) The part of the program you copied is meant to make you go and hit a wall, so don’t stop, but look for the nearest direction. The larger the deviation, the slower the step will be. There is no space detection here, so there is no function for this part, but you can expand the program with space detection in an instant.
Title: Re: i suffer
Post by: MasterGy on March 15, 2021, 04:25:05 pm
the larger the "try", so the deviation, the magnitude of the displacement, will be smaller. given by the "multi" variable. The drawing shows the operation in 2d, in the program in 3d.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: i suffer
Post by: MasterGy on March 29, 2021, 02:21:56 am
Here I wanted to see the spacecraft go and those rocks or planets, the bigger, the bigger their gravitational field. You can have fun with the mouse. The left mouse gives the gas to the spaceship. Here you can have fun with the landing, or when you pass a planet, you can feel how much you need to change the trajectory (drag your mouse) to avoid crashing. You can zoom with the mouse wheel.

Code: QB64: [Select]
  1. CONST pip180 = 3.141592654 / 180
  2.  
  3. global_speed = 1.5
  4. space_grav = 15
  5. space = 1000 'space size x-y
  6. planets = 600
  7. planetsize_min = 1
  8. planetsize_max = 12
  9. planet_dif = .05
  10. cr_c_max = 199
  11. zoom = 10
  12. me_buffer_size = 5000
  13.  
  14. 'creating 2d planet
  15. DIM cr(planets - 1, cr_c_max - 1, 1), cr_dat(planets - 1, 3), me_buffer(me_buffer_size - 1, 1)
  16. 'cd_dat 0-x,1-y,2-size,3-polars
  17. FOR aplanet = 0 TO planets - 1
  18.     cr_dat(aplanet, 2) = planetsize_min + (planetsize_max - planetsize_min) * RND(1) 'planet size
  19.     cr_l1 = (1 - planet_dif) * cr_dat(aplanet, 2)
  20.     cr_l2 = (1 + planet_dif) * cr_dat(aplanet, 2)
  21.     cr_dat(aplanet, 0) = space * RND(1) - space / 2 'X position
  22.     cr_dat(aplanet, 1) = space * RND(1) - space / 2 'Y position
  23.     cr_dat(aplanet, 3) = INT(cr_dat(aplanet, 2) * 6) 'polars
  24.  
  25.     FOR t = 0 TO cr_dat(aplanet, 3) - 1
  26.         cr_r = cr_l1 + (cr_l2 - cr_l1) * RND(1)
  27.         cr(aplanet, t, 0) = SIN(360 / cr_dat(aplanet, 3) * t * pip180) * cr_r
  28.         cr(aplanet, t, 1) = COS(360 / cr_dat(aplanet, 3) * t * pip180) * cr_r
  29. NEXT t, aplanet
  30.  
  31.  
  32.  
  33.  
  34. me_x = 0 'my Xpos
  35. me_y = 0 'my Ypos
  36. me_a = 30 'my angle
  37. me_size = 2 'arrow size
  38. me_size_a = .4
  39.  
  40. mon = _NEWIMAGE(800, 600, 32): SCREEN mon: _FULLSCREEN: _MOUSEHIDE
  41. centx = _WIDTH(mon) / 2: centy = _HEIGHT(mon) / 2
  42.  
  43.  
  44.  
  45.     'draw me
  46.     y1 = centy - me_size / 2 * zoom
  47.     y2 = y1 + me_size * zoom
  48.     LINE (centx, y1)-(centx, y2)
  49.     y2 = y1 + me_size_a * zoom
  50.     LINE (centx, y1)-(centx - me_size_a * zoom, y2)
  51.     LINE (centx, y1)-(centx + me_size_a * zoom, y2)
  52.  
  53.  
  54.     'my position center, but where any object ?
  55.  
  56.     grav_x = 0: grav_y = 0: grav_active = 0
  57.  
  58.     FOR aplanet = 0 TO planets - 1
  59.         angle1 = degree(me_x - cr_dat(aplanet, 0), me_y - cr_dat(aplanet, 1)) 'how many degree
  60.         angle2 = angle1 + angle_me '+arrow
  61.  
  62.         distance = SQR((me_x - cr_dat(aplanet, 0)) ^ 2 + (me_y - cr_dat(aplanet, 1)) ^ 2)
  63.  
  64.         cr_cx = (SIN(angle2 * pip180)) * distance 'planet origo position on monitor
  65.         cr_cy = (COS(angle2 * pip180)) * distance
  66.  
  67.         FOR t = 0 TO cr_dat(aplanet, 3)
  68.             IF t = cr_dat(aplanet, 3) THEN t2 = 0 ELSE t2 = t
  69.             px = cr(aplanet, t2, 0)
  70.             py = cr(aplanet, t2, 1)
  71.             angle_r = angle_me * pip180
  72.             px2 = (px * COS(angle_r)) + (py * SIN(angle_r))
  73.             py2 = (py * COS(angle_r)) - (px * SIN(angle_r))
  74.             px = (px2 + cr_cx) * zoom + centx
  75.             py = (py2 + cr_cy) * zoom + centy
  76.             IF t THEN LINE (px, py)-(px_l, py_l)
  77.             px_l = px: py_l = py
  78.         NEXT t
  79.  
  80.         'gravity planet
  81.         IF distance < space / 100 * space_grav THEN
  82.             grav_active = grav_active + 1
  83.             gravity = cr_dat(aplanet, 2) ^ 2 / distance ^ 2
  84.             'IF gravity > .01 THEN gravity = .01
  85.             grav_x = grav_x + SIN(angle1 * pip180) * gravity
  86.             grav_y = grav_y + COS(angle1 * pip180) * gravity
  87.  
  88.         END IF
  89.     NEXT aplanet
  90.  
  91.     'draw my way
  92.     FOR a_buff = 0 TO me_buffer_size - 1: IF me_buffer(a_buff, 0) = 0 THEN _CONTINUE
  93.         angle1 = degree(me_x - me_buffer(a_buff, 0), me_y - me_buffer(a_buff, 1)) 'how many degree
  94.         angle2 = angle1 + angle_me '+arrow
  95.  
  96.         distance = SQR((me_x - me_buffer(a_buff, 0)) ^ 2 + (me_y - me_buffer(a_buff, 1)) ^ 2)
  97.  
  98.         cr_cx = (SIN(angle2 * pip180)) * distance 'planet origo position on monitor
  99.         cr_cy = (COS(angle2 * pip180)) * distance
  100.  
  101.         PSET (centx + cr_cx * zoom, centy + cr_cy * zoom)
  102.     NEXT a_buff
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.     'control
  110.     mw = 0: mousex = 0: WHILE _MOUSEINPUT: mousex = mousex + _MOUSEMOVEMENTX: mw = mw + _MOUSEWHEEL: WEND: angle_me = angle_me + mousex
  111.     IF _MOUSEBUTTON(1) THEN speed = speed + .05
  112.     IF _MOUSEBUTTON(2) THEN speed = speed - .05
  113.  
  114.  
  115.  
  116.     'inertia vector
  117.     speed = speed - .01 * SGN(speed)
  118.     IF ABS(speed) > .5 THEN speed = .5 * SGN(speed)
  119.  
  120.  
  121.     vector_x_my = -SIN(pip180 * angle_me) * speed * global_speed
  122.     vector_y_my = -COS(pip180 * angle_me) * speed * global_speed
  123.  
  124.  
  125.     'gravity vector
  126.     angle_g = degree(grav_x, grav_y)
  127.     strong = SQR((grav_x - me_x) ^ 2 + (grav_y - me_y) ^ 2): IF strong > 2 THEN strong = 2
  128.     IF ABS(strong) > 1 THEN strong = 1 * SGN(strong)
  129.     vector_x_grav = -SIN(pip180 * angle_g) * strong / 5 * global_speed
  130.     vector_y_grav = -COS(pip180 * angle_g) * strong / 5 * global_speed
  131.  
  132.     'resulting vector
  133.     me_x = me_x + vector_x_my + vector_x_grav
  134.     me_y = me_y - vector_y_my + vector_y_grav
  135.  
  136.     IF me_x > space / 2 THEN me_x = me_x - space
  137.     IF me_x < -space / 2 THEN me_x = me_x + space
  138.     IF me_y > space / 2 THEN me_y = me_y - space
  139.     IF me_y < -space / 2 THEN me_y = me_y + space
  140.  
  141.     me_buffer(me_buffer_a, 0) = me_x
  142.     me_buffer(me_buffer_a, 1) = me_y
  143.  
  144.     me_buffer_a = me_buffer_a + 1: IF me_buffer_a = me_buffer_size THEN me_buffer_a = 0
  145.  
  146.     zoom = zoom + mw / 2
  147.     IF zoom > 50 THEN zoom = 50
  148.     IF zoom < .5 THEN zoom = .5
  149.  
  150.  
  151.     'view
  152.     _DISPLAY: CLS
  153.     'LOCATE 1, 1
  154.     'PRINT speed, SQR(grav_x ^ 2 + grav_y ^ 2)
  155.     '    PRINT "grav_active:"; grav_active
  156.  
  157.  
  158.  
  159.  
  160. FUNCTION degree (a, b)
  161.     qarany = (a + .00001) / (b + .00001): degree = honnan + ATN(qarany) / pip180
  162.     IF 0 > b THEN degree = degree - 180
  163.     IF degree < 0 THEN degree = degree + 360
  164.  
  165.  
Title: Re: i suffer
Post by: Aurel on March 29, 2021, 08:27:39 am
wow that is fast mouse move progie
but how to close program ??? ESC not work???
Title: Re: i suffer
Post by: bplus on March 29, 2021, 11:50:37 am
@Aurel Alt + F4 works, something to keep in mind for all these people who want full screen and forget about escape.

@MasterGy  very interesting, thanks :)  Interesting is you are getting the direction of mouse moves without tan, atan, or atan2 and instead of changing direction of mouse you change whole orientation of screen which is disorienting ;-)) but I wonder if smoother than my mouse action shooter? Also nice is doing so much with so little code!
Title: Re: i suffer
Post by: FellippeHeitor on March 29, 2021, 12:02:11 pm
It feels like this thread should have been several many separate threads. @MasterGy Maybe a new thread should be started if the new code has no correlation with the previous.
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on March 29, 2021, 12:07:40 pm
It feels like this thread should have been several many separate threads. @MasterGy Maybe a new thread should be started if the new code has no correlation with the previous.

What is in common is that when an artist suffers he gets creative just to cheer himself up.

You've got to admit these are some very creative cheers :)
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: FellippeHeitor on March 29, 2021, 12:12:02 pm
It would be a shame if this ended up containing several cool looking pieces of code-art but ended up buried under the cryptic title "i suffer".

Much like all your new "tools" end up buried under "another one for your toolbox".

With no clear description of what the thread/post actually contains, content gets lost - not that that's not already a characteristic of forum boards, but we could at least make it more easily searchable.
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: SpriggsySpriggs on March 29, 2021, 12:12:25 pm
I agree with Fellippe. This thread seems like it has taken a few different directions from when it was first created.
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on March 29, 2021, 12:31:28 pm
It would be a shame if this ended up containing several cool looking pieces of code-art but ended up buried under the cryptic title "i suffer".

Much like all your new "tools"

With no clear description of what the thread/post actually contains, content gets lost - not that that's not already a characteristic of forum boards, but we could at least make it more easily searchable.

I agree with Fellippe. This thread seems like it has taken a few different directions from when it was first created.


I am sure one or more of these ideas will "take" and end up in the programs section.

Meanwhile just enjoy the creative process and sharing of ideas. :)

Quote
end up buried under "another one for your toolbox".

Right here if anyone is interested, thanks for plug!
https://www.qb64.org/forum/index.php?topic=1511.msg107143#msg107143

There is a classic thread in FreeBASIC called Squares (if I recall correctly) that has gone on and on for years, it is the book of people having fun and sharing ideas even if it wanders all over the place.

PS for Pete's sake, I won't post a link ;-))
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: MasterGy on March 29, 2021, 02:43:18 pm
thank you! I didn’t put it in a separate topic because it just wanted to be a model. I want to make a 3D fighter game that moves around the planet (the starting point is a program where you can walk around the Earth) so you can feel gravity. The problem with the Earth program is that you can walk around, come, go, rotate, up, down, left, right in FPS mode. In fact, when we travel in space in a spaceship, we are not affected by a significant gravitational force from anywhere, we are weightless. There is no such thing as down, up, left, right. As soon as we reach the gravitational field of a planet, the up-and-down will have meaning. Since the spacecraft can be at any angle in space, FPS mode is not good. Because I get completely brainwashed from this problem to shoot the camera in 3d that we see from the spaceship. (BPLUS, that's why the arrow is glued to the middle of the screen, which is confusing to you because he's the reference point, everything moves relative to him) That's why I did it in 2D for the first time. I didn’t put it on a separate topic because it doesn’t matter that much. If anyone likes it, save it.
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on March 29, 2021, 02:57:08 pm
@MasterGy

I did like it and I did save it, into a long overdue MasterGy folder on my hard disk.

I believe you have the better position, platform, base, orientation with the nose of rocket going up and always being in the center of Universe. That is Human perspective. It might even be excellent training for space navigators forced to fly by-the-seat-of-their-pants (no instrumentation to help orientate).

Forgive me if I like god's view more. ;-)) seeing the ship and everything around it in one perspective.

I have a problem with jerkiness in my mouse action shooter that I am curious as to how you might handle:
Code: QB64: [Select]
  1. _Title "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. Const xmax = 1200
  23. Const ymax = 700
  24. Const nBullets = 15
  25. Const bSpeed = 30
  26. Const nTargets = 3 'should probably depend on level of play
  27. Const tSpeed = 5 'should probably depend on level of play
  28. Const shooterRadius = 50
  29.  
  30. Type shooterType
  31.     x As Single
  32.     y As Single
  33.     a As Single
  34.  
  35. Type bulletType
  36.     x As Integer
  37.     y As Integer
  38.     dx As Integer
  39.     dy As Integer
  40.     live As Integer
  41.  
  42. Type targetType
  43.     x As Single
  44.     y As Single
  45.     a As Single
  46.     r As Integer
  47.  
  48. Screen _NewImage(xmax, ymax, 32)
  49. _ScreenMove 100, 20
  50.  
  51.  
  52. Dim Shared GameOn, mb1, last1, score
  53.  
  54. 'targets
  55. Dim Shared t(nTargets - 1) As targetType
  56. For i = 0 To nTargets - 1: newTarget i: Next
  57.  
  58. 'bullets
  59. Dim Shared b(nBullets - 1) As bulletType
  60.  
  61. 'shooter
  62. Dim Shared shooter As shooterType
  63. shooter.x = xmax / 2
  64. shooter.y = ymax / 2
  65. shooter.a = 0
  66. lastx = xmax / 2: lasty = ymax / 2
  67.  
  68. 'game
  69. GameOn = 1
  70. While GameOn
  71.     Cls
  72.     _Title "Target Practice   Score:" + Str$(score)
  73.     mb1 = 0: mb2 = 0
  74.     shooter.x = _MouseX: shooter.y = _MouseY
  75.     If Abs(lastx - shooter.x) > 3 Or Abs(lasty - shooter.y) > 3 Then
  76.         shooter.a = _Atan2(shooter.y - lasty, shooter.x - lastx)
  77.         lastx = shooter.x: lasty = shooter.y
  78.     End If
  79.     t = Timer(.001)
  80.     If _MouseButton(1) Then 'when ship is heading north the left button should be left
  81.         If t - last1 > .15 Then mb1 = 1: last1 = t
  82.     End If
  83.     handleTargets
  84.     drawshooter
  85.     handleBullets
  86.     _Display
  87.     _Limit 30
  88.  
  89. Sub handleTargets
  90.     For i = 0 To nTargets - 1
  91.         'update position
  92.         t(i).x = t(i).x + tSpeed * Cos(t(i).a)
  93.         t(i).y = t(i).y + tSpeed * Sin(t(i).a)
  94.         'inbounds?
  95.         If t(i).x < -shooterRadius Or t(i).x > xmax + shooterRadius Or t(i).y < -shooterRadius Or t(i).y > ymax + shooterradiu Then
  96.             newTarget i
  97.         Else
  98.             If hitShooter(i) Then 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  99.                 'explosion
  100.                 Cls
  101.                 _PrintString (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  102.                 score = score - 100
  103.                 _Display
  104.                 _Delay .2
  105.                 ' fix target crashing into ship by removing target with reassigning
  106.                 newTarget i ' in oh this does not work
  107.             Else
  108.                 drawTarget i
  109.             End If
  110.         End If
  111.     Next
  112.  
  113. Sub newTarget (i)
  114.     'pick edge
  115.     edge = Int(Rnd * 4)
  116.     Select Case edge
  117.         Case 0: t(i).x = -shooterRadius: t(i).y = Rnd * (ymax - 300) + 150: t(i).a = Rnd * _Pi
  118.         Case 1: t(i).x = xmax + shooterRadius: t(i).y = Rnd * (ymax - 300) + 150: t(i).a = _Pi / 2 + Rnd * _Pi
  119.         Case 2: t(i).x = Rnd * xmax: t(i).y = -shooterRadius: t(i).a = Rnd * _Pi
  120.         Case 3: t(i).x = Rnd * xmax: t(i).y = ymax + shooterRadius: t(i).a = _Pi + Rnd * _Pi
  121.     End Select
  122.     t(i).r = (Int(Rnd * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  123.  
  124. Sub drawTarget (i)
  125.     For r = t(i).r To 0 Step -t(i).r / 10
  126.         count = (count + 1) Mod 2
  127.         If count Then c~& = _RGB32(255, 0, 0) Else c~& = _RGB32(255, 255, 255)
  128.         fcirc t(i).x, t(i).y, r, c~&
  129.     Next
  130.  
  131. Sub handleBullets ()
  132.     For i = 0 To nBullets - 1
  133.         If b(i).live = 0 And mb1 = 1 Then 'have in active bullet index to use
  134.             b(i).x = shooter.x + .5 * shooterRadius * Cos(shooter.a)
  135.             b(i).y = shooter.y + .5 * shooterRadius * Sin(shooter.a)
  136.             b(i).dx = bSpeed * Cos(shooter.a)
  137.             b(i).dy = bSpeed * Sin(shooter.a)
  138.             b(i).live = 1
  139.             mb1 = 0
  140.             score = score - 10 'bullets cost 10 points
  141.  
  142.         ElseIf b(i).live = 1 Then 'new location
  143.             b(i).x = b(i).x + b(i).dx
  144.             b(i).y = b(i).y + b(i).dy
  145.             If b(i).x > -50 And b(i).x < xmax + 50 And b(i).y > -50 And b(i).y < ymax + 50 Then 'in bounds draw it
  146.                 'check for collision with ...
  147.                 t = hitTarget(i)
  148.                 If t > -1 Then
  149.                     score = score + 130 - t(t).r
  150.                     b(i).live = 0
  151.                     newTarget t
  152.                 Else
  153.                     'draw bullet
  154.                     ba = _Atan2(b(i).dy, b(i).dx): b = 15
  155.                     x1 = b(i).x + b * Cos(ba)
  156.                     y1 = b(i).y + b * Sin(ba)
  157.                     x2 = b(i).x + b * Cos(ba + _Pi(5 / 6))
  158.                     y2 = b(i).y + b * Sin(ba + _Pi(5 / 6))
  159.                     x3 = b(i).x + b * Cos(ba + _Pi(7 / 6))
  160.                     y3 = b(i).y + b * Sin(ba + _Pi(7 / 6))
  161.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  162.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  163.                 End If
  164.             Else
  165.                 b(i).live = 0 'dectiveate
  166.             End If
  167.         End If
  168.     Next
  169.  
  170. Function hitTarget (bulletIndex)
  171.     hitTarget = -1
  172.     For i = 0 To nTargets - 1
  173.         If Sqr((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r Then hitTarget = i: Exit Function
  174.     Next
  175.  
  176. Function hitShooter (TargetIndex)
  177.     If Sqr((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r Then hitShooter = 1: Exit Function
  178.  
  179. Sub drawshooter ()
  180.     x1 = shooter.x + (shooterRadius - 30) * Cos(shooter.a)
  181.     y1 = shooter.y + (shooterRadius - 30) * Sin(shooter.a)
  182.     x2 = shooter.x + (shooterRadius + 20) * Cos(shooter.a + _Pi(11 / 16))
  183.     y2 = shooter.y + (shooterRadius + 20) * Sin(shooter.a + _Pi(11 / 16))
  184.     x3 = shooter.x + (shooterRadius + 20) * Cos(shooter.a - _Pi(11 / 16))
  185.     y3 = shooter.y + (shooterRadius + 20) * Sin(shooter.a - _Pi(11 / 16))
  186.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  187.     x1 = shooter.x + shooterRadius * Cos(shooter.a)
  188.     y1 = shooter.y + shooterRadius * Sin(shooter.a)
  189.     x2 = shooter.x + shooterRadius * Cos(shooter.a + _Pi(7 / 8))
  190.     y2 = shooter.y + shooterRadius * Sin(shooter.a + _Pi(7 / 8))
  191.     x3 = shooter.x + shooterRadius * Cos(shooter.a - _Pi(7 / 8))
  192.     y3 = shooter.y + shooterRadius * Sin(shooter.a - _Pi(7 / 8))
  193.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  194.     x2 = shooter.x + shooterRadius * Cos(shooter.a + _Pi(15 / 16))
  195.     y2 = shooter.y + shooterRadius * Sin(shooter.a + _Pi(15 / 16))
  196.     x3 = shooter.x + shooterRadius * Cos(shooter.a - _Pi(15 / 16))
  197.     y3 = shooter.y + shooterRadius * Sin(shooter.a - _Pi(15 / 16))
  198.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  199.  
  200.     'check shooter x, y  = fixed a long time ago!
  201.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  202.  
  203. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  204. Sub fTri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
  205.     a& = _NewImage(1, 1, 32)
  206.     _Dest a&
  207.     PSet (0, 0), K
  208.     _Dest 0
  209.     _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
  210.     _FreeImage a& '<<< this is important!
  211.  
  212. Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
  213.     Dim Radius As Integer, RadiusError As Integer
  214.     Dim X As Integer, Y As Integer
  215.  
  216.     Radius = Abs(R)
  217.     RadiusError = -Radius
  218.     X = Radius
  219.     Y = 0
  220.  
  221.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  222.  
  223.     ' Draw the middle span here so we don't draw it twice in the main loop,
  224.     ' which would be a problem with blending turned on.
  225.     Line (CX - X, CY)-(CX + X, CY), C, BF
  226.  
  227.     While X > Y
  228.         RadiusError = RadiusError + Y * 2 + 1
  229.         If RadiusError >= 0 Then
  230.             If X <> Y + 1 Then
  231.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  232.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  233.             End If
  234.             X = X - 1
  235.             RadiusError = RadiusError - X * 2
  236.         End If
  237.         Y = Y + 1
  238.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  239.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  240.     Wend
  241.  
  242.  

It flies nice but when it comes to precision shooting, specially if you stop to shoot, there is last moment jerk off target. @MasterGy I am wondering how you ( or anyone interested) might accomplish the flying and mouse-button shooting? (no keypresses except for escape of course)


Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: MasterGy on March 29, 2021, 03:56:10 pm
thanks for the advice ! all ideas, suggestions, thoughts are very good! thanks !

I like imaginative shooting games! I like the way you solved the direction of the shot and the position of the plane. Ideal !! I don't understand exactly what your problem is with him. What's jerking? I don't see jerks. If the plane was "spinning up" due to a small mouse movement, I would only put one distance condition there, 2 lines, I attached. But maybe you are thinking of another problem? Because I think it's as good as you did.

Code: QB64: [Select]
  1. _TITLE "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. CONST xmax = 1200
  23. CONST ymax = 700
  24. CONST nBullets = 15
  25. CONST bSpeed = 30
  26. CONST nTargets = 3 'should probably depend on level of play
  27. CONST tSpeed = 5 'should probably depend on level of play
  28. CONST shooterRadius = 50
  29.  
  30. TYPE shooterType
  31.     x AS SINGLE
  32.     y AS SINGLE
  33.     a AS SINGLE
  34.  
  35. TYPE bulletType
  36.     x AS INTEGER
  37.     y AS INTEGER
  38.     dx AS INTEGER
  39.     dy AS INTEGER
  40.     live AS INTEGER
  41.  
  42. TYPE targetType
  43.     x AS SINGLE
  44.     y AS SINGLE
  45.     a AS SINGLE
  46.     r AS INTEGER
  47.  
  48. SCREEN _NEWIMAGE(xmax, ymax, 32)
  49. _SCREENMOVE 100, 20
  50.  
  51.  
  52. DIM SHARED GameOn, mb1, last1, score
  53.  
  54. 'targets
  55. DIM SHARED t(nTargets - 1) AS targetType
  56. FOR i = 0 TO nTargets - 1: newTarget i: NEXT
  57.  
  58. 'bullets
  59. DIM SHARED b(nBullets - 1) AS bulletType
  60.  
  61. 'shooter
  62. DIM SHARED shooter AS shooterType
  63. shooter.x = xmax / 2
  64. shooter.y = ymax / 2
  65. shooter.a = 0
  66. lastx = xmax / 2: lasty = ymax / 2
  67.  
  68. 'game
  69. GameOn = 1
  70. WHILE GameOn
  71.     CLS
  72.     _TITLE "Target Practice   Score:" + STR$(score)
  73.     mb1 = 0: mb2 = 0
  74.  
  75.     shooter.x = _MOUSEX: shooter.y = _MOUSEY
  76.  
  77.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 10 THEN '-------------------------------------------------add 1. row
  78.  
  79.         IF ABS(lastx - shooter.x) > 3 OR ABS(lasty - shooter.y) > 3 THEN
  80.             shooter.a = _ATAN2(shooter.y - lasty, shooter.x - lastx)
  81.             lastx = shooter.x: lasty = shooter.y
  82.         END IF
  83.  
  84.     END IF '-------------------------------------------------------------------------------------------------------------- add 2.row
  85.  
  86.  
  87.     t = TIMER(.001)
  88.     IF _MOUSEBUTTON(1) THEN 'when ship is heading north the left button should be left
  89.         IF t - last1 > .15 THEN mb1 = 1: last1 = t
  90.     END IF
  91.     handleTargets
  92.     drawshooter
  93.     handleBullets
  94.     _DISPLAY
  95.     _LIMIT 30
  96.  
  97. SUB handleTargets
  98.     FOR i = 0 TO nTargets - 1
  99.         'update position
  100.         t(i).x = t(i).x + tSpeed * COS(t(i).a)
  101.         t(i).y = t(i).y + tSpeed * SIN(t(i).a)
  102.         'inbounds?
  103.         IF t(i).x < -shooterRadius OR t(i).x > xmax + shooterRadius OR t(i).y < -shooterRadius OR t(i).y > ymax + shooterradiu THEN
  104.             newTarget i
  105.         ELSE
  106.             IF hitShooter(i) THEN 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  107.                 'explosion
  108.                 CLS
  109.                 _PRINTSTRING (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  110.                 score = score - 100
  111.                 _DISPLAY
  112.                 _DELAY .2
  113.                 ' fix target crashing into ship by removing target with reassigning
  114.                 newTarget i ' in oh this does not work
  115.             ELSE
  116.                 drawTarget i
  117.             END IF
  118.         END IF
  119.     NEXT
  120.  
  121. SUB newTarget (i)
  122.     'pick edge
  123.     edge = INT(RND * 4)
  124.     SELECT CASE edge
  125.         CASE 0: t(i).x = -shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = RND * _PI
  126.         CASE 1: t(i).x = xmax + shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = _PI / 2 + RND * _PI
  127.         CASE 2: t(i).x = RND * xmax: t(i).y = -shooterRadius: t(i).a = RND * _PI
  128.         CASE 3: t(i).x = RND * xmax: t(i).y = ymax + shooterRadius: t(i).a = _PI + RND * _PI
  129.     END SELECT
  130.     t(i).r = (INT(RND * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  131.  
  132. SUB drawTarget (i)
  133.     FOR r = t(i).r TO 0 STEP -t(i).r / 10
  134.         count = (count + 1) MOD 2
  135.         IF count THEN c~& = _RGB32(255, 0, 0) ELSE c~& = _RGB32(255, 255, 255)
  136.         fcirc t(i).x, t(i).y, r, c~&
  137.     NEXT
  138.  
  139. SUB handleBullets ()
  140.     FOR i = 0 TO nBullets - 1
  141.         IF b(i).live = 0 AND mb1 = 1 THEN 'have in active bullet index to use
  142.             b(i).x = shooter.x + .5 * shooterRadius * COS(shooter.a)
  143.             b(i).y = shooter.y + .5 * shooterRadius * SIN(shooter.a)
  144.             b(i).dx = bSpeed * COS(shooter.a)
  145.             b(i).dy = bSpeed * SIN(shooter.a)
  146.             b(i).live = 1
  147.             mb1 = 0
  148.             score = score - 10 'bullets cost 10 points
  149.  
  150.         ELSEIF b(i).live = 1 THEN 'new location
  151.             b(i).x = b(i).x + b(i).dx
  152.             b(i).y = b(i).y + b(i).dy
  153.             IF b(i).x > -50 AND b(i).x < xmax + 50 AND b(i).y > -50 AND b(i).y < ymax + 50 THEN 'in bounds draw it
  154.                 'check for collision with ...
  155.                 t = hitTarget(i)
  156.                 IF t > -1 THEN
  157.                     score = score + 130 - t(t).r
  158.                     b(i).live = 0
  159.                     newTarget t
  160.                 ELSE
  161.                     'draw bullet
  162.                     ba = _ATAN2(b(i).dy, b(i).dx): b = 15
  163.                     x1 = b(i).x + b * COS(ba)
  164.                     y1 = b(i).y + b * SIN(ba)
  165.                     x2 = b(i).x + b * COS(ba + _PI(5 / 6))
  166.                     y2 = b(i).y + b * SIN(ba + _PI(5 / 6))
  167.                     x3 = b(i).x + b * COS(ba + _PI(7 / 6))
  168.                     y3 = b(i).y + b * SIN(ba + _PI(7 / 6))
  169.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  170.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  171.                 END IF
  172.             ELSE
  173.                 b(i).live = 0 'dectiveate
  174.             END IF
  175.         END IF
  176.     NEXT
  177.  
  178. FUNCTION hitTarget (bulletIndex)
  179.     hitTarget = -1
  180.     FOR i = 0 TO nTargets - 1
  181.         IF SQR((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r THEN hitTarget = i: EXIT FUNCTION
  182.     NEXT
  183.  
  184. FUNCTION hitShooter (TargetIndex)
  185.     IF SQR((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r THEN hitShooter = 1: EXIT FUNCTION
  186.  
  187. SUB drawshooter ()
  188.     x1 = shooter.x + (shooterRadius - 30) * COS(shooter.a)
  189.     y1 = shooter.y + (shooterRadius - 30) * SIN(shooter.a)
  190.     x2 = shooter.x + (shooterRadius + 20) * COS(shooter.a + _PI(11 / 16))
  191.     y2 = shooter.y + (shooterRadius + 20) * SIN(shooter.a + _PI(11 / 16))
  192.     x3 = shooter.x + (shooterRadius + 20) * COS(shooter.a - _PI(11 / 16))
  193.     y3 = shooter.y + (shooterRadius + 20) * SIN(shooter.a - _PI(11 / 16))
  194.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  195.     x1 = shooter.x + shooterRadius * COS(shooter.a)
  196.     y1 = shooter.y + shooterRadius * SIN(shooter.a)
  197.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(7 / 8))
  198.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(7 / 8))
  199.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(7 / 8))
  200.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(7 / 8))
  201.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  202.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(15 / 16))
  203.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(15 / 16))
  204.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(15 / 16))
  205.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(15 / 16))
  206.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  207.  
  208.     'check shooter x, y  = fixed a long time ago!
  209.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  210.  
  211. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  212. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  213.     a& = _NEWIMAGE(1, 1, 32)
  214.     _DEST a&
  215.     PSET (0, 0), K
  216.     _DEST 0
  217.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  218.     _FREEIMAGE a& '<<< this is important!
  219.  
  220. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  221.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  222.     DIM X AS INTEGER, Y AS INTEGER
  223.  
  224.     Radius = ABS(R)
  225.     RadiusError = -Radius
  226.     X = Radius
  227.     Y = 0
  228.  
  229.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  230.  
  231.     ' Draw the middle span here so we don't draw it twice in the main loop,
  232.     ' which would be a problem with blending turned on.
  233.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  234.  
  235.     WHILE X > Y
  236.         RadiusError = RadiusError + Y * 2 + 1
  237.         IF RadiusError >= 0 THEN
  238.             IF X <> Y + 1 THEN
  239.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  240.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  241.             END IF
  242.             X = X - 1
  243.             RadiusError = RadiusError - X * 2
  244.         END IF
  245.         Y = Y + 1
  246.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  247.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  248.     WEND
  249.  
  250.  
  251.  
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: MasterGy on March 29, 2021, 04:07:44 pm
anyway thanks this time BPLUS! :) you see, people are always learning! So far, I have solved the angle measurement in "degrees".

Code: QB64: [Select]
  1. FUNCTION degree (a, b)
  2.     qarany = (a + .00001) / (b + .00001): degree = honnan + ATN(qarany) / pip180
  3.     IF 0 > b THEN degree = degree - 180
  4.     IF degree < 0 THEN degree = degree + 360


I didn't know "_ATAN2", it's the same, only in radians :) Man always
 study! :)
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on March 29, 2021, 05:18:12 pm
Oh ha! Now I see it! LOL

Code: QB64: [Select]
  1. Function degree (a, b)
  2.     qarany = (a + .00001) / (b + .00001): degree = honnan + Atn(qarany) / pip180
  3.     If 0 > b Then degree = degree - 180
  4.     If degree < 0 Then degree = degree + 360
  5.  
  6.  

yeah, I know you had to be doing that somewhere! I forgot to search "atn" in your code. I searched, tan, atan, atan2 but forgot atn. :P

Adding .00001 interesting, is that to keep the divisor <> 0 ? Speaking of which, do I test for that? maybe that's the jerk ;-))
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: MasterGy on March 29, 2021, 05:33:03 pm
check! :) know that for me pip180 is a constant always (= pi / 180) :)
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on March 29, 2021, 06:52:07 pm
Well I just learned something new today!

Logically this is not a proper check for dividing by zero:
Code: QB64: [Select]
  1.     If Abs(lastx - shooter.x) > 3 Or Abs(lasty - shooter.y) > 3 Then
  2.         shooter.a = _Atan2(shooter.y - lasty, shooter.x - lastx)
  3.         lastx = shooter.x: lasty = shooter.y
  4.     End If
  5.  

update: well I fixed but now I am not sure if _ATAN2 ever has a problem with division by 0?

update 2: confirmed _ATAN2 has no division by 0 problems.

Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: MasterGy on March 30, 2021, 02:23:36 pm
I came up with an even finer solution for shooting.

Code: QB64: [Select]
  1. _TITLE "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. CONST pip180 = 3.14159265 / 180
  23. CONST xmax = 1200
  24. CONST ymax = 700
  25. CONST nBullets = 15
  26. CONST bSpeed = 30
  27. CONST nTargets = 3 'should probably depend on level of play
  28. CONST tSpeed = 5 'should probably depend on level of play
  29. CONST shooterRadius = 50
  30.  
  31. TYPE shooterType
  32.     x AS SINGLE
  33.     y AS SINGLE
  34.     a AS SINGLE
  35.  
  36. TYPE bulletType
  37.     x AS INTEGER
  38.     y AS INTEGER
  39.     dx AS INTEGER
  40.     dy AS INTEGER
  41.     live AS INTEGER
  42.  
  43. TYPE targetType
  44.     x AS SINGLE
  45.     y AS SINGLE
  46.     a AS SINGLE
  47.     r AS INTEGER
  48.  
  49. SCREEN _NEWIMAGE(xmax, ymax, 32)
  50. _SCREENMOVE 100, 20
  51.  
  52.  
  53. DIM SHARED GameOn, mb1, last1, score
  54.  
  55. 'targets
  56. DIM SHARED t(nTargets - 1) AS targetType
  57. FOR i = 0 TO nTargets - 1: newTarget i: NEXT
  58.  
  59. 'bullets
  60. DIM SHARED b(nBullets - 1) AS bulletType
  61.  
  62. 'shooter
  63. DIM SHARED shooter AS shooterType
  64. shooter.x = xmax / 2
  65. shooter.y = ymax / 2
  66. shooter.a = 0
  67. lastx = xmax / 2: lasty = ymax / 2
  68.  
  69. 'game
  70. GameOn = 1
  71. WHILE GameOn
  72.     CLS
  73.     _TITLE "Target Practice   Score:" + STR$(score)
  74.     mb1 = 0: mb2 = 0
  75.  
  76.     shooter.x = _MOUSEX: shooter.y = _MOUSEY
  77.  
  78.  
  79.  
  80.  
  81.  
  82.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 1 THEN
  83.         angle = degree(shooter.y - lasty, shooter.x - lastx) 'deg
  84.         dif_choice = 1000
  85.         FOR t = 0 TO 4
  86.             angle_dif = shooter_degree - (angle + 360 * (2 - t))
  87.             dif = ABS(angle_dif)
  88.             IF dif < dif_choice THEN angle_dif_choice = angle_dif: dif_choice = dif
  89.         NEXT t
  90.         shooter_degree = shooter_degree - angle_dif_choice * .25 'rotating speed (.25)
  91.         DO WHILE shooter_degree > 360: shooter_degree = shooter_degree - 360: LOOP
  92.         DO WHILE shooter_degree < 360: shooter_degree = shooter_degree + 360: LOOP
  93.         shooter.a = shooter_degree * pip180
  94.         lastx = shooter.x: lasty = shooter.y
  95.     END IF
  96.  
  97.  
  98.  
  99.  
  100.     t = TIMER(.001)
  101.     IF _MOUSEBUTTON(1) THEN 'when ship is heading north the left button should be left
  102.         IF t - last1 > .15 THEN mb1 = 1: last1 = t
  103.     END IF
  104.     handleTargets
  105.     drawshooter
  106.     handleBullets
  107.     _DISPLAY
  108.     _LIMIT 30
  109.  
  110. SUB handleTargets
  111.     FOR i = 0 TO nTargets - 1
  112.         'update position
  113.         t(i).x = t(i).x + tSpeed * COS(t(i).a)
  114.         t(i).y = t(i).y + tSpeed * SIN(t(i).a)
  115.         'inbounds?
  116.         IF t(i).x < -shooterRadius OR t(i).x > xmax + shooterRadius OR t(i).y < -shooterRadius OR t(i).y > ymax + shooterradiu THEN
  117.             newTarget i
  118.         ELSE
  119.             IF hitShooter(i) THEN 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  120.                 'explosion
  121.                 CLS
  122.                 _PRINTSTRING (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  123.                 score = score - 100
  124.                 _DISPLAY
  125.                 _DELAY .2
  126.                 ' fix target crashing into ship by removing target with reassigning
  127.                 newTarget i ' in oh this does not work
  128.             ELSE
  129.                 drawTarget i
  130.             END IF
  131.         END IF
  132.     NEXT
  133.  
  134. SUB newTarget (i)
  135.     'pick edge
  136.     edge = INT(RND * 4)
  137.     SELECT CASE edge
  138.         CASE 0: t(i).x = -shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = RND * _PI
  139.         CASE 1: t(i).x = xmax + shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = _PI / 2 + RND * _PI
  140.         CASE 2: t(i).x = RND * xmax: t(i).y = -shooterRadius: t(i).a = RND * _PI
  141.         CASE 3: t(i).x = RND * xmax: t(i).y = ymax + shooterRadius: t(i).a = _PI + RND * _PI
  142.     END SELECT
  143.     t(i).r = (INT(RND * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  144.  
  145. SUB drawTarget (i)
  146.     FOR r = t(i).r TO 0 STEP -t(i).r / 10
  147.         count = (count + 1) MOD 2
  148.         IF count THEN c~& = _RGB32(255, 0, 0) ELSE c~& = _RGB32(255, 255, 255)
  149.         fcirc t(i).x, t(i).y, r, c~&
  150.     NEXT
  151.  
  152. SUB handleBullets ()
  153.     FOR i = 0 TO nBullets - 1
  154.         IF b(i).live = 0 AND mb1 = 1 THEN 'have in active bullet index to use
  155.             b(i).x = shooter.x + .5 * shooterRadius * COS(shooter.a)
  156.             b(i).y = shooter.y + .5 * shooterRadius * SIN(shooter.a)
  157.             b(i).dx = bSpeed * COS(shooter.a)
  158.             b(i).dy = bSpeed * SIN(shooter.a)
  159.             b(i).live = 1
  160.             mb1 = 0
  161.             score = score - 10 'bullets cost 10 points
  162.  
  163.         ELSEIF b(i).live = 1 THEN 'new location
  164.             b(i).x = b(i).x + b(i).dx
  165.             b(i).y = b(i).y + b(i).dy
  166.             IF b(i).x > -50 AND b(i).x < xmax + 50 AND b(i).y > -50 AND b(i).y < ymax + 50 THEN 'in bounds draw it
  167.                 'check for collision with ...
  168.                 t = hitTarget(i)
  169.                 IF t > -1 THEN
  170.                     score = score + 130 - t(t).r
  171.                     b(i).live = 0
  172.                     newTarget t
  173.                 ELSE
  174.                     'draw bullet
  175.                     ba = _ATAN2(b(i).dy, b(i).dx): b = 15
  176.                     x1 = b(i).x + b * COS(ba)
  177.                     y1 = b(i).y + b * SIN(ba)
  178.                     x2 = b(i).x + b * COS(ba + _PI(5 / 6))
  179.                     y2 = b(i).y + b * SIN(ba + _PI(5 / 6))
  180.                     x3 = b(i).x + b * COS(ba + _PI(7 / 6))
  181.                     y3 = b(i).y + b * SIN(ba + _PI(7 / 6))
  182.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  183.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  184.                 END IF
  185.             ELSE
  186.                 b(i).live = 0 'dectiveate
  187.             END IF
  188.         END IF
  189.     NEXT
  190.  
  191. FUNCTION hitTarget (bulletIndex)
  192.     hitTarget = -1
  193.     FOR i = 0 TO nTargets - 1
  194.         IF SQR((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r THEN hitTarget = i: EXIT FUNCTION
  195.     NEXT
  196.  
  197. FUNCTION hitShooter (TargetIndex)
  198.     IF SQR((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r THEN hitShooter = 1: EXIT FUNCTION
  199.  
  200. SUB drawshooter ()
  201.     x1 = shooter.x + (shooterRadius - 30) * COS(shooter.a)
  202.     y1 = shooter.y + (shooterRadius - 30) * SIN(shooter.a)
  203.     x2 = shooter.x + (shooterRadius + 20) * COS(shooter.a + _PI(11 / 16))
  204.     y2 = shooter.y + (shooterRadius + 20) * SIN(shooter.a + _PI(11 / 16))
  205.     x3 = shooter.x + (shooterRadius + 20) * COS(shooter.a - _PI(11 / 16))
  206.     y3 = shooter.y + (shooterRadius + 20) * SIN(shooter.a - _PI(11 / 16))
  207.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  208.     x1 = shooter.x + shooterRadius * COS(shooter.a)
  209.     y1 = shooter.y + shooterRadius * SIN(shooter.a)
  210.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(7 / 8))
  211.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(7 / 8))
  212.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(7 / 8))
  213.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(7 / 8))
  214.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  215.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(15 / 16))
  216.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(15 / 16))
  217.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(15 / 16))
  218.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(15 / 16))
  219.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  220.  
  221.     'check shooter x, y  = fixed a long time ago!
  222.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  223.  
  224. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  225. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  226.     a& = _NEWIMAGE(1, 1, 32)
  227.     _DEST a&
  228.     PSET (0, 0), K
  229.     _DEST 0
  230.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  231.     _FREEIMAGE a& '<<< this is important!
  232.  
  233. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  234.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  235.     DIM X AS INTEGER, Y AS INTEGER
  236.  
  237.     Radius = ABS(R)
  238.     RadiusError = -Radius
  239.     X = Radius
  240.     Y = 0
  241.  
  242.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  243.  
  244.     ' Draw the middle span here so we don't draw it twice in the main loop,
  245.     ' which would be a problem with blending turned on.
  246.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  247.  
  248.     WHILE X > Y
  249.         RadiusError = RadiusError + Y * 2 + 1
  250.         IF RadiusError >= 0 THEN
  251.             IF X <> Y + 1 THEN
  252.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  253.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  254.             END IF
  255.             X = X - 1
  256.             RadiusError = RadiusError - X * 2
  257.         END IF
  258.         Y = Y + 1
  259.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  260.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  261.     WEND
  262.  
  263.  
  264. FUNCTION degree (a, b)
  265.     rd = (a + .00001) / (b + .0001): degree = ATN(rd) / pip180
  266.     IF 0 > b THEN degree = degree - 180
  267.     IF degree < 0 THEN degree = degree + 360
  268.  
  269.  
  270.  
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: MasterGy on March 30, 2021, 05:17:02 pm
I added explosion effects


Code: QB64: [Select]
  1. _TITLE "Mouse Action Shooter #2 Targets fix" 'B+ 2021-03-19
  2. 'Mouse Action Shooter started from eRATication 5 by bplus 2018-08-06"
  3. ' upodate Mouse Action Shooter with MB triggers 2019-04-01
  4. ' 2019-04-03 add some targets for practice
  5.  
  6. ' SCORE System:
  7. ' Right click to fire a bullet, they cost 10 points each.
  8. ' Targets range from 30 for biggest targets to 100 points for smallest Targets
  9. ' Get hit by target loose 100 points and delay of game.
  10.  
  11. '2019-04-04 Keeping Ashish Target fix, wait until completely off screen.
  12. ' Now give the bullets a little long range before deactivating them.
  13. ' Fix shooter x, y by locating in center of shooter instead of nose. It's already OK!
  14.  
  15. ' 2021-03-19 using this code for oh program and want to fix point when target crashes into shooter/ship
  16. ' by reassignning target new coordinates by saying NewTarget index that should fix the continuous crashing right?
  17. ' Let's see, in oh it doesn't work, how about here?  Works just as expected. So what's up with oh?
  18. ' (Fixed it was an index goof for public variables used in GoSubs).
  19.  
  20.  
  21. 'screen dimensions
  22. CONST pip180 = 3.14159265 / 180
  23. CONST xmax = 1200
  24. CONST ymax = 700
  25. CONST nBullets = 15
  26. CONST bSpeed = 30
  27. CONST nTargets = 3 'should probably depend on level of play
  28. CONST tSpeed = 5 'should probably depend on level of play
  29. CONST shooterRadius = 50
  30.  
  31. CONST explosions_buff = 2000: DIM SHARED explosions(explosions_buff - 1, 19) 'shards-dat array
  32. CONST explosions_s = 200 'number of shards 1 when exploding
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. TYPE shooterType
  43.     x AS SINGLE
  44.     y AS SINGLE
  45.     a AS SINGLE
  46.  
  47. TYPE bulletType
  48.     x AS INTEGER
  49.     y AS INTEGER
  50.     dx AS INTEGER
  51.     dy AS INTEGER
  52.     live AS INTEGER
  53.  
  54. TYPE targetType
  55.     x AS SINGLE
  56.     y AS SINGLE
  57.     a AS SINGLE
  58.     r AS INTEGER
  59.  
  60. SCREEN _NEWIMAGE(xmax, ymax, 32)
  61. _SCREENMOVE 100, 20
  62.  
  63.  
  64. DIM SHARED GameOn, mb1, last1, score
  65.  
  66. 'targets
  67. DIM SHARED t(nTargets - 1) AS targetType
  68. FOR i = 0 TO nTargets - 1: newTarget i: NEXT
  69.  
  70. 'bullets
  71. DIM SHARED b(nBullets - 1) AS bulletType
  72.  
  73. 'shooter
  74. DIM SHARED shooter AS shooterType
  75. shooter.x = xmax / 2
  76. shooter.y = ymax / 2
  77. shooter.a = 0
  78. lastx = xmax / 2: lasty = ymax / 2
  79.  
  80. 'game
  81. GameOn = 1
  82. WHILE GameOn
  83.     CLS
  84.     _TITLE "Target Practice   Score:" + STR$(score)
  85.     mb1 = 0: mb2 = 0
  86.  
  87.     shooter.x = _MOUSEX: shooter.y = _MOUSEY
  88.  
  89.  
  90.  
  91.  
  92.  
  93.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 1 THEN
  94.         angle = degree(shooter.y - lasty, shooter.x - lastx) 'deg
  95.         dif_choice = 1000
  96.         FOR t = 0 TO 4
  97.             angle_dif = shooter_degree - (angle + 360 * (2 - t))
  98.             dif = ABS(angle_dif)
  99.             IF dif < dif_choice THEN angle_dif_choice = angle_dif: dif_choice = dif
  100.         NEXT t
  101.         shooter_degree = shooter_degree - angle_dif_choice * .25 'rotating speed (.25)
  102.         DO WHILE shooter_degree > 360: shooter_degree = shooter_degree - 360: LOOP
  103.         DO WHILE shooter_degree < 360: shooter_degree = shooter_degree + 360: LOOP
  104.         shooter.a = shooter_degree * pip180
  105.         lastx = shooter.x: lasty = shooter.y
  106.     END IF
  107.  
  108.  
  109.  
  110.  
  111.     t = TIMER(.001)
  112.     IF _MOUSEBUTTON(1) THEN 'when ship is heading north the left button should be left
  113.         IF t - last1 > .15 THEN mb1 = 1: last1 = t
  114.     END IF
  115.     handleTargets
  116.     drawshooter
  117.     handleBullets
  118.     explosions_control
  119.     explosions_draw
  120.     _DISPLAY
  121.     _LIMIT 30
  122.  
  123. SUB handleTargets
  124.     FOR i = 0 TO nTargets - 1
  125.         'update position
  126.         t(i).x = t(i).x + tSpeed * COS(t(i).a)
  127.         t(i).y = t(i).y + tSpeed * SIN(t(i).a)
  128.         'inbounds?
  129.         IF t(i).x < -shooterRadius OR t(i).x > xmax + shooterRadius OR t(i).y < -shooterRadius OR t(i).y > ymax + shooterradiu THEN
  130.  
  131.             newTarget i
  132.         ELSE
  133.             IF hitShooter(i) THEN 'now I discovered in oh program this continues to crash and deduct 100 until target moves through shooter
  134.                 'explosion
  135.                 CLS
  136.                 _PRINTSTRING (xmax / 2 - 40, ymax / 2 - 10), "Bang!... Ouch!"
  137.                 score = score - 100
  138.                 _DISPLAY
  139.                 _DELAY .2
  140.                 ' fix target crashing into ship by removing target with reassigning
  141.                 newTarget i ' in oh this does not work
  142.  
  143.             ELSE
  144.                 drawTarget i
  145.             END IF
  146.         END IF
  147.     NEXT
  148.  
  149. SUB newTarget (i)
  150.     'pick edge
  151.     edge = INT(RND * 4)
  152.     SELECT CASE edge
  153.         CASE 0: t(i).x = -shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = RND * _PI
  154.         CASE 1: t(i).x = xmax + shooterRadius: t(i).y = RND * (ymax - 300) + 150: t(i).a = _PI / 2 + RND * _PI
  155.         CASE 2: t(i).x = RND * xmax: t(i).y = -shooterRadius: t(i).a = RND * _PI
  156.         CASE 3: t(i).x = RND * xmax: t(i).y = ymax + shooterRadius: t(i).a = _PI + RND * _PI
  157.     END SELECT
  158.     t(i).r = (INT(RND * 8) + 3) * 10 '30 to 100 score 130 - radius 100 to 30
  159.  
  160. SUB drawTarget (i)
  161.     FOR r = t(i).r TO 0 STEP -t(i).r / 10
  162.         count = (count + 1) MOD 2
  163.         IF count THEN c~& = _RGB32(255, 0, 0) ELSE c~& = _RGB32(255, 255, 255)
  164.         fcirc t(i).x, t(i).y, r, c~&
  165.     NEXT
  166.  
  167. SUB handleBullets ()
  168.     FOR i = 0 TO nBullets - 1
  169.         IF b(i).live = 0 AND mb1 = 1 THEN 'have in active bullet index to use
  170.             b(i).x = shooter.x + .5 * shooterRadius * COS(shooter.a)
  171.             b(i).y = shooter.y + .5 * shooterRadius * SIN(shooter.a)
  172.             b(i).dx = bSpeed * COS(shooter.a)
  173.             b(i).dy = bSpeed * SIN(shooter.a)
  174.             b(i).live = 1
  175.             mb1 = 0
  176.             score = score - 10 'bullets cost 10 points
  177.  
  178.         ELSEIF b(i).live = 1 THEN 'new location
  179.             b(i).x = b(i).x + b(i).dx
  180.             b(i).y = b(i).y + b(i).dy
  181.             IF b(i).x > -50 AND b(i).x < xmax + 50 AND b(i).y > -50 AND b(i).y < ymax + 50 THEN 'in bounds draw it
  182.                 'check for collision with ...
  183.                 t = hitTarget(i)
  184.                 IF t > -1 THEN
  185.                     score = score + 130 - t(t).r
  186.                     b(i).live = 0
  187.                     newTarget t
  188.  
  189.  
  190.                     explosions_add b(i).x, b(i).y, b(i).dx, b(i).dy
  191.                 ELSE
  192.                     'draw bullet
  193.                     ba = _ATAN2(b(i).dy, b(i).dx): b = 15
  194.                     x1 = b(i).x + b * COS(ba)
  195.                     y1 = b(i).y + b * SIN(ba)
  196.                     x2 = b(i).x + b * COS(ba + _PI(5 / 6))
  197.                     y2 = b(i).y + b * SIN(ba + _PI(5 / 6))
  198.                     x3 = b(i).x + b * COS(ba + _PI(7 / 6))
  199.                     y3 = b(i).y + b * SIN(ba + _PI(7 / 6))
  200.                     fTri x1, y1, x2, y2, x3, y3, _RGB32(10, 160, 160)
  201.                     'fcirc b(i).x, b(i).y, 4, _RGB32(64, 0, 0)
  202.                 END IF
  203.             ELSE
  204.                 b(i).live = 0 'dectiveate
  205.             END IF
  206.         END IF
  207.     NEXT
  208.  
  209. FUNCTION hitTarget (bulletIndex)
  210.     hitTarget = -1
  211.     FOR i = 0 TO nTargets - 1
  212.         IF SQR((t(i).x - b(bulletIndex).x) ^ 2 + (t(i).y - b(bulletIndex).y) ^ 2) <= t(i).r THEN hitTarget = i: EXIT FUNCTION
  213.     NEXT
  214.  
  215. FUNCTION hitShooter (TargetIndex)
  216.     IF SQR((shooter.x - t(TargetIndex).x) ^ 2 + (shooter.y - t(TargetIndex).y) ^ 2) <= t(i).r THEN hitShooter = 1: EXIT FUNCTION
  217.  
  218. SUB drawshooter ()
  219.     x1 = shooter.x + (shooterRadius - 30) * COS(shooter.a)
  220.     y1 = shooter.y + (shooterRadius - 30) * SIN(shooter.a)
  221.     x2 = shooter.x + (shooterRadius + 20) * COS(shooter.a + _PI(11 / 16))
  222.     y2 = shooter.y + (shooterRadius + 20) * SIN(shooter.a + _PI(11 / 16))
  223.     x3 = shooter.x + (shooterRadius + 20) * COS(shooter.a - _PI(11 / 16))
  224.     y3 = shooter.y + (shooterRadius + 20) * SIN(shooter.a - _PI(11 / 16))
  225.     fTri x1, y1, x2, y2, x3, y3, _RGB32(85, 45, 0)
  226.     x1 = shooter.x + shooterRadius * COS(shooter.a)
  227.     y1 = shooter.y + shooterRadius * SIN(shooter.a)
  228.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(7 / 8))
  229.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(7 / 8))
  230.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(7 / 8))
  231.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(7 / 8))
  232.     fTri x1, y1, x2, y2, x3, y3, _RGB32(0, 0, 200)
  233.     x2 = shooter.x + shooterRadius * COS(shooter.a + _PI(15 / 16))
  234.     y2 = shooter.y + shooterRadius * SIN(shooter.a + _PI(15 / 16))
  235.     x3 = shooter.x + shooterRadius * COS(shooter.a - _PI(15 / 16))
  236.     y3 = shooter.y + shooterRadius * SIN(shooter.a - _PI(15 / 16))
  237.     fTri x1, y1, x2, y2, x3, y3, _RGB32(255, 255, 255)
  238.  
  239.     'check shooter x, y  = fixed a long time ago!
  240.     'fcirc shooter.x, shooter.y, 4, _RGB32(140, 120, 140)
  241.  
  242. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  243. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  244.     a& = _NEWIMAGE(1, 1, 32)
  245.     _DEST a&
  246.     PSET (0, 0), K
  247.     _DEST 0
  248.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  249.     _FREEIMAGE a& '<<< this is important!
  250.  
  251. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  252.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  253.     DIM X AS INTEGER, Y AS INTEGER
  254.  
  255.     Radius = ABS(R)
  256.     RadiusError = -Radius
  257.     X = Radius
  258.     Y = 0
  259.  
  260.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  261.  
  262.     ' Draw the middle span here so we don't draw it twice in the main loop,
  263.     ' which would be a problem with blending turned on.
  264.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  265.  
  266.     WHILE X > Y
  267.         RadiusError = RadiusError + Y * 2 + 1
  268.         IF RadiusError >= 0 THEN
  269.             IF X <> Y + 1 THEN
  270.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  271.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  272.             END IF
  273.             X = X - 1
  274.             RadiusError = RadiusError - X * 2
  275.         END IF
  276.         Y = Y + 1
  277.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  278.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  279.     WEND
  280.  
  281.  
  282. FUNCTION degree (a, b)
  283.     rd = (a + .00001) / (b + .0001): degree = ATN(rd) / pip180
  284.     IF 0 > b THEN degree = degree - 180
  285.     IF degree < 0 THEN degree = degree + 360
  286.  
  287.  
  288. SUB explosions_add (x, y, xd, yd)
  289.     FOR t1 = 1 TO explosions_s
  290.         FOR t = 0 TO explosions_buff - 1
  291.             IF explosions(t, 0) THEN _CONTINUE
  292.             explosions(t, 0) = 1 'enable
  293.             explosions(t, 1) = x 'Xpos
  294.             explosions(t, 2) = y 'Ypos
  295.             explosions(t, 3) = 0 'xd / 2 'x direction
  296.             explosions(t, 4) = 0 'yd / 2 'y direction
  297.             angle = 360 * RND(1) 'random angle
  298.             speed = 50 * RND(1) 'shard speed
  299.             explosions(t, 5) = SIN(angle * pip180) * speed 'vector X
  300.             explosions(t, 6) = COS(angle * pip180) * speed 'vector Y
  301.             explosions(t, 7) = 100 * RND(1) 'boss cycle encounter
  302.             explosions(t, 8) = 360 * RND(1) ' random/actual angle in radian
  303.             explosions(t, 9) = (2 + 7 * RND(1)) * 4 'size
  304.             explosions(t, 10) = (2 + 8 * RND(1)) * 3 'stepping rotate in radian
  305.             explosions(t, 11) = 256 * RND(1) 'greyscale random color
  306.         NEXT t
  307.     NEXT t1
  308.  
  309. SUB explosions_control
  310.     FOR t = 0 TO explosions_buff - 1
  311.         IF explosions(t, 0) = 0 THEN _CONTINUE
  312.         explosions(t, 7) = explosions(t, 7) - 1 'cycle to dead
  313.         IF explosions(t, 7) <= 0 THEN explosions(t, 0) = 0: _CONTINUE 'if cycle 0, then inactive shard
  314.         explosions(t, 1) = explosions(t, 1) + explosions(t, 3) + explosions(t, 5) 'X pos add
  315.         explosions(t, 2) = explosions(t, 2) + explosions(t, 4) + explosions(t, 6) 'Y pos add
  316.         explosions(t, 8) = explosions(t, 8) + explosions(t, 10) 'actual degree in radian
  317.         explosions(t, 9) = explosions(t, 9) * .85 'size lower
  318.         explosions(t, 5) = explosions(t, 5) * .999 'vector X lower
  319.         explosions(t, 6) = explosions(t, 6) * .999 'vector Y lower
  320.     NEXT t
  321.  
  322. SUB explosions_draw
  323.     REDIM q(2, 1)
  324.     FOR t1 = 0 TO explosions_buff - 1
  325.         IF explosions(t1, 0) = 0 THEN _CONTINUE
  326.         FOR t = 0 TO 2
  327.             q(t, 0) = SIN((t * 120 + explosions(t1, 8)) * pip180) * explosions(t1, 9) + explosions(t1, 1)
  328.             q(t, 1) = COS((t * 120 + explosions(t1, 8)) * pip180) * explosions(t1, 9) + explosions(t1, 2)
  329.         NEXT t
  330.         fTri q(0, 0), q(0, 1), q(1, 0), q(1, 1), q(2, 0), q(2, 1), _RGB32(explosions(t1, 11), 0, 0)
  331.     NEXT t1
  332.    55:
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on March 30, 2021, 05:35:01 pm
@MasterGy

Not seeing much difference in shooting but love the explosions!

Here are mine: https://www.qb64.org/forum/index.php?topic=3173.msg124984#msg124984

(In Hexagonal Minesweeper they leave craters!)
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on March 31, 2021, 11:24:00 am
@MasterGy

I missed it on my first check but yes! You have fixed the jerkiness with the shooter with this:
Code: QB64: [Select]
  1.  
  2.  
  3.     IF SQR((shooter.y - lasty) ^ 2 + (shooter.x - lastx) ^ 2) > 1 THEN
  4.         angle = degree(shooter.y - lasty, shooter.x - lastx) 'deg
  5.         dif_choice = 1000
  6.         FOR t = 0 TO 4
  7.             angle_dif = shooter_degree - (angle + 360 * (2 - t))
  8.             dif = ABS(angle_dif)
  9.             IF dif < dif_choice THEN angle_dif_choice = angle_dif: dif_choice = dif
  10.         NEXT t
  11.         shooter_degree = shooter_degree - angle_dif_choice * .25 'rotating speed (.25)
  12.         DO WHILE shooter_degree > 360: shooter_degree = shooter_degree - 360: LOOP
  13.         DO WHILE shooter_degree < 360: shooter_degree = shooter_degree + 360: LOOP
  14.         shooter.a = shooter_degree * pip180
  15.         lastx = shooter.x: lasty = shooter.y
  16.     END IF
  17.  
  18.  

The test is to move and turn the shooter = ship in a tight circle, or spin even, and if the nose bounces between two angles with 5 -15 degrees difference it's "jerky".  MasterGy's version seems to have dampened down the the wild swings to a much smaller vibration 1-3 degrees.

Thank you! nice work. I will study and try to convert back to _ATAN2 if possible.
Title: Re: MasterGy is looking for ideas to implement ("i suffer")
Post by: bplus on April 01, 2021, 01:22:37 pm
@MasterGy

Thanks for showing it possible to handle Mouse Action Shooting without the jerk problem caused by a method too sensitive to any movement like unintended movement when pressing left or right mouse button or just stopping mouse movement which often ends in a little unintended flick.

I managed to work out a system not requiring conversion to degrees or testing for minimum angles.
I posted it here:
https://www.qb64.org/forum/index.php?topic=3173.msg131314#msg131314

I am intending to install it in new update of Asteroids, b+ style :)