Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:14 09 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Dev Diary: Space RPG - Definitely not Star Trek.

     Page 5 of 5    
Author Message
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 12:09am 31 Mar 2025
Copy link to clipboard 
Print this post

I know it's been a while since I've given an update on this project - but that doesn't mean I haven't been busy with it. Quite the opposite, there are some huge changes coming down the pipeline (that I'm quite excited about). But in the meantime, we had a discussion on a separate thread about using a data structure type variable within MMBASIC.

Original thread here: https://www.thebackshed.com/forum/ViewTopic.php?TID=17794&P=3

Up until now I've been using arrays to store game data, and using Constants to make them a bit more readable.

For example:
DIM FLOAT Ships(100,18)
CONST SHIP_TYPE = 1
CONST SHIP_X = 2
CONST SHIP_Y = 3
CONST SHIP_ANGLE = 4
CONST SHIP_SHIELDN = 5
CONST SHIP_SHIELDE = 6
CONST SHIP_SHIELDS = 7
CONST SHIP_SHIELDW = 8
CONST SHIP_SHIELD_MAX = 9
CONST SHIP_HULL = 10
CONST SHIP_ENGINES = 11
CONST SHIP_WEAPONS = 12
CONST SHIP_SENSORS = 13
CONST SHIP_LOGIC = 14  ' 0=None, 1=Attacking, 2=Fleeing
CONST SHIP_LOGIC2 = 15 ' Used as part of the logic
CONST SHIP_POWER = 16
CONST SHIP_DX = 17
CONST SHIP_DY = 18

So to reference the Angle of Ship 15 you would use
Ships(15,SHIP_ANGLE)

The realisation that we can use dots ('.') in variable names in MMBasic allows me to use a much neater solution where I define multiple arrays that look very similar to structures in other languages.
DIM FLOAT Ship.Type(100)
DIM FLOAT Ship.X(100)
DIM FLOAT Ship.Y(100)
DIM FLOAT Ship.Angle(100)
DIM FLOAT Ship.ShieldN(100)
DIM FLOAT Ship.ShieldE(100)
DIM FLOAT Ship.ShieldS(100)
DIM FLOAT Ship.ShieldW(100)
DIM FLOAT Ship.ShieldMax(100)
DIM FLOAT Ship.Hull(100)
DIM FLOAT Ship.Engines(100)
DIM FLOAT Ship.Weapons(100)
DIM FLOAT Ship.Sensors(100)
DIM FLOAT Ship.Logic(100)
DIM FLOAT Ship.Logic2(100)
DIM FLOAT Ship.Power(100)
DIM FLOAT Ship.DX(100)
DIM FLOAT Ship.DY(100)

This makes for much neater code, as shown below:
SHIPS(id%,SHIP_ANGLE) = SHIPS(id%,SHIP_ANGLE) + 5
IF SHIPS(id%,SHIP_ANGLE) >= 360 THEN SHIPS(id%,SHIP_ANGLE) = SHIPS(id%,SHIP_ANGLE) - 360

becomes
Ship.Angle(id%) = Ship.Angle(id%) + 5
IF Ship.Angle(id%) >= 360 THEN Ship.Angle(id%) = Ship.Angle(id%) - 360


So I've now gone through the code and changed it over to this method of variable, and it is a lot more readable.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7499
Posted: 08:45am 31 Mar 2025
Copy link to clipboard 
Print this post

That certainly looks a lot better. I think you've not been wasting time. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4854
Posted: 10:46am 31 Mar 2025
Copy link to clipboard 
Print this post

Hi Vegipete,

What about
Ship.Angle(id%) = (Ship.Angle(id%) + 5) Mod 360


Volhout
PicomiteVGA PETSCII ROBOTS
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 03:51pm 31 Mar 2025
Copy link to clipboard 
Print this post

  Mixtel90 said  That certainly looks a lot better. I think you've not been wasting time. :)

Thanks!

  Volhout said  Hi Vegipete,

What about
Ship.Angle(id%) = (Ship.Angle(id%) + 5) Mod 360

Volhout

Wrong Pete   Non-vegie model of Pete here.

But yes, thank you - that is a very nice efficiency. I will apply it.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4854
Posted: 04:51pm 31 Mar 2025
Copy link to clipboard 
Print this post

Oops…. Shame..


Sorry Pete

P.s. Is It really Needed to limit to 360? Maybe any angel can be use, and with 64bit floats you Will not easilly run into numerical limits within a normal game time of 1 million years..      …hours I mean.
Edited 2025-04-01 02:57 by Volhout
PicomiteVGA PETSCII ROBOTS
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 05:43pm 31 Mar 2025
Copy link to clipboard 
Print this post

  Volhout said  Oops…. Shame..
Sorry Pete

No need to be - Being mistaken for a user of such high esteem as VegiPete is a compliment!  

  Volhout said  P.s. Is It really Needed to limit to 360? Maybe any angel can be use, and with 64bit floats you Will not easilly run into numerical limits within a normal game time of 1 million years..      …hours I mean.


Good point, however although it might not matter to the computer, limiting it to 360 makes it easier for my feeble brain to debug. There's quite a lot of relative angle work. e.g. your ship might be facing 270 degrees (West) and another ship might be South West of you, but it's facing 180 (South), so their aft and port shields are the ones that will get hit by your shot. That sort of thing. Not overly complex, but enough that I don't want to make things harder for myself  
 
     Page 5 of 5    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025