So, I whipped up some movement and joystick control routines, and they're working, check it out:
Code: Select all
SCREEN #14 :'PMODE 4 (screen mode)
COLOR #0,#5 :'inverts the screen colors
CLS BLACK :'clears the screen (black)
'Variables
VAR x,y AS BYTE:x=(WIDTH/2)-8:y=(HEIGHT/2)-8 :'ship initial position
VAR xa,ya AS BYTE:xa=0:ya=0 :'enemy ship position (RND)
VAR xl,yl AS BYTE:xl=0:yl=0 :'shot position
GLOBAL x,y,xl,yl,xa,ya :'declare variables as global
GLOBAL ship,enemyShip,background :'makes image variables global
'Images
background := NEW IMAGE (16,16) :'creates background image 16x16
ship := LOAD IMAGE ("ship.png") :'loads player ship image
enemyShip := LOAD IMAGE ("enemyship.png") :'loads enemy ship image
GET IMAGE background FROM 0,0 :'captures part of the background
'======DEFINE PROCEDURES======
'Activate player movement
PROCEDURE movement
IF JRIGHT(0) AND x<215 THEN: :'if right joystick and ship not at right edge:
PUT IMAGE background AT (x-16),y :'redraws background behind ship
INC x :'moves ship right
ENDIF
IF JLEFT(0) AND x>25 THEN: :'if left joystick and ship not at left edge:
PUT IMAGE background AT (x+16),y :'redraws background behind ship
DEC x :'moves ship left
ENDIF
IF JUP(0) AND y>35 THEN: :'if up joystick and ship not at top edge:
PUT IMAGE background AT x,(y+16) :'redraws background behind ship
DEC y :'moves ship up
ENDIF
IF JDOWN(0) AND y<145 THEN: :'if down joystick and ship not at bottom edge:
PUT IMAGE background AT x,(y-16) :'redraws background behind ship
INC y :'moves ship down
ENDIF
END PROC
'Repositions the enemy ship on the screen in a random position-y
PROCEDURE reloadEnemyShipPosition
xa=240 :'sets x position to right edge
ya=RND(180)+10 :'sets random y position
END PROC
'Enemy ship movement
PROCEDURE moveEnemyShip
ADD xa,(-1) :'move enemy ship left
PUT IMAGE background AT (xa+16),ya :'redraws background behind ship
PUT IMAGE enemyShip AT xa, ya :'draws enemy ship at new position
IF xa <= 10 THEN: :'if enemy ship at left edge:
xa=10:PUT IMAGE background AT xa,ya :'reset ship and background
reloadEnemyShipPosition[]
ENDIF
END PROC
reloadEnemyShipPosition[]
'=========MAIN LOOP===========
DO :'start of main game loop
PUT IMAGE ship AT x, y :'draws player ship at current position
movement[] :'calls movement procedure
moveEnemyShip[] :'calls enemy ship movement procedure
LOOP :'end of main loop
Required images

