Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: PureBASIC Windowed Example - Simple 8 directional movement  (Read 917 times)

0 Members and 1 Guest are viewing this topic.
PureBASIC Windowed Example - Simple 8 directiona...
« on: July 16, 2008, 05:39:19 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
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.

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;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 ^^.
Logged
  • Super Fan Gamers!
Re: PureBASIC Windowed Example - Simple 8 direct...
« Reply #1 on: July 16, 2008, 11:43:47 am »
  • I need something new to put here...
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1181
unfortunately it has the old problem of diagonal walking is double speed, but oh well, it's still good for begginers.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.011 seconds with 38 queries.

anything