Author Topic: Knight VS Castle  (Read 4535 times)

0 Members and 1 Guest are viewing this topic.

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Knight VS Castle
« on: March 04, 2019, 07:03:13 am »
Good morning to everybody,

Yesterday I have write some QB lines....

I know, I stayed at the 90s, so I used the QB45 commands .....

You have to imagine a person who in about 1995 enters a time machine and finds himself in 2019 .... for this I still use the QB45.

However I see that the commands are perfectly compatible, but I have to learn the new "magic" commands (those with the underscore _ sign)

I only modified the screen (no screen 13).

It will be a very fast game ......

As soon as I can I will add lines ....

My biggest enemy is the lack of time for work commitments .....

Any suggestion is well accepted!

Have a nice day

Code: QB64: [Select]
  1. handle& = _NEWIMAGE(320, 240, 256)
  2. SCREEN handle&
  3.  
  4.  
  5.  
  6.  
  7. LINE (0, 0)-(320, 240), 54, BF
  8.  
  9. NVX = 50
  10. NVY = 50
  11. COLN = 15
  12.  
  13. CIRCLE (NVX - 10, NVY + 5), 5, COLN
  14. PAINT (NVX - 10, NVY + 5), COLN
  15.  
  16. CIRCLE (NVX, NVY), 10, COLN
  17. PAINT (NVX, NVY), COLN
  18. CIRCLE (NVX + 20, NVY - 10), 14, COLN
  19. PAINT (NVX + 20, NVY - 10), COLN
  20. CIRCLE (NVX + 40, NVY - 16), 18, COLN
  21. PAINT (NVX + 40, NVY - 16), COLN
  22. CIRCLE (NVX + 60, NVY - 10), 14, COLN
  23. PAINT (NVX + 60, NVY - 10), COLN
  24. CIRCLE (NVX + 80, NVY), 10, COLN
  25. PAINT (NVX + 80, NVY), COLN
  26. CIRCLE (NVX + 90, NVY + 5), 5, COLN
  27. PAINT (NVX + 90, NVY + 5), COLN
  28.  
  29.  
  30. LINE (NVX - 10, NVY)-(NVX + 90, NVY + 10), COLN, BF
  31. LINE (NVX - 15, NVY + 5)-(NVX + 95, NVY + 10), COLN, BF
  32. LINE (NVX - 18, NVY + 11)-(NVX + 98, NVY + 11), COLN
  33. LINE (NVX - 24, NVY + 12)-(NVX + 104, NVY + 12), COLN
  34. LINE (NVX - 34, NVY + 13)-(NVX + 114, NVY + 13), COLN
  35.  
  36.  
  37. '************** TERRENO
  38.  
  39. LINE (0, 200)-(320, 240), 262, BF
  40. LINE (0, 200)-(320, 208), 2, BF
  41. LINE (0, 200)-(320, 202), 10, BF
  42.  
  43. FOR T = 1 TO 80
  44.     TERX = INT(RND(1) * 320)
  45.     TERY = INT(RND(1) * 30) + 210
  46.  
  47.     LINE (TERX, TERY)-(TERX + 3, TERY + 2), 298, BF
  48.  
  49. '***** castello
  50.  
  51. CAX = 260
  52. CAY = 200
  53. CLCAS = 22
  54.  
  55.  
  56. PSET (CAX, CAY)
  57. DRAW "C22U100H20U20R20D20R20U20R20D20R20D120L60"
  58. PAINT (CAX + 20, CAY - 20), 22
  59.  
  60. 'PRZX = INT(RND(1) * 98) + 1
  61. 'RZY = INT(RND(1) * 98) + 1
  62.  
  63.  
  64. FOR T = 1 TO 40
  65.     PRZX = INT(RND(1) * 80) + 260
  66.     PRZY = INT(RND(1) * 100) + 95
  67.  
  68.     LINE (PRZX, PRZY)-(PRZX + 3, PRZY + 2), 20, BF
  69.  
  70.  
  71. ' WINDOWS
  72. CIRCLE (CAX + 40, CAY - 70), 8, 0
  73. PAINT (CAX + 40, CAY - 70), 0
  74. LINE (CAX + 32, CAY - 70)-(CAX + 48, CAY - 55), 0, BF
  75.  
  76. ' DOOR
  77. CIRCLE (CAX + 40, CAY - 25), 14, 0
  78. PAINT (CAX + 40, CAY - 25), 0
  79. LINE (CAX + 26, CAY - 25)-(CAX + 54, CAY), 0, BF
  80.  
  81.  
  82. LINE (CAX, CAY - 65)-(CAX + 10, CAY - 75), 0, BF
  83.  
  84.  
  85. '***** ATTACCANTE
  86.  
  87. ' GUN
  88. GUNX = 170
  89. GUNY = 193
  90.  
  91. LINE (GUNX - 12, GUNY - 5)-(GUNX + 16, GUNY), 21, BF
  92. LINE (GUNX + 16, GUNY - 6)-(GUNX + 17, GUNY + 1), 21, BF
  93.  
  94.  
  95. CIRCLE (GUNX, GUNY), 8, 0
  96. PSET (GUNX, GUNY)
  97. DRAW "C0U4D8U4R4L8R4E4G8E4F4H8"
  98.  
  99. FLX = 110
  100. FLY = 170
  101.  
  102. PSET (FLX, FLY)
  103.  
  104. DRAW "C42R12D18H6G6U18R12"
  105. PAINT (FLX + 2, FLY + 2), 42
  106.  
  107. LINE (FLX, FLY + 3)-(FLX + 12, FLY + 7), 14, BF
  108.  
  109. FLX = 265
  110. FLY = 80
  111.  
  112. PSET (FLX, FLY)
  113.  
  114. DRAW "C14R12D18H6G6U18R12"
  115. PAINT (FLX + 2, FLY + 2), 14
  116.  
  117. LINE (FLX, FLY + 3)-(FLX + 12, FLY + 7), 2, BF
  118.  
  119.  
  120. FLX = 305
  121. FLY = 80
  122.  
  123. PSET (FLX, FLY)
  124.  
  125. DRAW "C14R12D18H6G6U18R12"
  126. PAINT (FLX + 2, FLY + 2), 14
  127.  
  128. LINE (FLX, FLY + 3)-(FLX + 12, FLY + 7), 2, BF
  129.  
  130.  
  131.  
  132.  
  133.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Knight VS Castle
« Reply #1 on: March 04, 2019, 10:38:39 am »
Did you do the artwork yourself? I really like it. It looks like a professionally done screen for some type of 1990s Nintendo game. I put a bunch of SLEEP statements in the code you posted, just so I could see it being drawn step by step.

I have no talent for graphics, so I cannot comment as to how you might improve on what you are doing. I can tell you with QB64 there are many more color combinations available, with color blending and other features, but for what you are building, I doubt you would need to learn those.

I have a friend at my forum, Bob, who is great with computer art. You are welcome to check his stuff out in the QB64 samples files, inside your QB64 folder you downloaded, under "TheBOB".  Oh, there's a "Pete" in that samples folder, too, but that's that "other" Pete. He's a friend from another QB forum site, Pete's QB Forum. Anyway, if you ever want to stop by and chat with TheBOB, he posts at: https://www.tapatalk.com/groups/qbasic/

Again, great stuff so far and I know it's time consuming. You are always welcome to ask for help, especially when you are willing to share the code. It is a thousand times easier to help people when we get to see how they are putting a project together.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Knight VS Castle
« Reply #2 on: March 04, 2019, 11:19:19 am »
Thanks Pete,

second step: fire !

Code: QB64: [Select]
  1. handle& = _NEWIMAGE(320, 240, 256)
  2. SCREEN handle&
  3.  
  4.  
  5.  
  6.  
  7. LINE (0, 0)-(320, 240), 54, BF
  8.  
  9. NVX = 50
  10. NVY = 50
  11. COLN = 15
  12.  
  13. CIRCLE (NVX - 10, NVY + 5), 5, COLN
  14. PAINT (NVX - 10, NVY + 5), COLN
  15.  
  16. CIRCLE (NVX, NVY), 10, COLN
  17. PAINT (NVX, NVY), COLN
  18. CIRCLE (NVX + 20, NVY - 10), 14, COLN
  19. PAINT (NVX + 20, NVY - 10), COLN
  20. CIRCLE (NVX + 40, NVY - 16), 18, COLN
  21. PAINT (NVX + 40, NVY - 16), COLN
  22. CIRCLE (NVX + 60, NVY - 10), 14, COLN
  23. PAINT (NVX + 60, NVY - 10), COLN
  24. CIRCLE (NVX + 80, NVY), 10, COLN
  25. PAINT (NVX + 80, NVY), COLN
  26. CIRCLE (NVX + 90, NVY + 5), 5, COLN
  27. PAINT (NVX + 90, NVY + 5), COLN
  28.  
  29.  
  30. LINE (NVX - 10, NVY)-(NVX + 90, NVY + 10), COLN, BF
  31. LINE (NVX - 15, NVY + 5)-(NVX + 95, NVY + 10), COLN, BF
  32. LINE (NVX - 18, NVY + 11)-(NVX + 98, NVY + 11), COLN
  33. LINE (NVX - 24, NVY + 12)-(NVX + 104, NVY + 12), COLN
  34. LINE (NVX - 34, NVY + 13)-(NVX + 114, NVY + 13), COLN
  35.  
  36.  
  37. '************** TERRENO
  38.  
  39. LINE (0, 200)-(320, 240), 262, BF
  40. LINE (0, 200)-(320, 208), 2, BF
  41. LINE (0, 200)-(320, 202), 10, BF
  42.  
  43. FOR T = 1 TO 80
  44.     TERX = INT(RND(1) * 320)
  45.     TERY = INT(RND(1) * 30) + 210
  46.  
  47.     LINE (TERX, TERY)-(TERX + 3, TERY + 2), 298, BF
  48.  
  49. '***** castello
  50.  
  51. CAX = 260
  52. CAY = 200
  53. CLCAS = 22
  54.  
  55.  
  56. PSET (CAX, CAY)
  57. DRAW "C22U100H20U20R20D20R20U20R20D20R20D120L60"
  58. PAINT (CAX + 20, CAY - 20), 22
  59.  
  60. 'PRZX = INT(RND(1) * 98) + 1
  61. 'RZY = INT(RND(1) * 98) + 1
  62.  
  63.  
  64. FOR T = 1 TO 40
  65.     PRZX = INT(RND(1) * 80) + 260
  66.     PRZY = INT(RND(1) * 100) + 95
  67.  
  68.     LINE (PRZX, PRZY)-(PRZX + 3, PRZY + 2), 20, BF
  69.  
  70.  
  71. ' WINDOWS
  72. CIRCLE (CAX + 40, CAY - 70), 8, 0
  73. PAINT (CAX + 40, CAY - 70), 0
  74. LINE (CAX + 32, CAY - 70)-(CAX + 48, CAY - 55), 0, BF
  75.  
  76. ' DOOR
  77. CIRCLE (CAX + 40, CAY - 25), 14, 0
  78. PAINT (CAX + 40, CAY - 25), 0
  79. LINE (CAX + 26, CAY - 25)-(CAX + 54, CAY), 0, BF
  80.  
  81.  
  82. LINE (CAX, CAY - 65)-(CAX + 10, CAY - 75), 0, BF
  83.  
  84.  
  85. '***** ATTACCANTE
  86.  
  87. ' GUN
  88. GUNX = 100
  89. GUNY = 193
  90.  
  91. LINE (GUNX - 12, GUNY - 5)-(GUNX + 16, GUNY), 21, BF
  92. LINE (GUNX + 16, GUNY - 6)-(GUNX + 17, GUNY + 1), 21, BF
  93.  
  94.  
  95. CIRCLE (GUNX, GUNY), 8, 0
  96. PSET (GUNX, GUNY)
  97. DRAW "C0U4D8U4R4L8R4E4G8E4F4H8"
  98.  
  99. FLX = 40
  100. FLY = 170
  101.  
  102. PSET (FLX, FLY)
  103.  
  104. DRAW "C42R12D18H6G6U18R12"
  105. PAINT (FLX + 2, FLY + 2), 42
  106.  
  107. LINE (FLX, FLY + 3)-(FLX + 12, FLY + 7), 14, BF
  108.  
  109. FLX = 265
  110. FLY = 80
  111.  
  112. PSET (FLX, FLY)
  113.  
  114. DRAW "C14R12D18H6G6U18R12"
  115. PAINT (FLX + 2, FLY + 2), 14
  116.  
  117. LINE (FLX, FLY + 3)-(FLX + 12, FLY + 7), 2, BF
  118.  
  119.  
  120. FLX = 305
  121. FLY = 80
  122.  
  123. PSET (FLX, FLY)
  124.  
  125. DRAW "C14R12D18H6G6U18R12"
  126. PAINT (FLX + 2, FLY + 2), 14
  127.  
  128. LINE (FLX, FLY + 3)-(FLX + 12, FLY + 7), 2, BF
  129.  
  130. ' ********* LIFE BAR CASTLE
  131. LBCX = 260
  132. LBCY = 35
  133. LINE (LBCX, LBCY)-(LBCX + 42, LBCY + 7), 0, BF
  134. LINE (LBCX + 1, LBCY + 1)-(LBCX + 41, LBCY + 6), 2, BF
  135.  
  136.  
  137.  
  138. ' *********+ SHOT
  139. ALX = 95
  140. ALY = 207
  141.  
  142.  
  143. X = ALX + 20: Y = ALY - 20
  144. FOR T = 1 TO 15
  145.     X = X + 10
  146.     CIRCLE (X, Y), 3, 42
  147.     PAINT (X, Y), 42
  148.     CIRCLE (X, Y), 2, 41
  149.     PAINT (X, Y), 41
  150.     CIRCLE (X, Y), 1, 40
  151.     PAINT (X, Y), 40
  152.  
  153.     _DELAY 0.2
  154.  
  155.     CIRCLE (X, Y), 6, 54
  156.     PAINT (X, Y), 54
  157.  
  158.  
  159.  
  160.  

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Knight VS Castle
« Reply #3 on: March 04, 2019, 11:22:12 am »
Knight vs. Castle: not the deep chess problem that I was expecting!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Knight VS Castle
« Reply #4 on: March 04, 2019, 11:31:23 am »
Knight vs. Castle: not the deep chess problem that I was expecting!

I know, right? I had to look at the code before I realized it wasn't a chess project. Here's a screen shot of the first code submission.

 
Untitled.png
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Knight VS Castle
« Reply #5 on: March 04, 2019, 11:35:07 am »
Knight vs. Castle: not the deep chess problem that I was expecting!

True Qwerkey : D

I have to get familiar with the QB....

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Knight VS Castle
« Reply #6 on: March 04, 2019, 11:40:21 am »
I must say that the _delay command is really fantastic.
25 years ago I used a empty cycle for next .... but delay changed with the speed of the computer CPU ....

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Knight VS Castle
« Reply #7 on: March 04, 2019, 11:42:41 am »
In the third step, Castle will reply with a fire ball....

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Knight VS Castle
« Reply #8 on: March 04, 2019, 12:08:55 pm »
See if you like this cannon ball fire animation a bit better. Just added _LIMIT and changed delay from .2 to .1, which smooths out the animation.

Code: QB64: [Select]
  1. FOR T = 1 TO 15
  2.     _LIMIT 10
  3.     X = X + 10
  4.     CIRCLE (X, Y), 3, 42
  5.     PAINT (X, Y), 42
  6.     CIRCLE (X, Y), 2, 41
  7.     PAINT (X, Y), 41
  8.     CIRCLE (X, Y), 1, 40
  9.     PAINT (X, Y), 40
  10.  
  11.     _DELAY 0.1
  12.  
  13.     CIRCLE (X, Y), 6, 54
  14.     PAINT (X, Y), 54
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Knight VS Castle
« Reply #9 on: March 04, 2019, 12:35:53 pm »
Pete, this is silly code:

Code: QB64: [Select]
  1. FOR T = 1 TO 15
  2.     _LIMIT 10
  3.     _DELAY 0.1

I’ve seen you do things like this several times already, indicating that you don’t understand the two commands very well...

_LIMIT says, “This loop won’t run more than this number of times per second.”
_DELAY says, “Pause the program for this set amount of time.”

You don’t need to put both commands in the same loop...

FOR I = 1 TO 100
    _DELAY 0.1
LOOP

A 1/10 second delay in the above is going to make that loop take 10 seconds to execute.

FOR I = 1 TO 100
    _LIMIT 10
NEXT

Since the above loop only runs 10 times per second, it’ll take 10 seconds to execute.

No need to mix the two commands, as they’re both used for controlling execution speed...



So what’s the biggest difference in the two commands??

_DELAY is a hard pause, _LIMIT is an automatically adjustable pause.

FOR I = 1 TO 100
   PRINT “HELLO WORLD”
   _DELAY 0.1
NEXT

The above will take 10 seconds to run from the delay, PLUS the time it takes to print to the screen 10 times.

FOR I = 1 TO 100
    PRINT “HELLO WORLD”
    _LIMIT 10
NEXT

While the above will take 10 seconds to run.  _LIMIT will count the time it takes to perform the print and then pause 0.0997 seconds (or whatever is needed) to maintain the 10 loops per second limit you set.

_DELAY is a hard pause of a set time.
_LIMIT is an adjustable pause with a maximum number of loops being executed each second.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Knight VS Castle
« Reply #10 on: March 04, 2019, 01:10:57 pm »
The point is you can mix them, and vary the results of the animation, but I agree that you  don't need both, just the best value for _DELAY would do as well. I usually just use _LIMIT to reduce CPU usage in keyboard input loops, but it was fun to use it in this animation, well, until some party pooper came along, that is. In this example, lowering the frames rate below 10 will change the animation speed, although I do agree just adding to the delay would achieve much the same results. If it was a loop for a much longer use, like most video games, I would certainly want to limit the frames rate to save CPU usage. For this example, the _LIMIT could be removed and the results, with the smaller delay, would be comparable. Basically I just introduced a new QB64 statement to the user, but it isn't introducing it at its best. I hope he does know that he can use various delays like .12, .104, etc., up to 7 digits. That gives a lot animation potential.

So as for what the commands do,  I know what they are for.  Now go be a dear and find some of those "many" examples, so I can have a look at them.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Knight VS Castle
« Reply #11 on: March 04, 2019, 02:30:42 pm »
Thanks for your suggestions SMcNeill and Pete.

I will study the command _LIMIT and all other QB64 undescored commands (as soon as possible...)

Have a nice morning/afternoon/evening

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Knight VS Castle
« Reply #12 on: March 04, 2019, 02:50:53 pm »
Only one question. Can I borrow your cannon? I want to take another shot at that castle; that's with a silent "c", right? Sorry Steve, I couldn't _LIMIT resist. :D

OK, kidding between Steve and me aside, I'm curious if you are planning to make this into some type of game, or using it to reacquaint yourself with QB graphics programming. Maybe both? I mean it would be a lot of work, but the obvious game would be where you can maneuver your cannon back and forth and adjust the trajectory. Each strike could blow out a certain amount of bricks in the castle, and you'd need an algorithm to determine when enough damage was done to cause structural failure (sees castle tipping over). The AI strikes from the castle (fire balls) could take out the player before this is achieved. The player / AI could likewise be switched. Is that what you are "shooting" for? Pun intended.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Knight VS Castle
« Reply #13 on: March 04, 2019, 03:43:51 pm »
Hi Pete,
Just a try.
However, the fun is sharing code in the forum.
The algorithm is not a problem.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Knight VS Castle
« Reply #14 on: March 06, 2019, 09:54:26 am »
HI qb4ever

this graphic let me remember a mini game made in java. In this you fire with a cannon setting force and angle of the fire, moreover you set the type of potion that you fire to defend you laboratory, and there is also a wall as barrier to stop the zombies or skeleton or monsters that comes towards laboratory to destroy it!
sorry but I don't remember the exact name to post the link of this game.

Programming isn't difficult, only it's  consuming time and coffee