Just doing some simple stuff to perk the interest of new programmers that may want to make the move to a language from a RAD program but feel scared off by C++ and what not.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Windowed Screen Movement Test/Demo by Theforeshadower for PureBASIC 4.0 or better;;
;
;Let's get the basics up and outta the way;
;
;First, we initiate that we are using sprites and the keyboard;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
InitSprite()
InitKeyboard()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Now, we set up our window, let's keep it small. ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
OpenWindow(0, 0, 0, 320,240, "Windowed Screen Movement Test", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,320,240,0,0,0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Just variables we use later for the player's posistion;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
playerxposistion = 1
playeryposistion = 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;We declare a sprite then create a box onto the blank sprite;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CreateSprite(0,24,24)
StartDrawing(SpriteOutput(0))
Box(playerxposistion,playeryposistion,24,24,RGB(255,125,0))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;We must stop drawing before we flip the buffers;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
StopDrawing()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Our main function which must repeat or the program ends;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Repeat
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) And playeryposistion > 0 : playeryposistion -3 : EndIf
If KeyboardPushed(#PB_Key_Down) And playeryposistion < 216 : playeryposistion +3 : EndIf
If KeyboardPushed(#PB_Key_Left) And playerxposistion > 0 : playerxposistion -3 : EndIf
If KeyboardPushed(#PB_Key_Right) And playerxposistion < 296 : playerxposistion +3 : EndIf
ClearScreen(RGB(0,0,0))
DisplaySprite(0, playerxposistion, playeryposistion)
bulletx = playerxposistion +12
bullety = playeryposistion -12
Until KeyboardPushed(#PB_Key_Escape)
End
The executable is in the attachments.
Very simple. No extra packages required. Just install PureBASIC and copy/paste that right in ^^.