Microsoft Small Basic Triangle issue

Bobo Clown 0 Reputation points
2025-02-09T12:03:08.13+00:00

So basically, I'm a beginner trying to make a game on Small Basic. It's a space themed game, and there are going to be 2 spaceships, one red and one blue. So far, I'm coding the blue one and I want the controls to be like up arrow for blue to go forwards, down arrow to go back, left arrow to rotate left, and right arrow to rotate right. For this, I used the BluePlayer = Shapes.AddTriangle command, however, when I try to rotate or move the triangle, it disappears off screen. Please help. I will leave my code below for you to try to tinker around with it. Please comment if you come to any conclusion.

Code:

' Space Fighting Game"

' Setup

GraphicsWindow.BackgroundColor = "black"

GWW = 1025

GWH = 500

GraphicsWindow.Width = GWW

GraphicsWindow.Height = GWH

' Blue Player Setup

GraphicsWindow.BrushColor = "Aqua"

BlueX1 = GWW - 25

BlueY1 = GWH / 2 - 10

BlueX2 = BlueX1

BlueY2 = GWH / 2 + 10

BlueX3 = GWW - 50

BlueY3 = GWH / 2

PlayerBlue = Shapes.AddTriangle(BlueX1, BlueY1, BlueX2, BlueY2, BlueX3, BlueY3)

GraphicsWindow.KeyDown = WhenKeyPressed

Sub WhenKeyPressed

If GraphicsWindow.LastKey = "Up" Then

GraphicsWindow.Clear()

BlueX1 = BlueX1 - 10

BlueX2 = BlueX2 - 10

BlueX3 = BlueX3 - 10

PlayerBlue = Shapes.AddTriangle(BlueX1, BlueY1, BlueX2, BlueY2, BlueX3, BlueY3)

ElseIf GraphicsWindow.LastKey = "Down" Then

GraphicsWindow.Clear()

BlueX1 = BlueX1 + 10

BlueX2 = BlueX2 + 10

BlueX3 = BlueX3 + 10

PlayerBlue = Shapes.AddTriangle(BlueX1, BlueY1, BlueX2, BlueY2, BlueX3, BlueY3)

ElseIf GraphicsWindow.LastKey = "Left" Then

Shapes.Rotate(PlayerBlue, 100) 

Shapes.Move

EndIf

EndSub

Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
280 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LitDev 126 Reputation points
    2025-02-16T22:01:59.9+00:00

    Rotating triangles and lines in SB is tricky, the top/left is at 0,0 regatrdless of the triangle coordinates entered. Suggest you use a rectangle or image where the center of rotation is the center of the shape. Trick for triangles is to create the triangle where the desired top/left is at 0,0 and then move or rotate it, or use an extension method. For more questions or support you can head to https://litdev.uk/mybb, and a topic challenge on this https://litdev.uk/mybb/showthread.php?tid=242

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.