Now that we can draw the map, we need to place some mines on the game board. This is what makes the game "Minesweeper" rather than "Battleship", which requires largely the same stuff up until now. Game logic refers to the game rules and game play. This will come later, as it requires some game logic first. Minesweeper game visual bsic code#Why not draw it first? The reason is because when we draw the images, they would overwrite our rulers, whereas we want our rulers to appear on top of the icons.Ĭlever observers will note that we're missing some possible states in our drawing mechanism here - for example, there's no code for "incorrectly placed flag", represented by the image in pic_flagged_empty. You might wonder why we draw the grid AFTER we draw the icons. % Draw a ruler to separate squares visuallyĭraw.Line ( round (x * scale_x ), 0, round (x * scale_x ), maxy, black )ĭraw.Line ( 0, round (y * scale_y ), maxx, round (y * scale_y ), black ) Pic.Draw ( pic_question, draw_x, draw_y, picCopy ) Pic.Draw ( pic_flag, draw_x, draw_y, picCopy ) Pic.Draw ( pic_number (map (x,y ) ), draw_x, draw_y, picCopy ) Pic.Draw ( pic_boom, draw_x, draw_y, picCopy ) If the user revealed a non-bomb, show the numeral (or nothing if it's zero). % If the user revealed a bomb, show an explosion. Pic.Draw ( pic_none, draw_x, draw_y, picCopy ) % Taking into account which squares have been revealed by the user. This part is pretty simple and ends up being our very first bit of code: Pic_number (i ) := Pic.Scale ( pic_base_number (i ), scale_x_int, scale_y_int ) % This part uses the same clever trick described in the last part - since the numbers are all sequential, we can handle them neatly this way. Pic_flagged_empty := Pic.Scale ( pic_base_flagged_empty, scale_x_int, scale_y_int ) Pic_question := Pic.Scale ( pic_base_question, scale_x_int, scale_y_int ) Pic_bomb := Pic.Scale ( pic_base_bomb, scale_x_int, scale_y_int ) Pic_boom := Pic.Scale ( pic_base_boom, scale_x_int, scale_y_int ) Pic_none := Pic.Scale ( pic_base_none, scale_x_int, scale_y_int ) Pic_flag := Pic.Scale ( pic_base_flag, scale_x_int, scale_y_int ) Var scale_y_int : int := floor ( scale_y ) Var scale_x_int : int := floor ( scale_x ) So, we'll do it once right as the program starts, rather than each time we draw the map. This allows us to re-scale images however, it creates a new image each time, so we should probably do this as rarely as possible. Helpfully, the Pic module built into Turing has a method for just this purpose: Pic.Scale(). The requirements imply that we will be required to scale our images before using them. Minesweeper game visual bsic update#We will manually update the screen to prevent flickering.Since input will be mostly with the mouse, we will hide the cursor.We will define the map to be square (number of rows is the same as the number of columns), and our run window will also be square.We will base the game on a defined number of squares horizontally and vertically, and will scale our images so they fit on the given space (our run window).For simplicity, the map's squares will consume the entire run window.To do this, let's establish a set of requirements for how we draw the map: For example, even though we have images, we still don't have any way of drawing the map accurately. Minesweeper game visual bsic how to#We have a bit more to do before we can even start on the game logic (game rules and how to play, etc). Program Design - Laying the Foundation, Continued Part one can be found here, and should be completed before beginning this part. This is part 2 of the Basic Game Programming tutorial. Posted: Thu 12:36 pm Post subject: Basic Game Programming: Minesweeper, Part 2 Basic Game Programming: Minesweeper, Part 2 Wiki Blog Search Turing Chat Room Members
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |