Arrow Making Supplies
My homework is to move a sprite using the arrows keys up,left right and down.?
I asked my teacher and this was his response To make the sprite move, you need to supply variables as parameters, instead of fixed numbers. Then you add some 'if' statements which modify the variables, and hence move the sprite. This is my first class on coding and I don't know how to do that.
Heres my code so far I can press SPACEBAR to shoe the image how to move I haven't figured out. Any help will be appriciate.
void GameState::Draw()
{
if( keyboard[DIK_SPACE] )
{
// Draw a sprite somewhere random on screen
int x = 50;
int y = 100;
int size = 150;
aid_draw_sprite( spriteHandle, x, y, size, size );
}
}
Ok now this is coded to work with game maker so it may not work but its at least a good peice of code to look at, your trying to shoot for something like this anyways.
//check what direction is being pressed and move that way well applying image for that direction
if (keyboard_check(vk_right))
sprite_index = sp_player_right
direction = 0
speed = 3
image_index -= 0
if (keyboard_check(vk_left))
sprite_index = sp_player_left
direction = 180
speed = 3
image_index -= 0
if (keyboard_check(vk_up))
sprite_index = sp_player_up
direction = 90
speed = 3
image_index -= 0
if (keyboard_check(vk_down))
sprite_index = sp_player_down
direction = 270
speed = 3
image_index -= 0
//when not moving in that direction display subimage 0, standing still, and stop moving.
if (hspeed = 0)
if (sprite_index = sp_player_right)
image_index = 0
if (hspeed = 0)
if (sprite_index = sp_player_left)
image_index = 0
if (vspeed = 0)
if (sprite_index = sp_player_up)
image_index = 0
if (vspeed = 0)
if (sprite_index = sp_player_down)
image_index = 0
Now in game maker hspeed is horizontal, - is left and + is right, and vspeed is vertical, - is up and + is down. 0 is right, 180 is left, 90 is up, and 270 is down.
I haven't put any code in to stop the player once the arrow key is released. It should do it on its own but if not try changing keyboard_check to keyboard_check_pressed. Also know that I have four different sprites so my guy can walk up, down, left, and right.
Sorry this isn't exactly what you need but maybe it'll help
Making primitive/modern weapons and items
|
|
Wilton Bunny Basket Candy Mold $0.01 Candy Mold: Easter. This candy mold is constructed of a flexible and reusable plastic featuring four cavities: two 4" high bunnies and (2) 1x 4-1/2" x 2-1/2" nest/stands. Just melt your Wilton Candy Melts (not included), pour, cool and serve! Measurements: 11x 5-7/8". This package also includes instructions.... |
|
|
Wilton Bat Candy Picks, Cupcakes mold $1.99 WILTON-Halloween CandyPick Mold. With this candy mold and Wilton Candy Melts (not included); it's a breeze to create great tasting edible picks to decorate treats. This package contains one 11x6in re-usable plastic candy mold (1 design-Bat; eight cavities). Imported.... |
|
|
Snakes & Arrows $23.98 A return to their former glory days, Snakes and Arrows shows this seminal prog rock band reclaiming some of the sonic territory that they'd lost over the past few years. It's not certain what contributed to this artistic rebirth, but Rush has crafted a historical and emotional odyssey that shows many both where they've been and where they're going--from the baroque soundscapes of "The Main Monkey ... |
|
|
Porter-Cable PIN100 1/2-Inch to 1-Inch 23-Gauge Pin Nailer $89.99 The Porter-Cable PIN100 1/2-Inch to 1-Inch 23-Gauge Pin Nailer takes care of all of your finishing projects, such as crown molding and other molding, and does it quickly and efficiently. It uses a dual trigger feature to fire the 23-gauge micro pin nails from the 170 pin bottom load magazine. This smart pin nailer even recognizes the length of the nail and automatically adjusts accordingly. The ru... |
|
|
Zadro Next Generation LED Oval Wall Mirror, Satin Nickel, 1X-10X $119.99 Zadro Next Generation 1X/10X LED Light Oval Wall Mirror... |
|
|
Arrowhead Mills Spelt Flour, Whole Grain, 2 Pound Bags (Pack of 4) $18.48 All natural. Naturally nutritious. Organic. Spelt, the staff of life. An ancient cousin to modern wheat, delicious and nutritious Spelt was one of the first grains to be grown by early farmers as long ago as 5,000 BC. With its rich sienna color, this robust nutty flavored gem offers a good source of fiber. Its rediscovery is one of the exciting events of the modern health and nutrition renaissance... |
|
|
Wilton Jumbo Daisies Sprinkles $2.12 Add that extra touch with sprinkles! Easy to pour and store. Certified Kosher. Approximately 2.8 ounces. Available in a variety of styles, each sold separately.... |
|
|
Children's White FEATHER ANGEL WINGS $8.45 A perfect addition to that heavenly costume. These angel wings are made with real feathers. Elastic arm bands. Child size 15 W."... |
|
|
Melissa & Doug Cutting Food Box $11.65 This super-sized set enables kids to cut their food just like mom or dad. It's perfect for encouraging hand-eye coordination. This set includes more than 25 pieces, including a child-safe knife and cutting board, along with eight healthy choice selections for kids to prepare their own meals. Knives glide easily through each item, making a realistic crunching sound that kids love. Once cut apart, k... |
|
|
Melissa & Doug Deluxe Alphabet Stamp Set $11.44 The Wooden Alphabet Stamp Set by Melissa & Doug helps teach capital and lowercase letter recognition and basic colors, and encourages beginning spelling and fine motor skills.Recommended Activities include: Ask your child to name the capital letters while placing the wooden stamps in alphabetical order from A to Z. Repeat the activity with the lowercase letters, placing each beneath its correspond... |