Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std/pseudoOps.h"
- #include "std/l1_sub.h"
- #define MATH_USE_ADD
- #include "std/math.h"
- ;.1*256 = 25.6 ~= 26
- ;vel and pos are fixed point numbers with 8 bits of fraction
- #define accel (.1*256)
- #define current_canvas 3
- ;pitch is how many pixels across the current canvas is
- #define pitch (16*2**current_canvas)
- #define vram_start (0x8000-pitch**2)
- ;program start
- set_canvas(#,current_canvas)
- jmp 0x200
- !@= 0x200 ;loop start
- ;key event velocity change
- get_key(#,'w') && bzs no_w ;if 'w' key pressed,
- add8s_16(#,-accel, vel_y) ;^^vel_y -= accel
- :no_w: get_key(#,'a') && bzs no_a ;if 'a' key pressed,
- add8s_16(#,-accel, vel_x) ;^^vel_x -= accel
- :no_a: get_key(#,'s') && bzs no_s ;if 's' key pressed,
- add8s_16(#,accel, vel_y) ;^^vel_y += accel
- :no_s: get_key(#,'d') && bzs no_d ;if 'd' key pressed,
- add8s_16(#,accel, vel_x) ;^^vel_x += accel
- :no_d:
- add16_16(pos_x_low, vel_x) ;add x velocity to x position
- add16_16(pos_y_low, vel_y) ;add y velocity to y position
- ldi #,0 ;set index register to 0
- lda @,pos_x ;put x&y into sprites' x&y
- sta $,amoog && sta $,amoog_flip ;^^
- lda @,pos_y ;^^
- sta $,amoog+1 && sta $,amoog_flip+1 ;^^
- lda #,0 ;set every pixel of canvas to palette color 0
- sys #,0x05 ;^^
- lda @,vel_x+1 && and #,0x80 ;if x velocity negative,
- bnz .f ;^^blit the horizontally-flipped sprite instead
- ldc_imm(amoog) && jmp .r ;^^
- .f: ldc_imm(amoog_flip) ;^^
- .r: sys #,0x06 ;^^(sys #6 blits the sprite at address C (L&H))
- ldh @,pos_x ;this doesn't do anything other than put
- ldl @,pos_y ;^^the position into L&H as a sort of debug print
- wait_frame
- jmp 0x200 ;go to start of loop
- ;pitch/2-(w or h)/2 = centered
- :pos_x_low: !8 0 && :pos_x: !8 pitch/2-4
- :pos_y_low: !8 0 && :pos_y: !8 pitch/2-4
- :vel_x: !16 0 && :vel_y: !16 0
- #define rd 196 //palette color red
- #define bl 80 //palette color blue
- #define wh 231 //palette color white
- ;x,y, w,h, pixel data...
- :amoog: !8 0,0, 8,8
- !8 0, 0,rd,rd,rd,rd,rd,rd
- !8 0, 0,rd,rd,rd,rd,rd,rd
- !8 rd,rd,rd,rd,bl,wh,wh,wh
- !8 rd,rd,rd,rd,bl,bl,bl,bl
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 0, 0,rd,rd, 0, 0,rd,rd
- !8 0, 0,rd,rd, 0, 0,rd,rd
- :amoog_flip: !8 0,0, 8,8
- !8 rd,rd,rd,rd,rd,rd, 0, 0
- !8 rd,rd,rd,rd,rd,rd, 0, 0
- !8 wh,wh,wh,bl,rd,rd,rd,rd
- !8 bl,bl,bl,bl,rd,rd,rd,rd
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 rd,rd,rd,rd,rd,rd,rd,rd
- !8 rd,rd, 0, 0,rd,rd, 0, 0
- !8 rd,rd, 0, 0,rd,rd, 0, 0
- #include "std/math.asm"
- !savlbl "labels.txt" && !to "program.bin" && !save
Advertisement
Advertisement