Author Topic: Vector Library and WideScreen Asteroids  (Read 12412 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Vector Library and WideScreen Asteroids
« on: February 05, 2020, 11:13:16 pm »
---------------------------------------
UPDATE 02/11/20 9:21PM EST
Updated the .ZIP file below again. I made it to level 12 and ... crash. Found the bug and fixed it. The maximum asteroids that can ever be on the screen at once in a perfect scenario is 64 (16 large asteroids times 4 small asteroids). I set the asteroids array to 63 when it should have been 64. Oops.
---------------------------------------
UPDATE 02/07/20 3:15PM EST
The .ZIP has again been updated. The Button function has been completely rewritten to use the vector library's ObjPrint vector text command instead. _PRINTSTRING is just way too resource heavy to be used in real-time menus. Also made a few more efficiency changes. No matter how many objects on the screen now the drop down menu does not slow anything down.
---------------------------------------
UPDATE 02/06/20 11:15PM EST
I updated the .ZIP file below with a bug fixed and some inefficiencies in the collision routines I corrected. I also removed the pre-compiled .EXE to make the .ZIP file smaller.
---------------------------------------

Sorry I have been away for so long but I come bearing gifts :-)

I had to put the Sprite library on the back-burner because of unforeseen problems I encountered with it. Because of that I decided to step away from programming for a bit. When I got my head on straight again I decided to write a vector library. Of course I need to write a game to prove the library so I wrote Widescreen Asteroids.

Widescreen Asteroids is not a clone. It's what I always wanted in an Asteroids game. It's very close to the original with a few enhancements. The vector engine is fast so the game is filled with particle effects and, of course, asteroids. I hope you'll like the game. Please report any bugs or errors you find in the game.

I don't have documentation written yet for the vector library. Below is a crude listing of commands that it supports. I'll have the documentation finished soon.

The ZIP file contains everything needed to run and compile the game. It contains a pre-compiled .EXE so you can run the game right away if you wish. If you prefer to compile yourself simply delete "asteroids.exe".

--- CRUDE COMMAND LISTING FOR VECTOR LIBRARY ---

Sub         ObjActive   ObjID, Flag               Sets the active value of an object
Sub         ObjAngle   ObjID, Angle            Set the angle of an object
Sub         ObjBind      ObjID, X1, Y1, X2, Y2, Mode   Set the minimum X and Y coordinates allowed for object
Sub         ObjColor   ObjID, Lnumber, Clr         Set or reset the color for one or all line segments within an object
Sub         ObjDraw      ObjID                  Draw an object to the screen
Sub         ObjFriction   ObjID, Friction            Set the friction amount for an object
Sub         ObjInit                           Initialize variables for object library
Sub         ObjLines   ObjID                  Get all line info from an object at current angle (INTERNAL USE ONLY)
Sub         ObjMove      ObjID                  Update an object's position based on all current values
Sub         ObjPrint   tx, tx, Text, Scale, Clr   Print vector text at the coordinates specified
Sub         ObjPush      ObjID, Force            Push an object in its current direction
Sub         ObjPut      ObjID, X, Y               Set the X,Y coordinates of an object
Sub         ObjRotate   ObjID, Angle, Mode         Rotate an object to either absolute or relative angle, or auto rotate
Sub         ObjScale   ObjID, Scale            Set the X and Y scale of an object
Sub         ObjScaleX   ObjID, Scale            Set the X scale of an object
Sub         ObjScaleY   ObjID, Scale            Set the Y scale of an object
Sub         ObjStamp   ObjID, x, y, Angle, Scale, Clr   Place a copy of an object on-screen
Sub         ObjVectorX   ObjID, XV               Set the X vector value for an object
Sub         ObjVectorY   ObjID, YV               Set the Y vector value for an object

Function   ObjActive   ObjID                  Get the active value of an object
Function   ObjAngle   ObjID                  Get current angle of object
Function    ObjAngleO2O   ObjID1, ObjID1            Get the angle between two object center points
Function   ObjAngleP2P   x1, y1, x2, y2            Get the angle between two X,Y coordinate pairs
Function   ObjBoxHit   ObjID1, ObjID2            Return TRUE if two objects touching via bounding boxes
Function   ObjColor   ObjID, Lnumber            Get color of line within object
Function   ObjDistO2O   ObjID1, ObjID2            Get distance between center point of two objects
Function   ObjDistP2P   x1, y1, x2, y2            Get distance between two X,Y coordinate pairs
Function   ObjFixAngle   Angle                  Return the angle passed in from 0 to 360
Function   ObjFriction   ObjID                  Get current friction of object
Function   ObjHeight   ObjID                  Get current height of object
Function   ObjIntersect   p1x, p1y, q1x, q1y, p2x, p2y, q2x, q2y   Return TRUE if two line segments are intersecting
Function   ObjLineHit   ObjID, p2x, p2y, q2x,q2y   Return TRUE if a line segment is touching an object
Function   ObjLoad      File                  Load an object file into memory
Function   ObjObjectHit   ObjID1, ObjID2         Return TRUE if any line segments in two objects touch
Function   ObjMake      ObjID                  Make an object from objects in memory
Function   ObjMax      n1, n2                  Return the largest of two numbers
Function   ObjMaxX      ObjID                  Get maximum X coordinate allowed for object
Function   ObjMaxY      ObjID                  Get maximum Y coordinate allowed for object
Function   ObjMin      n1, n2                  Return the smallest of two numbers
Function   ObjMinX      ObjID                  Get minimum X coordinate allowed for object
Function   ObjMinY      ObjID                  Get minimum Y coordinate allowed for object
Function   ObjNCosine   Angle                  Get the cosine value of a negative angle
Function   ObjNSine   Angle                  Get the sine value of a negative angle
Function   OBJPCosine   Angle                  Get the cosine value of a positive angle
Function   ObjPSine   Angle                  Get the since value of a positive angle
Function   ObjRadius   ObjID                  Get current radius of object
Function   ObjRadiusHit   ObjID1, ObjID2         Return TRUE if two objects touching via radii distance
Function   ObjScale   ObjID                  Get scale of object if X and Y scales are the same, otherwise -1
Function   ObjScaleX   ObjID                  Get X scale of object
Function   ObjScaleY   ObjID                  Get Y scale of object
Function   ObjSpeed   ObjID                  Get current speed of object
Function   ObjVectorX   ObjID                  Get current X vector of object
Function   ObjVectorY   ObjID                  Get current Y vector of object
Function   ObjX      ObjID                  Get current X coordinate of object
Function   ObjX1      ObjID, Lnumber            Get start X coordinate of line within object
Function   ObjX2      ObjID, Lnumber            Get end X coordinate of line within object
Function   ObjY      ObjID                  Get current Y coordinate of object
Function   ObjY1      ObjID, Lnumber            Get start Y coordinate of line within object
Function   ObjY2      ObjID, Lnumber            Get end Y coordinate of line within object
Fucntion   ObjWidth   ObjID                  Get current width of object
Function   onSegment   p, q, r                  Return TRUE if point q lies on line segment pr (INTERNAL USE ONLY)
Function   Orientation   p, q, r                  Returns orientation of ordered triplet pair (INTERNAL USE ONLY)
* WIDESCREEN ASTEROIDS.zip (Filesize: 1.8 MB, Downloads: 364)
« Last Edit: February 11, 2020, 09:24:52 pm by TerryRitchie »
In order to understand recursion, one must first understand recursion.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #1 on: February 05, 2020, 11:22:59 pm »
This is very smooth, thanks for sharing!

(I like anything with the word vector in it, will be having a look under the hood!)

My only question - so where's the time machine? Today's date being the 5th!

Code: QB64: [Select]
  1. '                            Terry Ritchie
  2. '                         February 10th, 2020
  3. '                             QB64 V1.3
« Last Edit: February 05, 2020, 11:26:47 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #2 on: February 05, 2020, 11:26:00 pm »
This is awesome! Now I found out what I'm gonna be doing for the rest of the night. :-)
I am from a Kazakhstan, we follow the hawk.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #3 on: February 05, 2020, 11:31:58 pm »
This is very smooth, thanks for sharing!

(I like anything with the word vector in it, will be having a look under the hood!)

My only question - so where's the time machine? Today's date being the 5th!

Code: QB64: [Select]
  1. '                            Terry Ritchie
  2. '                         February 10th, 2020
  3. '                             QB64 V1.3

Oops :-) I changed January to February but forgot about the day.
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #4 on: February 05, 2020, 11:49:24 pm »
Hey welcome back!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #5 on: February 06, 2020, 12:33:55 am »
In order to understand recursion, one must first understand recursion.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #6 on: February 06, 2020, 12:35:52 am »
This is awesome! Now I found out what I'm gonna be doing for the rest of the night. :-)

Use the pause button now and then to give yourself a break :-)

By the way, my high score is just over 60,000, wave 11.
In order to understand recursion, one must first understand recursion.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #7 on: February 06, 2020, 01:04:10 am »
I can't blame you for being away for so long. It must have been murder trying to code even a few lines per day with such a bad case of asteroids, especially the wide screen kind. I hear those require lots of Preperation |---|.

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

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #8 on: February 06, 2020, 02:14:34 am »
I can't blame you for being away for so long. It must have been murder trying to code even a few lines per day with such a bad case of asteroids, especially the wide screen kind. I hear those require lots of Preperation |---|.

Pete

Son of a bitch I missed your humor! LOL
In order to understand recursion, one must first understand recursion.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #9 on: February 06, 2020, 02:21:55 am »
Use the pause button now and then to give yourself a break :-)

By the way, my high score is just over 60,000, wave 11.

so far im up to 16800, i forget which wave it was though, either 4 or 5.
Seriously think this might be better than the original
I am from a Kazakhstan, we follow the hawk.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #10 on: February 06, 2020, 04:54:24 am »
so far im up to 16800, i forget which wave it was though, either 4 or 5.
Seriously think this might be better than the original

That's what I was striving for. I love the coin-op Asteroids but always wish it was just a bit harder, with more effects, and more asteroids. The wide screen format provides the room for more asteroids. The program also notices when you "saucer hunt". The small saucers will start coming out and target you AND the remaining asteroids, forcing the next wave to appear.

The program continues to get progressively harder until wave 12. After that it will still count the waves encountered, but large asteroids will top out at 16. By that time though you have been thoroughly whipped just getting there. I never liked how in the original Asteroids you could somewhat "master" it. I doubt this version could be mastered, meaning that when you get a high score you've actually earned it. :-)

Oh, and there is a bug I just discovered tonight. I'm not yet sure how to trigger it but it seems if you hit an asteroid and one of your bullets hit it at the exact same time the kill will not get recorded and the ship will respawn in the exact location almost immediately. I don't yet see in the code where this could happen but it has happened to me twice now while playing. I've been purposely hurling myself at asteroids while firing in hopes of figuring out how I can trigger it at will to get an idea of where the bug lies.
« Last Edit: February 06, 2020, 04:59:36 am by TerryRitchie »
In order to understand recursion, one must first understand recursion.

FellippeHeitor

  • Guest
Re: Vector Library and WideScreen Asteroids
« Reply #11 on: February 06, 2020, 06:47:13 am »
Quote
(...) it seems if you hit an asteroid and one of your bullets hit it at the exact same time the kill will not get recorded and the ship will respawn in the exact location almost immediately

Call it a feature and name those “the resilient ones”.

Always rich times when you’re around Terry! Welcome back.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #12 on: February 06, 2020, 06:51:25 am »
That's what I was striving for. I love the coin-op Asteroids but always wish it was just a bit harder, with more effects, and more asteroids. The wide screen format provides the room for more asteroids. The program also notices when you "saucer hunt". The small saucers will start coming out and target you AND the remaining asteroids, forcing the next wave to appear.

The program continues to get progressively harder until wave 12. After that it will still count the waves encountered, but large asteroids will top out at 16. By that time though you have been thoroughly whipped just getting there. I never liked how in the original Asteroids you could somewhat "master" it. I doubt this version could be mastered, meaning that when you get a high score you've actually earned it. :-)

Oh, and there is a bug I just discovered tonight. I'm not yet sure how to trigger it but it seems if you hit an asteroid and one of your bullets hit it at the exact same time the kill will not get recorded and the ship will respawn in the exact location almost immediately. I don't yet see in the code where this could happen but it has happened to me twice now while playing. I've been purposely hurling myself at asteroids while firing in hopes of figuring out how I can trigger it at will to get an idea of where the bug lies.

I'm completely guilty of trying to saucer hunt. Didn't really work out as I hoped, now I know why... :-D
I am from a Kazakhstan, we follow the hawk.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Vector Library and WideScreen Asteroids
« Reply #13 on: February 06, 2020, 07:13:24 am »
Call it a feature and name those “the resilient ones”.

Always rich times when you’re around Terry! Welcome back.

Thanks :-)

I think I found another bug but this time with $EXEICON

I added $CHECKING:OFF as the first line of my asteroids.bas source code. As soon as I tried to compile I got an error. It seems that $EXEICON adds a "do{" statement just before it (see main.txt) but never concludes with a "}while".

If I REM out the $EXEICON line the compile error disappears.

When I compile with $EXEICON and $CHECKING:OFF this is what I get:

C++ Compilation failed (check .\internal\temp\compilelog.txt)

When I open compilelog.txt it reads:

In file included from qbx.cpp:2171:
..\\temp\\main.txt: In function 'void QBMAIN(void*)':
..\\temp\\main.txt:244:6: error: expected 'while' before 'SUB_PROCESSKEYS'
 void SUB_PROCESSKEYS(){
      ^~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

This is what I have in main.txt:

do{
sub__icon(NULL,NULL,0);
sub__icon(NULL,NULL,0);
sub__title(qbs_new_txt_len("Widescreen Asteroids",20));
qbs_cleanup(qbs_tmp_base,0);
qbg_screen(func__newimage( 1279 + 1 , 719 + 1 , 32 ,1),NULL,NULL,NULL,NULL,1);
sub_cls(NULL,NULL,0);
SUB_OBJINIT();
SUB_LOADASSETS();
SUB_SETFULLSCREEN();
do{
SUB_INTROSCREEN();
SUB_NEXTLEVEL();
do{
sub__limit( 60 );
sub_cls(NULL,NULL,0);
SUB_UPDATEGAME();
sub__display();
dl_continue_2:;
}while((!(*(int16*)(((char*)__UDT_GAME)+(32))))&&(!new_error));
dl_exit_2:;
dl_continue_1:;
}while(1);
dl_exit_1:;
sub_end();
return;
}

The last line should include a "while" and it doesn't. The very first "do{" seems to be created by $EXEICON.
In order to understand recursion, one must first understand recursion.

FellippeHeitor

  • Guest
Re: Vector Library and WideScreen Asteroids
« Reply #14 on: February 06, 2020, 09:15:43 am »
Thanks for the report. Looking into it now.